Exemplo n.º 1
0
        private SyncStateMetadata GetMetadataFromPropertyBag(MailboxSession mailboxSession, IStorePropertyBag propertyBag, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            StoreObjectId objectId = ((VersionedId)propertyBag.TryGetProperty(FolderSchema.Id)).ObjectId;
            int           num      = (int)propertyBag.TryGetProperty(FolderSchema.ItemCount);
            string        text     = (string)propertyBag.TryGetProperty(FolderSchema.DisplayName);

            syncLogger.TraceDebug <string, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] SyncState {0} has {1} children.", text, num);
            SyncStateMetadata syncStateMetadata;

            if (num > 0)
            {
                syncStateMetadata = this.GetSyncStateItemMetadata(mailboxSession, objectId, text, syncLogger);
                if (syncStateMetadata != null)
                {
                    syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Sync state was from item.");
                    return(syncStateMetadata);
                }
            }
            syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Sync state was from folder.");
            syncStateMetadata = this.GetMetadataFromPropertyBag(propertyBag, text, syncLogger);
            syncStateMetadata.FolderSyncStateId = objectId;
            syncStateMetadata.ItemSyncStateId   = null;
            return(syncStateMetadata);
        }
Exemplo n.º 2
0
 private SyncStateMetadata GetSyncStateItemMetadata(MailboxSession mailboxSession, Folder parentFolder, string displayName, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     using (QueryResult queryResult = parentFolder.ItemQuery(ItemQueryType.None, null, new SortBy[]
     {
         new SortBy(ItemSchema.Subject, SortOrder.Ascending)
     }, DeviceSyncStateMetadata.NullSyncPropertiesItems))
     {
         if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.Subject, displayName)))
         {
             IStorePropertyBag storePropertyBag = queryResult.GetPropertyBags(1)[0];
             StoreObjectId     objectId         = ((VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id)).ObjectId;
             syncLogger.TraceDebug <string, SmtpAddress, string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncStateItemMetadata] Sync state '{0}' for mailbox '{1}' is stored on item id '{2}'", displayName, mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, objectId.ToBase64String());
             SyncStateMetadata metadataFromPropertyBag = this.GetMetadataFromPropertyBag(storePropertyBag, displayName, syncLogger);
             metadataFromPropertyBag.FolderSyncStateId = parentFolder.Id.ObjectId;
             metadataFromPropertyBag.ItemSyncStateId   = objectId;
             return(metadataFromPropertyBag);
         }
     }
     syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncStateItemMetadata] Did not find child item with name {0}", displayName);
     return(null);
 }
Exemplo n.º 3
0
 private void ProcessSyncStateItems(Folder deviceFolder, ISyncLogger syncLogger)
 {
     using (QueryResult queryResult = deviceFolder.ItemQuery(ItemQueryType.None, null, null, DeviceSyncStateMetadata.NullSyncPropertiesItems))
     {
         for (;;)
         {
             IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(100);
             if (propertyBags == null || propertyBags.Length == 0)
             {
                 break;
             }
             foreach (IStorePropertyBag storePropertyBag in propertyBags)
             {
                 string            displayName             = (string)storePropertyBag.TryGetProperty(ItemSchema.Subject);
                 SyncStateMetadata metadataFromPropertyBag = this.GetMetadataFromPropertyBag(storePropertyBag, displayName, syncLogger);
                 if (metadataFromPropertyBag != null)
                 {
                     StoreObjectId objectId = ((VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id)).ObjectId;
                     metadataFromPropertyBag.FolderSyncStateId = null;
                     metadataFromPropertyBag.ItemSyncStateId   = objectId;
                     syncLogger.TraceDebug <SyncStateMetadata>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ProcessSyncStateItems] Found Item SyncState: {0}", metadataFromPropertyBag);
                     this.syncStateMap.TryAdd(metadataFromPropertyBag.Name, metadataFromPropertyBag);
                 }
                 else
                 {
                     syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ProcessSyncStateItems] Discovered unusable sync state for device {0}", this.Id);
                 }
             }
         }
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 private void ProcessSyncStateFolders(Folder deviceFolder, ISyncLogger syncLogger)
 {
     using (QueryResult queryResult = deviceFolder.FolderQuery(FolderQueryFlags.None, null, null, DeviceSyncStateMetadata.NullSyncPropertiesFolders))
     {
         for (;;)
         {
             IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(100);
             if (propertyBags == null || propertyBags.Length == 0)
             {
                 break;
             }
             foreach (IStorePropertyBag propertyBag in propertyBags)
             {
                 SyncStateMetadata metadataFromPropertyBag = this.GetMetadataFromPropertyBag(deviceFolder.Session as MailboxSession, propertyBag, syncLogger);
                 if (metadataFromPropertyBag != null)
                 {
                     syncLogger.TraceDebug <SyncStateMetadata>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ProcessSyncStateFolders] Found SyncState: {0}", metadataFromPropertyBag);
                     this.syncStateMap.TryAdd(metadataFromPropertyBag.Name, metadataFromPropertyBag);
                 }
                 else
                 {
                     syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ProcessSyncStateFolders] Discovered unusable sync state for device {0}", this.Id);
                 }
             }
         }
     }
 }
        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);
        }
Exemplo n.º 7
0
        public SyncStateMetadata GetMetadataFromPropertyBag(IStorePropertyBag propertyBag, string displayName, ISyncLogger syncLogger = null)
        {
            byte[] byteArray = null;
            if (!DeviceSyncStateMetadata.TryGetPropertyFromBag <byte[]>(propertyBag, InternalSchema.SyncFolderSourceKey, out byteArray, syncLogger))
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Creating custom sync state metadata for folder '{0}'", displayName);
                return(new SyncStateMetadata(this, displayName, null, null));
            }
            StoreObjectId storeObjectId = StoreObjectId.Deserialize(byteArray);

            syncLogger.TraceDebug <string, StoreObjectId>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Found SyncFolderSourceKey for {0}, so it is a FolderSyncState: {1}", displayName, storeObjectId);
            long localCommitTimeMax  = 0L;
            int  deletedCountTotal   = 0;
            int  syncKey             = 0;
            int  airSyncFilter       = 0;
            bool conversationMode    = false;
            int  airSyncSettingsHash = 0;
            int  airSyncMaxItems     = 0;
            VariantConfigurationSnapshot snapshot = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null);
            bool flag = snapshot != null && snapshot.DataStorage.IgnoreInessentialMetaDataLoadErrors != null && snapshot.DataStorage.IgnoreInessentialMetaDataLoadErrors.Enabled;

            syncLogger.TraceDebug <bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] ignoreInessentialMetaDataLoadErrors: {0}", flag);
            long airSyncLastSyncTime;
            bool flag2 = DeviceSyncStateMetadata.TryGetPropertyFromBag <long>(propertyBag, AirSyncStateSchema.MetadataLastSyncTime, out airSyncLastSyncTime, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <long>(propertyBag, AirSyncStateSchema.MetadataLocalCommitTimeMax, out localCommitTimeMax, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataDeletedCountTotal, out deletedCountTotal, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataSyncKey, out syncKey, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataFilter, out airSyncFilter, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <bool>(propertyBag, AirSyncStateSchema.MetadataConversationMode, out conversationMode, syncLogger) && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataSettingsHash, out airSyncSettingsHash, syncLogger);
            bool flag3 = flag2 && DeviceSyncStateMetadata.TryGetPropertyFromBag <int>(propertyBag, AirSyncStateSchema.MetadataMaxItems, out airSyncMaxItems, syncLogger);

            flag2 = (flag ? flag2 : flag3);
            if (flag2)
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Creating FolderSync metadata for folder '{0}'", displayName);
                return(new FolderSyncStateMetadata(this, displayName, null, null, localCommitTimeMax, deletedCountTotal, syncKey, conversationMode, airSyncFilter, airSyncLastSyncTime, airSyncSettingsHash, airSyncMaxItems, storeObjectId));
            }
            syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetMetadataFromPropertyBag] Failed to get nullSync properties for sync folder '{0}'.", displayName);
            return(new FolderSyncStateMetadata(this, displayName, null, null, 0L, 0, 0, false, 0, 0L, 0, 0, storeObjectId));
        }
        public List <DeviceSyncStateMetadata> GetAllDevices(MailboxSession mailboxSession, bool forceRefresh, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            syncLogger.TraceDebug <SmtpAddress, bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetAllDevices] Getting all devies for Mailbox: {0}, forceRefresh: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, forceRefresh);
            List <DeviceSyncStateMetadata> list = null;

            using (Folder syncRootFolder = this.GetSyncRootFolder(mailboxSession, syncLogger))
            {
                using (QueryResult queryResult = syncRootFolder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[]
                {
                    FolderSchema.Id,
                    FolderSchema.DisplayName
                }))
                {
                    for (;;)
                    {
                        object[][] rows = queryResult.GetRows(100);
                        if (rows == null || rows.Length == 0)
                        {
                            break;
                        }
                        object[][] array = rows;
                        for (int i = 0; i < array.Length; i++)
                        {
                            object[]       array2         = array[i];
                            StoreObjectId  deviceFolderId = ((VersionedId)array2[0]).ObjectId;
                            DeviceIdentity deviceIdentity = new DeviceIdentity((string)array2[1]);
                            syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetAllDevices] Found device: {0}", deviceIdentity);
                            DeviceSyncStateMetadata item;
                            if (forceRefresh)
                            {
                                item = this.devices.AddOrUpdate(deviceIdentity, new DeviceSyncStateMetadata(mailboxSession, deviceFolderId, syncLogger), (DeviceIdentity key, DeviceSyncStateMetadata old) => new DeviceSyncStateMetadata(mailboxSession, deviceFolderId, syncLogger));
                            }
                            else
                            {
                                item = this.devices.GetOrAdd(deviceIdentity, (DeviceIdentity key) => new DeviceSyncStateMetadata(mailboxSession, deviceFolderId, syncLogger));
                            }
                            if (list == null)
                            {
                                list = new List <DeviceSyncStateMetadata>();
                            }
                            list.Add(item);
                        }
                    }
                }
            }
            return(list);
        }
        public DeviceSyncStateMetadata GetDevice(MailboxSession mailboxSession, DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            DeviceSyncStateMetadata result;

            if (this.devices.TryGetValue(deviceIdentity, out result))
            {
                syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Cache hit for device: {0}", deviceIdentity);
                return(result);
            }
            syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Cache MISS for device: {0}", deviceIdentity);
            DeviceSyncStateMetadata result2;

            using (Folder syncRootFolder = this.GetSyncRootFolder(mailboxSession, syncLogger))
            {
                using (QueryResult queryResult = syncRootFolder.FolderQuery(FolderQueryFlags.None, null, UserSyncStateMetadata.displayNameSort, new PropertyDefinition[]
                {
                    FolderSchema.DisplayName,
                    FolderSchema.Id
                }))
                {
                    if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.DisplayName, deviceIdentity.CompositeKey)))
                    {
                        IStorePropertyBag       storePropertyBag        = queryResult.GetPropertyBags(1)[0];
                        StoreObjectId           objectId                = ((VersionedId)storePropertyBag.TryGetProperty(FolderSchema.Id)).ObjectId;
                        string                  text                    = (string)storePropertyBag.TryGetProperty(FolderSchema.DisplayName);
                        DeviceSyncStateMetadata deviceSyncStateMetadata = new DeviceSyncStateMetadata(mailboxSession, objectId, syncLogger);
                        DeviceSyncStateMetadata orAdd                   = this.devices.GetOrAdd(deviceIdentity, deviceSyncStateMetadata);
                        if (!object.ReferenceEquals(deviceSyncStateMetadata, orAdd))
                        {
                            syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Race condition adding new device '{0}' to cache.  Disarding new instance.", deviceIdentity);
                        }
                        else
                        {
                            syncLogger.TraceDebug <DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Added new device instance to user cache: {0}", deviceIdentity);
                        }
                        result2 = orAdd;
                    }
                    else
                    {
                        syncLogger.TraceDebug <SmtpAddress, DeviceIdentity>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Mailbox '{0}' does not contain a device folder for '{1}'", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, deviceIdentity);
                        result2 = null;
                    }
                }
            }
            return(result2);
        }
Exemplo n.º 10
0
        private static Folder CreateAndSaveFolder(MailboxSession mailboxSession, StoreObjectId containerId, CreateMode createMode, string displayName, string containerClass, Folder folderIn, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            Folder folder = null;
            bool   flag   = false;
            Folder result;

            try
            {
                if (folderIn == null)
                {
                    folder = Folder.Create(mailboxSession, containerId, StoreObjectType.Folder, displayName, createMode);
                    folder[SyncStateStorage.airsyncLockProp] = "0";
                }
                else
                {
                    folder = folderIn;
                }
                if (containerClass != null)
                {
                    folder[InternalSchema.ContainerClass] = containerClass;
                }
                StoreObjectId storeObjectId = null;
                if (!folder.IsNew)
                {
                    storeObjectId = folder.Id.ObjectId;
                }
                FolderSaveResult folderSaveResult = folder.Save();
                if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                {
                    syncLogger.TraceDebug <string, FolderSaveResult>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::CreateAndSaveFolder. Failed to create folder {0}, due to {1}.", displayName, folderSaveResult);
                    if (storeObjectId == null)
                    {
                        folder.Load(null);
                        storeObjectId = folder.StoreObjectId;
                    }
                    mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                    {
                        storeObjectId
                    });
                    throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));
                }
                folder.Load(SyncStateStorage.loggingEnabledAndCreateTimeAsArray);
                flag   = true;
                result = folder;
            }
            finally
            {
                if (!flag && folder != null)
                {
                    folder.Dispose();
                    folder = null;
                }
            }
            return(result);
        }
Exemplo n.º 11
0
 public FolderHierarchyChangeDetector.MailboxChangesManifest GetFolderHierarchyICSChanges(MailboxSession mailboxSession, out FolderHierarchyChangeDetector.SyncHierarchyManifestState latestState, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     latestState = this.SyncHierarchyManifestState;
     if (latestState == null)
     {
         syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetFolderHierarchyICSChanges] Old ICS state was missing from cache.  Must do expensive check instead.");
         return(null);
     }
     latestState = latestState.Clone();
     FolderHierarchyChangeDetector.MailboxChangesManifest mailboxChangesManifest = FolderHierarchyChangeDetector.RunICSManifestSync(false, latestState, mailboxSession, syncLogger);
     syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetFolderHierarchyICSChanges] Changes: {0}, Deletes: {1}", (mailboxChangesManifest == null || mailboxChangesManifest.ChangedFolders == null) ? "<NULL>" : mailboxChangesManifest.ChangedFolders.Count.ToString(), (mailboxChangesManifest == null || mailboxChangesManifest.DeletedFolders == null) ? "<NULL>" : mailboxChangesManifest.DeletedFolders.Count.ToString());
     return(mailboxChangesManifest);
 }
Exemplo n.º 12
0
        public static FolderHierarchyChangeDetector.MailboxChangesManifest RunICSManifestSync(bool catchup, FolderHierarchyChangeDetector.SyncHierarchyManifestState hierState, MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            syncLogger.TraceDebug <SmtpAddress, bool>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Checking for folder hierarhcy changes for Mailbox: {0}.  Catchup? {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, catchup);
            MapiStore _ContainedMapiStore = mailboxSession.__ContainedMapiStore;

            FolderHierarchyChangeDetector.MailboxChangesManifest    mailboxChangesManifest = new FolderHierarchyChangeDetector.MailboxChangesManifest();
            FolderHierarchyChangeDetector.ManifestHierarchyCallback iMapiManifestCallback  = new FolderHierarchyChangeDetector.ManifestHierarchyCallback(catchup, mailboxChangesManifest);
            try
            {
                using (MapiFolder ipmSubtreeFolder = _ContainedMapiStore.GetIpmSubtreeFolder())
                {
                    SyncConfigFlags syncConfigFlags = SyncConfigFlags.ManifestHierReturnDeletedEntryIds;
                    int             serverVersion   = mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion;
                    if ((serverVersion >= Server.E14MinVersion && serverVersion < Server.E15MinVersion) || (long)serverVersion >= FolderHierarchyChangeDetector.E15MinVersionSupportsOnlySpecifiedPropsForHierarchy)
                    {
                        syncConfigFlags |= SyncConfigFlags.OnlySpecifiedProps;
                    }
                    using (MapiHierarchyManifestEx mapiHierarchyManifestEx = ipmSubtreeFolder.CreateExportHierarchyManifestEx(syncConfigFlags, hierState.IdsetGiven, hierState.CnsetSeen, iMapiManifestCallback, FolderHierarchyChangeDetector.PropsToFetch, null))
                    {
                        while (mapiHierarchyManifestEx.Synchronize() != ManifestStatus.Done)
                        {
                        }
                        byte[] idSetGiven;
                        byte[] cnetSeen;
                        mapiHierarchyManifestEx.GetState(out idSetGiven, out cnetSeen);
                        syncLogger.TraceDebug <SmtpAddress, int, int>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Updating ICS state for mailbox: '{0}'.  Change Count: {1}, Delete Count: {2}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, mailboxChangesManifest.ChangedFolders.Count, mailboxChangesManifest.DeletedFolders.Count);
                        hierState.Update(idSetGiven, cnetSeen);
                    }
                }
            }
            catch (MapiPermanentException arg)
            {
                syncLogger.TraceDebug <SmtpAddress, MapiPermanentException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiPermanentException when determining folder ICS changes for mailbox: {0}.  Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg);
                return(null);
            }
            catch (MapiRetryableException arg2)
            {
                syncLogger.TraceDebug <SmtpAddress, MapiRetryableException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiRetryableException when determining folder ICS changes for mailbox: {0}.  Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg2);
                return(null);
            }
            return(mailboxChangesManifest);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public DeviceSyncStateMetadata TryRemove(DeviceIdentity deviceIdentity, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            DeviceSyncStateMetadata result;
            bool arg = this.devices.TryRemove(deviceIdentity, out result);

            syncLogger.TraceDebug <DeviceIdentity, bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.TryRemove] Tried to remove '{0}'.  Success? {1}", deviceIdentity, arg);
            return(result);
        }
Exemplo n.º 15
0
        public SyncStateMetadata TryAdd(SyncStateMetadata syncStateMetadata, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata syncStateMetadata2 = this.syncStateMap.GetOrAdd(syncStateMetadata.Name, syncStateMetadata);

            if (syncStateMetadata.GetType().IsSubclassOf(syncStateMetadata2.GetType()))
            {
                syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.TryAdd] New sync state metadata instance ({0}) is subclass of cached one ({1}).  Replacing.", syncStateMetadata.GetType().Name, syncStateMetadata2.GetType().Name);
                this.syncStateMap[syncStateMetadata.Name] = syncStateMetadata;
                syncStateMetadata2 = syncStateMetadata;
            }
            FolderSyncStateMetadata folderSyncStateMetadata = syncStateMetadata2 as FolderSyncStateMetadata;

            if (folderSyncStateMetadata != null && folderSyncStateMetadata.IPMFolderId != null)
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.TryAdd] Encountered FolderSyncStateMetadata instance for '{0}'.  Adding source key to reverse mapping.", syncStateMetadata.Name);
                this.ipmToFolderSyncStateMap[folderSyncStateMetadata.IPMFolderId] = folderSyncStateMetadata;
            }
            return(syncStateMetadata2);
        }
Exemplo n.º 16
0
        internal static Folder GetSyncFolderRoot(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            StoreObjectId storeObjectId = mailboxSession.GetDefaultFolderId(DefaultFolderType.SyncRoot);

            if (storeObjectId == null)
            {
                syncLogger.TraceDebug <Guid>(ExTraceGlobals.SyncTracer, 0L, "[SyncStateStorage.GetSyncFolderRoot] ExchangeSyncData folder missing for mailbox {0}.  Creating it now.", mailboxSession.MailboxGuid);
                storeObjectId = mailboxSession.CreateDefaultFolder(DefaultFolderType.SyncRoot);
            }
            return(Folder.Bind(mailboxSession, storeObjectId, SyncStateStorage.loggingEnabledAsArray));
        }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
0
 public void ChangeIPMFolderId(FolderSyncStateMetadata folderSyncStateMetadata, StoreObjectId oldId, ISyncLogger syncLogger = null)
 {
     if (syncLogger == null)
     {
         syncLogger = TracingLogger.Singleton;
     }
     if (oldId != null)
     {
         FolderSyncStateMetadata folderSyncStateMetadata2;
         this.ipmToFolderSyncStateMap.TryRemove(oldId, out folderSyncStateMetadata2);
     }
     syncLogger.TraceDebug <string, string, string>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.ChangeIPMFolderId] IPM Folder Id for collection '{0}' changed from '{1}' to '{2}'", folderSyncStateMetadata.Name, (oldId == null) ? "<NULL>" : oldId.ToBase64String(), (folderSyncStateMetadata.IPMFolderId == null) ? "<NULL>" : folderSyncStateMetadata.IPMFolderId.ToBase64String());
     if (folderSyncStateMetadata.IPMFolderId != null)
     {
         this.ipmToFolderSyncStateMap.TryAdd(folderSyncStateMetadata.IPMFolderId, folderSyncStateMetadata);
     }
 }
Exemplo n.º 19
0
        public void RecordLatestFolderHierarchySnapshot(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            FolderHierarchyChangeDetector.SyncHierarchyManifestState syncHierarchyManifestState = this.SyncHierarchyManifestState;
            bool catchup = false;

            if (syncHierarchyManifestState == null)
            {
                syncLogger.TraceDebug(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.RecordLatestFolderHierarchySnapshot] Last ICS snapshot was null.  Doing a catchup sync.");
                syncHierarchyManifestState      = new FolderHierarchyChangeDetector.SyncHierarchyManifestState();
                this.SyncHierarchyManifestState = syncHierarchyManifestState;
                catchup = true;
            }
            FolderHierarchyChangeDetector.RunICSManifestSync(catchup, syncHierarchyManifestState, mailboxSession, syncLogger);
        }
Exemplo n.º 20
0
        public SyncStateMetadata TryRemove(string name, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata syncStateMetadata;
            bool arg = this.syncStateMap.TryRemove(name, out syncStateMetadata);

            syncLogger.TraceDebug <string, bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.TryRemove] Removing '{0}'.  Success? {1}", name, arg);
            FolderSyncStateMetadata folderSyncStateMetadata = syncStateMetadata as FolderSyncStateMetadata;

            if (folderSyncStateMetadata != null && folderSyncStateMetadata.IPMFolderId != null)
            {
                this.ipmToFolderSyncStateMap.TryRemove(folderSyncStateMetadata.IPMFolderId, out folderSyncStateMetadata);
            }
            return(syncStateMetadata);
        }
Exemplo n.º 21
0
        private Folder GetSyncRootFolder(MailboxSession mailboxSession, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            Folder result = null;

            try
            {
                result = Folder.Bind(mailboxSession, DefaultFolderType.SyncRoot);
            }
            catch (ObjectNotFoundException)
            {
                syncLogger.TraceDebug <SmtpAddress>(ExTraceGlobals.SyncTracer, (long)this.GetHashCode(), "[UserSyncStateMetadata.GetDevice] Missing SyncRoot folder for mailbox {0}.  Recreating.", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress);
                mailboxSession.CreateDefaultFolder(DefaultFolderType.SyncRoot);
                result = Folder.Bind(mailboxSession, DefaultFolderType.SyncRoot);
            }
            return(result);
        }
Exemplo n.º 22
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);
 }
Exemplo n.º 23
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));
        }
Exemplo 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));
        }
Exemplo n.º 25
0
        public SyncStateMetadata GetSyncState(MailboxSession mailboxSession, string name, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata result;

            if (this.syncStateMap.TryGetValue(name, out result))
            {
                syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Cache hit for sync state: {0}", name);
                return(result);
            }
            syncLogger.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Cache MISS for sync state: {0}", name);
            using (Folder folder = Folder.Bind(mailboxSession, this.DeviceFolderId, new PropertyDefinition[]
            {
                FolderSchema.ItemCount,
                FolderSchema.ChildCount
            }))
            {
                int itemCount = folder.ItemCount;
                syncLogger.TraceDebug <string, int, bool>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] deviceFolder {0} has {1} items and subfolders? {2}", folder.DisplayName, itemCount, folder.HasSubfolders);
                SyncStateMetadata syncStateMetadata = null;
                if (itemCount > 0)
                {
                    syncStateMetadata = this.GetSyncStateItemMetadata(mailboxSession, folder, name, syncLogger);
                    if (syncStateMetadata != null)
                    {
                        syncLogger.TraceDebug <SyncStateMetadata>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Retrieved DIRECT item sync state: {0}", syncStateMetadata);
                        syncStateMetadata.FolderSyncStateId = null;
                    }
                }
                if (syncStateMetadata == null && folder.HasSubfolders)
                {
                    using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, new SortBy[]
                    {
                        new SortBy(FolderSchema.DisplayName, SortOrder.Ascending)
                    }, DeviceSyncStateMetadata.NullSyncPropertiesFolders))
                    {
                        if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.DisplayName, name)))
                        {
                            IStorePropertyBag propertyBag = queryResult.GetPropertyBags(1)[0];
                            syncStateMetadata = this.GetMetadataFromPropertyBag(mailboxSession, propertyBag, syncLogger);
                            if (syncStateMetadata != null)
                            {
                                syncLogger.TraceDebug <SyncStateMetadata>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Retrieved sub folder sync state: {0}", syncStateMetadata);
                            }
                        }
                    }
                }
                if (syncStateMetadata != null)
                {
                    SyncStateMetadata syncStateMetadata2 = this.syncStateMap.GetOrAdd(syncStateMetadata.Name, syncStateMetadata);
                    if (syncStateMetadata2.StorageType != syncStateMetadata.StorageType)
                    {
                        syncLogger.TraceDebug <StorageType, StorageType>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Metadata was already cached but had store type: {0}.  New instance was: {1}.  Using new instance.", syncStateMetadata2.StorageType, syncStateMetadata.StorageType);
                        this.syncStateMap[syncStateMetadata.Name] = syncStateMetadata;
                        syncStateMetadata2 = syncStateMetadata;
                    }
                    return(syncStateMetadata2);
                }
                syncLogger.TraceDebug <string, Guid>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "[DeviceSyncStateMetadata.GetSyncState] Cache miss for sync state {0}, Mailbox {1}, but search did not find it.", name, mailboxSession.MailboxGuid);
            }
            return(null);
        }