将Exchange Web服务(EWS)托管API用于synchronize a folder hierarchy或synchronize items时,客户端缓存位于何处?它只在内存中吗?它在磁盘上吗?有没有办法找到或控制缓存的位置?我似乎无法在任何地方找到相关信息。
答案 0 :(得分:2)
SyncFolderHierarchy
和SyncFolderItems
一起允许您有效地同步Exchange中邮箱中所有(或部分)文件夹的内容。
文章中指出的流程是指示性的。对SyncFolderItems
的调用会返回ChangeCollection<T>
,其中包含ItemChange
或FolderChange
类型的项目。如果您处理这些项目,则可以提取有关文件夹的其他信息,例如文件夹中每个项目的实际内容。
处理完ChangeCollection
后,您应该在某处存储SyncState
值。下次您致电SyncFolderItems
时,您会传递该值,而Exchange会返回下一批商品。
由于可能(尤其是第一次同步)项目中的项目数量超过SyncFolderItems
只能在一次通话中返回,因此您应该检查MoreChangesAvailable
以确定是否还有其他操作。
所有这一切都变成了这个循环:
// Track whether there are more items available for download on the server.
bool moreChangesAvailable = false;
do {
// Get a list of all items in the Inbox by calling SyncFolderHierarchy repeatedly until no more changes are available.
// The folderId parameter must be set to the root folder to synchronize,
// and must be same folder ID as used in previous synchronization calls.
// The propertySet parameter is set to IdOnly to reduce calls to the Exchange database,
// because any additional properties result in additional calls to the Exchange database.
// The ignoredItemIds parameter is set to null, so that no items are ignored.
// The maxChangesReturned parameter is set to return a maximum of 10 items (512 is the maximum).
// The syncScope parameter is set to Normal items, so that associated items will not be returned.
// The syncState parameter is set to cSyncState, which should be null in the initial call,
// and should be set to the sync state returned by the
// previous SyncFolderItems call in subsequent calls.
ChangeCollection<ItemChange> icc = service.SyncFolderItems(new FolderId(WellKnownFolderName.Inbox), PropertySet.IdOnly, null, 10, SyncFolderItemsScope.NormalItems, cSyncState);
// If the count of changes is zero, there are no changes to synchronize.
if (icc.Count <> 0) {
// Otherwise, write all the changes included in the response to the console.
foreach (ItemChange ic in icc) {
Console.WriteLine("ChangeType: " + ic.ChangeType.ToString());
Console.WriteLine("ItemId: " + ic.ItemId);
}
}
// Save the sync state for use in future SyncFolderContent requests.
// The sync state is used by the server to determine what changes to report
// to the client.
string sSyncState = icc.SyncState;
// Determine whether more changes are available on the server.
moreChangesAvailable = icc.MoreChangesAvailable;
}
while (moreChangesAvailable);
代码示例from MSDN,因为我不能说它比更好。
除非您选择自己存储客户端项目,否则不存在客户端缓存。如果你选择不存储它们,你可以简单地继续循环,直到你达到你感兴趣的东西开始的程度。例如,上面的代码不会下载任何内容,但每个项目的ItemChange
记录和ID(由PropertySet.IdOnly
表示)除外。
这MSDN article provides a great overview of the synchronization process。