MailboxChangesManifest IHierarchyChangesFetcher.EnumerateHierarchyChanges(SyncHierarchyManifestState hierState, EnumerateHierarchyChangesFlags flags, int maxChanges)
        {
            MailboxChangesManifest mailboxChangesManifest = this.EnumerateChanges(hierState, flags, maxChanges);

            MrsTracer.Provider.Debug("Discovered {0} changed, {1} deleted", new object[]
            {
                mailboxChangesManifest.ChangedFolders.Count,
                mailboxChangesManifest.DeletedFolders.Count
            });
            return(mailboxChangesManifest);
        }
        private MailboxChangesManifest EnumerateChanges(SyncHierarchyManifestState hierState, EnumerateHierarchyChangesFlags flags, int maxChanges)
        {
            MailboxChangesManifest mailboxChangesManifest = new MailboxChangesManifest();

            this.ConfigureMapiManifest(hierState, mailboxChangesManifest, flags, maxChanges);
            ManifestStatus manifestStatus;

            do
            {
                manifestStatus = this.mapiManifest.Synchronize();
            }while (manifestStatus != ManifestStatus.Done && manifestStatus != ManifestStatus.Yielded);
            byte[] idsetGiven;
            byte[] cnsetSeen;
            this.mapiManifest.GetState(out idsetGiven, out cnsetSeen);
            hierState.IdsetGiven = idsetGiven;
            hierState.CnsetSeen  = cnsetSeen;
            return(mailboxChangesManifest);
        }
示例#3
0
        private EasHierarchySyncState GetHierarchySyncState()
        {
            SyncHierarchyManifestState hierarchyData = this.SyncState.HierarchyData;
            EasHierarchySyncState      easHierarchySyncState;

            if (hierarchyData != null && !string.IsNullOrEmpty(hierarchyData.ProviderSyncState) && hierarchyData.ManualSyncData == null)
            {
                MrsTracer.Provider.Debug("EasMailbox.GetHierarchySyncState: Deserialize folder state from hierState.ProviderSyncState", new object[0]);
                easHierarchySyncState = EasHierarchySyncState.Deserialize(hierarchyData.ProviderSyncState);
            }
            else
            {
                MrsTracer.Provider.Debug("EasMailbox.GetHierarchySyncState: Get all the folders from the EAS server", new object[0]);
                string syncKey;
                Add[]  allFoldersOnServer = this.GetAllFoldersOnServer(out syncKey);
                easHierarchySyncState           = new EasHierarchySyncState(allFoldersOnServer, syncKey);
                hierarchyData.ProviderSyncState = easHierarchySyncState.Serialize(false);
            }
            hierarchyData.ManualSyncData = null;
            return(easHierarchySyncState);
        }
        private void ConfigureMapiManifest(SyncHierarchyManifestState syncState, MailboxChangesManifest changes, EnumerateHierarchyChangesFlags flags, int maxChanges)
        {
            if (this.isPagedEnumeration && !flags.HasFlag(EnumerateHierarchyChangesFlags.FirstPage))
            {
                this.callback.InitializeNextPage(changes, maxChanges);
                return;
            }
            this.callback = new ManifestHierarchyCallback(this.isPagedEnumeration);
            this.callback.InitializeNextPage(changes, maxChanges);
            SyncConfigFlags syncConfigFlags = SyncConfigFlags.ManifestHierReturnDeletedEntryIds;

            if (((this.mailbox.ServerVersion >= Server.E14MinVersion && this.mailbox.ServerVersion < Server.E15MinVersion) || (long)this.mailbox.ServerVersion >= ManifestHierarchyChangesFetcher.E15MinVersionSupportsOnlySpecifiedPropsForHierarchy) && !this.mailbox.IsPureMAPI)
            {
                syncConfigFlags |= SyncConfigFlags.OnlySpecifiedProps;
            }
            using (this.mailbox.RHTracker.Start())
            {
                this.mapiManifest = this.mapiFolder.CreateExportHierarchyManifestEx(syncConfigFlags, syncState.IdsetGiven, syncState.CnsetSeen, this.callback, new PropTag[]
                {
                    PropTag.EntryId
                }, null);
            }
        }
        protected override MailboxChangesManifest RunManualHierarchySync(bool catchup, SyncHierarchyManifestState hierState)
        {
            MrsTracer.Provider.Function("EasSourceMailbox.RunManualHierarchySync", new object[0]);
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            EasHierarchySyncState easHierarchySyncState = EasHierarchySyncState.Deserialize(hierState.ProviderSyncState);

            hierState.ProviderSyncState = null;
            EasHierarchySyncState easHierarchySyncState2 = base.RefreshFolderCache();
            EntryIdMap <EasHierarchySyncState.EasFolderData> entryIdMap = new EntryIdMap <EasHierarchySyncState.EasFolderData>();

            foreach (EasHierarchySyncState.EasFolderData easFolderData in easHierarchySyncState.FolderData)
            {
                entryIdMap[EasMailbox.GetEntryId(easFolderData.ServerId)] = easFolderData;
            }
            EntryIdMap <EasHierarchySyncState.EasFolderData> entryIdMap2 = new EntryIdMap <EasHierarchySyncState.EasFolderData>();

            foreach (EasHierarchySyncState.EasFolderData easFolderData2 in easHierarchySyncState2.FolderData)
            {
                entryIdMap2[EasMailbox.GetEntryId(easFolderData2.ServerId)] = easFolderData2;
            }
            MailboxChangesManifest mailboxChangesManifest = new MailboxChangesManifest();

            mailboxChangesManifest.DeletedFolders = new List <byte[]>();
            foreach (byte[] array in entryIdMap.Keys)
            {
                if (!entryIdMap2.ContainsKey(array))
                {
                    mailboxChangesManifest.DeletedFolders.Add(array);
                }
            }
            mailboxChangesManifest.ChangedFolders = new List <byte[]>();
            foreach (KeyValuePair <byte[], EasHierarchySyncState.EasFolderData> keyValuePair in entryIdMap2)
            {
                byte[] key = keyValuePair.Key;
                EasHierarchySyncState.EasFolderData value = keyValuePair.Value;
                EasHierarchySyncState.EasFolderData easFolderData3;
                if (entryIdMap.TryGetValue(key, out easFolderData3))
                {
                    if (easFolderData3.ParentId != value.ParentId || easFolderData3.DisplayName != value.DisplayName)
                    {
                        mailboxChangesManifest.ChangedFolders.Add(key);
                    }
                }
                else
                {
                    mailboxChangesManifest.ChangedFolders.Add(key);
                }
            }
            return(mailboxChangesManifest);
        }
        protected override MailboxChangesManifest DoManifestSync(EnumerateHierarchyChangesFlags flags, int maxChanges, SyncHierarchyManifestState hierState, MapiStore mapiStore)
        {
            MrsTracer.Provider.Function("EasSourceMailbox.DoManifestSync", new object[0]);
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            flags.HasFlag(EnumerateHierarchyChangesFlags.Catchup);
            EasHierarchySyncState easHierarchySyncState = EasHierarchySyncState.Deserialize(hierState.ProviderSyncState);
            string syncKey = easHierarchySyncState.SyncKey;
            string syncKey2;
            IReadOnlyCollection <Add> readOnlyCollection;
            MailboxChangesManifest    folderChangesOnServer = this.GetFolderChangesOnServer(syncKey, out syncKey2, out readOnlyCollection);
            bool flag = false;

            easHierarchySyncState.SyncKey = syncKey2;
            if (folderChangesOnServer.DeletedFolders != null)
            {
                List <Add> list = new List <Add>(folderChangesOnServer.DeletedFolders.Count);
                foreach (Add add in easHierarchySyncState.Folders)
                {
                    foreach (byte[] entryId in folderChangesOnServer.DeletedFolders)
                    {
                        if (StringComparer.Ordinal.Equals(add.ServerId, EasMailbox.GetStringId(entryId)))
                        {
                            list.Add(add);
                            break;
                        }
                    }
                }
                foreach (Add item in list)
                {
                    easHierarchySyncState.Folders.Remove(item);
                    flag = true;
                }
            }
            if (readOnlyCollection != null)
            {
                foreach (Add item2 in readOnlyCollection)
                {
                    easHierarchySyncState.Folders.Add(item2);
                    flag = true;
                }
            }
            hierState.ProviderSyncState = easHierarchySyncState.Serialize(false);
            if (flag)
            {
                base.RefreshFolderCache(easHierarchySyncState);
            }
            return(folderChangesOnServer);
        }