BOOL CXTPCalendarRemindersManager::GetUpcomingEventsAll(COleDateTime dtFrom, COleDateTimeSpan spPeriod, CXTPCalendarEventsPtr& rptrEvents) { rptrEvents = NULL; if (!m_pResourcesNf || !m_pResourcesNf->GetResourcesGroupedByDP()) { ASSERT(FALSE); return FALSE; } CXTPCalendarResources* pRCgroups = m_pResourcesNf->GetResourcesGroupedByDP(); int i; int nCount = pRCgroups->GetCount(); //-- check is all data providers opened ------------- for (i = 0; i < nCount; i++) { CXTPCalendarResource* pRC = pRCgroups->GetAt(i); ASSERT(pRC); CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL; ASSERT(pData); if (!pData || !pData->IsOpen()) { return FALSE; } } //-- read data ---------------- for (i = 0; i < nCount; i++) { CXTPCalendarResource* pRC = pRCgroups->GetAt(i); ASSERT(pRC); CXTPCalendarData* pData = pRC ? pRC->GetDataProvider() : NULL; if (!pData || !pData->IsOpen()) { ASSERT(FALSE); continue; } CXTPCalendarEventsPtr ptrEv = pData->GetUpcomingEvents(dtFrom, spPeriod); if (rptrEvents) { rptrEvents->Append(ptrEv); } else { rptrEvents = ptrEv; } pRC->FilterEventsByScheduleID(rptrEvents); } return TRUE; }
CString CXTPCalendarResourcesManager::GetDataProvider_ConnStr(int nIndex) const { CXTPCalendarData* pData = GetDataProvider(nIndex); if (pData) { return pData->GetConnectionString(); } return _T(""); }
void CXTPCalendarResourcesManager::RemoveDataProvider(int nIndex) { if (nIndex >= 0 && nIndex < m_arDataProviders.GetCount()) { CXTPCalendarData* pData = m_arDataProviders.GetAt(nIndex); if (pData && pData->IsOpen()) { pData->Close(); } m_arDataProviders.RemoveAt(nIndex); } }
BOOL CXTPCalendarResourcesManager::SetDataProvider(int nIndex, LPCTSTR pcszConnectionString, int eDPFlags) { if (nIndex < 0 || nIndex >= m_arDataProviders.GetCount()) { return FALSE; } CXTPCalendarData* pData = CXTPCalendarData::CreateDataProvider(pcszConnectionString); if (!pData) { return FALSE; } CXTPCalendarData* pData_prev = m_arDataProviders.GetAt(nIndex); if (pData_prev) { _SaveCloseDPifNeed(pData_prev); } //======================================== m_arDataProviders.SetAt(nIndex, pData); //---------------------------------------- BOOL bOpen = pData->Open(); if (!bOpen && (eDPFlags & xtpCalendarDPF_CreateIfNotExists)) { bOpen = pData->Create(); } if (pData->GetCustomProperties()) { COleVariant ovarSave((long)0); COleVariant ovarClose((long)0); if (eDPFlags & xtpCalendarDPF_SaveOnDestroy) { ovarSave = (long)1; } if (eDPFlags & xtpCalendarDPF_CloseOnDestroy) { ovarClose = (long)1; } VERIFY(pData->GetCustomProperties()->SetProperty(cszCalendarDPF_SaveOnDestroy, ovarSave) ); VERIFY(pData->GetCustomProperties()->SetProperty(cszCalendarDPF_CloseOnDestroy, ovarClose) ); } return bOpen; }
void CXTPCalendarResourcesManager::_Save(CXTPPropExchange* pPX) { if (!pPX || !pPX->IsStoring()) { ASSERT(FALSE); return; } pPX->ExchangeLocale(); CXTPPropExchangeSection secDPs(pPX->GetSection(_T("DataProviders"))); int nDPCount = GetDataProvidersCount(); CXTPPropExchangeEnumeratorPtr ptrEnumDPs(secDPs->GetEnumerator(_T("DataProvider"))); POSITION posStorage = ptrEnumDPs->GetPosition(nDPCount); for (int nDRNr = 0; nDRNr < nDPCount; nDRNr++) { CXTPCalendarData* pDP = GetDataProvider(nDRNr); ASSERT(pDP); if (!pDP) { continue; } CString strConnStr = pDP->GetConnectionString(); CXTPPropExchangeSection secDP(ptrEnumDPs->GetNext(posStorage)); PX_String(&secDP, _T("ConnectionString"), strConnStr); } //--------------------- CXTPPropExchangeSection secResources(pPX->GetSection(_T("Resources"))); int nRCCount = GetResourcesCount(); CXTPPropExchangeEnumeratorPtr ptrEnumRCs(secResources->GetEnumerator(_T("Resource"))); posStorage = ptrEnumRCs->GetPosition(nRCCount); for (int nRCNr = 0; nRCNr < nRCCount; nRCNr++) { CXTPCalendarResourceDescription* pRCdesc = GetResource(nRCNr); if (!pRCdesc || !pRCdesc->m_ptrResource) { ASSERT(FALSE); continue; } CXTPPropExchangeSection secRC(ptrEnumRCs->GetNext(posStorage)); CString strRCName = pRCdesc->m_ptrResource->GetName(); PX_String(&secRC, _T("Name"), strRCName); PX_Bool(&secRC, _T("Enabled"), pRCdesc->m_bEnabled); PX_Bool(&secRC, _T("GenerateName"), pRCdesc->m_bGenerateName); CXTPCalendarData* pRCdp = pRCdesc->m_ptrResource->GetDataProvider(); if (pRCdp) { CString strConnStr = pRCdp->GetConnectionString(); PX_String(&secRC, _T("ConnectionString"), strConnStr); int nSchIdsCount = 0; if (pRCdesc->m_ptrResource->GetSchedules()) { nSchIdsCount = (int)pRCdesc->m_ptrResource->GetSchedules()->GetSize(); } PX_Int(&secRC, _T("SchedulesCount"), nSchIdsCount); CXTPPropExchangeEnumeratorPtr ptrEnumSchIDs(secRC->GetEnumerator(_T("Schedules"))); POSITION posSchID = ptrEnumSchIDs->GetPosition(nSchIdsCount); for (int k = 0; k < nSchIdsCount; k++) { CXTPPropExchangeSection secSchID(ptrEnumSchIDs->GetNext(posSchID)); ULONG ulSchID = pRCdesc->m_ptrResource->GetSchedules()->GetAt(k); PX_ULong(&secSchID, _T("ScheduleID"), ulSchID); } } } }