使用Microsoft Exchange Services托管API,当同步项目超过512个时会发生什么?

时间:2014-03-10 03:17:52

标签: c# exchangewebservices ews-managed-api

给出以下代码:

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);

超过512项时会发生什么?这些项目会在do()的后续传递中被选中,还是需要再次调用sync?

1 个答案:

答案 0 :(得分:0)

如果项目超过512个,则设置MoreChangesAvailable标志。 在你的代码中,do ... while(changeList.MoreChangesAvailable)将运行,直到SyncFolderItems()调用返回的项目多于(在这种情况下为512) 每次执行do循环时,它都会将SyncState设置为前一个获得的值 打电话到这一行:

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

这可确保您不会收到已收到的项目。