Beispiel #1
0
        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);
        }
        public static bool SyncFolder(MailboxSession mailboxSession, StoreId sharingFolderId, Deadline processingDeadline)
        {
            if (!SharingEngine.tracker.Start(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, sharingFolderId))
            {
                SharingEngine.Tracer.TraceError <StoreId>(0L, "{0}: Folder is already syncing", sharingFolderId);
                throw new PendingSynchronizationException();
            }
            bool             result           = true;
            SharingEngine    sharingEngine    = null;
            LocalFolder      localFolder      = null;
            ItemSynchronizer itemSynchronizer = null;

            try
            {
                SharingLog.LogEntry(mailboxSession, "Starting sync for folder " + sharingFolderId);
                localFolder = SharingEngine.GetLocalFolder(mailboxSession, sharingFolderId);
                localFolder.UpdateLastAttemptedSyncTime();
                itemSynchronizer = SharingEngine.CreateItemSynchronizer(mailboxSession, localFolder);
                sharingEngine    = SharingEngine.Create(mailboxSession, sharingFolderId);
                result           = sharingEngine.Execute(mailboxSession, localFolder, itemSynchronizer, processingDeadline);
            }
            catch (Exception arg)
            {
                SharingLog.LogEntry(mailboxSession, string.Format("Synchronization finished unexpectedly due to the following error: {0}, External Url {1}", arg, (sharingEngine != null && sharingEngine.ExchangeService != null) ? sharingEngine.ExchangeService.Url : "Not specified"));
                throw;
            }
            finally
            {
                SharingEngine.UnblockFolderSync(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, sharingFolderId);
                if (itemSynchronizer != null)
                {
                    itemSynchronizer = null;
                }
                if (localFolder != null)
                {
                    localFolder.Dispose();
                    localFolder = null;
                }
                if (sharingEngine != null)
                {
                    sharingEngine.Dispose();
                }
            }
            return(result);
        }