Beispiel #1
0
        /// <summary>
        /// Gets the first page of the desired tally.
        /// </summary>
        /// <param name="firstPageNumber">The page number of the first page.</param>
        /// <param name="quest">The quest being tallied.</param>
        /// <param name="adapter">The forum adapter that handles the quest's thread.</param>
        /// <param name="token">A cancellation token.</param>
        /// <returns>Returns the thread page that starts the tally.</returns>
        private async Task <HtmlDocument?> GetFirstPage(
            int firstPageNumber, IQuest quest, IForumAdapter2 adapter,
            IPageProvider pageProvider, CancellationToken token)
        {
            string firstPageUrl = adapter.GetUrlForPage(quest, firstPageNumber);

            // Make sure to bypass the cache, since it may have changed since the last load.
            HtmlDocument?page = await pageProvider.GetHtmlDocumentAsync(
                firstPageUrl, $"Page {firstPageNumber}",
                CachingMode.BypassCache, ShouldCache.Yes,
                SuppressNotifications.No, token)
                                .ConfigureAwait(false);

            return(page);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a collection of all pages that need to be loaded for the tally,
        /// other than the first page (which was already loaded).
        /// </summary>
        /// <param name="firstPageNumber">The first page number of the tally.</param>
        /// <param name="lastPageNumber">The last page number of the tally.</param>
        /// <param name="quest">The quest being tallied.</param>
        /// <param name="adapter">The forum adapter that handles the quest's thread.</param>
        /// <param name="token">The cancellation token.</param>
        /// <returns>Returns a collection of pages being loaded.</returns>
        private IEnumerable <Task <HtmlDocument?> > GetRemainingPages(
            int firstPageNumber, int lastPageNumber,
            IQuest quest, IForumAdapter2 adapter,
            IPageProvider pageProvider, CancellationToken token)
        {
            if (lastPageNumber <= firstPageNumber)
            {
                yield break;
            }

            for (int pageNum = firstPageNumber + 1; pageNum <= lastPageNumber; pageNum++)
            {
                var pageUrl     = adapter.GetUrlForPage(quest, pageNum);
                var shouldCache = (pageNum == lastPageNumber) ? ShouldCache.No : ShouldCache.Yes;

                yield return(pageProvider.GetHtmlDocumentAsync(
                                 pageUrl, $"Page {pageNum}",
                                 CachingMode.UseCache, shouldCache,
                                 SuppressNotifications.No, token));
            }
        }