Exemple #1
0
        public static void BuildFolderTree(MailboxSession mailboxSession, SyncState syncState)
        {
            StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Root);

            SharingSubscriptionData[] array = null;
            using (SharingSubscriptionManager sharingSubscriptionManager = new SharingSubscriptionManager(mailboxSession))
            {
                array = sharingSubscriptionManager.GetAll();
            }
            using (Folder folder = Folder.Bind(mailboxSession, defaultFolderId))
            {
                FolderTree folderTree;
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.DeepTraversal, null, null, FolderTree.fetchProperties))
                {
                    folderTree = new FolderTree();
                    object[][] rows;
                    do
                    {
                        rows = queryResult.GetRows(10000);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            MailboxSyncItemId mailboxSyncItemId  = MailboxSyncItemId.CreateForNewItem(((VersionedId)rows[i][0]).ObjectId);
                            MailboxSyncItemId mailboxSyncItemId2 = MailboxSyncItemId.CreateForNewItem((StoreObjectId)rows[i][1]);
                            folderTree.AddFolder(mailboxSyncItemId);
                            object obj = rows[i][3];
                            int    num = (obj is PropertyError) ? 0 : ((int)obj);
                            if ((num & 1073741824) != 0)
                            {
                                for (int j = 0; j < array.Length; j++)
                                {
                                    if (array[j].LocalFolderId.Equals(mailboxSyncItemId.NativeId))
                                    {
                                        folderTree.SetPermissions(mailboxSyncItemId, SyncPermissions.Readonly);
                                        folderTree.SetOwner(mailboxSyncItemId, array[j].SharerIdentity);
                                        break;
                                    }
                                }
                            }
                            if (!defaultFolderId.Equals(mailboxSyncItemId2.NativeId))
                            {
                                folderTree.AddFolder(mailboxSyncItemId2);
                                folderTree.LinkChildToParent(mailboxSyncItemId2, mailboxSyncItemId);
                            }
                            if ((bool)rows[i][2])
                            {
                                folderTree.SetHidden(mailboxSyncItemId, true);
                            }
                        }
                    }while (rows.Length != 0);
                }
                syncState[CustomStateDatumType.FullFolderTree]         = folderTree;
                syncState[CustomStateDatumType.RecoveryFullFolderTree] = syncState[CustomStateDatumType.FullFolderTree];
            }
        }
        // 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);
        }
        // Token: 0x060009BF RID: 2495 RVA: 0x000395CC File Offset: 0x000377CC
        private static string GetOrAddSyncFolderId(SyncState folderIdMappingSyncState, StoreObjectId mailboxFolderId)
        {
            FolderIdMapping   folderIdMapping   = (FolderIdMapping)folderIdMappingSyncState[CustomStateDatumType.IdMapping];
            FolderTree        folderTree        = (FolderTree)folderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
            MailboxSyncItemId mailboxSyncItemId = MailboxSyncItemId.CreateForNewItem(mailboxFolderId);
            string            text = folderIdMapping[mailboxSyncItemId];

            if (text == null)
            {
                text = folderIdMapping.Add(mailboxSyncItemId);
                folderTree.AddFolder(mailboxSyncItemId);
            }
            return(text);
        }
        protected override void ProcessCommand(FolderCommand.FolderRequest folderRequest, XmlDocument doc)
        {
            string                    namespaceURI      = doc.DocumentElement.NamespaceURI;
            DefaultFolderType         defaultFolderType = base.MailboxSession.IsDefaultFolderType(folderRequest.ServerId);
            AirSyncPermanentException ex;

            if (defaultFolderType != DefaultFolderType.None)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteOfDefaultFolder");
                ex = new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, base.ConstructErrorXml(StatusCode.Sync_InvalidSyncKey), null, false);
                throw ex;
            }
            AggregateOperationResult aggregateOperationResult = base.MailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreObjectId[]
            {
                folderRequest.ServerId
            });

            if (aggregateOperationResult.OperationResult != OperationResult.Failed)
            {
                base.FolderHierarchySync.RecordClientOperation(folderRequest.ServerId, ChangeType.Delete, null);
                folderRequest.RecoverySyncKey = folderRequest.SyncKey;
                folderRequest.SyncKey         = base.GetNextNumber(folderRequest.SyncKey);
                base.SyncStateChanged         = true;
                base.FolderHierarchySyncState[CustomStateDatumType.SyncKey]         = new Int32Data(folderRequest.SyncKey);
                base.FolderHierarchySyncState[CustomStateDatumType.RecoverySyncKey] = new Int32Data(folderRequest.RecoverySyncKey);
                FolderIdMapping   folderIdMapping = (FolderIdMapping)base.FolderIdMappingSyncState[CustomStateDatumType.IdMapping];
                FolderTree        folderTree      = (FolderTree)base.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
                MailboxSyncItemId folderId        = MailboxSyncItemId.CreateForNewItem(folderRequest.ServerId);
                folderTree.RemoveFolderAndChildren(folderId, folderIdMapping);
                folderIdMapping.CommitChanges();
                base.ProtocolLogger.IncrementValue("F", PerFolderProtocolLoggerData.ClientDeletes);
                XmlNode xmlNode = doc.CreateElement("Status", namespaceURI);
                xmlNode.InnerText = "1";
                XmlNode xmlNode2 = doc.CreateElement("SyncKey", namespaceURI);
                xmlNode2.InnerText = folderRequest.SyncKey.ToString(CultureInfo.InvariantCulture);
                doc.DocumentElement.AppendChild(xmlNode);
                doc.DocumentElement.AppendChild(xmlNode2);
                return;
            }
            if (aggregateOperationResult.GroupOperationResults != null && aggregateOperationResult.GroupOperationResults.Length > 0 && aggregateOperationResult.GroupOperationResults[0] != null && aggregateOperationResult.GroupOperationResults[0].Exception is ObjectNotFoundException)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteOfNonExistentFolder");
                ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolError, base.ConstructErrorXml(StatusCode.Sync_ProtocolError), null, false);
                throw ex;
            }
            base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteFailed");
            ex = new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, base.ConstructErrorXml(StatusCode.Sync_ClientServerConversion), null, false);
            throw ex;
        }
Exemple #5
0
 public bool SetHiddenDueToParent(bool newValue, FolderTree fullFolderTree, HashSet <ISyncItemId> visibilityChangedList)
 {
     if (this.HiddenDueToParent != newValue)
     {
         this.HiddenDueToParent = newValue;
         if (!this.hidden)
         {
             foreach (ISyncItemId syncItemId in this.Children)
             {
                 if (visibilityChangedList != null)
                 {
                     visibilityChangedList.Add(syncItemId);
                 }
                 fullFolderTree.SetHiddenDueToParent(syncItemId, newValue, visibilityChangedList);
             }
         }
         return(true);
     }
     return(false);
 }
        // Token: 0x0600088B RID: 2187 RVA: 0x00032D38 File Offset: 0x00030F38
        protected StoreObjectId GetXsoFolderId(string syncFolderId, out SyncPermissions permissions)
        {
            StoreObjectId result = null;

            permissions = SyncPermissions.FullAccess;
            if (syncFolderId == "0")
            {
                result = base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root);
            }
            else
            {
                MailboxSyncItemId mailboxSyncItemId = ((FolderIdMapping)this.folderIdMappingSyncState[CustomStateDatumType.IdMapping])[syncFolderId] as MailboxSyncItemId;
                if (mailboxSyncItemId != null)
                {
                    FolderTree folderTree = (FolderTree)this.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
                    result      = (StoreObjectId)mailboxSyncItemId.NativeId;
                    permissions = folderTree.GetPermissions(mailboxSyncItemId);
                }
            }
            return(result);
        }
			// Token: 0x06000932 RID: 2354 RVA: 0x00036550 File Offset: 0x00034750
			public bool SetHidden(bool newValue, FolderTree fullFolderTree, HashSet<ISyncItemId> visibilityChangedList)
			{
				bool result = false;
				if (this.ParentId == null && this.HiddenDueToParent)
				{
					this.HiddenDueToParent = false;
					result = true;
				}
				if (this.hidden != newValue)
				{
					this.hidden = newValue;
					foreach (ISyncItemId syncItemId in this.Children)
					{
						if (visibilityChangedList != null)
						{
							visibilityChangedList.Add(syncItemId);
						}
						fullFolderTree.SetHiddenDueToParent(syncItemId, newValue || this.HiddenDueToParent, visibilityChangedList);
					}
					result = true;
				}
				return result;
			}
Exemple #8
0
        public override void HandleSyncStateVersioning(SyncState syncState)
        {
            if (syncState == null)
            {
                throw new ArgumentNullException("syncState");
            }
            if (syncState.BackendVersion == null)
            {
                return;
            }
            bool flag = true;

            if (syncState.BackendVersion < 2 || syncState.BackendVersion > this.Version)
            {
                flag = false;
            }
            else if (syncState.BackendVersion.Value != this.Version)
            {
                switch (syncState.BackendVersion.Value)
                {
                case 2:
                    FolderTree.BuildFolderTree(syncState.StoreObject.Session as MailboxSession, syncState);
                    break;

                case 3:
                    break;

                default:
                    flag = false;
                    break;
                }
            }
            if (!flag)
            {
                syncState.HandleCorruptSyncState();
            }
        }
 // Token: 0x060008C8 RID: 2248 RVA: 0x00034B7C File Offset: 0x00032D7C
 protected override void ProcessCommand(FolderCommand.FolderRequest folderRequest, XmlDocument doc)
 {
     if (FolderCommand.IsEmptyOrWhiteSpacesOnly(folderRequest.DisplayName))
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "EmptyDisplayName");
         AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, base.ConstructErrorXml(StatusCode.Sync_NotificationGUID), null, false);
         throw ex;
     }
     using (Folder folder = Folder.Create(base.MailboxSession, folderRequest.ParentId, StoreObjectType.Folder))
     {
         string namespaceURI = doc.DocumentElement.NamespaceURI;
         folder.DisplayName = folderRequest.DisplayName;
         string classNameFromType = AirSyncUtility.GetClassNameFromType(folderRequest.Type);
         if (classNameFromType == null)
         {
             AirSyncPermanentException ex;
             if (!this.IsValidSpecialFolderType(base.Version, folderRequest.Type))
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidFolderType");
                 ex = new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, base.ConstructErrorXml(StatusCode.Sync_NotificationGUID), null, false);
                 throw ex;
             }
             base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "CreateOfSpecialFolder");
             ex = new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, base.ConstructErrorXml(StatusCode.Sync_InvalidSyncKey), null, false);
             throw ex;
         }
         else
         {
             folder.ClassName = classNameFromType;
             try
             {
                 folder.Save();
                 folder.Load();
             }
             catch (ObjectExistedException innerException)
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FolderExistsOnCreate");
                 AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), innerException, false);
                 throw ex;
             }
             catch (InvalidOperationException innerException2)
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidOperationOnCreate");
                 AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, base.ConstructErrorXml(StatusCode.Sync_NotificationGUID), innerException2, false);
                 throw ex;
             }
             catch (ObjectValidationException innerException3)
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ObjectValidationOnCreate");
                 AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), innerException3, false);
                 throw ex;
             }
             base.FolderHierarchySync.RecordClientOperation(folder.Id.ObjectId, ChangeType.Add, folder);
             folderRequest.RecoverySyncKey = folderRequest.SyncKey;
             folderRequest.SyncKey         = base.GetNextNumber(folderRequest.SyncKey);
             base.SyncStateChanged         = true;
             base.FolderHierarchySyncState[CustomStateDatumType.SyncKey]         = new Int32Data(folderRequest.SyncKey);
             base.FolderHierarchySyncState[CustomStateDatumType.RecoverySyncKey] = new Int32Data(folderRequest.RecoverySyncKey);
             XmlNode xmlNode = doc.CreateElement("Status", namespaceURI);
             xmlNode.InnerText = "1";
             XmlNode xmlNode2 = doc.CreateElement("SyncKey", namespaceURI);
             xmlNode2.InnerText = folderRequest.SyncKey.ToString(CultureInfo.InvariantCulture);
             XmlNode         xmlNode3        = doc.CreateElement("ServerId", namespaceURI);
             FolderIdMapping folderIdMapping = (FolderIdMapping)base.FolderIdMappingSyncState[CustomStateDatumType.IdMapping];
             ISyncItemId     syncItemId      = MailboxSyncItemId.CreateForNewItem(folder.Id.ObjectId);
             xmlNode3.InnerText = folderIdMapping.Add(syncItemId);
             folderIdMapping.CommitChanges();
             doc.DocumentElement.AppendChild(xmlNode);
             doc.DocumentElement.AppendChild(xmlNode2);
             doc.DocumentElement.AppendChild(xmlNode3);
             FolderTree folderTree = (FolderTree)base.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
             folderTree.AddFolder(syncItemId);
             if (!base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root).Equals(folderRequest.ParentId))
             {
                 ISyncItemId parentId = MailboxSyncItemId.CreateForNewItem(folderRequest.ParentId);
                 folderTree.LinkChildToParent(parentId, syncItemId);
             }
             base.ProtocolLogger.IncrementValue("F", PerFolderProtocolLoggerData.ClientAdds);
         }
     }
 }
Exemple #10
0
        protected override void ProcessCommand(FolderCommand.FolderRequest folderRequest, XmlDocument doc)
        {
            DefaultFolderType defaultFolderType = base.MailboxSession.IsDefaultFolderType(folderRequest.ServerId);

            if (defaultFolderType != DefaultFolderType.None)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "UpdateOfDefaultFolder");
                AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), null, false);
                throw ex;
            }
            if (FolderCommand.IsEmptyOrWhiteSpacesOnly(folderRequest.DisplayName))
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "UpdateOfEmptyDisplayName");
                AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, base.ConstructErrorXml(StatusCode.Sync_NotificationGUID), null, false);
                throw ex;
            }
            string namespaceURI = doc.DocumentElement.NamespaceURI;

            using (Folder folder = Folder.Bind(base.MailboxSession, folderRequest.ServerId, null))
            {
                try
                {
                    this.ProcessFolderNameChange(folderRequest, folder);
                    if (folderRequest.ParentId.Equals(folderRequest.ServerId))
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "UpdateUnderSelf");
                        AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), null, false);
                        throw ex;
                    }
                    if (!folderRequest.ParentId.Equals(folder.ParentId))
                    {
                        using (Folder.Bind(base.MailboxSession, folderRequest.ParentId, null))
                        {
                        }
                        AggregateOperationResult aggregateOperationResult = base.MailboxSession.Move(folderRequest.ParentId, new StoreObjectId[]
                        {
                            folderRequest.ServerId
                        });
                        if (aggregateOperationResult.OperationResult == OperationResult.Failed)
                        {
                            AirSyncPermanentException ex;
                            if (aggregateOperationResult.GroupOperationResults != null && aggregateOperationResult.GroupOperationResults[0] != null && aggregateOperationResult.GroupOperationResults[0].Exception is ObjectExistedException)
                            {
                                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "UpdateOfNonExistentFolder");
                                ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), null, false);
                                throw ex;
                            }
                            base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "UpdateFailed");
                            ex = new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, base.ConstructErrorXml(StatusCode.Sync_ClientServerConversion), null, false);
                            throw ex;
                        }
                    }
                    FolderTree    folderTree      = (FolderTree)base.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
                    ISyncItemId   syncItemId      = MailboxSyncItemId.CreateForNewItem(folderRequest.ServerId);
                    StoreObjectId defaultFolderId = base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root);
                    ISyncItemId   parentId        = folderTree.GetParentId(syncItemId);
                    if (parentId != null)
                    {
                        folderTree.UnlinkChild(parentId, syncItemId);
                    }
                    if (!defaultFolderId.Equals(folderRequest.ParentId))
                    {
                        ISyncItemId parentId2 = MailboxSyncItemId.CreateForNewItem(folderRequest.ParentId);
                        folderTree.LinkChildToParent(parentId2, syncItemId);
                    }
                }
                catch (ObjectNotFoundException innerException)
                {
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ObjectNotFoundOnUpdate");
                    AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ServerError, base.ConstructErrorXml(StatusCode.Sync_ServerError), innerException, false);
                    throw ex;
                }
                catch (ObjectExistedException innerException2)
                {
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ObjectExistedOnUpdate");
                    AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), innerException2, false);
                    throw ex;
                }
                base.FolderHierarchySync.RecordClientOperation(folder.Id.ObjectId, ChangeType.Change, folder);
                folderRequest.RecoverySyncKey = folderRequest.SyncKey;
                folderRequest.SyncKey         = base.GetNextNumber(folderRequest.SyncKey);
                base.SyncStateChanged         = true;
                base.FolderHierarchySyncState[CustomStateDatumType.SyncKey]         = new Int32Data(folderRequest.SyncKey);
                base.FolderHierarchySyncState[CustomStateDatumType.RecoverySyncKey] = new Int32Data(folderRequest.RecoverySyncKey);
                base.ProtocolLogger.IncrementValue("F", PerFolderProtocolLoggerData.ClientChanges);
            }
            XmlNode xmlNode = doc.CreateElement("Status", namespaceURI);

            xmlNode.InnerText = "1";
            XmlNode xmlNode2 = doc.CreateElement("SyncKey", namespaceURI);

            xmlNode2.InnerText = folderRequest.SyncKey.ToString(CultureInfo.InvariantCulture);
            doc.DocumentElement.AppendChild(xmlNode);
            doc.DocumentElement.AppendChild(xmlNode2);
        }
 // Token: 0x06000886 RID: 2182 RVA: 0x00032504 File Offset: 0x00030704
 internal override Command.ExecutionState ExecuteCommand()
 {
     try
     {
         FolderCommand.FolderRequest folderRequest = this.ParseRequest();
         XmlDocument xmlDocument = new SafeXmlDocument();
         XmlNode     newChild    = xmlDocument.CreateElement(base.XmlRequest.LocalName, base.XmlRequest.NamespaceURI);
         xmlDocument.AppendChild(newChild);
         try
         {
             base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.ClientSyncKey, folderRequest.SyncKey);
             this.LoadSyncState(folderRequest.SyncKey);
             this.ConvertSyncIdsToXsoIds(folderRequest);
             this.folderHierarchySync = this.folderHierarchySyncState.GetFolderHierarchySync(new ChangeTrackingDelegate(FolderCommand.ComputeChangeTrackingHash));
             if (folderRequest.SyncKey != 0)
             {
                 if (!this.folderHierarchySyncState.Contains(CustomStateDatumType.SyncKey))
                 {
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "I");
                     base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "RecoveryNotAllowed");
                     throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
                 }
                 int data  = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.SyncKey, -1);
                 int data2 = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.RecoverySyncKey, -1);
                 if (folderRequest.SyncKey != data && (!this.allowRecovery || folderRequest.SyncKey != data2))
                 {
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "I");
                     base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidSyncKey");
                     throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
                 }
                 FolderIdMapping folderIdMapping = (FolderIdMapping)this.folderIdMappingSyncState[CustomStateDatumType.IdMapping];
                 if (folderRequest.SyncKey == data)
                 {
                     AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Committing folderIdMapping.");
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "S");
                     folderIdMapping.CommitChanges();
                     this.folderHierarchySync.AcknowledgeServerOperations();
                 }
                 else
                 {
                     AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Clearing changes on folderIdMapping.");
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "R");
                     folderIdMapping.ClearChanges();
                     this.folderIdMappingSyncState[CustomStateDatumType.FullFolderTree] = this.folderIdMappingSyncState[CustomStateDatumType.RecoveryFullFolderTree];
                 }
             }
             else
             {
                 base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "F");
                 base.SendServerUpgradeHeader = true;
             }
             this.ProcessCommand(folderRequest, xmlDocument);
             if (this.folderHierarchySyncState != null)
             {
                 int data3 = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.AirSyncProtocolVersion, -1);
                 if (base.Version > data3)
                 {
                     AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, this, "Changing sync state protocol version from {0} to {1}.", data3, base.Version);
                     this.folderHierarchySyncState[CustomStateDatumType.AirSyncProtocolVersion] = new Int32Data(base.Version);
                     this.syncStateChanged = true;
                 }
             }
             if (this.syncStateChanged)
             {
                 if (this.folderHierarchySyncState != null)
                 {
                     this.folderHierarchySyncState.CustomVersion = new int?(5);
                     this.folderHierarchySyncState.Commit();
                 }
                 if (this.folderIdMappingSyncState != null)
                 {
                     FolderIdMapping folderIdMapping2 = this.folderIdMappingSyncState[CustomStateDatumType.IdMapping] as FolderIdMapping;
                     FolderTree      folderTree       = this.folderIdMappingSyncState[CustomStateDatumType.FullFolderTree] as FolderTree;
                     if (folderIdMapping2.IsDirty || folderTree.IsDirty)
                     {
                         this.folderIdMappingSyncState.Commit();
                     }
                 }
             }
         }
         finally
         {
             if (this.folderIdMappingSyncState != null)
             {
                 this.folderIdMappingSyncState.Dispose();
             }
             if (this.folderHierarchySyncState != null)
             {
                 this.folderHierarchySyncState.Dispose();
             }
         }
         base.XmlResponse = xmlDocument;
     }
     catch (ObjectNotFoundException innerException)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FolderNotFound");
         throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, this.ConstructErrorXml(StatusCode.Sync_ProtocolError), innerException, false);
     }
     catch (CorruptDataException ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "CorruptData");
         AirSyncDiagnostics.TraceDebug <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "Corrupted data found, replacing error with wrongsynckey error to force client to refresh.\r\n{0}", arg);
         throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), ex, false);
     }
     catch (QuotaExceededException)
     {
         throw;
     }
     catch (StoragePermanentException ex2)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, ex2.GetType().ToString());
         throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, this.ConstructErrorXml(StatusCode.Sync_ClientServerConversion), ex2, false);
     }
     catch (ArgumentException innerException2)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ArgumentException");
         throw new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, this.ConstructErrorXml(StatusCode.Sync_NotificationGUID), innerException2, false);
     }
     catch (FormatException innerException3)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FormatException");
         throw new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, this.ConstructErrorXml(StatusCode.Sync_NotificationGUID), innerException3, false);
     }
     return(Command.ExecutionState.Complete);
 }
        // Token: 0x060008A6 RID: 2214 RVA: 0x00033214 File Offset: 0x00031414
        protected override void ProcessCommand(FolderCommand.FolderRequest folderRequest, XmlDocument doc)
        {
            bool    flag         = folderRequest.SyncKey == 0;
            string  namespaceURI = doc.DocumentElement.NamespaceURI;
            XmlNode xmlNode      = doc.CreateElement("Status", namespaceURI);

            doc.DocumentElement.AppendChild(xmlNode);
            xmlNode.InnerText = "1";
            base.DeviceSyncStateMetadata.RecordLatestFolderHierarchySnapshot(base.MailboxSession, base.Context);
            HierarchySyncOperations hierarchySyncOperations = base.FolderHierarchySync.EnumerateServerOperations(base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root), false);

            if (hierarchySyncOperations.Count > 0)
            {
                folderRequest.RecoverySyncKey = folderRequest.SyncKey;
                folderRequest.SyncKey         = base.GetNextNumber(folderRequest.SyncKey);
                base.FolderHierarchySyncState[CustomStateDatumType.SyncKey] = new Int32Data(folderRequest.SyncKey);
                if (folderRequest.RecoverySyncKey > 0)
                {
                    base.FolderHierarchySyncState[CustomStateDatumType.RecoverySyncKey]        = new Int32Data(folderRequest.RecoverySyncKey);
                    base.FolderIdMappingSyncState[CustomStateDatumType.RecoveryFullFolderTree] = base.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
                }
                base.SyncStateChanged = true;
            }
            XmlNode xmlNode2 = doc.CreateElement("SyncKey", namespaceURI);

            doc.DocumentElement.AppendChild(xmlNode2);
            xmlNode2.InnerText = folderRequest.SyncKey.ToString(CultureInfo.InvariantCulture);
            Dictionary <ISyncItemId, XmlNode> dictionary = new Dictionary <ISyncItemId, XmlNode>(flag ? (hierarchySyncOperations.Count + FolderSyncCommand.virtualFolders.Length) : hierarchySyncOperations.Count);
            XmlNode xmlNode3 = doc.CreateElement("Changes", namespaceURI);

            doc.DocumentElement.AppendChild(xmlNode3);
            StoreObjectId         defaultFolderId = base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Root);
            FolderIdMapping       folderIdMapping = (FolderIdMapping)base.FolderIdMappingSyncState[CustomStateDatumType.IdMapping];
            FolderTree            folderTree      = (FolderTree)base.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];
            HashSet <ISyncItemId> hashSet         = new HashSet <ISyncItemId>();
            HashSet <ISyncItemId> hashSet2        = new HashSet <ISyncItemId>();
            bool flag2 = false;

            AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). changes.Count={0}", hierarchySyncOperations.Count);
            for (int i = 0; i < hierarchySyncOperations.Count; i++)
            {
                HierarchySyncOperation hierarchySyncOperation = hierarchySyncOperations[i];
                MailboxSyncItemId      mailboxSyncItemId      = MailboxSyncItemId.CreateForNewItem(hierarchySyncOperation.ItemId);
                MailboxSyncItemId      mailboxSyncItemId2     = MailboxSyncItemId.CreateForNewItem(hierarchySyncOperation.ParentId);
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). change# {0}. changeType{1}. Processing folder: {2} with parent {3}", new object[]
                {
                    i,
                    Enum.GetName(typeof(ChangeType), hierarchySyncOperation.ChangeType),
                    mailboxSyncItemId,
                    mailboxSyncItemId2
                });
                string parentShortId = null;
                bool   flag3         = false;
                switch (hierarchySyncOperation.ChangeType)
                {
                case ChangeType.Add:
                {
                    if (folderTree.AddFolder(mailboxSyncItemId))
                    {
                        AirSyncDiagnostics.TraceDebug <MailboxSyncItemId, MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Adding folder {0} with Parent {1} to Full Folder Tree.", mailboxSyncItemId, mailboxSyncItemId2);
                    }
                    folderTree.SetOwner(mailboxSyncItemId, hierarchySyncOperation.Owner);
                    folderTree.SetPermissions(mailboxSyncItemId, hierarchySyncOperation.Permissions);
                    if (!defaultFolderId.Equals(mailboxSyncItemId2.NativeId))
                    {
                        if (folderTree.AddFolder(mailboxSyncItemId2))
                        {
                            AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Adding parent folder {0} to Full Folder Tree.", mailboxSyncItemId2);
                            hashSet2.Add(mailboxSyncItemId2);
                        }
                        folderTree.LinkChildToParent(mailboxSyncItemId2, mailboxSyncItemId, hashSet);
                        parentShortId = (folderIdMapping.Contains(mailboxSyncItemId2) ? folderIdMapping[mailboxSyncItemId2] : folderIdMapping.Add(mailboxSyncItemId2));
                        flag3         = folderTree.IsHidden(mailboxSyncItemId2);
                    }
                    bool sharedFolder = folderTree.IsSharedFolder(mailboxSyncItemId);
                    AirSyncUtility.GetAirSyncFolderType(base.MailboxSession, sharedFolder, hierarchySyncOperation.ItemId, hierarchySyncOperation.ClassName);
                    if (!this.IsFolderVisible(hierarchySyncOperation, flag3))
                    {
                        folderTree.SetHidden(mailboxSyncItemId, true, hashSet);
                        AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Added folder {0} is set to hidden and will not be sent to client.", mailboxSyncItemId);
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Added folder {0} will be sent to client. Details next...", mailboxSyncItemId);
                        string text = folderIdMapping.Contains(mailboxSyncItemId) ? folderIdMapping[mailboxSyncItemId] : folderIdMapping.Add(mailboxSyncItemId);
                        dictionary[mailboxSyncItemId] = this.CreateChangeNode(doc, namespaceURI, hierarchySyncOperation.ChangeType, folderTree, mailboxSyncItemId, hierarchySyncOperation, text, parentShortId, ref flag2);
                        hashSet2.Add(mailboxSyncItemId);
                    }
                    break;
                }

                case ChangeType.Change:
                    if (!folderTree.Contains(mailboxSyncItemId))
                    {
                        AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "Could not find folder {0} with item ID {1} in the full folder tree, skipping...  FolderIdMappingSyncState backend version is {2} and current version is {3}.", new object[]
                        {
                            hierarchySyncOperation.DisplayName,
                            mailboxSyncItemId,
                            base.FolderIdMappingSyncState.BackendVersion,
                            base.FolderIdMappingSyncState.Version
                        });
                    }
                    else
                    {
                        if (!defaultFolderId.Equals(mailboxSyncItemId2.NativeId))
                        {
                            if (folderTree.AddFolder(mailboxSyncItemId2))
                            {
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId, MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Changed folder {0} has new parent {1} to be sent to client.", mailboxSyncItemId, mailboxSyncItemId2);
                                hashSet2.Add(mailboxSyncItemId2);
                            }
                            flag3 = folderTree.IsHidden(mailboxSyncItemId2);
                            if (!flag3)
                            {
                                parentShortId = (folderIdMapping.Contains(mailboxSyncItemId2) ? folderIdMapping[mailboxSyncItemId2] : folderIdMapping.Add(mailboxSyncItemId2));
                            }
                        }
                        ISyncItemId parentId = folderTree.GetParentId(mailboxSyncItemId);
                        if (!mailboxSyncItemId2.Equals(parentId))
                        {
                            if (parentId != null)
                            {
                                folderTree.UnlinkChild(parentId, mailboxSyncItemId);
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId, ISyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Removing changed folder {0} as child from old parent {1} in Full Folder Tree.", mailboxSyncItemId, parentId);
                            }
                            if (!defaultFolderId.Equals(mailboxSyncItemId2.NativeId))
                            {
                                folderTree.LinkChildToParent(mailboxSyncItemId2, mailboxSyncItemId, hashSet);
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId, MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Adding changed folder {0} as child to new parent {1} in Full Folder Tree.", mailboxSyncItemId, mailboxSyncItemId2);
                            }
                            else
                            {
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Changed folder {0} now has no parent in Full Folder Tree.", mailboxSyncItemId);
                            }
                        }
                        folderTree.SetOwner(mailboxSyncItemId, hierarchySyncOperation.Owner);
                        folderTree.SetPermissions(mailboxSyncItemId, hierarchySyncOperation.Permissions);
                        bool sharedFolder = folderTree.IsSharedFolder(mailboxSyncItemId);
                        AirSyncUtility.GetAirSyncFolderType(base.MailboxSession, sharedFolder, hierarchySyncOperation.ItemId, hierarchySyncOperation.ClassName);
                        if (!this.IsFolderVisible(hierarchySyncOperation, flag3))
                        {
                            folderTree.SetHidden(mailboxSyncItemId, true, hashSet);
                            if (folderIdMapping.Contains(mailboxSyncItemId))
                            {
                                string text = folderIdMapping[mailboxSyncItemId];
                                folderIdMapping.Delete(new ISyncItemId[]
                                {
                                    mailboxSyncItemId
                                });
                                dictionary[mailboxSyncItemId] = this.CreateDeleteNode(doc, namespaceURI, text);
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Changed folder {0} is now hidden; deleting from client.", mailboxSyncItemId);
                            }
                        }
                        else
                        {
                            folderTree.SetHidden(mailboxSyncItemId, false, hashSet);
                            string text;
                            if (!folderIdMapping.Contains(mailboxSyncItemId))
                            {
                                text = folderIdMapping.Add(mailboxSyncItemId);
                                hierarchySyncOperation.ChangeType = ChangeType.Add;
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Changed folder {0} is now visible; adding to client.", mailboxSyncItemId);
                            }
                            else
                            {
                                text = folderIdMapping[mailboxSyncItemId];
                                AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Changed folder {0} is being sent to client.", mailboxSyncItemId);
                            }
                            dictionary[mailboxSyncItemId] = this.CreateChangeNode(doc, namespaceURI, hierarchySyncOperation.ChangeType, folderTree, mailboxSyncItemId, hierarchySyncOperation, text, parentShortId, ref flag2);
                        }
                    }
                    break;

                case ChangeType.Delete:
                    if (folderTree.Contains(mailboxSyncItemId))
                    {
                        if (folderIdMapping.Contains(mailboxSyncItemId))
                        {
                            string text = folderIdMapping[mailboxSyncItemId];
                            dictionary[mailboxSyncItemId] = this.CreateDeleteNode(doc, namespaceURI, text);
                            AirSyncDiagnostics.TraceDebug <MailboxSyncItemId, string>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Deleted folder {0} with Short Id {1} is being sent to client.", mailboxSyncItemId, text);
                        }
                        folderTree.RemoveFolderAndChildren(mailboxSyncItemId, folderIdMapping);
                        AirSyncDiagnostics.TraceDebug <MailboxSyncItemId>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Deleted folder {0} and children are being removed from Full Folder Tree.", mailboxSyncItemId);
                    }
                    break;
                }
            }
            if (flag)
            {
                this.AddVirtualFolders(doc, namespaceURI, dictionary);
            }
            using (HashSet <ISyncItemId> .Enumerator enumerator = hashSet.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ISyncItemId itemId = enumerator.Current;
                    if (folderTree.IsHidden(itemId))
                    {
                        dictionary.Remove(itemId);
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.ProcessCommand(). Removing hidden folder {0} from list of changes being sent to client.", new object[]
                        {
                            itemId.NativeId
                        });
                        if (folderIdMapping.Contains(itemId))
                        {
                            if (!hashSet2.Contains(itemId))
                            {
                                dictionary[itemId] = this.CreateDeleteNode(doc, namespaceURI, folderIdMapping[itemId]);
                            }
                            folderIdMapping.Delete(new ISyncItemId[]
                            {
                                itemId
                            });
                        }
                    }
                    else if (!dictionary.ContainsKey(itemId))
                    {
                        HierarchySyncOperation hierarchySyncOperation2 = (from change in hierarchySyncOperations
                                                                          where change.ItemId == (StoreObjectId)itemId.NativeId
                                                                          select change).First <HierarchySyncOperation>();
                        string parentShortId2 = folderIdMapping[folderTree.GetParentId(itemId)];
                        if (folderIdMapping.Contains(itemId))
                        {
                            flag2 = true;
                            AirSyncDiagnostics.TraceError <string, object>(ExTraceGlobals.RequestsTracer, this, "Hidden folder {0} with item ID {1} is in folderIdMapping table.", hierarchySyncOperation2.DisplayName, itemId.NativeId);
                        }
                        else
                        {
                            string shortId = folderIdMapping.Add(itemId);
                            dictionary[itemId] = this.CreateChangeNode(doc, namespaceURI, ChangeType.Add, folderTree, itemId, hierarchySyncOperation2, shortId, parentShortId2, ref flag2);
                        }
                    }
                }
            }
            XmlNode xmlNode4 = doc.CreateElement("Count", namespaceURI);

            xmlNode4.InnerText = dictionary.Count.ToString(CultureInfo.InvariantCulture);
            xmlNode3.AppendChild(xmlNode4);
            foreach (XmlNode newChild in dictionary.Values)
            {
                xmlNode3.AppendChild(newChild);
            }
            if (flag2)
            {
                Exception exception = new InvalidOperationException("FolderSyncCommand.ProcessCommand found errors.  See traces above.");
                if (GlobalSettings.SendWatsonReport)
                {
                    AirSyncDiagnostics.SendWatson(exception, false);
                }
            }
        }
        // Token: 0x060008A9 RID: 2217 RVA: 0x00033BC0 File Offset: 0x00031DC0
        private XmlNode CreateChangeNode(XmlDocument doc, string nameSpaceUri, ChangeType changeType, FolderTree fullFolderTree, ISyncItemId mailboxSyncId, HierarchySyncOperation op, string shortId, string parentShortId, ref bool sendWatson)
        {
            XmlNode xmlNode = null;

            switch (changeType)
            {
            case ChangeType.Add:
                xmlNode = doc.CreateElement("Add", nameSpaceUri);
                base.ProtocolLogger.IncrementValue("F", PerFolderProtocolLoggerData.ServerAdds);
                break;

            case ChangeType.Change:
                xmlNode = doc.CreateElement("Update", nameSpaceUri);
                base.ProtocolLogger.IncrementValue("F", PerFolderProtocolLoggerData.ServerChanges);
                break;
            }
            AirSyncDiagnostics.TraceDebug <string, string, string>(ExTraceGlobals.AlgorithmTracer, this, "FolderSyncCommand.CreateChangeNode(). <{0}> node for folder {1} with short ID {2} will be sent to client.", Enum.GetName(typeof(ChangeType), changeType), op.DisplayName, shortId);
            XmlNode xmlNode2 = doc.CreateElement("ServerId", nameSpaceUri);

            xmlNode2.InnerText = shortId;
            xmlNode.AppendChild(xmlNode2);
            XmlNode xmlNode3 = doc.CreateElement("ParentId", nameSpaceUri);

            xmlNode3.InnerText = (string.IsNullOrEmpty(parentShortId) ? "0" : parentShortId);
            xmlNode.AppendChild(xmlNode3);
            XmlNode xmlNode4 = doc.CreateElement("DisplayName", nameSpaceUri);

            if (op.DisplayName.Length < 255)
            {
                xmlNode4.InnerText = op.DisplayName;
            }
            else
            {
                using (Folder folder = op.GetFolder())
                {
                    xmlNode4.InnerText = folder.DisplayName;
                }
            }
            xmlNode.AppendChild(xmlNode4);
            XmlNode xmlNode5 = doc.CreateElement("Type", nameSpaceUri);

            xmlNode5.InnerText = AirSyncUtility.GetAirSyncFolderType(base.MailboxSession, fullFolderTree.IsSharedFolder(mailboxSyncId), op.ItemId, op.ClassName);
            xmlNode.AppendChild(xmlNode5);
            SyncPermissions permissions = fullFolderTree.GetPermissions(mailboxSyncId);

            if (permissions != SyncPermissions.FullAccess)
            {
                if (base.Version < 140)
                {
                    sendWatson = true;
                    AirSyncDiagnostics.TraceError <string, SyncPermissions>(ExTraceGlobals.RequestsTracer, this, "Error trying to change folder {0} with permissions {1}.  Permissions must be FullAccess.", op.DisplayName, permissions);
                }
                else
                {
                    XmlNode xmlNode6 = doc.CreateElement("Permissions", nameSpaceUri);
                    XmlNode xmlNode7 = xmlNode6;
                    int     num      = (int)permissions;
                    xmlNode7.InnerText = num.ToString(CultureInfo.InvariantCulture);
                    xmlNode.AppendChild(xmlNode6);
                }
            }
            if (fullFolderTree.IsSharedFolder(mailboxSyncId))
            {
                string owner = fullFolderTree.GetOwner(mailboxSyncId);
                if (base.Version < 140)
                {
                    sendWatson = true;
                    AirSyncDiagnostics.TraceError <string, string>(ExTraceGlobals.RequestsTracer, this, "Folder {0} with owner {1} is marked as shared in a version lower than 14.", op.DisplayName, owner);
                }
                else
                {
                    XmlNode xmlNode8 = doc.CreateElement("Owner", nameSpaceUri);
                    xmlNode8.InnerText = owner;
                    xmlNode.AppendChild(xmlNode8);
                }
            }
            return(xmlNode);
        }
Exemple #14
0
        public void ParseQueryNode(XmlElement queryNode)
        {
            this.searchCriteriaBuilder = new MailboxSearchCriteriaBuilder(this.context.Request.Culture);
            if (!this.mailboxSession.Mailbox.IsContentIndexingEnabled)
            {
                AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_ContentIndexingNotEnabled, "ContentIndexingNotEnabled", new string[]
                {
                    this.mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn
                });
            }
            this.queryFilter = this.searchCriteriaBuilder.ParseTopLevelClassAndFolders(queryNode, this.mailboxSession.Mailbox.IsContentIndexingEnabled, this.versionFactory, this.context);
            this.schemaCache = this.searchCriteriaBuilder.SchemaCache;
            if (this.FolderIdMappingSyncState == null || !this.FolderIdMappingSyncState.Contains(CustomStateDatumType.FullFolderTree))
            {
                AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.AlgorithmTracer, this, "FolderIdMappingSyncState error: {0}", (this.FolderIdMappingSyncState != null) ? "no FullFolderTree" : "FolderIdMappingSyncState is null");
                throw new SearchNeedToFolderSyncException();
            }
            List <string>   list            = this.searchCriteriaBuilder.FolderScope;
            FolderIdMapping folderIdMapping = (FolderIdMapping)this.FolderIdMappingSyncState[CustomStateDatumType.IdMapping];
            FolderTree      folderTree      = (FolderTree)this.FolderIdMappingSyncState[CustomStateDatumType.FullFolderTree];

            if (list.Count == 0)
            {
                this.folderScope = new StoreId[]
                {
                    this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Root)
                };
            }
            else
            {
                int num = 0;
                this.folderScope = new StoreId[list.Count];
                foreach (string text in list)
                {
                    StoreObjectId storeObjectId = null;
                    if (text == "0")
                    {
                        storeObjectId = this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Root);
                    }
                    else
                    {
                        SyncCollection.CollectionTypes collectionType = AirSyncUtility.GetCollectionType(text);
                        if (collectionType != SyncCollection.CollectionTypes.Mailbox && collectionType != SyncCollection.CollectionTypes.Unknown)
                        {
                            throw new AirSyncPermanentException(StatusCode.InvalidCombinationOfIDs, false)
                                  {
                                      ErrorStringForProtocolLogger = "BadIdComboInMbxSearch"
                                  };
                        }
                        MailboxSyncItemId mailboxSyncItemId = folderIdMapping[text] as MailboxSyncItemId;
                        if (mailboxSyncItemId != null)
                        {
                            if (folderTree.IsSharedFolder(mailboxSyncItemId))
                            {
                                throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false)
                                      {
                                          ErrorStringForProtocolLogger = "AccessDeniedInMbxSearch"
                                      };
                            }
                            storeObjectId = (StoreObjectId)mailboxSyncItemId.NativeId;
                        }
                    }
                    if (storeObjectId == null)
                    {
                        throw new SearchNeedToFolderSyncException();
                    }
                    try
                    {
                        using (Folder.Bind(this.mailboxSession, storeObjectId))
                        {
                        }
                    }
                    catch (ObjectNotFoundException)
                    {
                        throw new SearchNeedToFolderSyncException();
                    }
                    this.folderScope[num++] = storeObjectId;
                }
            }
            foreach (object obj in folderTree)
            {
                ISyncItemId       syncItemId         = (ISyncItemId)obj;
                MailboxSyncItemId mailboxSyncItemId2 = syncItemId as MailboxSyncItemId;
                if (mailboxSyncItemId2 != null && (folderTree.IsHidden(syncItemId) || folderTree.IsSharedFolder(syncItemId)))
                {
                    this.searchCriteriaBuilder.ExcludedFolders.Add((StoreObjectId)mailboxSyncItemId2.NativeId);
                }
            }
            if (this.mailboxSchemaOptions.HasBodyPartPreferences)
            {
                if (this.searchCriteriaBuilder.Conversation == null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "<BodyPartPreference> is only supported when search for ConversationId");
                    throw new AirSyncPermanentException(StatusCode.Sync_ObjectNotFound, false)
                          {
                              ErrorStringForProtocolLogger = "BodyPartNotSupported"
                          };
                }
                this.searchCriteriaBuilder.Conversation.LoadBodySummaries();
            }
        }
Exemple #15
0
 public void AddChild(ISyncItemId childId, FolderTree fullFolderTree, HashSet <ISyncItemId> visibilityChangedList)
 {
     this.Children.Add(childId);
     fullFolderTree.SetHiddenDueToParent(childId, this.Hidden, visibilityChangedList);
 }