Example #1
0
 protected int GetItemEstimate(EasConnectionWrapper easConnectionWrapper, EasSyncOptions options)
 {
     MrsTracer.Provider.Function("EasFolder.GetItemEstimate: SyncKey={0}", new object[]
     {
         options.SyncKey
     });
     return(easConnectionWrapper.GetCountOfItemsToSync(base.ServerId, options));
 }
        internal int GetCountOfItemsToSync(string folderId, EasSyncOptions options)
        {
            GetItemEstimateRequest  getItemEstimateRequest = EasRequestGenerator.CreateEstimateRequest(options.SyncKey, folderId, options.RecentOnly);
            GetItemEstimateResponse itemEstimate           = this.GetItemEstimate(getItemEstimateRequest);

            if (itemEstimate.Estimate == null)
            {
                return(0);
            }
            return(itemEstimate.Estimate.Value);
        }
Example #3
0
        private EasSyncResult ProcessPrimingSync(EasConnectionWrapper easConnection, EasSyncOptions options, SyncResponse syncResponse)
        {
            bool   flag;
            string syncKeyForFolder = this.GetSyncKeyForFolder(syncResponse, out flag);

            if (string.IsNullOrEmpty(syncKeyForFolder))
            {
                throw new EasSyncCouldNotFindFolderException(base.ServerId);
            }
            options.SyncKey = syncKeyForFolder;
            return(this.SyncMessages(easConnection, options));
        }
        List <MessageRec> ISourceFolder.EnumerateMessagesPaged(int maxPageSize)
        {
            SyncContentsManifestState syncContentsManifestState = base.Mailbox.SyncState[base.EntryId];
            EasFolderSyncState        persistedSyncState        = base.Mailbox.GetPersistedSyncState(syncContentsManifestState);

            if (string.IsNullOrEmpty(this.nextEnumerateKey))
            {
                this.nextEnumerateKey = persistedSyncState.CrawlerSyncKey;
            }
            else
            {
                persistedSyncState.CrawlerSyncKey = this.nextEnumerateKey;
                persistedSyncState.CrawlerDeletions.AddRange(this.pendingDeletes);
                syncContentsManifestState.Data = persistedSyncState.Serialize();
            }
            EasSyncOptions options = new EasSyncOptions
            {
                SyncKey            = this.nextEnumerateKey,
                RecentOnly         = false,
                MaxNumberOfMessage = maxPageSize
            };
            EasSyncResult easSyncResult = base.SyncMessages(base.Mailbox.CrawlerConnectionWrapper, options);

            if (this.estimatedItemCount == 0)
            {
                options.SyncKey         = easSyncResult.SyncKeyRequested;
                this.estimatedItemCount = base.GetItemEstimate(base.Mailbox.CrawlerConnectionWrapper, options);
            }
            if (easSyncResult.MessageRecs.Count == 0)
            {
                return(null);
            }
            this.nextEnumerateKey = easSyncResult.NewSyncKey;
            List <MessageRec> list = new List <MessageRec>(easSyncResult.MessageRecs.Count);

            foreach (MessageRec messageRec in easSyncResult.MessageRecs)
            {
                if (persistedSyncState.ChangesSynced == null || !(messageRec.CreationTimestamp < persistedSyncState.ChangesSynced.Value) || !(messageRec.CreationTimestamp > persistedSyncState.ChangesSynced.Value - EasRequestGenerator.RecentSyncTimeSpan))
                {
                    if (EasSourceFolder.FindMessageCategory(messageRec) == EasMessageCategory.Delete)
                    {
                        this.pendingDeletes.Add(EasMailbox.GetStringId(messageRec.EntryId));
                    }
                    else
                    {
                        list.Add(messageRec);
                    }
                }
            }
            return(list);
        }
        FolderChangesManifest ISourceFolder.EnumerateChanges(EnumerateContentChangesFlags flags, int maxChanges)
        {
            FolderChangesManifest     folderChangesManifest     = base.CreateInitializedChangesManifest();
            SyncContentsManifestState syncContentsManifestState = base.Mailbox.SyncState[base.EntryId];
            EasFolderSyncState        persistedSyncState        = base.Mailbox.GetPersistedSyncState(syncContentsManifestState);
            string         syncKey = persistedSyncState.SyncKey;
            EasSyncOptions options = new EasSyncOptions
            {
                SyncKey            = syncKey,
                RecentOnly         = true,
                MaxNumberOfMessage = 512
            };
            EasSyncResult     easSyncResult = base.SyncMessages(base.Mailbox.EasConnectionWrapper, options);
            List <MessageRec> messageRecs   = easSyncResult.MessageRecs;

            this.EnumerateIncrementalChanges(folderChangesManifest, messageRecs);
            this.MergePendingDeletes(folderChangesManifest, persistedSyncState.CrawlerDeletions);
            persistedSyncState.SyncKey       = easSyncResult.NewSyncKey;
            persistedSyncState.ChangesSynced = new DateTime?(DateTime.UtcNow);
            persistedSyncState.CrawlerDeletions.Clear();
            syncContentsManifestState.Data = persistedSyncState.Serialize();
            return(folderChangesManifest);
        }
Example #6
0
        private EasSyncResult GetMessageRecsAndNewSyncKey(SyncResponse syncResponse, EasSyncOptions options)
        {
            List <MessageRec> list = new List <MessageRec>(options.MaxNumberOfMessage);
            bool   hasMoreAvailable;
            string text = this.GetSyncKeyForFolder(syncResponse, out hasMoreAvailable);

            if (string.IsNullOrEmpty(text))
            {
                text = options.SyncKey;
            }
            else
            {
                list.AddRange(this.CreateMessageRecsForAdditions(syncResponse.Additions));
                list.AddRange(this.CreateMessageRecsForDeletions(syncResponse.Deletions));
                list.AddRange(this.CreateMessageRecsForChanges(syncResponse.Changes));
            }
            return(new EasSyncResult
            {
                MessageRecs = list,
                SyncKeyRequested = options.SyncKey,
                NewSyncKey = text,
                HasMoreAvailable = hasMoreAvailable
            });
        }
Example #7
0
        protected EasSyncResult SyncMessages(EasConnectionWrapper easConnectionWrapper, EasSyncOptions options)
        {
            MrsTracer.Provider.Function("EasFolder.SyncMessages: SyncKey={0}", new object[]
            {
                options.SyncKey
            });
            bool         recentOnly = !EasFolder.IsCalendarFolder(base.EasFolderType) && options.RecentOnly && !EasFolder.IsContactFolder(base.EasFolderType);
            SyncResponse syncResponse;

            try
            {
                syncResponse = easConnectionWrapper.Sync(base.ServerId, options, recentOnly);
            }
            catch (EasRequiresSyncKeyResetException ex)
            {
                MrsTracer.Provider.Error("Encountered RequiresSyncKeyReset error: {0}", new object[]
                {
                    ex
                });
                options.SyncKey = "0";
                syncResponse    = easConnectionWrapper.Sync(base.ServerId, options, recentOnly);
            }
            if (!(options.SyncKey == "0"))
            {
                return(this.GetMessageRecsAndNewSyncKey(syncResponse, options));
            }
            return(this.ProcessPrimingSync(easConnectionWrapper, options, syncResponse));
        }
        internal SyncResponse Sync(string folderId, EasSyncOptions options, bool recentOnly)
        {
            SyncRequest syncRequest = EasRequestGenerator.CreateSyncRequestForAllMessages(options.SyncKey, folderId, options.MaxNumberOfMessage, recentOnly);

            return(this.Sync(syncRequest));
        }