Ejemplo n.º 1
0
        internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncStateName, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator, ISyncLogger syncLogger = null)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("syncStateName", syncStateName);
            SyncStateInfo syncStateInfo        = new FolderSyncStateInfo(syncStateName);
            StoreObject   syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            });

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            byte[] valueOrDefault = syncStateStoreObject.GetValueOrDefault <byte[]>(InternalSchema.SyncFolderSourceKey);
            if (syncProviderFactory != null)
            {
                try
                {
                    syncProviderFactory.SetCollectionIdFromBytes(valueOrDefault);
                }
                catch (ArgumentException innerException)
                {
                    syncStateStorage.DeleteFolderSyncState(syncStateName);
                    syncStateStorage.DeviceMetadata.TryRemove(syncStateName, null);
                    throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(syncStateName), innerException);
                }
            }
            FolderSyncStateMetadata folderSyncStateMetadata = FolderSyncState.GetFolderSyncStateMetadata(syncStateStorage, syncStateStoreObject.Session as MailboxSession, syncStateName, syncLogger);

            if (creator == null)
            {
                return(new FolderSyncState(syncStateStorage, syncStateStoreObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
            }
            return(creator(syncStateStorage, syncStateStoreObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
        }
Ejemplo n.º 2
0
        private static FolderSyncStateMetadata GetFolderSyncStateMetadata(SyncStateStorage syncStateStorage, MailboxSession mailboxSession, string name, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata       syncState = syncStateStorage.DeviceMetadata.GetSyncState(mailboxSession, name, syncLogger);
            FolderSyncStateMetadata folderSyncStateMetadata = syncState as FolderSyncStateMetadata;

            if (folderSyncStateMetadata == null)
            {
                syncLogger.TraceDebug <SmtpAddress, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetFolderSyncStateMetadata] SyncStateMetadata in place of FolderSyncStateMetadata for Mailbox: {0}, State: {1}.  Trying re-read...", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, name);
                syncStateStorage.DeviceMetadata.TryRemove(name, syncLogger);
                syncState = syncStateStorage.DeviceMetadata.GetSyncState(mailboxSession, name, syncLogger);
                folderSyncStateMetadata = (syncState as FolderSyncStateMetadata);
                if (folderSyncStateMetadata == null)
                {
                    syncStateStorage.DeleteFolderSyncState(name);
                    syncStateStorage.DeviceMetadata.TryRemove(name, null);
                    throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(name), new InvalidOperationException("SyncStateMetadata in place of FolderSyncStateMetadata"));
                }
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetFolderSyncStateMetadata] Re-read of sync state {0} was successful.", name);
            }
            return(folderSyncStateMetadata);
        }
Ejemplo n.º 3
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.º 4
0
 private SyncStateRootStorage(SyncStateStorage syncStateStorage)
 {
     if (syncStateStorage == null)
     {
         throw new ArgumentNullException("syncStateStorage");
     }
     this.syncStateStorage = syncStateStorage;
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
        internal static FolderHierarchySyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, StoreObjectId storeObjectId, ISyncLogger syncLogger = null)
        {
            SyncStateInfo syncStateInfo        = new FolderHierarchySyncStateInfo();
            StoreObject   syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, new PropertyDefinition[0]);

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            SyncStateMetadata syncState = syncStateStorage.DeviceMetadata.GetSyncState(syncStateParentFolder.Session as MailboxSession, syncStateInfo.UniqueName, syncLogger);

            return(new FolderHierarchySyncState(syncStateStorage, syncStateStoreObject, syncState, syncStateInfo, false, syncLogger));
        }
Ejemplo n.º 8
0
        internal static CustomSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, SyncStateInfo syncStateInfo, ISyncLogger syncLogger, params PropertyDefinition[] propertiesToFetch)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata syncStateMetadata    = null;
            StoreObject       syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, out syncStateMetadata, propertiesToFetch);

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            return(new CustomSyncState(syncStateStorage, syncStateStoreObject, syncStateMetadata, syncStateInfo, false));
        }
Ejemplo n.º 9
0
        internal static CustomSyncState CreateSyncState(SyncStateStorage syncStateStorage, SyncStateInfo syncStateInfo, Folder syncStateParentFolder, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            StoreObject storeObject = SyncState.CreateSyncStateStoreObject(syncStateStorage, syncStateInfo, syncStateParentFolder, null, null, syncLogger);

            if (syncStateStorage.DeviceMetadata.TryRemove(syncStateInfo.UniqueName, syncLogger) != null)
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[CustomSyncState.CreateSyncState] Removed stale cached sync state metadata for device {0}, sync state {1}", syncStateStorage.DeviceMetadata.Id, syncStateInfo.UniqueName);
            }
            SyncStateMetadata syncStateMetadata = (storeObject is Item) ? new SyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, syncStateStorage.SaveOnDirectItems ? null : storeObject.ParentId, storeObject.Id.ObjectId) : new SyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, storeObject.Id.ObjectId, null);

            return(new CustomSyncState(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, true));
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 public bool MoveNext()
 {
     this.CheckDisposed("MoveNext");
     if (this.current != null)
     {
         this.current.Dispose();
         this.current = null;
     }
     if (this.devices == null || this.index >= this.devices.Count)
     {
         return(false);
     }
     this.index++;
     if (this.index >= this.devices.Count)
     {
         return(false);
     }
     this.current = SyncStateStorage.GetSyncStateStorage(this.mailboxSession, this.devices[this.index], this.syncLogger);
     return(this.current != null || this.MoveNext());
 }
Ejemplo n.º 13
0
 public static bool GetMailboxLoggingEnabled(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     if (mailboxSession.IsConnected)
     {
         StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.SyncRoot);
         if (defaultFolderId == null)
         {
             return(false);
         }
         using (Folder folder = Folder.Bind(mailboxSession, defaultFolderId, SyncStateStorage.loggingEnabledAsArray))
         {
             return(SyncStateStorage.IsMailboxLoggingEnabled(folder));
         }
     }
     syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, 0L, "[SyncStateStorage.GetMailboxLoggingEnabled] MailboxSession was not connected - defaulting to false since we can't write to the mailbox.");
     return(false);
 }
Ejemplo n.º 14
0
        internal static FolderSyncState CreateSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncFolderId, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(syncFolderId);
            StoreObject   storeObject   = SyncState.CreateSyncStateStoreObject(syncStateStorage, syncStateInfo, syncStateParentFolder, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            }, new object[]
            {
                syncProviderFactory.GetCollectionIdBytes()
            }, syncLogger);

            if (syncStateStorage.DeviceMetadata.TryRemove(syncStateInfo.UniqueName, syncLogger) != null)
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.CreateSyncState] Removed stale cached sync state metadata for device {0}, sync state {1}", syncStateStorage.DeviceMetadata.Id, syncStateInfo.UniqueName);
            }
            FolderSyncStateMetadata syncStateMetadata = (storeObject is Item) ? new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, syncStateStorage.SaveOnDirectItems ? null : storeObject.ParentId, storeObject.Id.ObjectId, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes())) : new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, storeObject.Id.ObjectId, null, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes()));

            return(new FolderSyncState(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, syncProviderFactory, true, syncLogger));
        }
Ejemplo n.º 15
0
        public static SyncStateRootStorage GetOrCreateSyncStateRootStorage(MailboxSession mailboxSession, string protocol, ISyncLogger syncLogger = null)
        {
            if (mailboxSession == null)
            {
                throw new ArgumentNullException("mailboxSession");
            }
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            string           protocol2        = protocol + "Root";
            DeviceIdentity   deviceIdentity   = new DeviceIdentity("RootDeviceId", "RootDeviceType", protocol2);
            SyncStateStorage syncStateStorage = SyncStateStorage.Bind(mailboxSession, deviceIdentity, syncLogger);

            if (syncStateStorage == null)
            {
                syncStateStorage = SyncStateStorage.Create(mailboxSession, deviceIdentity, StateStorageFeatures.ContentState, syncLogger);
            }
            return(new SyncStateRootStorage(syncStateStorage));
        }
Ejemplo n.º 16
0
        protected static StoreObject GetSyncStateStoreObject(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, SyncStateInfo syncStateInfo, byte[] identBytes, ISyncLogger syncLogger, params PropertyDefinition[] propsToReturn)
        {
            FolderSyncStateMetadata folderSyncStateMetadata = FolderSyncState.GetFolderSyncStateMetadata(syncStateStorage, syncStateParentFolder.Session as MailboxSession, syncStateInfo.UniqueName, syncLogger);

            if (folderSyncStateMetadata == null)
            {
                return(null);
            }
            StoreObject storeObject = null;

            if (folderSyncStateMetadata.StorageType != StorageType.Folder)
            {
                if (folderSyncStateMetadata.StorageType != StorageType.Item)
                {
                    if (folderSyncStateMetadata.StorageType != StorageType.DirectItem)
                    {
                        goto IL_85;
                    }
                }
                try
                {
                    storeObject = Microsoft.Exchange.Data.Storage.Item.Bind(syncStateParentFolder.Session, folderSyncStateMetadata.ItemSyncStateId, SyncState.AppendAdditionalProperties(propsToReturn));
                    ((Item)storeObject).OpenAsReadWrite();
                    return(storeObject);
                }
                catch
                {
                    storeObject.Dispose();
                    throw;
                }
IL_85:
                throw new InvalidOperationException("Unsupported storage type for sync state");
            }
            storeObject = Folder.Bind(syncStateParentFolder.Session, folderSyncStateMetadata.FolderSyncStateId, SyncState.AppendAdditionalProperties(propsToReturn));
            return(storeObject);
        }
Ejemplo n.º 17
0
 public static SyncStateStorage Create(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, StateStorageFeatures features, ISyncLogger syncLogger = null)
 {
     return(SyncStateStorage.Create(mailboxSession, deviceIdentity, features, false, syncLogger));
 }
Ejemplo n.º 18
0
 protected CustomSyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, SyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, bool syncStateIsNew) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, syncStateIsNew, null)
 {
 }
 protected FolderHierarchySyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, SyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, bool newSyncState, ISyncLogger syncLogger = null) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, newSyncState, syncLogger)
 {
 }
Ejemplo n.º 20
0
 protected FolderSyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, FolderSyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, ISyncProviderFactory syncProviderFactory, bool newSyncState, ISyncLogger syncLogger = null) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, newSyncState, syncLogger)
 {
     this.syncProviderFactory = syncProviderFactory;
 }
 internal static FolderHierarchySyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncLogger syncLogger = null)
 {
     return(FolderHierarchySyncState.GetSyncState(syncStateStorage, syncStateParentFolder, null, syncLogger));
 }
Ejemplo n.º 22
0
        internal static bool IsMailboxLoggingEnabled(Folder rootFolder)
        {
            ExDateTime?loggingEnabledTime = SyncStateStorage.GetLoggingEnabledTime(rootFolder);

            return(loggingEnabledTime != null && ExDateTime.UtcNow < loggingEnabledTime.Value.IncrementDays(SyncStateStorage.loggingExpirationInDays));
        }
Ejemplo n.º 23
0
 internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, string syncFolderId, ISyncLogger syncLogger = null)
 {
     return(FolderSyncState.GetSyncState(syncStateStorage, syncStateParentFolder, null, syncFolderId, syncLogger));
 }
Ejemplo n.º 24
0
        internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder deviceFolder, ISyncProviderFactory syncProviderFactory, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("syncStateStorage", syncStateStorage);
            ArgumentValidator.ThrowIfNull("deviceFolder", deviceFolder);
            ArgumentValidator.ThrowIfNull("syncProviderFactory", syncProviderFactory);
            byte[] collectionIdBytes = syncProviderFactory.GetCollectionIdBytes();
            if (collectionIdBytes == null || collectionIdBytes.Length == 0)
            {
                throw new ArgumentException("SyncProviderFactory CollectionId bytes cannot be null or empty.");
            }
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.Deserialize(collectionIdBytes);
            }
            catch (ArgumentException innerException)
            {
                syncLogger.TraceError <string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] The IPMFolderBytes that the provider gave us are invalid for folder {0}", deviceFolder.DisplayName);
                throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(deviceFolder.DisplayName), innerException);
            }
            FolderSyncStateMetadata folderSyncStateMetadata = null;

            if (!syncStateStorage.DeviceMetadata.SyncStatesByIPMFolderId.TryGetValue(storeObjectId, out folderSyncStateMetadata))
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] Cache miss for device {0}, IPM folder Id {1}", syncStateStorage.DeviceMetadata.Id, storeObjectId.ToBase64String());
                return(null);
            }
            SyncStateMetadata syncStateMetadata = folderSyncStateMetadata;
            StoreObject       storeObject       = SyncState.GetSyncStateStoreObject(deviceFolder, ref syncStateMetadata, syncLogger, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            });

            if (!object.ReferenceEquals(folderSyncStateMetadata, syncStateMetadata))
            {
                FolderSyncStateMetadata folderSyncStateMetadata2 = syncStateMetadata as FolderSyncStateMetadata;
                if (folderSyncStateMetadata2 == null)
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} has non-folder sync state for {1}.  Returning null.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    if (storeObject != null)
                    {
                        storeObject.Dispose();
                        storeObject = null;
                    }
                }
                else
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} had  state folder sync state metadata for {1}.  Replacing.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    folderSyncStateMetadata = folderSyncStateMetadata2;
                }
            }
            if (storeObject == null)
            {
                return(null);
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(folderSyncStateMetadata.Name);

            if (creator == null)
            {
                return(new FolderSyncState(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
            }
            return(creator(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
        }
Ejemplo n.º 25
0
 internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncStateName, ISyncLogger syncLogger = null)
 {
     return(FolderSyncState.GetSyncState(syncStateStorage, syncStateParentFolder, syncProviderFactory, syncStateName, null, syncLogger));
 }
Ejemplo n.º 26
0
 internal static CustomSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, SyncStateInfo syncStateInfo, ISyncLogger syncLogger = null)
 {
     return(CustomSyncState.GetSyncState(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, null));
 }