public static async Task Fetch(Topic currentTopic) { await ThreadUI.Invoke(() => { Loc.Topic.IsTopicLoading = true; }); var html = await HttpClientHelper.Get(currentTopic.TopicDrapURI); if (string.IsNullOrEmpty(html)) { return; } await ThreadUI.Invoke(() => { Loc.Topic.CurrentTopic.Html = html; }); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var postNodes = htmlDoc.DocumentNode.Descendants("table") .Where(x => x.GetAttributeValue("class", "") == "messagetable") .ToArray(); if (postNodes == null || !postNodes.Any()) { return; } string TempHTMLMessagesList = ""; string TempHTMLMessage = ""; string TempHTMLTopic = ""; string BodyTemplate = ""; string MessageTemplate = ""; // This is absolutely quick and dirty code :o Assembly asm = typeof(App).GetTypeInfo().Assembly; using (Stream stream = asm.GetManifestResourceStream(HFRRessources.Tpl_Topic)) using (StreamReader reader = new StreamReader(stream)) { BodyTemplate = reader.ReadToEnd(); } using (Stream stream = asm.GetManifestResourceStream(HFRRessources.Tpl_Message)) using (StreamReader reader = new StreamReader(stream)) { MessageTemplate = reader.ReadToEnd(); } var i = 0; foreach (var postNode in postNodes) { TempHTMLMessage = MessageTemplate; // Id de la réponse var reponseId = postNode.Descendants("a") .FirstOrDefault(x => x.GetAttributeValue("href", "").StartsWith("#t")) .GetAttributeValue("href", "") .Replace("#t", ""); // Pseudo var pseudo = postNode.Descendants("b").FirstOrDefault(x => x.GetAttributeValue("class", "") == "s2").InnerText.CleanFromWeb(); // Mood var mood = postNode.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "MoodStatus")?.InnerText.CleanFromWeb(); // Img var avatarUri = "ms-appx-web:///Assets/HTML/UI/rsz_no_avatar.png"; var avatarClass = "no_avatar"; var divAvatarNode = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "avatar_center"); if (divAvatarNode != null && divAvatarNode.ChildNodes.Any()) { var imgAvatarNode = divAvatarNode.FirstChild; var uri = imgAvatarNode.GetAttributeValue("src", ""); if (!string.IsNullOrEmpty(uri)) { avatarUri = uri; avatarClass = ""; } } // Date var date = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "toolbar").InnerText.CleanFromWeb(); date = date.Replace("Posté le ", ""); // Content var content = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("id", "").Contains("para")).InnerHtml; int lastPostText = content.IndexOf("<div style=\"clear: both;\"> </div>", StringComparison.Ordinal); if (lastPostText == -1) { lastPostText = content.Length; } content = content.Substring(0, lastPostText); content = content.CleanFromWeb(); TempHTMLMessage = TempHTMLMessage.Replace("%%ID%%", i.ToString()); TempHTMLMessage = TempHTMLMessage.Replace("%%POSTID%%", reponseId); if (pseudo == "Modération") { TempHTMLMessage = TempHTMLMessage.Replace("%%moderation%%", "moderation"); } else { TempHTMLMessage = TempHTMLMessage.Replace("%%moderation%%", ""); } TempHTMLMessage = TempHTMLMessage.Replace("%%no_avatar_class%%", avatarClass); if (Loc.Settings.SquareAvatarStylePreferred) { TempHTMLMessage = TempHTMLMessage.Replace("%%round_avatar_class%%", ""); } else { TempHTMLMessage = TempHTMLMessage.Replace("%%round_avatar_class%%", "round"); } TempHTMLMessage = TempHTMLMessage.Replace("%%AUTEUR_AVATAR%%", avatarUri); TempHTMLMessage = TempHTMLMessage.Replace("%%AUTEUR_PSEUDO%%", pseudo); TempHTMLMessage = TempHTMLMessage.Replace("%%MESSAGE_DATE%%", date); TempHTMLMessage = TempHTMLMessage.Replace("%%MESSAGE_CONTENT%%", content); TempHTMLMessagesList += TempHTMLMessage; i++; } // Get URL of the new post form var url = htmlDoc.DocumentNode.Descendants("form").FirstOrDefault(x => x.GetAttributeValue("id", "") == "repondre_form").GetAttributeValue("action", ""); currentTopic.TopicNewPostUriForm = WebUtility.HtmlDecode(url); TempHTMLTopic = BodyTemplate.Replace("%%MESSAGES%%", TempHTMLMessagesList); // Get Accent Color await ThreadUI.Invoke(() => { SolidColorBrush color = (SolidColorBrush)App.Current.Resources["SystemControlHighlightAltListAccentLowBrush"]; var colorString = $"{color.Color.R.ToString()}, {color.Color.G.ToString()}, {color.Color.B.ToString()}"; TempHTMLTopic = TempHTMLTopic.Replace("%%ACCENTCOLOR%%", colorString); }); // Get user selected font-size var fontSize = Loc.Settings.FontSizePreferred; TempHTMLTopic = TempHTMLTopic.Replace("%%FONTSIZE%%", fontSize.ToString()); // Create/Open WebSite-Cache folder var subfolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(Strings.WebSiteCacheFolderName, CreationCollisionOption.OpenIfExists); var file = await subfolder.CreateFileAsync($"{Strings.WebSiteCacheFileName}", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, TempHTMLTopic); await ThreadUI.Invoke(() => { Loc.Topic.UpdateTopicWebView(currentTopic); Loc.Topic.IsTopicLoading = false; }); }
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(); int i = 0; string[] favorisTopicNames = htmlDoc.DocumentNode.Descendants("a") .Where(x => x.GetAttributeValue("class", "") == "cCatTopic" && x.GetAttributeValue("title", "").Contains("Sujet")) .Select(y => y.InnerText).ToArray(); string[] favorisTopicNumberOfPages = htmlDoc.DocumentNode.Descendants("td") .Where(x => x.GetAttributeValue("class", "") == "sujetCase4") .Select(y => y.InnerText).ToArray(); string[] favorisTopicUri = htmlDoc.DocumentNode.Descendants("a") .Where(x => x.GetAttributeValue("class", "") == "cCatTopic" && x.GetAttributeValue("title", "").Contains("Sujet")) .Select(y => y.GetAttributeValue("href", "")).ToArray(); //Debug.WriteLine(string.Join("\n\r", favorisTopicUri)); string[] favorisLastPost = htmlDoc.DocumentNode.Descendants("td") .Where(x => x.GetAttributeValue("class", "").Contains("sujetCase9")) .Select(y => y.InnerText).ToArray(); string[] favorisIsHot = htmlDoc.DocumentNode.Descendants("img") .Where(x => x.GetAttributeValue("alt", "") == "Off" || x.GetAttributeValue("alt", "") == "On") .Select(y => y.GetAttributeValue("alt", "")).ToArray(); string[] favorisBalise = htmlDoc.DocumentNode.Descendants("a") .Where(x => x.GetAttributeValue("href", "").Contains("#t")) .Select(y => y.GetAttributeValue("href", "")).ToArray(); //Debug.WriteLine(string.Join("\n\r", favorisBalise)); string[] mpArray = htmlDoc.DocumentNode.Descendants("a").Where(x => x.GetAttributeValue("class", "") == "red") .Select(y => y.InnerText).ToArray(); /* DG */ stopwatch.Stop(); Debug.WriteLine("Bench Middle: " + stopwatch.ElapsedTicks + " mS: " + stopwatch.ElapsedMilliseconds); stopwatch.Reset(); stopwatch.Start(); /* DG */ int j = 0; var topics = new ObservableCollection <Topic>(); foreach (string line in favorisTopicNames) { if (favorisIsHot[i] == "On") { var numberOfPagesTopicLine = favorisTopicNumberOfPages[i] != " " ? int.Parse(favorisTopicNumberOfPages[i]) : 1; var firstTopicCatId = WebUtility.HtmlDecode(favorisBalise[j]).IndexOf("&cat=", StringComparison.Ordinal) + "&cat=".Length; var lastTopicCatId = WebUtility.HtmlDecode(favorisBalise[j]) .IndexOf("&", firstTopicCatId, StringComparison.Ordinal); int topicCatId; int.TryParse( WebUtility.HtmlDecode(favorisBalise[j]) .Substring(firstTopicCatId, lastTopicCatId - firstTopicCatId), out topicCatId); var firstTopicSubCatId = WebUtility.HtmlDecode(favorisBalise[j]) .IndexOf("&subcat=", StringComparison.Ordinal) + "&subcat=".Length; var lastTopicSubCatId = WebUtility.HtmlDecode(favorisBalise[j]) .IndexOf("&", firstTopicSubCatId, StringComparison.Ordinal); var topicSubCatId = WebUtility.HtmlDecode(favorisBalise[j]) .Substring(firstTopicSubCatId, lastTopicSubCatId - firstTopicSubCatId); var firstTopicId = WebUtility.HtmlDecode(favorisBalise[j]).IndexOf("&post=", StringComparison.Ordinal) + "&post=".Length; var lastTopicId = WebUtility.HtmlDecode(favorisBalise[j]) .LastIndexOf("&page", StringComparison.Ordinal); var topicId = WebUtility.HtmlDecode(favorisBalise[j]) .Substring(firstTopicId, lastTopicId - firstTopicId); var firstReponseId = WebUtility.HtmlDecode(favorisBalise[j]).IndexOf("#t", StringComparison.Ordinal) + "#t".Length; var lastReponseId = WebUtility.HtmlDecode(favorisBalise[j]).Length; var reponseId = "rep" + WebUtility.HtmlDecode(favorisBalise[j]) .Substring(firstReponseId, lastReponseId - firstReponseId); var firstPageNumber = WebUtility.HtmlDecode(favorisBalise[j]).IndexOf("&page=", StringComparison.Ordinal) + "&page=".Length; var lastPageNumber = WebUtility.HtmlDecode(favorisBalise[j]) .LastIndexOf("&p=", StringComparison.Ordinal); var pageNumber = int.Parse(WebUtility.HtmlDecode(favorisBalise[j]) .Substring(firstPageNumber, lastPageNumber - firstPageNumber)); // URL du flag var drapURI = WebUtility.HtmlDecode(favorisBalise[j]); // Formatage topic name string topicNameFav = TopicNameHelper.Shorten(WebUtility.HtmlDecode(line)); // Conversion date string favorisSingleLastPostTimeString = Regex.Replace( Regex.Replace(WebUtility.HtmlDecode(favorisLastPost[i].Substring(0, 28)), "à", ""), "-", "/"); DateTime favorisSingleLastPostDt; favorisSingleLastPostDt = DateTime.Parse(favorisSingleLastPostTimeString, new CultureInfo("fr-FR")); double favorisSingleLastPostTime; favorisSingleLastPostTime = Convert.ToDouble(favorisSingleLastPostDt.ToFileTime()); // Nom du dernier posteur string favorisLastPostUser = WebUtility.HtmlDecode(favorisLastPost[i].Substring(28, favorisLastPost[i].Length - 28)); // Temps depuis dernier post TimeSpan timeSpent; timeSpent = DateTime.Now.Subtract(favorisSingleLastPostDt); string favorisLastPostText = TopicNameHelper.TimeSinceLastReadMsg(timeSpent, favorisLastPostUser); topics.Add(new Topic() { TopicName = topicNameFav, TopicCatId = topicCatId, TopicSubCatId = topicSubCatId, TopicId = topicId, TopicCatName = HFRCats.PlainNameFromId(topicCatId), TopicLastPostDate = favorisSingleLastPostTime, TopicLastPost = favorisLastPostText, TopicLastPostTimeSpan = timeSpent, TopicNbPage = numberOfPagesTopicLine, TopicCurrentPage = pageNumber, TopicReponseId = reponseId, TopicIndexCategory = HFRCats.GetHFRIndexFromId(topicCatId), TopicDrapURI = drapURI, }); j++; } i++; } /* DG */ stopwatch.Stop(); Debug.WriteLine("Bench End: " + stopwatch.ElapsedTicks + " mS: " + stopwatch.ElapsedMilliseconds); /* DG */ Debug.WriteLine("Drapeaux fetched"); return(topics); }
public static async Task Fetch(Thread currentThread) { await ThreadUI.Invoke(() => { Loc.Thread.IsThreadLoading = true; }); var html = await HttpClientHelper.Get(currentThread.ThreadUri); if (string.IsNullOrEmpty(html)) { return; } var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); //Refresh Current/Number of pages var pagesList = htmlDoc.DocumentNode.Descendants("tr") .Where(x => x.GetAttributeValue("class", "") == "cBackHeader fondForum2PagesHaut") .SelectMany(tr => tr.Descendants("div")) .Where(x => x.GetAttributeValue("class", "") == "left") .FirstOrDefault(); int nbPage = 1; int currentPage = 1; if (pagesList != null) { var nbPageStr = pagesList.Descendants("a") .LastOrDefault().InnerText; int.TryParse(nbPageStr, out nbPage); var currentPageStr = pagesList.Descendants("b") .LastOrDefault().InnerText; int.TryParse(currentPageStr, out currentPage); if (currentPage > nbPage) { nbPage = currentPage; } } await ThreadUI.Invoke(() => { Loc.Thread.CurrentThread.ThreadNbPage = nbPage; Loc.Thread.CurrentThread.ThreadCurrentPage = currentPage; }); var postNodes = htmlDoc.DocumentNode.Descendants("table") .Where(x => x.GetAttributeValue("class", "") == "messagetable") .ToArray(); if (postNodes == null || !postNodes.Any()) { return; } string TempHTMLMessagesList = ""; string TempHTMLMessage = ""; string TempHTMLTopic = ""; string BodyTemplate = ""; string MessageTemplate = ""; // This is absolutely quick and dirty code :o Assembly asm = typeof(App).GetTypeInfo().Assembly; using (Stream stream = asm.GetManifestResourceStream(HFRRessources.Tpl_Topic)) using (StreamReader reader = new StreamReader(stream)) { BodyTemplate = reader.ReadToEnd(); } using (Stream stream = asm.GetManifestResourceStream(HFRRessources.Tpl_Message)) using (StreamReader reader = new StreamReader(stream)) { MessageTemplate = reader.ReadToEnd(); } var i = 0; foreach (var postNode in postNodes) { TempHTMLMessage = MessageTemplate; // Id de la réponse var reponseId = postNode.Descendants("a") .FirstOrDefault(x => x.GetAttributeValue("href", "").StartsWith("#t")) .GetAttributeValue("href", "") .Replace("#t", ""); // Pseudo var pseudo = postNode.Descendants("b").FirstOrDefault(x => x.GetAttributeValue("class", "") == "s2").InnerText.CleanFromWeb(); if (Loc.Settings.IgnoreListMembersList != null && Loc.Settings.IgnoreListMembersList.Contains(pseudo)) { Debug.WriteLine("Post form member in Ignore list, switching to next post"); continue; } // Mood var mood = postNode.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "MoodStatus")?.InnerText.CleanFromWeb(); // Img var avatarUri = "ms-appx-web:///Assets/HTML/UI/rsz_no_avatar.png"; var avatarClass = "no_avatar"; var divAvatarNode = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "avatar_center"); if (divAvatarNode != null && divAvatarNode.ChildNodes.Any()) { var imgAvatarNode = divAvatarNode.FirstChild; var uri = imgAvatarNode.GetAttributeValue("src", ""); if (!string.IsNullOrEmpty(uri)) { avatarUri = uri; avatarClass = ""; } } var toolbar = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "toolbar"); // Date var date = toolbar.InnerText.CleanFromWeb(); date = date.Replace("Posté le ", ""); // Can edit bool canEdit = toolbar.Descendants("img").Any(x => x.GetAttributeValue("alt", "") == "edit" && x.GetAttributeValue("title", "").Contains("Edit")); // Content var contentHtml = postNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("id", "").Contains("para")); if (Loc.Settings.TubecastEnabled) { var youtubeRegex = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"); var youtubeEntries = contentHtml.Descendants("a").Where(x => x.GetAttributeValue("href", "").Contains("www.youtube.com") || x.GetAttributeValue("href", "").Contains("//youtu.be")); foreach (var youtubeEntry in youtubeEntries) { var videoUrl = youtubeEntry.GetAttributeValue("href", ""); Match youtubeMatch = youtubeRegex.Match(videoUrl); if (youtubeMatch.Success) { videoUrl = "vnd.youtube:" + youtubeMatch.Groups[1].Value; youtubeEntry.SetAttributeValue("href", videoUrl); } } } var content = contentHtml.InnerHtml; int lastPostText = content.IndexOf("<div style=\"clear: both;\"> </div>", StringComparison.Ordinal); if (lastPostText == -1) { lastPostText = content.Length; } content = content.Substring(0, lastPostText); content = content.CleanFromWeb(); TempHTMLMessage = TempHTMLMessage.Replace("%%ID%%", i.ToString()); TempHTMLMessage = TempHTMLMessage.Replace("%%POSTID%%", reponseId); if (pseudo == "Modération") { TempHTMLMessage = TempHTMLMessage.Replace("%%moderation%%", "moderation"); } else { TempHTMLMessage = TempHTMLMessage.Replace("%%moderation%%", ""); } TempHTMLMessage = TempHTMLMessage.Replace("%%no_avatar_class%%", avatarClass); if (Loc.Settings.SquareAvatarStylePreferred) { TempHTMLMessage = TempHTMLMessage.Replace("%%round_avatar_class%%", ""); } else { TempHTMLMessage = TempHTMLMessage.Replace("%%round_avatar_class%%", "round"); } if (canEdit) { // Post is editable TempHTMLMessage = TempHTMLMessage.Replace("%%PERSONALPOST%%", ""); } else { // Post is not personal, hide personal actions TempHTMLMessage = TempHTMLMessage.Replace("%%PERSONALPOST%%", "personal_post_button_hidden"); } TempHTMLMessage = TempHTMLMessage.Replace("%%AUTEUR_AVATAR%%", avatarUri); TempHTMLMessage = TempHTMLMessage.Replace("%%AUTEUR_PSEUDO%%", pseudo); TempHTMLMessage = TempHTMLMessage.Replace("%%MESSAGE_DATE%%", date); TempHTMLMessage = TempHTMLMessage.Replace("%%MESSAGE_CONTENT%%", content); TempHTMLMessagesList += TempHTMLMessage; i++; } // Get URL of the new post form var url = htmlDoc.DocumentNode.Descendants("form").FirstOrDefault(x => x.GetAttributeValue("id", "") == "repondre_form").GetAttributeValue("action", ""); currentThread.ThreadNewPostUriForm = WebUtility.HtmlDecode(url); TempHTMLTopic = BodyTemplate.Replace("%%MESSAGES%%", TempHTMLMessagesList); // Get Accent Color await ThreadUI.Invoke(() => { SolidColorBrush color = (SolidColorBrush)App.Current.Resources["SystemControlHighlightAltListAccentLowBrush"]; var colorString = $"{color.Color.R.ToString()}, {color.Color.G.ToString()}, {color.Color.B.ToString()}"; TempHTMLTopic = TempHTMLTopic.Replace("%%ACCENTCOLOR%%", colorString); }); // Get desired theme if (Loc.Settings.IsApplicationThemeDark) { TempHTMLTopic = TempHTMLTopic.Replace("%%COLOR-FG%%", "white").Replace("%%COLOR-BG%%", "black").Replace("%%COLOR-QUOTE%%", "#252525"); } else { TempHTMLTopic = TempHTMLTopic.Replace("%%COLOR-FG%%", "black").Replace("%%COLOR-BG%%", "white").Replace("%%COLOR-QUOTE%%", "#E3E3E3"); } // Get user selected font-size var fontSize = Loc.Settings.FontSizePreferred; TempHTMLTopic = TempHTMLTopic.Replace("%%FONTSIZE%%", fontSize.ToString()); // Get user selected header transparency setting var postHeaderTransparency = Loc.Settings.PostHeaderTransparencyPreferred; TempHTMLTopic = TempHTMLTopic.Replace("%%headerPostTransparency%%", (1 - postHeaderTransparency).ToString().Replace(",", ".")); // Create/Open WebSite-Cache folder var subfolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(Strings.WebSiteCacheFolderName, CreationCollisionOption.OpenIfExists); var file = await subfolder.CreateFileAsync($"{Strings.WebSiteCacheFileName}", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, TempHTMLTopic); await ThreadUI.Invoke(() => { Loc.Thread.UpdateThreadWebView(currentThread); Loc.Thread.IsThreadLoading = false; }); }
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); }
private static async Task <Editor> Fetch(EditorPackage package) { if (string.IsNullOrEmpty(package.PostUriForm)) { return(null); } var html = await HttpClientHelper.Get(package.PostUriForm); HtmlNode.ElementsFlags.Remove("form"); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); HtmlNode formNode = htmlDoc.DocumentNode.Descendants("form").First(x => (string)x.GetAttributeValue("id", "") == "hop"); //Submit URL string submitUrl = formNode.GetAttributeValue("action", ""); //All inputs/select data Dictionary <string, string> formInputs = new Dictionary <string, string>(); foreach (HtmlNode node in formNode.Descendants("input")) { if (node.GetAttributeValue("value", "") != "" && node.GetAttributeValue("name", "") != "") { if (node.GetAttributeValue("name", "") == "MsgIcon") { // Message' icon - Only if checked if (node.GetAttributeValue("checked", "") == "checked") { formInputs.Add(node.GetAttributeValue("name", ""), node.GetAttributeValue("value", "")); } } else if (node.GetAttributeValue("type", "") == "checkbox") { // Checkboxes formInputs.Add(node.GetAttributeValue("name", ""), node.GetAttributeValue("checked", "") == "checked" ? "1" : "0"); } else { try { formInputs.Add(node.GetAttributeValue("name", ""), node.GetAttributeValue("value", "")); } catch (Exception) { Debug.WriteLine("ext0 =" + node.GetAttributeValue("name", "") + "," + node.GetAttributeValue("value", "")); throw; } } } } foreach (HtmlNode node in formNode.Descendants("select")) { if (node.GetAttributeValue("name", "") == "subcat") { #warning "Categories list used to select/change FP category not implemented" } // add Selected category (on edit), or first one if none selected. HtmlNode selectedNode = node .Descendants("option") .FirstOrDefault(x => (string)x.GetAttributeValue("selected", "") == "selected"); if (selectedNode != null) { formInputs.Add(node.GetAttributeValue("name", ""), selectedNode.GetAttributeValue("value", "")); } else { formInputs.Add(node.GetAttributeValue("name", ""), node.Descendants("option").First().GetAttributeValue("value", " ")); } } foreach (HtmlNode node in formNode.Descendants("textarea")) { formInputs.Add(node.GetAttributeValue("name", ""), WebUtility.HtmlDecode(node.InnerText) + Environment.NewLine); } var smileys = new List <Smiley>(); foreach (HtmlNode node in formNode.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "smiley" || x.GetAttributeValue("class", "") == "dynamic_smilies")?.Descendants("img")) { var url = node.GetAttributeValue("src", ""); var tag = node.GetAttributeValue("title", ""); if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(tag)) { var smiley = new Smiley(url, tag); smileys.Add(smiley); } } //Debug.WriteLine("Parsing OK"); //foreach (KeyValuePair<string, string> entry in formInputs) //{ // Debug.WriteLine("inputs = " + entry.Key + " " + entry.Value); //} // Populate with multi quote temporary content if found and that content_form is empty var content = ""; if (formInputs.TryGetValue("content_form", out content)) { if (string.IsNullOrEmpty(content.CleanFromWeb())) { if (!string.IsNullOrEmpty(Loc.Editor.MultiQuoteTemporaryContent)) { formInputs["content_form"] = Loc.Editor.MultiQuoteTemporaryContent; Loc.Editor.MultiQuoteTemporaryContent = null; } } } return(new Editor { FromUrl = package.PostUriForm, SubmitUrl = submitUrl, Data = formInputs, idxTopic = 0, Intent = package.Intent, Smileys = smileys }); }