// Token: 0x06001786 RID: 6022 RVA: 0x0008BA3C File Offset: 0x00089C3C public bool UpgradeSyncState(Dictionary <string, StoreObjectId> mapping, Dictionary <string, StoreObjectType> contentTypeTable, HashSet <string> folderList, MailboxUtility box, StoreObjectId parentStoreObjectId) { using (SafeHGlobalHandle safeHGlobalHandle = NativeMethods.AllocHGlobal(Marshal.SizeOf(typeof(CommonInfo)))) { foreach (string text in mapping.Keys) { StoreObjectId storeId = mapping[text]; if (folderList.Contains(text)) { MemoryStream memoryStream = null; try { memoryStream = box.GetSyncState(parentStoreObjectId, text); if (memoryStream == null) { continue; } if (!SyncStateUpgradeHelper.MakeCppCall(safeHGlobalHandle, memoryStream.GetBuffer(), (int)memoryStream.Length, contentTypeTable, text)) { return(false); } } finally { if (memoryStream != null) { MailboxUtility.ReclaimStream(memoryStream); } } CommonInfo commonInfo = (CommonInfo)Marshal.PtrToStructure(safeHGlobalHandle.DangerousGetHandle(), typeof(CommonInfo)); if (!this.CopyAndUpgradeCommon(commonInfo, storeId, text, contentTypeTable[text], safeHGlobalHandle)) { return(false); } } } this.maxFolderSeen++; foreach (TiSyncUpgrade tiSyncUpgrade in this.needsParentId) { string shortParentId = string.Empty + this.maxFolderSeen; tiSyncUpgrade.UpdateMappingWithParent(shortParentId); this.maxFolderSeen++; } } return(true); }
public static SyncStateUpgradeResult CheckAndUpgradeSyncStates(MailboxSession mailboxSession, DeviceIdentity deviceIdentity) { if (mailboxSession == null) { throw new ArgumentNullException("mailboxSession"); } SafeHGlobalHandle safeHGlobalHandle = SafeHGlobalHandle.InvalidHandle; TiFolderSyncUpgrade tiFolderSyncUpgrade = new TiFolderSyncUpgrade(); tiFolderSyncUpgrade.MailboxSession = mailboxSession; MailboxUtility mailboxUtility = new MailboxUtility(); MailboxUtilityDeviceInfo mailboxUtilityDeviceInfo = null; MemoryStream memoryStream = null; try { mailboxUtility.MailboxSessionForUtility = mailboxSession; mailboxUtilityDeviceInfo = mailboxUtility.GetDevice(deviceIdentity); if (mailboxUtilityDeviceInfo == null) { AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Failed to retrieve device info for: {0}", deviceIdentity); return(SyncStateUpgradeResult.NoTiSyncState); } AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Starting sync state upgrade for device: {0}", deviceIdentity); safeHGlobalHandle = NativeMethods.AllocHGlobal(Marshal.SizeOf(typeof(FolderInfo))); StoreObjectId storeObjectId = null; storeObjectId = mailboxUtilityDeviceInfo.StoreObjectId; HashSet <string> folderList = mailboxUtilityDeviceInfo.FolderList; FolderInfo folderInfo = default(FolderInfo); bool containsFoldersyncFile = false; memoryStream = mailboxUtility.GetSyncState(storeObjectId, "FolderSyncFile"); if (memoryStream != null) { using (SafeHGlobalHandle safeHGlobalHandle2 = NativeMethods.AllocHGlobal((int)memoryStream.Length)) { Marshal.Copy(memoryStream.GetBuffer(), 0, safeHGlobalHandle2.DangerousGetHandle(), (int)memoryStream.Length); int num = SyncStateUpgrader.Foldersync_upgrade(safeHGlobalHandle2, (uint)memoryStream.Length, safeHGlobalHandle); if (num != 0) { throw new AirSyncPermanentException(false); } } folderInfo = (FolderInfo)Marshal.PtrToStructure(safeHGlobalHandle.DangerousGetHandle(), typeof(FolderInfo)); containsFoldersyncFile = true; MailboxUtility.ReclaimStream(memoryStream); memoryStream = null; } Dictionary <string, StoreObjectType> dictionary2; Dictionary <string, StoreObjectId> dictionary = SyncStateUpgrader.UpgradeFolderSyncHierarchySyncState(tiFolderSyncUpgrade, containsFoldersyncFile, folderInfo, deviceIdentity, out dictionary2); if (dictionary == null) { mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true); } else { SyncStateUpgradeHelper syncStateUpgradeHelper = new SyncStateUpgradeHelper(mailboxSession, tiFolderSyncUpgrade.SyncStateStorage); foreach (string key in dictionary2.Keys) { StoreObjectType storeObjectType = dictionary2[key]; if (storeObjectType != StoreObjectType.Folder && storeObjectType != StoreObjectType.ContactsFolder && storeObjectType != StoreObjectType.CalendarFolder && storeObjectType != StoreObjectType.TasksFolder) { AirSyncDiagnostics.TraceDebug <StoreObjectType>(ExTraceGlobals.TiUpgradeTracer, null, "Removing unknown Ti folder of type {0}", storeObjectType); dictionary.Remove(key); } } if (!syncStateUpgradeHelper.UpgradeSyncState(dictionary, dictionary2, folderList, mailboxUtility, storeObjectId)) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.TiUpgradeTracer, null, "Failed to upgrade folders for {0}", mailboxUtilityDeviceInfo.DisplayName); mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true); return(SyncStateUpgradeResult.UpgradeFailed); } tiFolderSyncUpgrade.UpdateLastFolderId(syncStateUpgradeHelper.MaxFolderSeen); } AirSyncDiagnostics.FaultInjectionTracer.TraceTest(3236310333U); } catch (Exception arg) { if (mailboxUtilityDeviceInfo != null) { mailboxUtility.DeleteSyncStateStorage(new DeviceIdentity(mailboxUtilityDeviceInfo.DisplayName, mailboxUtilityDeviceInfo.ParentDisplayName, "AirSync")); } AirSyncDiagnostics.TraceDebug <DeviceIdentity, Exception>(ExTraceGlobals.TiUpgradeTracer, null, "Sync state upgrade failed for device: {0}\r\nException:\r\n{1}", deviceIdentity, arg); throw; } finally { if (memoryStream != null) { MailboxUtility.ReclaimStream(memoryStream); memoryStream = null; } if (mailboxUtilityDeviceInfo != null) { mailboxUtility.DeleteFolder(mailboxUtilityDeviceInfo.StoreObjectId, true); } if (tiFolderSyncUpgrade != null) { tiFolderSyncUpgrade.Close(); tiFolderSyncUpgrade = null; } safeHGlobalHandle.Close(); } AirSyncDiagnostics.TraceDebug <DeviceIdentity>(ExTraceGlobals.TiUpgradeTracer, null, "Finished sync state upgrade for device: {0}", deviceIdentity); return(SyncStateUpgradeResult.UpgradeComplete); }