示例#1
0
        private static SyncStateStorage GetSyncStateStorage(MailboxSession session, DeviceSyncStateMetadata deviceMetadata, ISyncLogger syncLogger = null)
        {
            if (deviceMetadata == null)
            {
                return(null);
            }
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            Folder           folder           = null;
            SyncStateStorage syncStateStorage = null;
            bool             flag             = false;
            SyncStateStorage result;

            try
            {
                try
                {
                    folder           = Folder.Bind(session, deviceMetadata.DeviceFolderId, SyncStateStorage.loggingEnabledAndCreateTimeAsArray);
                    syncStateStorage = new SyncStateStorage(folder, deviceMetadata, syncLogger);
                }
                catch (ObjectNotFoundException)
                {
                    syncLogger.TraceDebug <DeviceSyncStateMetadata>(ExTraceGlobals.SyncTracer, 0L, "[SyncStateStorage.Create] Did not find SyncStateStorage for device {0}.  Removing from cache.", deviceMetadata);
                    UserSyncStateMetadata userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(session, syncLogger);
                    userSyncStateMetadata.TryRemove(deviceMetadata.Id, syncLogger);
                    deviceMetadata = userSyncStateMetadata.GetDevice(session, deviceMetadata.Id, syncLogger);
                    if (deviceMetadata != null)
                    {
                        folder           = Folder.Bind(session, deviceMetadata.DeviceFolderId, SyncStateStorage.loggingEnabledAndCreateTimeAsArray);
                        syncStateStorage = new SyncStateStorage(folder, deviceMetadata, syncLogger);
                    }
                }
                flag   = true;
                result = syncStateStorage;
            }
            finally
            {
                if (!flag)
                {
                    if (syncStateStorage != null)
                    {
                        syncStateStorage.Dispose();
                        syncStateStorage = null;
                    }
                    if (folder != null)
                    {
                        folder.Dispose();
                        folder = null;
                    }
                }
            }
            return(result);
        }
示例#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);
        }
示例#3
0
        public static SyncStateStorage Bind(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata   userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            DeviceSyncStateMetadata device = userSyncStateMetadata.GetDevice(mailboxSession, deviceIdentity, syncLogger);

            if (device != null)
            {
                return(SyncStateStorage.GetSyncStateStorage(mailboxSession, device, syncLogger));
            }
            return(null);
        }