static async Task <List <Topic> > FetchThreads(SubCategory subCategory) { var url = subCategory.Url.Replace("liste_sujet-1", $"liste_sujet-{Loc.SubCategory.ThreadsPage}"); var html = await HttpClientHelper.Get(url); if (string.IsNullOrEmpty(html)) { return(null); } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var topicNodes = htmlDoc.DocumentNode.Descendants("tr").Where(x => x.GetAttributeValue("class", "").Contains("sujet ligne_booleen")).ToArray(); if (topicNodes == null) { return(null); } var topics = new List <Topic>(); foreach (var topicNode in topicNodes) { var subject = ThreadHelper.ThreadName(topicNode); subject = ThreadNameHelper.Shorten(subject); var author = ThreadHelper.ThreadAuthor(topicNode); var nbPage = ThreadHelper.GetNbPageFromNode(topicNode); var sujetCase3Node = topicNode.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sujetCase3"); var topicUrl = sujetCase3Node.Descendants("a").FirstOrDefault(x => x.GetAttributeValue("href", "").StartsWith("/hfr/")).GetAttributeValue("href", ""); var topicIsStickyNodes = sujetCase3Node.Descendants("img"); var topicIsSticky = topicIsStickyNodes.FirstOrDefault(x => x.GetAttributeValue("src", "").Contains("flechesticky")); var topicIsClosed = topicIsStickyNodes.FirstOrDefault(x => x.GetAttributeValue("alt", "") == "closed"); var topic = new Topic(); topic.ThreadName = subject; topic.ThreadAuthor = author; topic.TopicIsSticky = topicIsSticky != null; topic.TopicIsClosed = topicIsClosed != null; topic.ThreadNbPage = nbPage; topic.ThreadUri = topicUrl; topics.Add(topic); } return(topics); }
static async Task <ObservableCollection <Topic> > Fetch(FollowedTopicType topicType) { var url = ""; switch (topicType) { case FollowedTopicType.Favoris: url = HFRUrl.FavsUrl; break; case FollowedTopicType.Drapeaux: url = HFRUrl.DrapsUrl; break; case FollowedTopicType.Lus: url = HFRUrl.ReadsUrl; break; default: break; } var html = await HttpClientHelper.Get(url); if (string.IsNullOrEmpty(html)) { return(null); } /* DG */ Stopwatch stopwatch = new Stopwatch(); Debug.WriteLine("Start Bench"); stopwatch.Reset(); stopwatch.Start(); /* DG */ var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); string[] userIdArray = htmlDoc.DocumentNode.Descendants("a") .Where(x => x.GetAttributeValue("href", "").Contains("/user/allread.php?id_user="******"href", "")).ToArray(); int userID = Convert.ToInt32(userIdArray[0].Split('=')[1].Split('&')[0]); await ThreadUI.Invoke(() => Loc.Main.AccountManager.CurrentAccount.UserId = userID); Loc.Main.AccountManager.UpdateCurrentAccountInDB(); /* DG */ stopwatch.Stop(); Debug.WriteLine("Bench Middle: " + stopwatch.ElapsedTicks + " mS: " + stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); /* DG */ var messagesArray = ThreadHelper.GetPostNodesFromHtmlDoc(htmlDoc); if (messagesArray == null) { return(null); } var topics = new ObservableCollection <Topic>(); foreach (var msg in messagesArray) { var sujetCase10 = ThreadHelper.GetSujetCase10(msg); var id = ThreadHelper.GetIdFromSujetCase10Node(sujetCase10); var catId = ThreadHelper.GetCatIdFromSujetCase10Node(sujetCase10); var sujetCase9 = ThreadHelper.GetSujetCase9(msg); var threadLastPostDateTime = ThreadHelper.GetDateTimeLastPostFromNode(sujetCase9); var lastPoster = ThreadHelper.ThreadLastPostMemberPseudo(sujetCase9); var isNew = ThreadHelper.NewPost(msg); var subject = ThreadHelper.ThreadName(msg); subject = ThreadNameHelper.Shorten(subject); var nbPage = ThreadHelper.GetNbPageFromNode(msg); var author = ThreadHelper.ThreadAuthor(msg); var threadUrl = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sujetCase5")?.FirstChild?.GetAttributeValue("href", "")?.CleanFromWeb(); // For Favorites page where we are already in the last post, the star/flag icon is missing so we go to the last post if (string.IsNullOrEmpty(threadUrl)) { threadUrl = msg.Descendants("td").FirstOrDefault(x => x.GetAttributeValue("class", "").Contains("sujetCase9"))?.FirstChild?.GetAttributeValue("href", "")?.CleanFromWeb(); } var subCatId = ThreadHelper.GetSubCatId(threadUrl); var rep = ThreadHelper.GetBookmarkId(threadUrl); var currentPage = ThreadHelper.GetCurrentPage(threadUrl); var topic = new Topic(); topic.ThreadId = id; topic.ThreadName = subject; topic.ThreadUri = threadUrl; topic.ThreadAuthor = author; topic.ThreadHasNewPost = isNew; topic.ThreadLastPostDate = threadLastPostDateTime; topic.ThreadLastPostMemberPseudo = lastPoster; topic.ThreadNbPage = nbPage; topic.ThreadCurrentPage = currentPage; topic.ThreadBookmarkId = rep; topic.TopicCatId = catId; topic.TopicSubCatId = subCatId; topics.Add(topic); } /* DG */ stopwatch.Stop(); Debug.WriteLine("Bench End: " + stopwatch.ElapsedTicks + " mS: " + stopwatch.ElapsedMilliseconds); /* DG */ Debug.WriteLine("Drapeaux fetched"); return(topics); }