Ejemplo n.º 1
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.º 2
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));
        }