Beispiel #1
0
        public async Task <Thread> GetThreadAsync(Thread thread, bool goToNewestPost = false)
        {
            thread.Posts.Clear();
            var baseUri = string.Format(EndPoints.ThreadPage, thread.ThreadId);

            if (goToNewestPost)
            {
                baseUri += string.Format(EndPoints.GotoNewPost);
            }
            else if (thread.CurrentPage > 1)
            {
                baseUri += string.Format(EndPoints.PageNumber, thread.CurrentPage);
            }
            var result = await _webManager.GetDataAsync(baseUri);

            var document = await _webManager.Parser.ParseAsync(result.ResultHtml);

            return(ThreadHandler.ParseThread(document, thread));
        }
        /// <summary>
        /// Gets a thread. Can be used with or without authentication, but depending on the thread it may be behind a paywall.
        /// This should be wrapped to check for <see cref="PaywallException"/>.
        /// </summary>
        /// <param name="threadId">A Thread Id.</param>
        /// <param name="pageNumber">The page number. Defaults to 1.</param>
        /// <param name="goToNewestPost">Goes to the newest page and post in a thread. Overrides pageNumber if set to True.</param>
        /// <param name="token">A CancellationToken.</param>
        /// <returns>A Thread.</returns>
        public async Task <Models.Threads.Thread> GetThreadAsync(int threadId, int pageNumber = 1, bool goToNewestPost = false, CancellationToken token = default)
        {
            var baseUri = string.Format(CultureInfo.InvariantCulture, EndPoints.ThreadPage, threadId);

            if (goToNewestPost)
            {
                baseUri += string.Format(CultureInfo.InvariantCulture, EndPoints.GotoNewPost);
            }
            else if (pageNumber > 1)
            {
                baseUri += string.Format(CultureInfo.InvariantCulture, EndPoints.PageNumber, pageNumber);
            }

            var result = await this.webManager.GetDataAsync(baseUri, token).ConfigureAwait(false);

            var document = await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false);

            return(ThreadHandler.ParseThread(document));
        }