djfoxer.dp.notification.Core.Logic.DpLogic.GetBlogMainStatistics C# (CSharp) Method

GetBlogMainStatistics() public method

public GetBlogMainStatistics ( int pageNo, List postLink, HttpClient httpClient ) : Task>
pageNo int
postLink List
httpClient HttpClient
return Task>
        public async Task<List<Post>> GetBlogMainStatistics(int pageNo, List<Post> postLink, HttpClient httpClient)
        {

            var request = new HttpRequestMessage(HttpMethod.Get, new Uri(Const.BlogPrefix + pageNo + ".html"));
            var response = await httpClient.SendRequestAsync(request);

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(await response.Content.ReadAsStringAsync());

            var divWithLinks = doc.DocumentNode.Descendants("div")
                    .Where(d => d.Attributes.Contains("class") &&
                    d.Attributes["class"].Value.Contains("contentText"))
                    .FirstOrDefault();
            if (divWithLinks != null)
            {
                int lastOrderId = postLink.Select(x => x.OrderId).LastOrDefault();

                divWithLinks.Descendants("tr").ToList().ForEach(x =>
                {
                    var elemA = x.Descendants("a").FirstOrDefault();
                    var elemSpan = x.Descendants("span").FirstOrDefault();

                    if (elemA != null && elemSpan != null)
                    {
                        var newPost = new Post()
                        {
                            Title = elemA.InnerText,
                            Url = elemA.Attributes["href"].Value,
                            IsPublished = elemSpan.InnerText == Const.PostStatusPublished,
                            IsHomePage = elemSpan.Attributes.Contains("class") &&
                                elemSpan.Attributes["class"].Value.Contains(Const.PostHomePage),
                            OrderId = ++lastOrderId
                        };
                        newPost.Id = newPost.Url
                            .Split(new string[] { ",", ".html" }, StringSplitOptions.RemoveEmptyEntries)
                                .Reverse().First();
                        postLink.Add(newPost);
                    }


                });
            }

            var nextLink = doc.DocumentNode.Descendants("div")
                .Where(d => d.Attributes.Contains("class") &&
                    d.Attributes["class"].Value.Contains("controls"))
                    .FirstOrDefault();

            var nextUrl = (Const.BlogPrefix + (pageNo + 1) + ".html");

            if (nextLink != null && nextLink.Descendants("a").Where(a => a.Attributes.Contains("href") &&
            a.Attributes["href"].Value == nextUrl).Count() > 0)
            {
                await GetBlogMainStatistics((pageNo + 1), postLink, httpClient);
            }

            return postLink;
        }
    }