コード例 #1
0
        public UserSyncStateMetadata Get(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            UserSyncStateMetadata userSyncStateMetadata = null;

            if (!this.cache.TryGetValue(mailboxSession.MailboxGuid, out userSyncStateMetadata))
            {
                syncLogger.TraceDebug <Guid>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadataCache.Get] Cache miss for mailbox {0}", mailboxSession.MailboxGuid);
                userSyncStateMetadata = new UserSyncStateMetadata(mailboxSession);
                lock (this.instanceLock)
                {
                    UserSyncStateMetadata result = null;
                    if (this.cache.TryGetValue(mailboxSession.MailboxGuid, out result))
                    {
                        syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadataCache.Get] Second TryGet returned cached value.  Discarding new one.");
                        return(result);
                    }
                    this.cache.TryAddSliding(mailboxSession.MailboxGuid, userSyncStateMetadata, UserSyncStateMetadataCache.CacheEntrySlidingLiveTimeEntry.Value);
                }
                return(userSyncStateMetadata);
            }
            syncLogger.TraceDebug <SmtpAddress>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadataCache.Get] Cache hit for user: {0}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress);
            if (userSyncStateMetadata.MailboxGuid != mailboxSession.MailboxGuid)
            {
                throw new InvalidOperationException(string.Format("[UserSyncStateMetadataCache.Get] cached userState for mailbox {0} was keyed off incorrect mailbox {1}", userSyncStateMetadata.MailboxGuid, mailboxSession.MailboxGuid));
            }
            return(userSyncStateMetadata);
        }
コード例 #2
0
            public SyncStateStorageEnumerator(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
            {
                this.syncLogger = (syncLogger ?? TracingLogger.Singleton);
                UserSyncStateMetadata userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, this.syncLogger);

                this.devices        = userSyncStateMetadata.GetAllDevices(mailboxSession, true, this.syncLogger);
                this.index          = -1;
                this.mailboxSession = mailboxSession;
            }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public static bool DeleteSyncStateStorage(MailboxSession mailboxSession, StoreObjectId deviceFolderId, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            ArgumentValidator.ThrowIfNull("folderId", deviceFolderId);
            bool result = false;

            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata    userSyncStateMetadata    = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            AggregateOperationResult aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
            {
                deviceFolderId
            });

            syncLogger.Information <string>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Result = {0}", aggregateOperationResult.OperationResult.ToString());
            userSyncStateMetadata.TryRemove(deviceIdentity, syncLogger);
            List <DeviceSyncStateMetadata> allDevices = userSyncStateMetadata.GetAllDevices(mailboxSession, false, syncLogger);

            if (allDevices != null)
            {
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    syncLogger.Information <DeviceIdentity, DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Found device folder '{0}', Looking for folder '{1}'", deviceSyncStateMetadata.Id, deviceIdentity);
                    if (deviceSyncStateMetadata.Id.Equals(deviceIdentity))
                    {
                        try
                        {
                            aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                            {
                                deviceSyncStateMetadata.DeviceFolderId
                            });
                            syncLogger.Information <DeviceIdentity, DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. try Deleting SyncState folder again.folderName:{0}, originalFolder:{1}, result:{2}", deviceSyncStateMetadata.Id, deviceIdentity, aggregateOperationResult.OperationResult.ToString());
                            continue;
                        }
                        catch
                        {
                            syncLogger.Information(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Error deleting the sync state folder.");
                            continue;
                        }
                    }
                    if (deviceSyncStateMetadata.Id.IsProtocol("AirSync"))
                    {
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }
コード例 #6
0
        public static GetSyncStateResult GetData(MailboxSession session, ParsedCallData callData)
        {
            GetSyncStateResult getSyncStateResult = new GetSyncStateResult();

            getSyncStateResult.LoggingEnabled = SyncStateStorage.GetMailboxLoggingEnabled(session, null);
            using (SyncStateStorage.GetSyncFolderRoot(session, null))
            {
                UserSyncStateMetadata          userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(session, null);
                List <DeviceSyncStateMetadata> allDevices            = userSyncStateMetadata.GetAllDevices(session, true, null);
                getSyncStateResult.Devices = new List <DeviceData>(allDevices.Count);
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    if (SyncStateDiagnostics.ShouldAddDevice(callData, deviceSyncStateMetadata.Id))
                    {
                        DeviceData deviceData = new DeviceData
                        {
                            Name        = deviceSyncStateMetadata.Id.CompositeKey,
                            SyncFolders = new List <SyncStateFolderData>(),
                            FolderId    = deviceSyncStateMetadata.DeviceFolderId
                        };
                        getSyncStateResult.Devices.Add(deviceData);
                        foreach (KeyValuePair <string, SyncStateMetadata> keyValuePair in deviceSyncStateMetadata.SyncStates)
                        {
                            bool flag = string.Equals(keyValuePair.Key, callData.SyncStateName, StringComparison.OrdinalIgnoreCase);
                            if (callData.SyncStateName == null || flag)
                            {
                                SyncStateFolderData syncStateFolderData = new SyncStateFolderData
                                {
                                    Name        = keyValuePair.Key,
                                    StorageType = keyValuePair.Value.StorageType.ToString()
                                };
                                if (flag)
                                {
                                    SyncStateDiagnostics.GetSyncStateBlob(session, keyValuePair.Value, syncStateFolderData);
                                }
                                else
                                {
                                    syncStateFolderData.SyncStateSize = -1;
                                }
                                deviceData.SyncFolders.Add(syncStateFolderData);
                            }
                        }
                    }
                }
            }
            return(getSyncStateResult);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static bool DeleteSyncStateStorage(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            syncLogger.Information <DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Need to delete folder {0}", deviceIdentity);
            SyncStateTypeFactory.GetInstance().RegisterInternalBuilders();
            UserSyncStateMetadata          userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(mailboxSession, syncLogger);
            List <DeviceSyncStateMetadata> allDevices            = userSyncStateMetadata.GetAllDevices(mailboxSession, false, syncLogger);
            bool result = false;

            if (allDevices != null)
            {
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    syncLogger.Information <DeviceIdentity>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. Found syncstate folder {0}", deviceSyncStateMetadata.Id);
                    if (string.Compare(deviceSyncStateMetadata.Id.Protocol, deviceIdentity.Protocol, StringComparison.Ordinal) == 0)
                    {
                        if (deviceSyncStateMetadata.Id.Equals(deviceIdentity))
                        {
                            mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                            {
                                deviceSyncStateMetadata.DeviceFolderId
                            });
                            userSyncStateMetadata.TryRemove(deviceSyncStateMetadata.Id, syncLogger);
                        }
                        else
                        {
                            syncLogger.Information(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::DeleteSyncStateStorage. found more devices with same protocol");
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #9
0
 private void HandleRemoveItem(Guid key, UserSyncStateMetadata value, RemoveReason removeReason)
 {
     ExTraceGlobals.SyncProcessTracer.TraceDebug <Guid, RemoveReason>((long)this.GetHashCode(), "[UserSyncStateMetadataCache.HandleRemoveItem] Mailbox {0} removed from cache due to reason: {1}", key, removeReason);
 }