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: 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); }
// 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: 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); } } }