Ejemplo n.º 1
0
 public static void UpdateMailboxLoggingEnabled(MailboxSession mailboxSession, bool mailboxLoggingEnabled, ISyncLogger syncLogger = null)
 {
     using (Folder syncFolderRoot = SyncStateStorage.GetSyncFolderRoot(mailboxSession, syncLogger))
     {
         if (mailboxLoggingEnabled)
         {
             syncFolderRoot[SyncStateStorage.airsyncMailboxLoggingEnabledProp] = ExDateTime.UtcNow;
         }
         else
         {
             syncFolderRoot.Delete(SyncStateStorage.airsyncMailboxLoggingEnabledProp);
         }
         syncFolderRoot.Save();
         syncFolderRoot.Load();
         Folder folder = null;
         try
         {
             folder = SyncStateStorage.CreateAndSaveFolder(mailboxSession, syncFolderRoot.Id.ObjectId, CreateMode.OpenIfExists, SyncStateStorage.MailboxLoggingTriggerFolder, null, null, syncLogger);
             if (folder != null)
             {
                 syncFolderRoot.DeleteObjects(DeleteItemFlags.SoftDelete, new StoreId[]
                 {
                     folder.Id.ObjectId
                 });
             }
         }
         finally
         {
             if (folder != null)
             {
                 folder.Dispose();
             }
         }
     }
 }
Ejemplo n.º 2
0
        public static SyncStateStorage Create(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, StateStorageFeatures features, bool onlySetPropsIfAlreadyExists, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            EnumValidator.ThrowIfInvalid <StateStorageFeatures>(features, "features");
            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata   userSyncStateMetadata   = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            DeviceSyncStateMetadata deviceSyncStateMetadata = userSyncStateMetadata.GetDevice(mailboxSession, deviceIdentity, syncLogger);
            SyncStateStorage        syncStateStorage        = (deviceSyncStateMetadata == null) ? null : SyncStateStorage.GetSyncStateStorage(mailboxSession, deviceSyncStateMetadata, syncLogger);

            if (syncStateStorage == null || onlySetPropsIfAlreadyExists)
            {
                Folder           folder            = null;
                SyncStateStorage syncStateStorage2 = null;
                bool             flag = false;
                try
                {
                    folder = SyncStateStorage.CreateAndSaveFolder(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.SyncRoot), CreateMode.OpenIfExists, deviceIdentity.CompositeKey, null, (syncStateStorage == null) ? null : syncStateStorage.folder, syncLogger);
                    if (deviceSyncStateMetadata != null && deviceSyncStateMetadata.DeviceFolderId != folder.Id.ObjectId)
                    {
                        userSyncStateMetadata.TryRemove(deviceSyncStateMetadata.Id, syncLogger);
                        deviceSyncStateMetadata = null;
                    }
                    if (deviceSyncStateMetadata == null)
                    {
                        deviceSyncStateMetadata = new DeviceSyncStateMetadata(mailboxSession, folder.Id.ObjectId, syncLogger);
                        deviceSyncStateMetadata = userSyncStateMetadata.GetOrAdd(deviceSyncStateMetadata);
                    }
                    syncStateStorage2 = new SyncStateStorage(folder, deviceSyncStateMetadata, syncLogger);
                    flag = true;
                    return(syncStateStorage2);
                }
                finally
                {
                    if (!flag)
                    {
                        if (syncStateStorage2 != null)
                        {
                            syncStateStorage2.Dispose();
                            syncStateStorage2 = null;
                        }
                        if (folder != null)
                        {
                            folder.Dispose();
                            folder = null;
                        }
                    }
                }
                return(syncStateStorage);
            }
            return(syncStateStorage);
        }