// 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);
        }
 // 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);
         }
     }
 }
예제 #3
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);
        }