poomclient2server.cpp

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

CPP
502
字号
                currentLongHash = calculateAppointmentHash(pAppointment);

                // set these objlist to write to file...
                currentOid.push_back(currentLongOid);
                currentHash.push_back(currentLongHash);
                pAppointment->Release();
            }
            else if (dataType == olFolderTasks) {
                currentLongOid = 0;
                pItems->Item(i + 1, (IDispatch**)&pTask);
                pTask->get_Oid(&currentLongOid);
                currentLongHash = calculateTaskHash(pTask);

                // set these objlist to write to file...
                currentOid.push_back(currentLongOid);
                currentHash.push_back(currentLongHash);
                pTask->Release();
            }
        }

        /*
        * Normal behaviour: get the WinItem to retrieve the CRC.
        */
        else {
            currentLongOid = 0;
            IDispatch* pDisp  = NULL;
            IItem*     ppItem = NULL;
            pItems->Item (i + 1, (IDispatch**)&pDisp);

            if (pDisp == NULL) {
                LOG.error("fillModifiedOidArray: invalid item %d", i+1);
                continue;
            }
            HRESULT hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);
            ppItem->get_Oid(&currentLongOid);
            
            WinItem* winItem = NULL;
            if (dataType == olFolderContacts) {
                winItem = contactToWinContact(ppItem, isSIF);
            }
            else if (dataType == olFolderCalendar) {
                winItem = appointmentToWinEvent(ppItem, isSIF);
            }
            else if (dataType == olFolderTasks) {
                winItem = taskToWinTask(ppItem, isSIF);
            }

            if (winItem) {
                currentLongHash = winItem->getCRC();
                // set these objlist to write to file...
                currentOid.push_back(currentLongOid);
                currentHash.push_back(currentLongHash);
                currentOidHash[currentLongOid] = currentLongHash;
                
                delete winItem;
                ppItem->Release();
                pDisp->Release();
            }
            else {
                LOG.error("fillModifiedOidArray: error converting IItem to WinItem.");
            }
        }


        //
        // Check differences of CRC.
        //
        int itemFound = 0;
        j = lastFound + 1;

        while ((j < previousCountItems && itemFound == 0)) {
            long previousLongOid = previousOid[j];

            if (currentLongOid == previousLongOid) {
                itemFound = 1;
                lastFound = j;

                long previousLongHash = previousHash[j];

                if (currentLongHash != previousLongHash) {
                    // if different hash then into updateOid to pass to setModifiedItems
                    updateOid.push_back(currentLongOid);

                } else {
                    // nothing to do...
                }
            }
            j++;
        }
        if (itemFound == 0) {
            newOid.push_back(currentLongOid);
        }

    } // end for


    i = 0;
    lastFound = -1;

    for (j = 0; j < previousCountItems; j++) {

        int itemFound = 0;
        i = lastFound + 1;

        long previousLongOid = previousOid[j];

        int count = currentOid.size();
        while ((i < count && itemFound == 0)) {
            long currentLongOid = currentOid[i];

            if (currentLongOid == previousLongOid) {
                itemFound = 1;
                lastFound = i;
            }
            i++;
        }

        if (itemFound == 0) {
            deleteOid.push_back(previousLongOid);
        }

    } // end for

    pItems->Release ();
    pFolder->Release ();
}



/**
* Used by the getFirstItem and getNextItem of the sync source to fill the item.
* For the slow sync
*/
void fillSyncItem(SyncItem* syncItem, int dataType, bool isSIF, map<long,long> &currentOidHash) {

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

    // Get the item from oid
    long oid = wcstol(syncItem->getKey(), NULL, 10);
    IItem*   ppItem  = NULL;
    WinItem* winItem = NULL;
    polApp->GetItemFromOidEx(oid, 0, &ppItem);

    //
    // Convert data: IItem -> WinItem
    // ------------------------------
    if (dataType == olFolderContacts) {
        winItem = contactToWinContact(ppItem, isSIF);
    }
    else if (dataType == olFolderCalendar) {
        winItem = appointmentToWinEvent(ppItem, isSIF);
    }
    else if (dataType == olFolderTasks) {
        winItem = taskToWinTask(ppItem, isSIF);
    }

    LOG.info("Retrieved item '%ls'", winItem->getName().c_str());

    // Save the CRC.
    long crc = winItem->getCRC();
    currentOidHash[oid] = crc;

    // Format the string and set data into syncItem.
    wstring& stringItem = winItem->toString();
    char* data = toMultibyte(stringItem.c_str());
    syncItem->setData(data, strlen(data)*sizeof(char));


    if (data)    { delete [] data;    }
    if (winItem) { delete winItem;    }
    if (ppItem)  { ppItem->Release(); }

    releaseOutlookApp(polApp);

}

int deleteAllItems(int dataType) {

    IContact     *pContact;
    IAppointment *pAppointment;
    ITask        *pTask;

    IFolder *pFolder;
    IPOutlookItemCollection *pItems;

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return -1;

    if( FAILED(polApp->GetDefaultFolder (dataType, &pFolder)) ) {
        LOG.error("deleteAllItems: can't open folder: %d", dataType);
        return -1;
    }

    pFolder->get_Items (&pItems);
    int numItems = 0;

    pItems->get_Count(&numItems);

    LOG.info("Items to delete: %i", numItems);

    for (int i = 1; i <=numItems; i++) {
        try {
            if (dataType == olFolderContacts) { // it's a contact
                pItems->Item(1,(IDispatch **)&pContact);
                pContact->Delete();
                pContact->Release();
            }
            else if (dataType == olFolderCalendar){ // it's an appointments
                pItems->Item(1,(IDispatch **)&pAppointment);
                //pAppointment->Cancel();   it sends the cancellation to the recipients
                pAppointment->Delete();
                pAppointment->Release();
            }
            else if (dataType == olFolderTasks){ // it's an task
                pItems->Item(1,(IDispatch **)&pTask);
                pTask->Delete();
                pTask->Release();
            }
        } 
        catch(...) {
            LOG.debug("Exception in deleting all items. Continue until num items: %i", numItems);
        }
    }

    pItems->Release ();
    pFolder->Release ();

    releaseOutlookApp(polApp);
    return numItems;

}

/*
* Call function to remove all the appointment exceptions and transform them into
* normal appointment with only delete exceptions
*/
void normalizeAllExceptions() {

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

    normalizeAppointmentExceptions(polApp);

    releaseOutlookApp(polApp);
}

⌨️ 快捷键说明

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