Esempio n. 1
0
 public FolderSyncState CreateFolderSyncState(ISyncProviderFactory syncProviderFactory, string syncFolderId)
 {
     this.CheckDisposed("CreateFolderSyncState");
     this.syncLogger.Information <int>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "SyncStateStorage::CreateFolderSyncState. Hashcode = {0}", this.GetHashCode());
     ArgumentValidator.ThrowIfNull("syncProviderFactory", syncProviderFactory);
     ArgumentValidator.ThrowIfNull("syncFolderId", syncFolderId);
     return(FolderSyncState.CreateSyncState(this, this.folder, syncProviderFactory, syncFolderId, this.syncLogger));
 }
Esempio n. 2
0
        public AggregateOperationResult DeleteFolderSyncState(ISyncProviderFactory syncFactory)
        {
            this.CheckDisposed("DeleteFolderSyncState");
            this.syncLogger.Information <int>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "SyncStateStorage::DeleteFolderSyncState. Hashcode = {0}", this.GetHashCode());
            ArgumentValidator.ThrowIfNull("syncFactory", syncFactory);
            StoreObjectId           storeObjectId = StoreObjectId.Deserialize(syncFactory.GetCollectionIdBytes());
            FolderSyncStateMetadata folderSyncStateMetadata;

            if (this.DeviceMetadata.SyncStatesByIPMFolderId.TryGetValue(storeObjectId, out folderSyncStateMetadata))
            {
                return(this.InternalDeleteSyncState(folderSyncStateMetadata.Name));
            }
            this.syncLogger.TraceDebug <string>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[SyncStateStorage.DeleteFolderSyncState] Did not find cached mapping for IPM Folder Id {0}", storeObjectId.ToBase64String());
            return(null);
        }
Esempio n. 3
0
        public FolderSyncState GetFolderSyncState(ISyncProviderFactory syncProviderFactory, string syncFolderName, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator)
        {
            this.CheckDisposed("GetFolderSyncState");
            this.syncLogger.Information <int>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "SyncStateStorage::GetFolderSyncState. Hashcode = {0}", this.GetHashCode());
            if (syncProviderFactory == null && string.IsNullOrEmpty(syncFolderName))
            {
                throw new ArgumentNullException("syncProviderFactory and syncFolderName");
            }
            FolderSyncState result;

            try
            {
                result = (string.IsNullOrEmpty(syncFolderName) ? FolderSyncState.GetSyncState(this, this.folder, syncProviderFactory, creator, this.syncLogger) : FolderSyncState.GetSyncState(this, this.folder, syncProviderFactory, syncFolderName, creator, this.syncLogger));
            }
            catch (ObjectNotFoundException arg)
            {
                this.syncLogger.TraceDebug <string, ObjectNotFoundException>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[SyncStateStorage.GetFolderSyncState] Hark! SyncState '{0}' was not found.  Exception: {1}", (syncFolderName == null) ? "<Null>" : syncFolderName, arg);
                result = null;
            }
            return(result);
        }
Esempio n. 4
0
 public FolderSyncState GetFolderSyncState(ISyncProviderFactory syncProviderFactory, string syncStateName)
 {
     return(this.GetFolderSyncState(syncProviderFactory, syncStateName, null));
 }
Esempio n. 5
0
 public FolderSyncState GetFolderSyncState(ISyncProviderFactory syncProviderFactory)
 {
     return(this.GetFolderSyncState(syncProviderFactory, null));
 }
Esempio n. 6
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));
        }
Esempio n. 7
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));
        }
Esempio n. 8
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));
 }
Esempio n. 9
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));
        }
Esempio n. 10
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;
 }