private static LocalFolder Bind(MailboxSession mailboxSession, StoreId folderId, LocalFolder.ProcessFolderDelegate processFolder) { SharingBindingManager sharingBindingManager = new SharingBindingManager(mailboxSession); SharingBindingData sharingBindingDataInFolder = sharingBindingManager.GetSharingBindingDataInFolder(folderId); if (sharingBindingDataInFolder == null) { LocalFolder.Tracer.TraceError <IExchangePrincipal, StoreId>(0L, "{0}: Unable to find the binding for folder {1}, fail sync", mailboxSession.MailboxOwner, folderId); throw new SubscriptionNotFoundException(); } bool flag = false; Item item = null; Folder folder = null; LocalFolder localFolder = null; try { item = LocalFolder.BindToBindingMessage(mailboxSession, sharingBindingDataInFolder.Id); folder = Folder.Bind(mailboxSession, folderId, LocalFolder.extraProperties); localFolder = new LocalFolder(mailboxSession, folder, sharingBindingDataInFolder.RemoteFolderId, item); processFolder(localFolder); flag = true; } finally { if (!flag) { if (localFolder != null) { localFolder.Dispose(); } else { if (item != null) { item.Dispose(); } if (folder != null) { folder.Dispose(); } } localFolder = null; } } return(localFolder); }
private void SafeUpdateBindingItem(Action <Item> stampBindingItem) { stampBindingItem(this.binding); ConflictResolutionResult conflictResolutionResult = this.binding.Save(SaveMode.ResolveConflicts); if (conflictResolutionResult.SaveStatus == SaveResult.IrresolvableConflict) { LocalFolder.Tracer.TraceDebug <LocalFolder>((long)this.GetHashCode(), "{0}: Conflict occurs when saving the binding message. Reload and try saving again.", this); StoreObjectId objectId = this.binding.Id.ObjectId; this.binding.Dispose(); this.binding = LocalFolder.BindToBindingMessage(this.mailboxSession, objectId); this.binding.OpenAsReadWrite(); stampBindingItem(this.binding); this.binding.Save(SaveMode.NoConflictResolution); } this.binding.Load(); }