//The big issue here will be the whether the input time is local or UTC, there could be problems //between users in different timezones and the proper realization of template... //TODO: review code to ensure template is realized properly void RecurrenceManager::RealizeRecurrences(unsigned __int64 date) { if(date > m_pDataManager->GetDayManagerInstance()->GetToday() - 1) { SYSTEMTIME st = ModelUtils::I64ToSystemTime(date); StringBuffer sb(_T("//recurrence[schedule/@")); sb.append(days[st.wDayOfWeek]); sb.append(_T("='true']")); BSTR xpath = SysAllocString(sb); MSXML2::IXMLDOMNodeList *pList = 0; HRESULT hr = m_pXMLDoc->selectNodes(xpath, &pList); if(hr == S_OK && pList) { MSXML2::IXMLDOMNode *pNode = 0; while((hr = pList->nextNode(&pNode)) == S_OK) { RealizeRecurrence(pNode, st); pNode->Release(); } pList->Release(); } } }
Task::TaskSet * CTaskModel::GetChildren(Task::TaskSet *pSet) { //if(!m_pTaskManager)return pSet; MSXML2::IXMLDOMNodeList *pNodeList = 0; BSTR xpath = SysAllocString(_T("./task")); HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList); SysFreeString(xpath); MSXML2::IXMLDOMNode *pNode = 0; if(pNodeList) { while((hr = pNodeList->nextNode(&pNode)) == S_OK) { unsigned __int64 childID = 0; XMLHelper::GetAttributeI64(pNode, TASKID, &childID); Task *pTask = new(childID) CTaskModel(pNode); if(pTask) { pSet->Add(*pTask); } pNode->Release(); pNode = 0; } } pNodeList->Release(); pNodeList = 0; return pSet; }
TEST_FIXTURE(XmlFixture, CreateChild2) { MSXML2::IXMLDOMNode *node = 0; HRESULT hr = XMLHelper::CreateChild(root, &node, _T("test")); CHECK_OK(hr); CHECK(node); node->Release(); node = 0; BSTR query = SysAllocString(_T("//test")); MSXML2::IXMLDOMNodeList *nodeList = 0; hr = doc->selectNodes(query, &nodeList); SysFreeString(query); CHECK_OK(hr); CHECK(nodeList); long length = 0; hr = nodeList->get_length(&length); CHECK_OK(hr); CHECK_EQUAL(1, length); hr = nodeList->nextNode(&node); CHECK_OK(hr); CHECK(node); BSTR name = 0; hr = node->get_nodeName(&name); CHECK_OK(hr); CHECK_EQUAL(0, _tcscmp(name, _T("test"))); SysFreeString(name); }
//TODO: review usage of TaskIDSet, in particular the local allocation and copying of contents Task::TaskIDSet CTaskModel::GetAllPrerequisites() { TaskIDSet ts; MSXML2::IXMLDOMNodeList *pNodeList = 0; BSTR xpath = SysAllocString(_T("ancestor-or-self::task/prerequisite")); HRESULT hr = m_pNode->selectNodes(xpath, &pNodeList); SysFreeString(xpath); MSXML2::IXMLDOMNode *pNode = 0; unsigned __int64 id = 0; BSTR bstr = 0; if(pNodeList) { while((hr = pNodeList->nextNode(&pNode)) == S_OK) { if(pNode) { hr = XMLHelper::GetAttribute(pNode, _T("taskid"), &bstr); if(hr == S_OK) { id = ModelUtils::fromHexString(bstr, wcslen(bstr)); ts.Add(id); id = 0; SysFreeString(bstr); } bstr = 0; pNode->Release(); pNode = 0; } } pNodeList->Release(); } return ts; }