protected override void ConvertSyncIdsToXsoIds(FolderCommand.FolderRequest folderRequest)
        {
            SyncCollection.CollectionTypes collectionType = AirSyncUtility.GetCollectionType(folderRequest.SyncServerId);
            if (collectionType != SyncCollection.CollectionTypes.Mailbox && collectionType != SyncCollection.CollectionTypes.Unknown)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteOfVFolder");
                AirSyncPermanentException ex = new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, base.ConstructErrorXml(StatusCode.Sync_InvalidSyncKey), null, false);
                throw ex;
            }
            SyncPermissions syncPermissions;

            folderRequest.ServerId = base.GetXsoFolderId(folderRequest.SyncServerId, out syncPermissions);
            if (folderRequest.ServerId == null)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteOfInvalidId");
                AirSyncPermanentException ex2 = new AirSyncPermanentException(StatusCode.Sync_ProtocolError, base.ConstructErrorXml(StatusCode.Sync_ProtocolError), null, false);
                throw ex2;
            }
            if (syncPermissions == SyncPermissions.FullAccess)
            {
                return;
            }
            if (base.Version < 140)
            {
                throw new InvalidOperationException("Pre-Version 14 device should not see a non-FullAccess folder! Folder Access Level: " + syncPermissions);
            }
            base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeleteOfNonFullAccessFolder");
            AirSyncPermanentException ex3 = new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, base.ConstructErrorXml(StatusCode.Sync_InvalidSyncKey), null, false);

            throw ex3;
        }
Example #2
0
 private void ProcessFolderNameChange(FolderCommand.FolderRequest folderRequest, Folder folder)
 {
     if (folder.DisplayName != folderRequest.DisplayName)
     {
         folder.DisplayName = folderRequest.DisplayName;
         FolderSaveResult folderSaveResult = folder.Save();
         if (folderSaveResult.Exception != null)
         {
             throw folderSaveResult.Exception;
         }
         if (folderSaveResult.OperationResult == OperationResult.PartiallySucceeded)
         {
             if (folderSaveResult.PropertyErrors.Length > 0)
             {
                 PropertyError propertyError = folderSaveResult.PropertyErrors[0];
                 if (propertyError.PropertyErrorCode == PropertyErrorCode.FolderNameConflict)
                 {
                     base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FolderNameConflict");
                     throw new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, base.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), null, false);
                 }
                 this.ThrowUnknownFolderError(propertyError.PropertyErrorCode.ToString());
             }
             this.ThrowUnknownFolderError("PartialSuccessNoPropertyErrors");
         }
         folder.Load();
     }
 }
        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;
        }
 // 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);
         }
     }
 }
Example #5
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: 0x0600088C RID: 2188
 protected abstract void ProcessCommand(FolderCommand.FolderRequest folderRequest, XmlDocument doc);
 // Token: 0x06000889 RID: 2185
 protected abstract void ConvertSyncIdsToXsoIds(FolderCommand.FolderRequest folderRequest);
 // Token: 0x06000887 RID: 2183 RVA: 0x000329D0 File Offset: 0x00030BD0
 internal FolderCommand.FolderRequest ParseRequest()
 {
     FolderCommand.FolderRequest folderRequest = new FolderCommand.FolderRequest();
     foreach (object obj in base.XmlRequest.ChildNodes)
     {
         XmlNode xmlNode = (XmlNode)obj;
         string  name    = xmlNode.Name;
         if (name == "SyncKey")
         {
             string text = xmlNode.InnerText;
             int    num  = text.LastIndexOf('}');
             if (num > 0 && num < text.Length - 1)
             {
                 text = text.Substring(num + 1);
                 this.allowRecovery = false;
             }
             else
             {
                 this.allowRecovery = true;
             }
             int num2;
             if (!int.TryParse(text, out num2))
             {
                 AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Cannot parse the sync key. syncKeyString = {0}.", text);
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "CannotParseSyncKey_" + text);
                 throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
             }
             AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, this, "Folder command sync key is {0}.", num2);
             folderRequest.SyncKey = num2;
             if (folderRequest.SyncKey == 0 && this.CommandXmlTag != "FolderSync")
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ZeroSyncKeyOnNonSync");
                 throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
             }
         }
         else if (name == "ServerId")
         {
             folderRequest.SyncServerId = xmlNode.InnerText;
             AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Folder command sync server Id is {0}.", folderRequest.SyncServerId);
         }
         else if (name == "ParentId")
         {
             folderRequest.SyncParentId = xmlNode.InnerText;
             AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Folder command sync parent Id is {0}.", folderRequest.SyncParentId);
         }
         else if (name == "DisplayName")
         {
             folderRequest.DisplayName = xmlNode.InnerText;
             AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Folder command folder name is {0}.", folderRequest.DisplayName);
             bool flag = true;
             if (string.IsNullOrEmpty(folderRequest.DisplayName))
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NoFolderName");
                 throw new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, this.ConstructErrorXml(StatusCode.Sync_NotificationGUID), null, false);
             }
             foreach (char c in folderRequest.DisplayName.ToCharArray())
             {
                 if (c != '\\' && c != '/')
                 {
                     flag = false;
                     break;
                 }
             }
             if (flag)
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadFolderName");
                 throw new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, this.ConstructErrorXml(StatusCode.Sync_ProtocolVersionMismatch), null, false);
             }
         }
         else
         {
             if (!(name == "Type"))
             {
                 throw new InvalidOperationException("Unkown Folder Command Content");
             }
             folderRequest.Type = xmlNode.InnerText;
             AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Folder command folder type is {0}.", folderRequest.Type);
         }
     }
     return(folderRequest);
 }
 // 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: 0x060008A4 RID: 2212 RVA: 0x00033193 File Offset: 0x00031393
 protected override void ConvertSyncIdsToXsoIds(FolderCommand.FolderRequest folderRequest)
 {
 }