给出以下代码:
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?
如果有512个以上的项目,则会设置MoreChangesAvailable标志。在您的代码中,do ... while(changeList.MoreChangesAvailable)将一直运行,直到有更多的项目超过SyncFolderItems()调用返回的值为止。(在本例中为512)每次执行do循环时,它将SyncState设置为在此行上一次调用中获得的值:
u.SyncStates[folderContentsChange.FolderId] = changeList.SyncState;
这样可以确保您不会收到已经收到的物品。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句