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

StackOverflow https://stackoverflow.com/questions/22291499

Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top