使用 PullSubscription 时如何确定 EWS 中日历项的修订

How can I determine the revision of a calendar item in EWS when using a PullSubscription

我正在尝试与 Exchange 日历进行一些同步工作。我想让另一个外部日历与 Exchange 保持同步。目前,当其他应用程序在 Exchange 中触发某种创建或更新时,该更改随后会发送回其他日历,从而形成无限循环。

本来希望在绑定Appointment项时使用AppointmentSequenceNumber属性,但无论更新多少次,它的值始终为0。我在我的 PropertySet 中包含了 AppointmentSequenceNumber。

如果有人知道捕获这些更新并防止它们被发回的方法,那将非常有帮助。

谢谢。

        PropertySet pSet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Subject, ItemSchema.Body, AppointmentSchema.Start, AppointmentSchema.End,AppointmentSchema.ArchiveTag, AppointmentSchema.InstanceKey, AppointmentSchema.AppointmentSequenceNumber);
        ChangeCollection<ItemChange> changes = null;
        .....
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013)
        {
            Url = new Uri(exInfo.ServiceURL),
            Credentials = new WebCredentials(exInfo.UserName, exInfo.Password)
        };

        //Pull Subscription Info
        Microsoft.Exchange.WebServices.Data.PullSubscription sub = service.SubscribeToPullNotifications(
            new FolderId[] { WellKnownFolderName.Calendar }, 30, "",
            EventType.Created, EventType.Modified, EventType.Deleted);
        syncState = exInfo.SyncState;
        //Pull Changes
        while (!syncComplete )//&& Count < MaxItems)
        {
            changes = service.SyncFolderItems(new FolderId(WellKnownFolderName.Calendar),
            PropertySet.FirstClassProperties, null, 100, SyncFolderItemsScope.NormalItems, syncState);

        foreach (ItemChange change in changes)
        {
            if (change.ChangeType != ChangeType.Delete) { eventItem = Appointment.Bind(service, change.ItemId, pSet); }
            switch (change.ChangeType)
            {
                case ChangeType.Update:
                   ...
                    break;
                case ChangeType.Create:
                    ...
                    break;
                case ChangeType.Delete:
                   ...
                    break;
            }    
            Count++;           
        }            
        syncState = changes.SyncState;
        syncComplete = !changes.MoreChangesAvailable;
        }...

AppointmentSequenceNumber 仅对会议有效;在正常约会中不使用它。

I had hoped to use the AppointmentSequenceNumber property when binding the Appointment item

即使它是递增的,那也行不通。 Exchange 将始终为您提供当前版本,绑定中唯一有效的是约会的 EWSId(或重复序列)。

If anyone knows of a way to catch these updates and keep them from being sent back, that would be very helpful.

同步很复杂,但(从通知的角度来看)如果您在 Exchange 中修改项目,它将触发通知并且项目的 ChangeKey 属性将被更新 (quote):

"When you work with items in Exchange, another value to keep in mind is the ChangeKey attribute. This value, in addition to the item ID, is used to keep track of the state of an item. Any time an item is changed, a new change key is generated. When you perform an UpdateItem operation, for example, you can use the ChangeKey attribute to let the server know that your update is being applied to the most current version of the item. If another application made a change to the item you’re updating, the change keys won’t match and you will not be able to perform the update."