poomserver2client.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 547 行 · 第 1/2 页

CPP
547
字号
        IItem* ppItem = NULL;
        hr = polApp->GetItemFromOidEx(oidToUpdate, 0, &ppItem);
        if (hr == S_OK) {
            WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, contactFields);

            if (winItem) {
                WinContact* winC = (WinContact*)winItem;
                winContactToContact(*winC, ppItem);

                // calculate the new winC with all the fields to get the right crc
                delete winItem;
                winItem = contactToWinContact(ppItem, false);

                long hash = winItem->getCRC();
                currentOidHash[oidToUpdate] = hash;

                delete winItem;
            }
            ppItem->Release();
        }
        else {
            LOG.debug("Error updating contact...");
        }
    }
    else if (dataType == olFolderCalendar){

        IItem* ppItem = NULL;
        hr = polApp->GetItemFromOidEx(oidToUpdate, 0, &ppItem);
        if (hr == S_OK) {
            WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, appointmentFields);
            if (winItem) {
                WinEvent* winE = (WinEvent*)winItem;
                hr = winEventToAppointment(*winE, ppItem, path, oidToUpdate);
                if (SUCCEEDED(hr)) {
                    // calculate the new winC with all the fields to get the right crc
                    delete winItem;
                    winItem = appointmentToWinEvent(ppItem, true);
                    long hash = winItem->getCRC();
                    LOG.debug("hash = %ld", hash);
                    currentOidHash[oidToUpdate] = hash;
                }
                delete winItem;
            }
            ppItem->Release();
        }
        else {
            LOG.debug("Error updating appointment...");
        }
    }

    else if (dataType == olFolderTasks){

        IItem* ppItem = NULL;
        hr = polApp->GetItemFromOidEx(oidToUpdate, 0, &ppItem);
        if (hr == S_OK) {
            WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, taskFields);
            if (winItem) {
                WinTask* winT = (WinTask*)winItem;
                hr = winTaskToTask(*winT, ppItem, path, oidToUpdate);
                if (SUCCEEDED(hr)) {
                    // calculate the new winC with all the fields to get the right crc
                    delete winItem;
                    winItem = taskToWinTask(ppItem, true);
                    long hash = winItem->getCRC();
                    LOG.debug("hash = %ld", hash);
                    currentOidHash[oidToUpdate] = hash;
                }
                delete winItem;
            }
            ppItem->Release();
        }
        else {
            LOG.debug("Error updating task...");
        }
    }

    releaseOutlookApp(polApp);
    LOG.debug("Exiting setModifiedItemsPOOM...");
    return hr;

}

/*
Use to delete item from server to PPC
*/
long manageDeletedItems(SyncItem* syncItem, int dataType, map<long,long> &currentOidHash) {

    LOG.debug("Enter manageDeletedItemsPOOM... ");
    if (syncItem == NULL)
        return -1;

    const wchar_t* key = syncItem->getKey();

    LOG.debug("in managerDeletedItems... ");
    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return -1;

    long oidToDelete = 0;
    wchar_t* local = NULL;
    HRESULT h = NULL;

    oidToDelete = wcstol(key, &local, 0);

    // to delete contacts
    if (dataType == olFolderContacts) {
        IContact *pContact;
        h = polApp->GetItemFromOid (oidToDelete, (IDispatch**)&pContact);
        if (h == S_OK) {
            pContact->Delete();
            pContact->Save();
            pContact->Release();
            currentOidHash.erase(oidToDelete);
        }

    }
    // to delete appointments
    else if (dataType == olFolderCalendar){
        IAppointment *pAppointment;
        h = polApp->GetItemFromOid (oidToDelete, (IDispatch**)&pAppointment);
        if (h == S_OK) {
            // pAppointment->Cancel();  it sends the cancellation to the recipients
            pAppointment->Delete();
            pAppointment->Release();
            currentOidHash.erase(oidToDelete);
        }

    }
    // to delete tasks
    else if (dataType == olFolderTasks){
        ITask *pTask;
        h = polApp->GetItemFromOid (oidToDelete, (IDispatch**)&pTask);
        if (h == S_OK) {
            pTask->Delete();
            pTask->Release();
        }
    }

    releaseOutlookApp(polApp);
    LOG.debug("Exiting manageDeletedItemsPOOM... ");
    return h;
}

/*
* Only if the previous version of the the plug-in is minor then 6.5.0, the way to calculate the
* CRC of the contact is different (old way). In this case the CRC must be recalculated
* in the newer way. At the end of the calculation, the flag for the contact
* set by the installer must be deleted.
*/
void writeCurrentItems(int dataType, wchar_t* path, map<long,long> &currentOidHash) {

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL) {
        return;
    }

    IPOutlookItemCollection* pItems = NULL;
    IFolder* pFolder = NULL;
    polApp->GetDefaultFolder(dataType, &pFolder);
    pFolder->get_Items(&pItems);
    pItems->Sort(TEXT("[Oid]"), FALSE);

    int countItems = 0;
    vector<long> currentOid;
    vector<long> currentHash;

    // if there is the file appOidToReset.dat the crc of these items must be put at 0
    vector<long> oidToReset;
    if (dataType == olFolderCalendar) {
        readAppOidToReset(oidToReset, path);
    }
    pItems->get_Count(&countItems);



    if (getUpdateFlag(dataType) == true) {
        currentOid.clear();
        currentHash.clear();
    } 
    else {
        if (countItems != currentOidHash.size()) {
            LOG.info("map and count are different...");
        }
        map<long,long>::iterator it;
        for (it = currentOidHash.begin(); it != currentOidHash.end(); it++) {
            currentOid.push_back((*it).first);

            if ( dataType == olFolderCalendar && isOidToReset((*it).first, oidToReset) ) {
                // To manage event exceptions:
                // Some events must be sent next time as modified, so we reset their hash.
                currentHash.push_back(0);
            }
            else {
                currentHash.push_back((*it).second);
            }
        }
    }



    for (int j=0; j<countItems; j++) {
        long oid = 0;


        if (getUpdateFlag(dataType) == true) {

            IDispatch* pDisp  = NULL;
            IItem*     ppItem = NULL;

            // Item values start from element number 1 not 0!!!!!
            pItems->Item (j + 1, (IDispatch**)&pDisp);
            HRESULT hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);
            ppItem->get_Oid(&oid);

            WinItem* winItem = NULL;
            if (dataType == olFolderContacts) {
                winItem = contactToWinContact(ppItem, false);
            }
            else if (dataType == olFolderCalendar) {
                winItem = appointmentToWinEvent(ppItem, false);
            }
            else if (dataType == olFolderTasks) {
                winItem = taskToWinTask(ppItem, false);
            }

            if (winItem) {
                long currentLongHash = winItem->getCRC();
                currentOid.push_back(oid);

                if ( dataType == olFolderCalendar && isOidToReset(oid, oidToReset) ) {
                    // To manage event exceptions:
                    // Some events must be sent next time as modified, so we reset their hash.
                    currentHash.push_back(0);
                }
                else {
                    currentHash.push_back(currentLongHash);
                }

                delete winItem;
                ppItem->Release();
                pDisp->Release();
            }
        }
    }

    writeToFile(currentOid, currentHash, dataType, path);

    // reset the flags to use the old way to retrieve the items hash
    resetUpdateFlags();

    pItems->Release ();
    pFolder->Release ();
    currentOid.clear();
    currentHash.clear();
    releaseOutlookApp(polApp);
}



bool isOidToReset(const long oid, vector<long>& oidToReset) {

    bool found = false;
    vector<long>::iterator it;

    for (it = oidToReset.begin(); it != oidToReset.end(); it++) {
        if ((*it) == oid) {
            oidToReset.erase(it);
            found = true;
            break;
        }
    }
    return found;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?