简体   繁体   中英

Using the Microsoft Exchange Services Managed API, what happens when there are more than 512 items to sync?

Given the following code:

ExchangeService service = ExchangeServiceUtilities.CreateExchangeService(s, u);


ChangeCollection<FolderChange> folderChanges = null;
do
{
  folderChanges = service.SyncFolderHierarchy(PropertySet.IdOnly, u.Watermark);
  // Update the synchronization 
  u.Watermark = folderChanges.SyncState;
  // Process all changes. If required, add a GetItem call here to request additional properties.

  foreach (var folderContentsChange in folderChanges)
  {
    // This example just prints the ChangeType and ItemId to the console.
    // A LOB application would apply business rules to each 
    ChangeCollection<ItemChange> changeList = null;
    do
    {
      string value = u.SyncStates.ContainsKey(folderContentsChange.FolderId) ? u.SyncStates[folderContentsChange.FolderId] : null;
      changeList = service.SyncFolderItems(folderContentsChange.FolderId, PropertySet.FirstClassProperties, null,512, SyncFolderItemsScope.NormalItems, value);
      u.SyncStates[folderContentsChange.FolderId] = changeList.SyncState;
      foreach (var itemChange in changeList)
      {

      }
    } while (changeList.MoreChangesAvailable);
  }                  
} while (folderChanges.MoreChangesAvailable);

What happens when there are more than 512 items? Will those items be picked up in subsequent passes of the do(), or will I need to call sync again?

If there are more than 512 items, the MoreChangesAvailable flag is set. In your code, the do...while(changeList.MoreChangesAvailable) will run till there are more items than returned by the SyncFolderItems() call.(in this case 512) Each time the do loop is executed, it sets the SyncState to the value obtained in the previous call at this line:

u.SyncStates[folderContentsChange.FolderId] = changeList.SyncState;

This ensures that you do not receive items already received.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM