// Token: 0x06001809 RID: 6153 RVA: 0x0008D7B8 File Offset: 0x0008B9B8
        private void UpdateMapping(Dictionary <string, StoreObjectId> mapping)
        {
            FolderIdMapping folderIdMapping = (FolderIdMapping)this.folderIdMappingSyncState[CustomStateDatumType.IdMapping];
            Dictionary <StoreObjectId, FolderStateEntry> data = ((GenericDictionaryData <StoreObjectIdData, StoreObjectId, FolderStateEntry>) this.syncState[SyncStateProp.ClientState]).Data;

            foreach (string text in mapping.Keys)
            {
                StoreObjectId storeObjectId = mapping[text];
                folderIdMapping.Add(MailboxSyncItemId.CreateForNewItem(storeObjectId), text);
                if (data.ContainsKey(storeObjectId))
                {
                    FolderStateEntry folderStateEntry = data[storeObjectId];
                    if (folderStateEntry.ChangeKey.Length == 1 && folderStateEntry.ChangeKey[0] == 1)
                    {
                        folderStateEntry.ChangeTrackingHash = "blah".GetHashCode();
                    }
                    else
                    {
                        folderStateEntry.ChangeTrackingHash = FolderCommand.ComputeChangeTrackingHash(this.mailboxSession, mapping[text], null);
                    }
                }
            }
            folderIdMapping.CommitChanges();
            StoreObjectId defaultFolderId = this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox);

            mapping.Add("EmailSyncFile", defaultFolderId);
            defaultFolderId = this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Contacts);
            mapping.Add("ContactsSyncFile", defaultFolderId);
            defaultFolderId = this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Calendar);
            mapping.Add("CalendarSyncFile", defaultFolderId);
            defaultFolderId = this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Tasks);
            mapping.Add("TasksSyncFile", defaultFolderId);
        }
Пример #2
0
        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);
         }
     }
 }
 // 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);
 }