Ejemplo n.º 1
0
        // Token: 0x0600176A RID: 5994 RVA: 0x0008B5C8 File Offset: 0x000897C8
        internal MemoryStream GetSyncState(StoreObjectId parentFolderId, string syncstateName)
        {
            if (!this.parentIdToSyncstates.ContainsKey(parentFolderId))
            {
                Dictionary <string, StoreObjectId> dictionary = new Dictionary <string, StoreObjectId>();
                using (Folder folder = Folder.Bind(this.MailboxSessionForUtility, parentFolderId))
                {
                    using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, null, MailboxUtility.itemIdSubjectProperties))
                    {
                        object[][] rows = queryResult.GetRows(10000);
                        while (rows != null && rows.Length > 0)
                        {
                            for (int i = 0; i < rows.Length; i++)
                            {
                                string        text = rows[i][1] as string;
                                StoreObjectId storeOrVersionedId = MailboxUtility.GetStoreOrVersionedId(rows[i][0]);
                                if (text != null && storeOrVersionedId != null)
                                {
                                    dictionary[text] = storeOrVersionedId;
                                }
                            }
                            rows = queryResult.GetRows(10000);
                        }
                    }
                }
                this.parentIdToSyncstates[parentFolderId] = dictionary;
            }
            if (!this.parentIdToSyncstates[parentFolderId].ContainsKey(syncstateName))
            {
                return(null);
            }
            StoreObjectId storeId = this.parentIdToSyncstates[parentFolderId][syncstateName];

            using (Item item = Item.Bind(this.MailboxSessionForUtility, storeId))
            {
                IList <AttachmentHandle> handles = item.AttachmentCollection.GetHandles();
                if (handles.Count > 0)
                {
                    using (Attachment attachment = item.AttachmentCollection.Open(handles[0]))
                    {
                        StreamAttachment streamAttachment = attachment as StreamAttachment;
                        if (streamAttachment != null)
                        {
                            using (Stream contentStream = streamAttachment.GetContentStream())
                            {
                                MemoryStream memoryStream = MailboxUtility.bufferPool.Acquire(1000);
                                StreamHelper.CopyStream(contentStream, memoryStream, 0, (int)contentStream.Length);
                                return(memoryStream);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 // Token: 0x0600176C RID: 5996 RVA: 0x0008B7DC File Offset: 0x000899DC
 private static StoreObjectId GetFolderIdByDisplayName(Folder parentFolder, string folderName)
 {
     object[][] array = null;
     using (QueryResult queryResult = parentFolder.FolderQuery(FolderQueryFlags.None, null, MailboxUtility.sortByDisplayName, new PropertyDefinition[]
     {
         FolderSchema.Id
     }))
     {
         ComparisonFilter seekFilter = new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.DisplayName, folderName);
         queryResult.SeekToCondition(SeekReference.OriginBeginning, seekFilter);
         array = queryResult.GetRows(1);
     }
     if (array != null && array.Length == 1)
     {
         return(MailboxUtility.GetStoreOrVersionedId(array[0][0]));
     }
     return(null);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 // Token: 0x06001767 RID: 5991 RVA: 0x0008B328 File Offset: 0x00089528
 public MailboxUtilityDeviceInfo GetDevice(DeviceIdentity deviceIdentity)
 {
     using (Folder folder = Folder.Bind(this.MailboxSessionForUtility, this.MailboxSessionForUtility.GetDefaultFolderId(DefaultFolderType.Configuration)))
     {
         StoreObjectId folderIdByDisplayName = MailboxUtility.GetFolderIdByDisplayName(folder, "Microsoft-Server-ActiveSync");
         if (folderIdByDisplayName == null)
         {
             return(null);
         }
         using (Folder folder2 = Folder.Bind(this.MailboxSessionForUtility, folderIdByDisplayName))
         {
             StoreObjectId folderIdByDisplayName2 = MailboxUtility.GetFolderIdByDisplayName(folder2, deviceIdentity.DeviceType);
             if (folderIdByDisplayName2 == null)
             {
                 return(null);
             }
             using (QueryResult queryResult = folder2.FolderQuery(FolderQueryFlags.DeepTraversal, null, null, MailboxUtility.folderProperties))
             {
                 QueryFilter seekFilter = new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.DisplayName, deviceIdentity.DeviceId);
                 queryResult.SeekToCondition(SeekReference.OriginBeginning, seekFilter);
                 object[]   array = null;
                 object[][] rows;
                 while (array == null && (rows = queryResult.GetRows(10000)) != null && rows.Length > 0)
                 {
                     for (int i = 0; i < rows.Length; i++)
                     {
                         StoreObjectId storeObjectId = rows[i][1] as StoreObjectId;
                         if (storeObjectId.CompareTo(folderIdByDisplayName2) == 0)
                         {
                             array = rows[i];
                             break;
                         }
                     }
                 }
                 if (array != null)
                 {
                     StoreObjectId storeOrVersionedId = MailboxUtility.GetStoreOrVersionedId(array[0]);
                     if (storeOrVersionedId == null)
                     {
                         return(null);
                     }
                     using (Folder folder3 = Folder.Bind(this.MailboxSessionForUtility, storeOrVersionedId))
                     {
                         using (QueryResult queryResult2 = folder3.ItemQuery(ItemQueryType.None, null, null, MailboxUtility.itemSubjectProperty))
                         {
                             object[][]       rows2   = queryResult2.GetRows(10000);
                             HashSet <string> hashSet = new HashSet <string>();
                             while (rows2 != null && rows2.Length > 0)
                             {
                                 for (int j = 0; j < rows2.Length; j++)
                                 {
                                     string text = rows2[j][0] as string;
                                     if (text != null)
                                     {
                                         hashSet.TryAdd(text);
                                     }
                                 }
                                 rows2 = queryResult2.GetRows(10000);
                             }
                             return(new MailboxUtilityDeviceInfo(deviceIdentity.DeviceId, deviceIdentity.DeviceType, storeOrVersionedId, hashSet));
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }