Exemple #1
0
        // Token: 0x0600178C RID: 6028 RVA: 0x0008BC0C File Offset: 0x00089E0C
        private static bool MakeCppCall(SafeHGlobalHandle pciInfo, byte[] bytes, int length, Dictionary <string, StoreObjectType> contentTypeTable, string serverId)
        {
            int num = 0;

            using (SafeHGlobalHandle safeHGlobalHandle = NativeMethods.AllocHGlobal(length))
            {
                Marshal.Copy(bytes, 0, safeHGlobalHandle.DangerousGetHandle(), length);
                switch (contentTypeTable[serverId])
                {
                case StoreObjectType.Folder:
                    num = SyncStateUpgradeHelper.Email_upgrade(safeHGlobalHandle, (uint)length, pciInfo);
                    break;

                case StoreObjectType.CalendarFolder:
                    num = SyncStateUpgradeHelper.Cal_upgrade(safeHGlobalHandle, (uint)length, pciInfo);
                    break;

                case StoreObjectType.ContactsFolder:
                    num = SyncStateUpgradeHelper.Con_upgrade(safeHGlobalHandle, (uint)length, pciInfo);
                    break;

                case StoreObjectType.TasksFolder:
                    num = SyncStateUpgradeHelper.Task_upgrade(safeHGlobalHandle, (uint)length, pciInfo);
                    break;

                default:
                    return(false);
                }
            }
            return(num == 0);
        }
Exemple #2
0
 // 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);
 }
Exemple #3
0
        // Token: 0x0600178D RID: 6029 RVA: 0x0008BCAC File Offset: 0x00089EAC
        private bool CopyAndUpgradeCommon(CommonInfo commonInfo, StoreObjectId storeId, string parentServerId, StoreObjectType type, SafeHGlobalHandle pciInfo)
        {
            Dictionary <string, string> dictionary = null;
            List <TagNode> list = null;
            Dictionary <string, CommonNode> dictionary2 = new Dictionary <string, CommonNode>((int)commonInfo.NumCommonNodes);
            string        text          = null;
            long          num           = 1L;
            TiSyncUpgrade tiSyncUpgrade = new TiSyncUpgrade(parentServerId, this.mailboxSession, this.syncStateStorage);

            try
            {
                dictionary = new Dictionary <string, string>((int)commonInfo.NumMapping);
                if (commonInfo.NumMapping > 0U)
                {
                    MappingNodeStruct mappingNodeStruct = (MappingNodeStruct)Marshal.PtrToStructure(commonInfo.Mappingnodes, typeof(MappingNodeStruct));
                    int num2 = mappingNodeStruct.ShortId.LastIndexOf(':');
                    if (num2 != -1)
                    {
                        text = mappingNodeStruct.ShortId.Substring(0, num2);
                        uint num3;
                        if (uint.TryParse(text, out num3))
                        {
                            this.maxFolderSeen = ((this.maxFolderSeen > (int)num3) ? this.maxFolderSeen : ((int)num3));
                        }
                        else
                        {
                            this.needsParentId.Add(tiSyncUpgrade);
                        }
                    }
                    else
                    {
                        this.needsParentId.Add(tiSyncUpgrade);
                    }
                    for (uint num4 = 0U; num4 < commonInfo.NumMapping; num4 += 1U)
                    {
                        int    num5 = mappingNodeStruct.LongId.LastIndexOf(':');
                        string key;
                        if (num5 != -1)
                        {
                            key = mappingNodeStruct.LongId.Substring(num5 + 1);
                        }
                        else
                        {
                            key = mappingNodeStruct.LongId;
                        }
                        dictionary.Add(key, mappingNodeStruct.ShortId);
                        num2 = mappingNodeStruct.ShortId.LastIndexOf(':');
                        if (num2 != -1)
                        {
                            string s = mappingNodeStruct.ShortId.Substring(num2 + 1);
                            uint   num6;
                            if (uint.TryParse(s, out num6))
                            {
                                num = ((num > (long)((ulong)num6)) ? num : ((long)((ulong)num6)));
                            }
                        }
                        if (num4 < commonInfo.NumMapping - 1U)
                        {
                            mappingNodeStruct = (MappingNodeStruct)Marshal.PtrToStructure(mappingNodeStruct.Next, typeof(MappingNodeStruct));
                        }
                    }
                }
                else
                {
                    this.needsParentId.Add(tiSyncUpgrade);
                }
                CommonNodeStruct commonNodeStruct;
                if (commonInfo.NumCommonNodes > 0U)
                {
                    commonNodeStruct = (CommonNodeStruct)Marshal.PtrToStructure(commonInfo.Nodes, typeof(CommonNodeStruct));
                }
                else
                {
                    commonNodeStruct = default(CommonNodeStruct);
                }
                for (uint num7 = 0U; num7 < commonInfo.NumCommonNodes; num7 += 1U)
                {
                    if (commonNodeStruct.SentToClient == 1)
                    {
                        if (!dictionary.ContainsKey(commonNodeStruct.ServerId))
                        {
                            dictionary.Add(commonNodeStruct.ServerId, commonNodeStruct.ServerId);
                        }
                        ExDateTime endTimeIn = (commonNodeStruct.EndTime == 0L) ? ExDateTime.MinValue : ExDateTime.FromFileTimeUtc(commonNodeStruct.EndTime);
                        dictionary2.Add(commonNodeStruct.ServerId, new CommonNode(commonNodeStruct.ServerId, commonNodeStruct.VersionId, commonNodeStruct.SentToClient, commonNodeStruct.IsEmail, commonNodeStruct.Read, commonNodeStruct.IsCalendar, endTimeIn));
                    }
                    if (num7 < commonInfo.NumCommonNodes - 1U)
                    {
                        commonNodeStruct = (CommonNodeStruct)Marshal.PtrToStructure(commonNodeStruct.Next, typeof(CommonNodeStruct));
                    }
                }
                list = new List <TagNode>((int)commonInfo.NumSupportedTags);
                TagNodeStruct tagNodeStruct = default(TagNodeStruct);
                if (commonInfo.NumSupportedTags > 0U)
                {
                    tagNodeStruct = (TagNodeStruct)Marshal.PtrToStructure(commonInfo.Tagnodes, typeof(TagNodeStruct));
                }
                for (uint num8 = 0U; num8 < commonInfo.NumSupportedTags; num8 += 1U)
                {
                    list.Add(new TagNode(tagNodeStruct.NameSpace, tagNodeStruct.Tag));
                    if (num8 < commonInfo.NumSupportedTags - 1U)
                    {
                        tagNodeStruct = (TagNodeStruct)Marshal.PtrToStructure(tagNodeStruct.Next, typeof(TagNodeStruct));
                    }
                }
            }
            finally
            {
                SyncStateUpgradeHelper.Commoninfo_cleanup(pciInfo);
            }
            uint version;

            switch (commonInfo.Version)
            {
            case 65542U:
                version = 20U;
                break;

            case 65543U:
                version = 21U;
                break;

            case 65544U:
                version = 25U;
                break;

            default:
                version = 10U;
                break;
            }
            return(tiSyncUpgrade.Upgrade(storeId, dictionary2, dictionary, list, type, new string(commonInfo.SyncKey), text, (int)num, version));
        }
Exemple #4
0
        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);
        }