Ejemplo n.º 1
0
        // Token: 0x06000884 RID: 2180 RVA: 0x000323A8 File Offset: 0x000305A8
        public static bool FolderSyncRequired(SyncStateStorage syncStateStorage, HierarchySyncOperations folderHierarchyChanges, SyncState folderIdMappingSyncState = null)
        {
            bool flag = folderIdMappingSyncState == null;

            try
            {
                if (folderIdMappingSyncState == null)
                {
                    folderIdMappingSyncState = syncStateStorage.GetCustomSyncState(new FolderIdMappingSyncStateInfo(), new PropertyDefinition[0]);
                    if (folderIdMappingSyncState == null)
                    {
                        return(true);
                    }
                }
                FolderTree folderTree = (FolderTree)folderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
                if (folderTree == null)
                {
                    return(true);
                }
                for (int i = 0; i < folderHierarchyChanges.Count; i++)
                {
                    HierarchySyncOperation hierarchySyncOperation = folderHierarchyChanges[i];
                    MailboxSyncItemId      folderId  = MailboxSyncItemId.CreateForNewItem(hierarchySyncOperation.ItemId);
                    MailboxSyncItemId      folderId2 = MailboxSyncItemId.CreateForNewItem(hierarchySyncOperation.ParentId);
                    if (!folderTree.Contains(folderId2))
                    {
                        return(true);
                    }
                    if (!folderTree.Contains(folderId))
                    {
                        if (!folderTree.IsHidden(folderId2))
                        {
                            return(true);
                        }
                    }
                    else if (!folderTree.IsHidden(folderId) || (folderTree.IsHiddenDueToParent(folderId) && !folderTree.IsHidden(folderId2)))
                    {
                        return(true);
                    }
                }
            }
            finally
            {
                if (flag && folderIdMappingSyncState != null)
                {
                    folderIdMappingSyncState.Dispose();
                }
            }
            return(false);
        }
        public override void OpenSyncState(bool autoLoadFilterAndSyncKey, SyncStateStorage syncStateStorage)
        {
            if (!(base.StoreSession is MailboxSession))
            {
                throw new InvalidOperationException();
            }
            RecipientInfoCacheSyncProviderFactory recipientInfoCacheSyncProviderFactory = (RecipientInfoCacheSyncProviderFactory)base.SyncProviderFactory;

            if (base.SyncKey != 0U || autoLoadFilterAndSyncKey)
            {
                base.SyncState = syncStateStorage.GetFolderSyncState(base.SyncProviderFactory, base.CollectionId);
                if (base.SyncState == null)
                {
                    if (autoLoadFilterAndSyncKey)
                    {
                        base.Status          = SyncBase.ErrorCodeStatus.InvalidSyncKey;
                        base.ResponseSyncKey = base.SyncKey;
                        throw new AirSyncPermanentException(false)
                              {
                                  ErrorStringForProtocolLogger = "NoSyncStateInRICacheSync"
                              };
                    }
                    using (CustomSyncState customSyncState = syncStateStorage.GetCustomSyncState(new FolderIdMappingSyncStateInfo(), new PropertyDefinition[0]))
                    {
                        if (customSyncState == null || customSyncState[CustomStateDatumType.IdMapping] == null)
                        {
                            base.Status = SyncBase.ErrorCodeStatus.InvalidCollection;
                            throw new AirSyncPermanentException(false)
                                  {
                                      ErrorStringForProtocolLogger = "BadFolderMapTreeInRICacheSync"
                                  };
                        }
                    }
                    base.Status          = SyncBase.ErrorCodeStatus.InvalidSyncKey;
                    base.ResponseSyncKey = base.SyncKey;
                    throw new AirSyncPermanentException(false)
                          {
                              ErrorStringForProtocolLogger = "Sk0ErrorInRICacheSync"
                          };
                }
                else
                {
                    base.CheckProtocolVersion();
                    if (autoLoadFilterAndSyncKey)
                    {
                        if (!base.SyncState.Contains(CustomStateDatumType.SyncKey))
                        {
                            base.Status          = SyncBase.ErrorCodeStatus.InvalidSyncKey;
                            base.ResponseSyncKey = base.SyncKey;
                            throw new AirSyncPermanentException(false)
                                  {
                                      ErrorStringForProtocolLogger = "NoSyncStateKeyInRICacheSync"
                                  };
                        }
                        base.SyncKey = ((UInt32Data)base.SyncState[CustomStateDatumType.SyncKey]).Data;
                        if (base.SyncState.Contains(CustomStateDatumType.RecoverySyncKey))
                        {
                            base.RecoverySyncKey = ((UInt32Data)base.SyncState[CustomStateDatumType.RecoverySyncKey]).Data;
                        }
                        base.FilterType = (AirSyncV25FilterTypes)base.SyncState.GetData <Int32Data, int>(CustomStateDatumType.FilterType, 0);
                        base.SyncState[CustomStateDatumType.MaxItems] = new Int32Data(base.MaxItems);
                    }
                }
            }
            if (base.SyncKey == 0U)
            {
                SyncState syncState = null;
                try
                {
                    syncState = syncStateStorage.GetCustomSyncState(new FolderIdMappingSyncStateInfo(), new PropertyDefinition[0]);
                    if ((FolderIdMapping)syncState[CustomStateDatumType.IdMapping] == null)
                    {
                        base.Status          = SyncBase.ErrorCodeStatus.ServerError;
                        base.ResponseSyncKey = 0U;
                        AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "Id Mapping not created on SK0-returning ServerError on RI collection");
                        throw new AirSyncPermanentException(false)
                              {
                                  ErrorStringForProtocolLogger = "NoIdMappingInRICacheSync"
                              };
                    }
                }
                finally
                {
                    if (syncState != null)
                    {
                        syncState.Dispose();
                    }
                }
                syncStateStorage.DeleteFolderSyncState(base.CollectionId);
                base.SyncState = syncStateStorage.CreateFolderSyncState(base.SyncProviderFactory, base.CollectionId);
                base.SyncState.RegisterColdDataKey("IdMapping");
                base.SyncState.RegisterColdDataKey("CustomCalendarSyncFilter");
                base.SyncState[CustomStateDatumType.IdMapping] = new ItemIdMapping(base.CollectionId);
                base.ClassType = "RecipientInfoCache";
                base.SyncState[CustomStateDatumType.AirSyncClassType] = new ConstStringData(StaticStringPool.Instance.Intern(base.ClassType));
            }
            else
            {
                object obj = base.SyncState[CustomStateDatumType.AirSyncClassType];
                if (obj == null || string.IsNullOrEmpty(((ConstStringData)obj).Data))
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ClassType for RI folder was null in sync state");
                    base.ClassType = "RecipientInfoCache";
                }
                else
                {
                    if (!string.Equals("RecipientInfoCache", ((ConstStringData)obj).Data, StringComparison.OrdinalIgnoreCase))
                    {
                        base.Status = SyncBase.ErrorCodeStatus.ObjectNotFound;
                        string text = string.Format("Invalid Class Type in RI sync state: {0}", ((ConstStringData)obj).Data);
                        AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, text);
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, new LocalizedString(text), false)
                              {
                                  ErrorStringForProtocolLogger = "BadClassStateInRICacheSync"
                              };
                    }
                    base.ClassType = ((ConstStringData)obj).Data;
                }
            }
            if (base.SyncState.CustomVersion != null && base.SyncState.CustomVersion.Value > 9)
            {
                throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.SyncStateVersionInvalid, EASServerStrings.MismatchSyncStateError, true)
                      {
                          ErrorStringForProtocolLogger = "MismatchedSyncStateInRICacheSync"
                      };
            }
            base.SyncState[CustomStateDatumType.AirSyncProtocolVersion] = new Int32Data(base.ProtocolVersion);
        }