void AddMoreItems() { Busy = true; int start = items.Count; int end = start + 20; for (int i = start; i < end; i++) { HtmlWeb web = new HtmlWeb(); //Encoding enc = CustomEncoding("iso-8859-2"); CustomEncoding enc = new CustomEncoding(); web.LoadCompleted += new EventHandler <HtmlDocumentLoadCompleted>(_DownLoadCompleted); web.LoadAsync(baseAddress + i, enc); /*HtmlWeb.LoadAsync(baseAddress + i, (s, args) => * { * if (args.Document != null) * { * * items.Add(new ItemViewModel() * { * Path = args.Document.DocumentNode.SelectSingleNode("//img[@class = \"image\"]").GetAttributeValue("src", "Błąd pobierania"), * Title = i + ": " + args.Document.DocumentNode.SelectSingleNode("//table[@class=\"maintable\"]//td[text()='\n']//td[@align=\"center\"]").FirstChild.InnerText.Trim(), * Album = args.Document.DocumentNode.SelectSingleNode("//table[@class=\"maintable\"]//td[text()='\n']//td[@align=\"center\"]//a").FirstChild.InnerText, * AlbumPath = args.Document.DocumentNode.SelectSingleNode("//table[@class=\"maintable\"]//td[text()='\n']//td[@align=\"center\"]").GetAttributeValue("a", string.Empty), * numer = i * }); * } * });*/ } //Busy = false; }
public void StartPresentationTextRetrieval(string url) { _hw = new HtmlWeb(); _hw.LoadCompleted += hw_LoadCompleted; _hw.LoadAsync(url); }
private void GetOilList() { var htmlGet = new HtmlWeb(); htmlGet.LoadCompleted += new EventHandler <HtmlDocumentLoadCompleted>(OilLoadedHandler); htmlGet.LoadAsync(oilSite); }
private void GetNgvList() { var htmlGet = new HtmlWeb(); htmlGet.LoadCompleted += new EventHandler <HtmlDocumentLoadCompleted>(NgvLoadedHandler); htmlGet.LoadAsync(ngvSite); }
private void GetLpgList() { var htmlGet = new HtmlWeb(); htmlGet.LoadCompleted += new EventHandler <HtmlDocumentLoadCompleted>(LpgLoadedHandler); htmlGet.LoadAsync(lpgSite); }
private void myButton_Click(object sender, RoutedEventArgs e) { myTextBlock.Text = "Please enter a CRN below:"; string crn = myTextBox.Text; if (crn != "") { HtmlWeb.LoadAsync("https://selfservice.mypurdue.purdue.edu/prod/bwckschd.p_disp_detail_sched?term_in=201320&crn_in=" + crn, DownloadCompleted); } }
partial void Method_Execute() { var wc = new HtmlWeb(); // string url = "http://www.nu.nl/feeds/rss/algemeen.rss"; wc.LoadAsync("http://google.com"); wc.LoadCompleted += new EventHandler <HtmlDocumentLoadCompleted>(DownloadCompleted); //wc. // }
private void FetchSite(object sender, RoutedEventArgs e) { HtmlWeb.LoadAsync("http://www.google.com", (s, args) => { Results.Text = String.Join(Environment.NewLine, args.Document.DocumentNode.Descendants("a"). Select( x => x.GetAttributeValue("href", "")).ToArray()); }); }
/// <summary> /// Starts the daily text retrieval. /// </summary> /// <param name="d">The d.</param> public void StartDailyTextRetrieval(DateTime d) { string url = App.Settings.UseCustomDTUrl ? App.Settings.CustomDTUrl : string.Format(StringResources.Application_DailyTextURL, DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); if (string.IsNullOrEmpty(url)) { return; } _hw = new HtmlWeb(); _hw.LoadCompleted += hw_LoadCompleted; _hw.LoadAsync(url); }
private void FetchSite(object sender, RoutedEventArgs e) { //HtmlWeb.LoadAsync("http://www.google.com", (s, args) => // { // Results.Text = String.Join(Environment.NewLine, // args.Document.DocumentNode.Descendants("a"). // Select( // x => // x.GetAttributeValue("href", "")).ToArray()); // }); var web = new HtmlWeb(); web.LoadCompleted += SiteLoaded; web.LoadAsync("http://www.google.com"); // HtmlWeb.LoadAsync("http://www.google.com", SiteLoaded); }
public static void Scrape(MainPage page) { _page = page; var web = new HtmlWeb(); web.LoadCompleted += ParseBandwidthDocument; var settings = IsolatedStorageSettings.ApplicationSettings; var siteToLoad = (String)settings["user"] == "testuser" ? "http://alexmullans.com/bandwidth.html" : "http://netreg.rose-hulman.edu/tools/networkUsage.pl"; web.LoadAsync(siteToLoad, new UTF8Encoding(), (String)settings["user"], (String)settings["pass"], "rose-hulman"); }
private void CheckFav() { try { // Affichage favoris string urlFav = "http://forum.hardware.fr/forum1f.php?owntopic=" + (string)store["favorisType"]; HtmlWeb.LoadAsync(urlFav, container as CookieContainer, (s, args) => { try { int i = 0; string[] favorisTopicNames = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.InnerText).ToArray(); string[] favorisTopicNumberOfPages = args.Document.DocumentNode.Descendants("td").Where(x => (string)x.GetAttributeValue("class", "") == "sujetCase4"). Select(y => y.InnerText).ToArray(); string[] favorisTopicUri = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.GetAttributeValue("href", "")).ToArray(); string[] favorisLastPost = args.Document.DocumentNode.Descendants("td").Where(x => (bool)x.GetAttributeValue("class", "").Contains("sujetCase9") == true). Select(y => y.InnerText).ToArray(); string[] favorisIsHot = args.Document.DocumentNode.Descendants("img").Where(x => (string)x.GetAttributeValue("alt", "") == "Off" || (string)x.GetAttributeValue("alt", "") == "On"). Select(y => y.GetAttributeValue("alt", "")).ToArray(); string[] favorisBalise = args.Document.DocumentNode.Descendants("a").Where(x => (bool)x.GetAttributeValue("href", "").Contains("#t")). Select(y => y.GetAttributeValue("href", "")).ToArray(); string[] mpArray = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "red"). Select(y => y.InnerText).ToArray(); string numberOfPagesTopicLine = ""; int j = 0; foreach (string line in favorisTopicNames) { if (favorisIsHot[i] == "On") { // Nombre de pages if (favorisTopicNumberOfPages[i] != " ") { numberOfPagesTopicLine = favorisTopicNumberOfPages[i]; } else { numberOfPagesTopicLine = "1"; } string topicCatId; int firstTopicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&cat=") + "&cat=".Length; int lastTopicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&", firstTopicCatId); topicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstTopicCatId, lastTopicCatId - firstTopicCatId); string topicId; int firstTopicId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&post=") + "&post=".Length; int lastTopicId = HttpUtility.HtmlDecode(favorisBalise[j]).LastIndexOf("&page"); topicId = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstTopicId, lastTopicId - firstTopicId); string reponseId; int firstReponseId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("#t") + "#t".Length; int lastReponseId = HttpUtility.HtmlDecode(favorisBalise[j]).Length; reponseId = "rep" + HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstReponseId, lastReponseId - firstReponseId); string pageNumber; int firstPageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&page=") + "&page=".Length; int lastPageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).LastIndexOf("&p="); pageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstPageNumber, lastPageNumber - firstPageNumber); // Formatage topic name string topicNameFav; topicNameFav = Regex.Replace(HttpUtility.HtmlDecode(line), "topic unique", "T.U.", RegexOptions.IgnoreCase); topicNameFav = Regex.Replace(HttpUtility.HtmlDecode(line), "topique unique", "T.U.", RegexOptions.IgnoreCase); topicNameFav = Regex.Replace(topicNameFav, "topic unik", "T.U.", RegexOptions.IgnoreCase); topicNameFav = Regex.Replace(topicNameFav, "topik unik", "T.U.", RegexOptions.IgnoreCase); // Conversion date string favorisSingleLastPostTimeString; favorisSingleLastPostTimeString = Regex.Replace(Regex.Replace(HttpUtility.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; favorisLastPostUser = HttpUtility.HtmlDecode(favorisLastPost[i].Substring(28, favorisLastPost[i].Length - 28)); // Temps depuis dernier post string favorisLastPostText; TimeSpan timeSpent; timeSpent = DateTime.Now.Subtract(favorisSingleLastPostDT); favorisLastPostText = HFR7.HFRClasses.TimeSpentTopic.Run(timeSpent, favorisLastPostUser); favObject.Add(new HFR7.HFRClasses.TopicFav() { TopicNameFav = topicNameFav, TopicCatIdFav = topicCatId, TopicIdFav = topicId, TopicCatNameFav = HFR7.HFRClasses.GetCatName.PlainNameFromId(topicCatId), TopicUriFav = "?idcat=" + topicCatId + "&idtopic=" + topicId + "&topicname=" + HttpUtility.UrlEncode(line) + "&pagenumber=" + pageNumber + "&jump=" + reponseId + "&numberofpages=" + numberOfPagesTopicLine, TopicLastPostDateDouble = favorisSingleLastPostTime, TopicLastPost = favorisLastPostText, TopicNumberOfPages = numberOfPagesTopicLine, TopicPage = pageNumber, TopicJump = reponseId }); j++; } i++; } if (mpArray.Length != 0 && isMpNotified == "false" && activateMpNotif == "true") { if (Convert.ToInt32(mpArray[0].Split(' ')[2]) == 1) { ShellToast mpToast = new ShellToast(); mpToast.Title = "HFR7"; mpToast.Content = "1 nouveau message privé."; mpToast.Show(); ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(); StandardTileData NewAppTileData = new StandardTileData { BackTitle = "HFR7", BackBackgroundImage = new Uri("Images/tiles/backtile.png", UriKind.Relative), BackContent = "1 nouveau message privé." }; if (isoStore.FileExists("isMpNotified.txt")) { isoStore.DeleteFile("isMpNotified.txt"); } using (var file = isoStore.OpenFile("isMpNotified.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { writer.Write("true"); } } TileToFind.Update(NewAppTileData); } if (Convert.ToInt32(mpArray[0].Split(' ')[2]) > 1) { ShellToast mpToast = new ShellToast(); mpToast.Title = "HFR7"; mpToast.Content = mpArray[0].Split(' ')[2] + " nouveaux messages privés."; mpToast.Show(); ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(); StandardTileData NewAppTileData = new StandardTileData { BackTitle = "HFR7", BackBackgroundImage = new Uri("Images/tiles/backtile.png", UriKind.Relative), BackContent = mpArray[0].Split(' ')[2] + " nouveaux messages privés." }; if (isoStore.FileExists("isMpNotified.txt")) { isoStore.DeleteFile("isMpNotified.txt"); } using (var file = isoStore.OpenFile("isMpNotified.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { writer.Write("true"); } } TileToFind.Update(NewAppTileData); } } else if (mpArray.Length == 0) { if (isoStore.FileExists("isMpNotified.txt")) { isoStore.DeleteFile("isMpNotified.txt"); } using (var file = isoStore.OpenFile("isMpNotified.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { writer.Write("false"); } } } // Mises à jour des tiles topics foreach (ShellTile tile in ShellTile.ActiveTiles) { if (tile.NavigationUri.ToString() != "/") { foreach (TopicFav fav in favObject) { string tilePostId; int firstTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=") + "&idtopic=".Length; int lastTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&topicname=", firstTilePostId); tilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTilePostId, lastTilePostId - firstTilePostId)); string tileCatId; int firstTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("?idcat=") + "?idcat=".Length; int lastTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=", firstTileCatId); tileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTileCatId, lastTileCatId - firstTileCatId)); // Set the properties to update for the Application Tile. // Empty strings for the text values and URIs will result in the property being cleared. if (tilePostId == fav.TopicIdFav) { StandardTileData NewTileData = new StandardTileData { BackContent = "Nouveaux messages !", BackgroundImage = new Uri("Images/tiles/" + HFR7.HFRClasses.GetCatName.ShortNameFromId(tileCatId) + "_new.png", UriKind.Relative), BackBackgroundImage = new Uri("Images/tiles/unread.png", UriKind.Relative) //BackgroundImage = new Uri("AchatsVentes.png", UriKind.Relative) }; // Update the Application Tile tile.Update(NewTileData); break; } StandardTileData NewTileDataRead = new StandardTileData { BackContent = "Pas de nouveaux messages", BackgroundImage = new Uri("Images/tiles/" + HFR7.HFRClasses.GetCatName.ShortNameFromId(tileCatId) + ".png", UriKind.Relative), BackBackgroundImage = new Uri("Images/tiles/read.png", UriKind.Relative) }; // Update the Application Tile tile.Update(NewTileDataRead); } } } //Mise à jour de la tile principale int numberOfUnreadFav = favObject.Count; ShellTile MainTileToFind = ShellTile.ActiveTiles.FirstOrDefault(); StandardTileData MainNewAppTileData = new StandardTileData { Count = numberOfUnreadFav }; MainTileToFind.Update(MainNewAppTileData); // Notifications ShellToast notifToast = new ShellToast(); XmlSerializer serializer = new XmlSerializer(notifTopicList.GetType()); using (var file = isoStore.OpenFile("notifications.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (var reader = new StreamReader(file)) { object deserialized = serializer.Deserialize(reader.BaseStream); notifTopicList = (List <NotifTopics>)deserialized; } } foreach (TopicFav fav in favObject) { int containsNotif = -1; int h = 0; foreach (NotifTopics notifTopic in notifTopicList) { if (fav.TopicIdFav == notifTopic.TopicId && notifTopic.TopicIsNotif == false) { containsNotif = h; notifToast.Title = "HFR7"; notifToast.Content = "Nouvelle réponse : " + fav.TopicNameFav; notifToast.NavigationUri = new Uri("/ReadTopic.xaml?idcat=" + fav.TopicCatIdFav + "&idtopic=" + fav.TopicIdFav + "&topicname=" + HttpUtility.UrlEncode(fav.TopicNameFav) + "&pagenumber=" + fav.TopicPage + "&jump=" + fav.TopicJump + "&numberofpages=" + fav.TopicNumberOfPages, UriKind.Relative); notifToast.Show(); } h++; } if (containsNotif != -1) { notifTopicList.RemoveAt(containsNotif); notifTopicList.Add(new NotifTopics() { TopicCatId = fav.TopicCatIdFav.ToString(), TopicId = fav.TopicIdFav.ToString(), TopicIsNotif = true, TopicJump = fav.TopicJump.ToString(), TopicName = fav.TopicNameFav.ToString(), TopicNumberOfPages = fav.TopicNumberOfPages.ToString(), TopicPageNumber = fav.TopicPage.ToString() }); } if (isoStore.FileExists("notifications.xml")) { isoStore.DeleteFile("notifications.xml"); } using (var file = isoStore.OpenFile("notifications.xml", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { serializer.Serialize(writer.BaseStream, notifTopicList); } } } NotifyComplete(); } catch { TileErreur(); } }); } catch { TileErreur(); } }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { //Récupération de l'URI de la catégorie NavigationContext.QueryString.TryGetValue("caturi", out catUri); ////Réduction de l'URI catUriShort = catUri.Substring(4).Replace("/", "-"); //Récupération du nom du forum NavigationContext.QueryString.TryGetValue("catname", out catName); ApplicationTitle.Text = catName.ToUpper(); //Vérification si premier lancement de la catégorie var appStorage = IsolatedStorageFile.GetUserStoreForApplication(); string fileName = "firstlaunch" + catUriShort + ".txt"; if (!appStorage.FileExists(fileName)) { //PREMIER LANCEMENT ////Affichage du canvas d'attente premierLancementCanvas.Visibility = System.Windows.Visibility.Visible; ////Création du XML dans l'ISF IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication(); using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("souscat" + catUriShort + ".xml", FileMode.Create, isoStore)) { XDocument docModel = XDocument.Load("XMLFile.xml"); docModel.Save(isoStream); } using (IsolatedStorageFileStream isoStreamCategories = new IsolatedStorageFileStream("souscat" + catUriShort + ".xml", FileMode.Open, isoStore)) { docSousCat = XDocument.Load(isoStreamCategories); } ////Chargement des catégories vers le XML IsolatedStorageFileStream isoStreamSave = new IsolatedStorageFileStream("souscat" + catUriShort + ".xml", FileMode.Create, isoStore); HtmlWeb.LoadAsync("http://forum.hardware.fr" + catUri, null, (s, args) => { int i = 0; string[] categories = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cHeader"). Select(y => y.InnerText).ToArray(); string[] uriCategorie = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cHeader"). Select(x => x.GetAttributeValue("href", "")).ToArray(); foreach (string line in categories) { XElement categorie = new XElement("SousCategorie", new XAttribute("Name", HttpUtility.HtmlDecode(line)), new XAttribute("Uri", uriCategorie[i])); docSousCat.Root.Add(categorie); i++; } docSousCat.Save(isoStreamSave); isoStreamSave.Close(); LoadSousCategories(); premierLancementCanvas.Visibility = System.Windows.Visibility.Collapsed; }); ////Sauvegarde du premier lancement using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { writer.Write("true"); } } } else { LoadSousCategories(); } }
public void PremiereConnexion() { CookieContainer container = store["HFRcookies"] as CookieContainer; // Ajout des préférences AppSettings.CheckAndAdd(currentVersion); // Id utilisateur + Url avatar HtmlWeb.LoadAsync("https://forum.hardware.fr/", container, (s, args) => { if (args.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."));; } else { string[] userIdArray = args.Document.DocumentNode.Descendants("a").Where(x => (bool)x.GetAttributeValue("href", "").Contains("/user/allread.php?id_user="******"href", "")).ToArray(); store.Add("userId", Convert.ToInt32(userIdArray[0].Split('=')[1].Split('&')[0])); } HtmlWeb.LoadAsync("https://forum.hardware.fr/user/editprofil.php?config=hfr.inc&page=2", container, (t, argt) => { if (argt.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."));; } else { string[] userCitation = argt.Document.DocumentNode.Descendants("input").Where(x => (string)x.GetAttributeValue("name", "") == "citation"). Select(y => y.GetAttributeValue("value", "")).ToArray(); store.Add("citation", userCitation[0]); } HtmlWeb.LoadAsync("https://forum.hardware.fr/user/editprofil.php?config=hfr.inc&page=5", container, (u, argu) => { if (argu.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."));; } else { string[] userAvatarFileArray = argu.Document.DocumentNode.Descendants("img").Where(x => (bool)x.GetAttributeValue("src", "").Contains("http://forum-images.hardware.fr/images/mesdiscussions-") == true). Select(y => y.GetAttributeValue("src", "")).ToArray(); string[] userHash = argu.Document.DocumentNode.Descendants("input").Where(x => (bool)x.GetAttributeValue("name", "").Contains("hash_check") == true). Select(y => y.GetAttributeValue("value", "")).ToArray(); store.Add("hash", userHash[0]); if (userAvatarFileArray.Length != 0) { foreach (string line in userAvatarFileArray) { store.Add("userAvatarFile", line.Split('/')[4]); } _webClient.OpenReadAsync(new Uri("http://forum-images.hardware.fr/images/" + store["userAvatarFile"] as string)); } else { Dispatcher.BeginInvoke(() => { store.Remove("isConnected"); store.Add("isConnected", ""); NavigationService.Navigate(new Uri("/WelcomePage.xaml?from=connect", UriKind.Relative)); }); } } }); }); }); }
void MainPage_Loaded(object sender, RoutedEventArgs e) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("el-GR"); HtmlWeb.LoadAsync("http://www.minfin.gr/portal/", HtmlWeb_Loaded); }
private void DownloadMp() { if (isoStore.FileExists("mp-" + mpId + ".html")) { isoStore.DeleteFile("mp-" + mpId + ".html"); } // Création du pattern de la page docTopic = XDocument.Load("MP_HTMLfile_" + currentTheme + ".html"); // Construction de URL du MP //https://forum.hardware.fr/forum2.php?cat=prive&post=1705945&page=1 string urlMp = "https://forum.hardware.fr/forum2.php?config=hfr.inc&cat=prive&post=" + mpId + "&page=" + numberOfPages + "&random=" + randomNumber.ToString(); //string urlMp = "https://forum.hardware.fr/forum2.php?config=hfr.inc&cat=prive&post=1633240&page=1&random=" + randomNumber.ToString(); // Récupération et parsage de l'HTML du MP sur HFR HtmlWeb.LoadAsync(urlMp, container, (s, args) => { if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur dans la lecture du MP. Informations : " + args.Error.Message + ", " + args.Error.Data); progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } if (args.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."));; } int i = 0; args.Document.OptionWriteEmptyNodes = true; string[] mpText = args.Document.DocumentNode.Descendants("div").Where(x => (bool)x.GetAttributeValue("id", "").Contains("para") == true). Select(y => y.InnerHtml).ToArray(); string[] messCase1 = args.Document.DocumentNode.Descendants("td") .Where(x => (bool)x.GetAttributeValue("class", "").Contains("messCase1") == true && (bool)x.InnerHtml.Contains("<div><b class=\"s2\">Publicité</b></div>") == false && (bool)x.InnerHtml.Contains("Auteur") == false) .Select(x => x.InnerHtml).ToArray(); string[] messCase2 = args.Document.DocumentNode.Descendants("td") .Where(x => (bool)x.GetAttributeValue("class", "").Contains("messCase2") == true && (bool)x.InnerHtml.Contains("<div><b class=\"s2\">Publicité</b></div>") == false) .Select(x => x.InnerText).ToArray(); string[] toolbar = args.Document.DocumentNode.Descendants("div") .Where(x => (bool)x.GetAttributeValue("class", "").Contains("toolbar") == true) .Select(x => x.InnerHtml).ToArray(); foreach (string line in mpText) { string dateHeure; string posterPseudo; string reponseId; string tableGlobalType; // Date et heure int firstDate = toolbar[i].IndexOf("Posté le ") + "Posté le ".Length;; int lastDate = 31; dateHeure = Regex.Replace(toolbar[i].Substring(firstDate, lastDate), " ", " "); // Pseudo int firstPseudo = messCase1[i].IndexOf("<b class=\"s2\">") + "<b class=\"s2\">".Length; int lastPseudo = messCase1[i].LastIndexOf("</b>"); posterPseudo = messCase1[i].Substring(firstPseudo, lastPseudo - firstPseudo); posterPseudo = posterPseudo.Replace(((char)8203).ToString(), ""); // char seperator (jocebug) // Id de la réponse int firstReponseId = messCase1[i].IndexOf("title=\"n°") + "title=\"n°".Length; int lastReponseId = messCase1[i].LastIndexOf("\" alt=\"n°"); reponseId = messCase1[i].Substring(firstReponseId, lastReponseId - firstReponseId); // Mise en forme du texte int lastPostText = mpText[i].IndexOf("<span class=\"signature\">"); if (lastPostText == -1) { lastPostText = mpText[i].Length; } string postText = mpText[i].Substring(0, lastPostText); postText = Regex.Replace(HttpUtility.HtmlDecode(postText), " target=\"_blank\"", ""); // Affichage des images ? //if ((string)store["displayImages"] == "always") //postText = Regex.Replace(postText, "md_verif_size(this,'Cliquez pour agrandir','2','250')", "resize(this)"); //else //{ // // Très sale mais fonctionne : vérification si l'image est un smiley ou non // postText = Regex.Replace(postText, "<img src=\"http://forum-images.hardware.fr/", "<save=\"http://forum-images.hardware.fr/"); // postText = Regex.Replace(postText, "<img src=\"", "<a class=\"cLink\" href=\"§"); // postText = Regex.Replace(postText, "<save=\"http://forum-images.hardware.fr/", "<img src=\"http://forum-images.hardware.fr/"); // postText = Regex.Replace(postText, "style=\"margin: 5px\" />", ">Image</a>"); //} // Close icon uri string closeIconUri; if (currentTheme == "light") { closeIconUri = "http://reho.st/thumb/http://self/pic/7e245621270799c85a73129c8987a861fc1b00a2.png"; } else { closeIconUri = "http://reho.st/http://self/pic/fd15923f5210a70161468f6019643695ae57ef98.png"; } // Vérification si posteur = utilisateur de l'appli triangleUriEnvoye = "http://reho.st/http://self/pic/eba141848517d633c15fa519ecaf49d8c99758fc.png"; triangleUriRecu = "http://reho.st/http://self/pic/eba141848517d633c15fa519ecaf49d8c99758fc.png"; if (posterPseudo.ToLower() == userPseudo.ToLower()) { tableGlobalType = "User"; //if (currentTheme == "dark") //{ // triangleUriEnvoye = "http://reho.st/http://self/pic/afbdb13a508cde183cca7efcc3cee7a2234681fb.png"; //} //else //{ // triangleUriEnvoye = "http://reho.st/http://self/pic/320a43454faca6e539d1f3a3de06a91842e36c66.png"; //} } else { tableGlobalType = "Sender"; //if (currentTheme == "dark") //{ // triangleUriRecu = "http://reho.st/http://self/pic/2fb379ab9953769ab90506a1f0698f1af4c2ed8c.png"; //} //else //{ // triangleUriRecu = "http://reho.st/http://self/pic/d9bbf2b3b409f8259eb1b567e5a8e22e8635df2b.png"; //} } // Parsage du MP XElement post; // Avatars activés post = new XElement("table", new XAttribute("class", "tableGlobal" + tableGlobalType), new XElement("tr", new XAttribute("class", "trPost"), new XElement("td", new XAttribute("colspan", "3"), new XElement("div", new XAttribute("class", "divPost"), postText))), new XElement("tr", new XAttribute("class", "trDateHeure"), new XElement("td", new XAttribute("colspan", "3"), dateHeure)) ); docTopic.Root.Element("body").Add(post); if (i == mpText.Length - 2) { // Bas de page XElement last = new XElement("a", new XAttribute("name", "bas")); docTopic.Root.Element("body").Add(last); } i++; } // Ouverture du flux // Modification du HTML try { content = docTopic.ToString(); content = Regex.Replace(content, "<", "<"); content = Regex.Replace(content, ">", ">"); content = Regex.Replace(content, "</b><br /><br /><p>", "</b><p>"); content = Regex.Replace(content, "<br /> <br /> <br />", "<br />"); content = Regex.Replace(content, "#PINCHTOZOOMOPTION", (string)store["pinchToZoomOption"]); content = Regex.Replace(content, "#ACHANGER", accentColor); } catch { MessageBox.Show("Erreur dans la mise en forme du HTML"); } // Ecriture du HTML dans le fichier using (var file = isoStore.OpenFile("mp-" + mpId + ".html", System.IO.FileMode.Create, System.IO.FileAccess.Write)) { using (var writer = new StreamWriter(file)) { writer.Write(content); } } // Navigation vers ce fichier Dispatcher.BeginInvoke(() => { NavigateMp(); }); }); }
private void searchButton_Click(object sender, RoutedEventArgs e) { // Cachage du WB smileyWB.Visibility = System.Windows.Visibility.Collapsed; // Keyword keyword = keywordTextBox.Text; if (keywordTextBox.Text == "") { MessageBox.Show("Veuillez entrer un mot clé."); } else if (keyword.Length < 3) { MessageBox.Show("Le mot clé doit faire au moins 3 caractères."); } else { // Création du pattern de la page using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("smiley-" + HttpUtility.UrlEncode(keyword) + ".html", FileMode.Create, isoStore)) { XDocument docModel = XDocument.Load("SmileyHTMLfile_" + currentTheme + ".html"); docModel.Save(isoStream); } using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("smiley-" + HttpUtility.UrlEncode(keyword) + ".html", FileMode.Open, isoStore)) { docSmiley = XDocument.Load(isoStream); } globalProgressBar.Visibility = System.Windows.Visibility.Visible; // Lancement de la recherche HtmlWeb.LoadAsync("https://forum.hardware.fr/wikismilies.php?config=hfr.inc&threecol=0", null, new string[] { "findcode=", "findkeyword=" + keyword }, (s, args) => { string[] smileyUrl = args.Document.DocumentNode.Descendants("img").Where(x => (bool)x.GetAttributeValue("title", "").Contains("[:") == true). Select(y => y.GetAttributeValue("src", "")).ToArray(); string[] smileyCode = args.Document.DocumentNode.Descendants("img").Where(x => (bool)x.GetAttributeValue("title", "").Contains("[:") == true). Select(y => y.GetAttributeValue("title", "")).ToArray(); int i = 0; if (smileyUrl.Length == 0) { XElement result = new XElement("font", new XAttribute("class", "fontClass"), "Aucun smiley n'a été trouvé."); docSmiley.Root.Element("body").Add(result); } foreach (var smile in smileyUrl) { if (i < 200) { XElement smileyImg = new XElement("a", new XAttribute("class", "link"), new XAttribute("href", smileyCode[i]), new XElement("img", new XAttribute("src", smile))); docSmiley.Root.Element("body").Add(smileyImg); i++; } } using (IsolatedStorageFileStream isoStreamSave = new IsolatedStorageFileStream("smiley-" + HttpUtility.UrlEncode(keyword) + ".html", FileMode.Create, isoStore)) { docSmiley.Save(isoStreamSave); } Dispatcher.BeginInvoke(() => { smileyWB.Navigate(new Uri("smiley-" + HttpUtility.UrlEncode(keyword) + ".html", UriKind.Relative)); }); }); } }
public void Hap() { HtmlWeb.LoadAsync("http://www.joemonster.org/mg/displayimage.php?album=lastup&pos=0", _DownLoadCompleted); }
public void DownloadTopicsDrapals(int listPageNumber) { // Progress Bar SystemTray.ProgressIndicator.IsVisible = true; //===================== //CHARGEMENT DES DRAPAUX //===================== drapObject.Clear(); string urlDrap = "https://forum.hardware.fr/forum1.php?cat=" + idCat + "&owntopic=1"; HtmlWeb.LoadAsync(urlDrap, container, (s, args) => { if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur dans la récupération des drapeaux : " + args.Error.Message + ", " + args.Error.InnerException + ", " + args.Error.Data); SystemTray.ProgressIndicator.IsVisible = false; }); } if (args.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard.")); } else { string[] favorisTopicNames = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.InnerText).ToArray(); string[] favorisTopicNumberOfPages = args.Document.DocumentNode.Descendants("td").Where(x => (string)x.GetAttributeValue("class", "") == "sujetCase4"). Select(y => y.InnerText).ToArray(); string[] favorisTopicUri = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.GetAttributeValue("href", "")).ToArray(); string[] favorisLastPost = args.Document.DocumentNode.Descendants("td").Where(x => (bool)x.GetAttributeValue("class", "").Contains("sujetCase9") == true). Select(y => y.InnerText).ToArray(); string[] favorisIsHot = args.Document.DocumentNode.Descendants("img").Where(x => (string)x.GetAttributeValue("alt", "") == "Off" || (string)x.GetAttributeValue("alt", "") == "On"). Select(y => y.GetAttributeValue("alt", "")).ToArray(); string[] favorisBalise = args.Document.DocumentNode.Descendants("a").Where(x => (bool)x.GetAttributeValue("href", "").Contains("#t")). Select(y => y.GetAttributeValue("href", "")).ToArray(); string numberOfPagesTopicLine = ""; int i = 0; int j = 0; foreach (string line in favorisTopicNames) { // Nombre de pages if (favorisTopicNumberOfPages[j] != " ") { numberOfPagesTopicLine = favorisTopicNumberOfPages[j]; } else { numberOfPagesTopicLine = "1"; } string topicCatId; int firstTopicCatId = HttpUtility.HtmlDecode(favorisTopicUri[j]).IndexOf("&cat=") + "&cat=".Length; int lastTopicCatId = HttpUtility.HtmlDecode(favorisTopicUri[j]).IndexOf("&", firstTopicCatId); topicCatId = HttpUtility.HtmlDecode(favorisTopicUri[j]).Substring(firstTopicCatId, lastTopicCatId - firstTopicCatId); string topicId; int firstTopicId = HttpUtility.HtmlDecode(favorisTopicUri[j]).IndexOf("&post=") + "&post=".Length; int lastTopicId = HttpUtility.HtmlDecode(favorisTopicUri[j]).LastIndexOf("&page"); topicId = HttpUtility.HtmlDecode(favorisTopicUri[j]).Substring(firstTopicId, lastTopicId - firstTopicId); string pageNumber; string reponseId; if (favorisIsHot[j] == "On") { int firstPageNumber = HttpUtility.HtmlDecode(favorisBalise[i]).IndexOf("&page=") + "&page=".Length; int lastPageNumber = HttpUtility.HtmlDecode(favorisBalise[i]).LastIndexOf("&p="); pageNumber = HttpUtility.HtmlDecode(favorisBalise[i]).Substring(firstPageNumber, lastPageNumber - firstPageNumber); int firstReponseId = HttpUtility.HtmlDecode(favorisBalise[i]).IndexOf("#t") + "#t".Length; int lastReponseId = HttpUtility.HtmlDecode(favorisBalise[i]).Length; reponseId = "rep" + HttpUtility.HtmlDecode(favorisBalise[i]).Substring(firstReponseId, lastReponseId - firstReponseId); i++; } else { pageNumber = numberOfPagesTopicLine; reponseId = "bas"; } // Formatage topic name string topicNameFav; topicNameFav = Regex.Replace(HttpUtility.HtmlDecode(line), "Topic unique", "T.U."); topicNameFav = Regex.Replace(topicNameFav, "Topic Unique", "T.U."); // Conversion date string favorisSingleLastPostTimeString; favorisSingleLastPostTimeString = Regex.Replace(Regex.Replace(HttpUtility.HtmlDecode(favorisLastPost[j].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; favorisLastPostUser = HttpUtility.HtmlDecode(favorisLastPost[j].Substring(28, favorisLastPost[j].Length - 28)); // Temps depuis dernier post string favorisLastPostText; TimeSpan timeSpent; timeSpent = DateTime.Now.Subtract(favorisSingleLastPostDT); favorisLastPostText = HFRClasses.TimeSpentTopic.Run(timeSpent, favorisLastPostUser); drapObject.Add(new HFRClasses.TopicFav() { TopicNameFav = topicNameFav, TopicCatIdFav = topicCatId, TopicIdFav = topicId, TopicCatNameFav = HFRClasses.GetCatName.PlainNameFromId(topicCatId), TopicGroup = "drapeaux", TopicUriFav = "/ReadTopic.xaml?idcat=" + topicCatId + "&idtopic=" + topicId + "&topicname=" + HttpUtility.UrlEncode(line) + "&souscatname=" + HttpUtility.UrlEncode(souscatName) + "&souscaturi=" + HttpUtility.UrlEncode(souscatUri) + "&pagenumber=" + pageNumber + "&numberofpages=" + numberOfPagesTopicLine + "&from=listdrapcat&jump=" + reponseId, TopicLastPostDateDouble = favorisSingleLastPostTime, TopicLastPost = favorisLastPostText, TopicIsHot = favorisIsHot[j], TopicNumberOfPages = numberOfPagesTopicLine }); j++; } } // Binding Dispatcher.BeginInvoke(() => { // Tri et binding //var drapParCat = from topic in drapObject // group topic by topic.TopicGroup into c // select new Group<HFRClasses.TopicFav>(c.Key, c); //drapList.ItemsSource = drapParCat.ToList(); List <GroupFav <TopicFav> > DataSource = GroupFav <TopicFav> .CreateGroups(drapObject, System.Threading.Thread.CurrentThread.CurrentUICulture, (TopicFav tf) => { return(tf.TopicCatNameFav); }, true); drapList.ItemsSource = DataSource; try { SystemTray.ProgressIndicator.IsVisible = false; } catch { } if (topicsList.ItemsSource != null) { SystemTray.ProgressIndicator.IsVisible = false; } }); }); //===================== //CHARGEMENT DES TOPICS //===================== // Si utilisation du cache, déserialization //if (cacheTopic && isoStore.FileExists("topics" + souscatUriShort + ".xml")) //{ // XmlSerializer serializer = new XmlSerializer(topicsObject.GetType()); // using (var file = isoStore.OpenFile("topics" + souscatUriShort + ".xml", System.IO.FileMode.Open, System.IO.FileAccess.Read)) // { // using (var reader = new StreamReader(file)) // { // object deserialized = serializer.Deserialize(reader.BaseStream); // topicsObjectCache = (List<HFRClasses.TopicNorm>)deserialized; // // Tri // var topicsParGroupeCache = from categorie in topicsObjectCache // group categorie by categorie.TopicGroup into c // orderby c.Key // select new Group<HFRClasses.TopicNorm>(c.Key, c); // // Binding // Dispatcher.BeginInvoke(() => topicsList.ItemsSource = topicsParGroupeCache); // } // } //} //// Si le cache n'est pas utilisé, on télécharge la liste //else if (!cacheTopic) //{ //if (isoStore.FileExists("topics" + souscatUriShort + ".xml")) isoStore.DeleteFile("topics" + souscatUriShort + ".xml"); //string uriTopicsList = "https://forum.hardware.fr/forum1.php?cat=" + idCat+ "&subcat=" + souscatName + "&page=" + listPageNumber; string uriTopicsList = "https://forum.hardware.fr" + souscatUri; //string uriTopicsList = "http://www.scrubs-fr.net/perso/hfr7/cat0/catzero.htm"; HtmlWeb.LoadAsync(uriTopicsList, container, (s, args) => { if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur dans la lecture de la liste de sujets. Vérifiez votre connectivité. Informations déboguage : " + args.Error.Message + ", " + args.Error.Data); SystemTray.ProgressIndicator.IsVisible = false; }); } if (args.Document == null) { Dispatcher.BeginInvoke(() => MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."));; } else { int i = 0; string[] nameTopics = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.InnerText).ToArray(); string[] idTopics = args.Document.DocumentNode.Descendants("a").Where(x => (bool)x.GetAttributeValue("title", "").Contains("Sujet n°") == true). Select(y => y.GetAttributeValue("title", "").Split('°')[1]).ToArray(); string[] uriTopics = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(x => x.GetAttributeValue("href", "")).ToArray(); //string[] iconTopics = args.Document.DocumentNode.Descendants("img").Where(x => (bool)x.GetAttributeValue("src", "").Contains("http://forum-images.hardware.fr/") == true && ((bool)x.GetAttributeValue("src", "").Contains("sondage") == true || (bool)x.GetAttributeValue("src", "").Contains("icon") == true)). // Select(x => x.GetAttributeValue("src", "")).ToArray(); string[] drapTopics = args.Document.DocumentNode.Descendants("td").Where(x => (string)x.GetAttributeValue("class", "") == "sujetCase5"). Select(x => x.InnerHtml).ToArray(); string[] lastPostTopics = args.Document.DocumentNode.Descendants("td").Where(x => (bool)x.GetAttributeValue("class", "").Contains("sujetCase9") == true). Select(y => y.InnerText).ToArray(); string[] numberOfPagesTopic = args.Document.DocumentNode.Descendants("td").Where(x => (string)x.GetAttributeValue("class", "") == "sujetCase4"). Select(y => y.InnerText).ToArray(); // Suppression de la liste actuelle string iconTopicsLine = ""; string drapTopicsLine = ""; string drapTopicPage = ""; string drapTopicReponse = ""; string numberOfPagesTopicLine = ""; foreach (string line in nameTopics) { // Nombre de pages if (numberOfPagesTopic[i] != " ") { numberOfPagesTopicLine = numberOfPagesTopic[i]; } else { numberOfPagesTopicLine = "1"; } //// Type de topic //if (iconTopics[i].Contains("sondage")) iconTopicsLine = "Images/ImagesTopics/sondage.png"; //else if (iconTopics[i].Contains("flag1")) iconTopicsLine = "Images/ImagesTopics/drapal.png"; //else if (iconTopics[i].Contains("flag0")) iconTopicsLine = "Images/ImagesTopics/drapal.lu.png"; //else iconTopicsLine = "Images/ImagesTopics/topic.png"; // Drapeau ou pas //if (drapTopics[i].Contains("flag0")) drapTopicsLine = "Images/ImagesTopics/drapal.lu.png"; //if (drapTopics[i].Contains("favoris")) drapTopicsLine = "etoile"; // Formatage du nom du sujet string topicName; topicName = TopicNameShortener.Shorten(HttpUtility.HtmlDecode(line)); // Conversion date string favorisSingleLastPostTimeString; favorisSingleLastPostTimeString = Regex.Replace(Regex.Replace(HttpUtility.HtmlDecode(lastPostTopics[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; favorisLastPostUser = HttpUtility.HtmlDecode(lastPostTopics[i].Substring(28, lastPostTopics[i].Length - 28)); // Temps depuis dernier post string favorisLastPostText; TimeSpan timeSpent; timeSpent = DateTime.Now.Subtract(favorisSingleLastPostDT); favorisLastPostText = HFRClasses.TimeSpentTopic.Run(timeSpent, favorisLastPostUser); // Ajout à l'instance topicsObject.Add(new HFRClasses.TopicNorm() { TopicName = topicName, TopicUri = "/ReadTopic.xaml?idcat=" + idCat + "&idtopic=" + idTopics[i] + "&topicname=" + HttpUtility.UrlEncode(line) + "&souscaturi=" + HttpUtility.UrlEncode(souscatUri) + "&souscatname=" + HttpUtility.UrlEncode(souscatName) + "&pagenumber=1&numberofpages=" + numberOfPagesTopicLine + "&from=listtopicscat", TopicUriDrap = "/ReadTopic.xaml?idcat=" + idCat + "&idtopic=" + idTopics[i] + "&topicname=" + HttpUtility.UrlEncode(line) + "&souscaturi=" + HttpUtility.UrlEncode(souscatUri) + "&souscatname=" + HttpUtility.UrlEncode(souscatName) + "&pagenumber=1&numberofpages=" + numberOfPagesTopicLine + "&from=listtopicscat", TopicCatId = idCat, TopicId = idTopics[i], TopicGroup = "page " + listPageNumber, TopicLastPostDateDouble = favorisSingleLastPostTime, TopicLastPost = favorisLastPostText, TopicNumberOfPages = numberOfPagesTopicLine }); i++; } Dispatcher.BeginInvoke(() => { // Tri //var topicsParGroupe = from o in topicsObject // group o by o.TopicGroup into c // orderby c.Key // select new Group<HFRClasses.TopicNorm>(c.Key, c); // Binding if (drapList.ItemsSource != null) { SystemTray.ProgressIndicator.IsVisible = false; } List <GroupFav <TopicNorm> > DataSource = GroupFav <TopicNorm> .CreateGroups(topicsObject, System.Threading.Thread.CurrentThread.CurrentUICulture, (TopicNorm tf) => { return(tf.TopicGroup); }, true); topicsList.ItemsSource = DataSource; //topicsList.ItemsSource = topicsParGroupe.ToList(); }); //// Serialization //XmlSerializer serializer = new XmlSerializer(topicsObject.GetType()); //if (isoStore.FileExists("topics" + souscatUriShort + ".xml")) isoStore.DeleteFile("topics" + souscatUriShort + ".xml"); //using (var file = isoStore.OpenFile("topics" + souscatUriShort + ".xml", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) //{ // using (var writer = new StreamWriter(file)) // { // serializer.Serialize(writer.BaseStream, topicsObject); // } //} } }); }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { SystemTray.ProgressIndicator = new ProgressIndicator(); if ((string)store["disableLandscape"] == "true") { AnswerTopicPage.SupportedOrientations = SupportedPageOrientation.Portrait; } // Background clair ou foncé if ((Visibility)Resources["PhoneDarkThemeVisibility"] == System.Windows.Visibility.Visible) { currentTheme = "dark"; } else { currentTheme = "light"; } //if (AnswerTopicPage.Orientation == PageOrientation.Landscape || AnswerTopicPage.Orientation == PageOrientation.LandscapeLeft || AnswerTopicPage.Orientation == PageOrientation.LandscapeRight) currentOrientation = "landscape"; //else currentOrientation = "portrait"; //backgroundImageBrush.ImageSource = new BitmapImage(new Uri("Images/" + currentTheme + "/Background/Background_" + currentOrientation + ".jpg", UriKind.Relative)); // Cookie container = store["HFRcookies"] as CookieContainer; if (container.Count < 3) { List <Cookie> listCookies = store["listHFRcookies"] as List <Cookie>; foreach (Cookie c in listCookies) { container.Add(new Uri("https://forum.hardware.fr", UriKind.Absolute), c); } store.Remove("HFRcookies"); store.Add("HFRcookies", container); } //GET NavigationContext.QueryString.TryGetValue("pagenumber", out pageNumber); NavigationContext.QueryString.TryGetValue("idtopic", out idTopic); NavigationContext.QueryString.TryGetValue("idcat", out idCat); NavigationContext.QueryString.TryGetValue("topicname", out topicName); topicName = HttpUtility.UrlDecode(topicName); NavigationContext.QueryString.TryGetValue("action", out action); NavigationContext.QueryString.TryGetValue("numberofpages", out numberOfPages); NavigationContext.QueryString.TryGetValue("position", out position); NavigationContext.QueryString.TryGetValue("smileyCode", out smileyCode); NavigationContext.QueryString.TryGetValue("reponseid", out reponseId); NavigationContext.QueryString.TryGetValue("hfrrehost", out hfrRehost); NavigationContext.QueryString.TryGetValue("back", out backAction); NavigationContext.QueryString.TryGetValue("numrep", out numRep); // DEBUG //pageNumber = "7994"; //topicName = "loal.com"; //numberOfPages = "8000"; //numRep = "27926498"; //idTopic = "55667"; //idCat = "13"; //action = "answer"; // Nettoyage du backstack if (backAction == "tool") { NavigationService.RemoveBackEntry(); NavigationService.RemoveBackEntry(); } // Navigated back if (store.Contains("navigatedBack") && backAction != "tool") { navigatedBack = true; store.Remove("navigatedBack"); } // Si sauvegarde if (store.Contains("saveAnswer") && (action == "answer" || action == "edit" || action == "quote" || store.Contains("activated"))) { if (idTopic == (string)store["saveAnswerTopicNumber"]) { saveAnswer = (string)store["saveAnswer"]; // Si smiley if (store.Contains("quotedText")) { quotedText = (string)store["quotedText"]; store.Remove("quotedText"); if (quotedText.Length > 100 && !store.Contains("listQuoteText")) { showQuoteButton.Visibility = System.Windows.Visibility.Visible; answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; } } if (position != null && smileyCode != null) { saveAnswer = saveAnswer.Insert(Convert.ToInt32(position), " " + smileyCode + " "); answerTextBox.Text = saveAnswer; answerTextBox.Select(Convert.ToInt32(position) + smileyCode.Length + 2, 0); store.Remove("smileyCode"); } if (position != null && hfrRehost != null) { saveAnswer = saveAnswer.Insert(Convert.ToInt32(position), hfrRehost); answerTextBox.Text = saveAnswer; answerTextBox.Select(Convert.ToInt32(position) + hfrRehost.Length, 0); } } } // Si liste de quote if (action == "answer") { PageTitle.Text = "votre réponse"; if (!store.Contains("listQuoteText")) { answerTextBox.Focus(); } } if (store.Contains("listQuoteText") && (action == "answer" || action == "quote")) { string listQuoteText = (string)store["listQuoteText"]; answerTextBox.Text = answerTextBox.Text + listQuoteText; store.Remove("listQuoteText"); if (store.Contains("quotedText")) { store.Remove("quotedText"); } store.Add("quotedText", listQuoteText); } // Hash check hash = store["hash"] as String; if (action == "quote" && backAction != "tool" && navigatedBack == false) { PageTitle.Text = "votre réponse"; // Verrouillage de l'answerBox answerTextBox.IsEnabled = false; ApplicationBar.IsVisible = false; // Progress Bar progressBar.Visibility = System.Windows.Visibility.Visible; // On cherche la quote string urlQuote = "https://forum.hardware.fr/message.php?config=hfr.inc&cat=" + idCat + "&post=" + idTopic + "&numrep=" + numRep; HtmlWeb.LoadAsync(urlQuote, container, (s, args) => { Dispatcher.BeginInvoke(() => progressBar.Visibility = System.Windows.Visibility.Visible); if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur dans la lecture de la quote. Informations : " + args.Error.Message + ", " + args.Error.Data); progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } if (args.Document == null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."); answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } else { string[] quoteText = args.Document.DocumentNode.Descendants("textarea").Where(x => (string)x.GetAttributeValue("name", "") == "content_form"). Select(y => y.InnerText).ToArray(); quotedText = HttpUtility.HtmlDecode(quoteText[0]).Substring(0, HttpUtility.HtmlDecode(quoteText[0]).Length - 1); if (store.Contains("quotedText")) { store.Remove("quotedText"); } store.Add("quotedText", quotedText); Dispatcher.BeginInvoke(() => { if (quotedText.Length > 100 && !store.Contains("listQuoteText")) { showQuoteButton.Visibility = System.Windows.Visibility.Visible; answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; } else { showQuoteButton.Visibility = System.Windows.Visibility.Collapsed; answerTextBox.Text = answerTextBox.Text + quotedText; answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; } }); } }); } if (action == "delete") { answerTextBox.Visibility = System.Windows.Visibility.Collapsed; NavigationContext.QueryString.TryGetValue("numrep", out numRep); MessageBoxResult result = MessageBox.Show("Êtes-vous sûr de supprimer ce message ?", "Confirmation", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { PageTitle.Text = "suppression en cours..."; DeleteAnswer(); } else { NavigationService.GoBack(); } } if (action == "edit" && backAction != "tool") { PageTitle.Text = "édition"; NavigationContext.QueryString.TryGetValue("numrep", out numRep); // Verrouillage de l'answerBox answerTextBox.IsEnabled = false; ApplicationBar.IsVisible = false; // Progress Bar progressBar.Visibility = System.Windows.Visibility.Visible; // On cherche le post à éditer NavigationContext.QueryString.TryGetValue("numrep", out numRep); string urlEdit = "https://forum.hardware.fr/message.php?config=hfr.inc&cat=" + idCat + "&post=" + idTopic + "&numreponse=" + numRep; HtmlWeb.LoadAsync(urlEdit, container, (s, args) => { Dispatcher.BeginInvoke(() => progressBar.Visibility = System.Windows.Visibility.Visible); if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur dans la lecture du post. Informations : " + args.Error.Message + ", " + args.Error.Data); progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } if (args.Document == null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Serveur en cours de maintenance. Veuillez réessayer plus tard."); answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } else { string[] editText = args.Document.DocumentNode.Descendants("textarea").Where(x => (string)x.GetAttributeValue("name", "") == "content_form"). Select(y => y.InnerText).ToArray(); Dispatcher.BeginInvoke(() => { answerTextBox.Text = HttpUtility.HtmlDecode(editText[0]) + Environment.NewLine; answerTextBox.IsEnabled = true; ApplicationBar.IsVisible = true; progressBar.Visibility = System.Windows.Visibility.Collapsed; }); } }); } }
private void FindFav() { // Affichage favoris favObject.Clear(); string urlFav = "https://forum.hardware.fr/forum1f.php?owntopic=" + (string)store["favorisType"]; HtmlWeb.LoadAsync(urlFav, container as CookieContainer, (s, args) => { if (args.Error != null) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Impossible d'accéder au serveur. Vérifiez votre connectivité ou l'état de HFR."); progressBar.Visibility = System.Windows.Visibility.Collapsed; globalTextblock.Text = "erreur !"; }); } else { int i = 0; string[] favorisTopicNames = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.InnerText).ToArray(); string[] favorisTopicNumberOfPages = args.Document.DocumentNode.Descendants("td").Where(x => (string)x.GetAttributeValue("class", "") == "sujetCase4"). Select(y => y.InnerText).ToArray(); string[] favorisTopicUri = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "cCatTopic" && (bool)x.GetAttributeValue("title", "").Contains("Sujet") == true). Select(y => y.GetAttributeValue("href", "")).ToArray(); string[] favorisLastPost = args.Document.DocumentNode.Descendants("td").Where(x => (bool)x.GetAttributeValue("class", "").Contains("sujetCase9") == true). Select(y => y.InnerText).ToArray(); string[] favorisIsHot = args.Document.DocumentNode.Descendants("img").Where(x => (string)x.GetAttributeValue("alt", "") == "Off" || (string)x.GetAttributeValue("alt", "") == "On"). Select(y => y.GetAttributeValue("alt", "")).ToArray(); string[] favorisBalise = args.Document.DocumentNode.Descendants("a").Where(x => (bool)x.GetAttributeValue("href", "").Contains("#t")). Select(y => y.GetAttributeValue("href", "")).ToArray(); string[] mpArray = args.Document.DocumentNode.Descendants("a").Where(x => (string)x.GetAttributeValue("class", "") == "red"). Select(y => y.InnerText).ToArray(); string numberOfPagesTopicLine = ""; int j = 0; // Mises à jour des tiles topics foreach (ShellTile tile in ShellTile.ActiveTiles) { if (tile.NavigationUri.ToString() != "/") { foreach (TopicFav fav in favObject) { string tilePostId; int firstTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=") + "&idtopic=".Length; int lastTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&topicname=", firstTilePostId); tilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTilePostId, lastTilePostId - firstTilePostId)); string tileCatId; int firstTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("?idcat=") + "?idcat=".Length; int lastTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=", firstTileCatId); tileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTileCatId, lastTileCatId - firstTileCatId)); // Set the properties to update for the Application Tile. // Empty strings for the text values and URIs will result in the property being cleared. if (tilePostId == fav.TopicIdFav) { StandardTileData NewTileData = new StandardTileData { BackContent = "Nouveaux messages !", BackgroundImage = new Uri("Images/tiles/" + HFRClasses.GetCatName.ShortNameFromId(tileCatId) + "_new.png", UriKind.Relative), BackBackgroundImage = new Uri("Images/tiles/unread.png", UriKind.Relative) }; // Update the Application Tile tile.Update(NewTileData); break; } StandardTileData NewTileDataRead = new StandardTileData { BackContent = "Pas de nouveaux messages", BackgroundImage = new Uri("Images/tiles/" + HFRClasses.GetCatName.ShortNameFromId(tileCatId) + ".png", UriKind.Relative), BackBackgroundImage = new Uri("Images/tiles/read.png", UriKind.Relative) }; // Update the Application Tile tile.Update(NewTileDataRead); } } } ////Mise à jour de la tile principale //int numberOfUnreadFav = favObject.Count; //ShellTile MainTileToFind = ShellTile.ActiveTiles.FirstOrDefault(); //StandardTileData MainNewAppTileData = new StandardTileData //{ // Count = numberOfUnreadFav //}; //MainTileToFind.Update(MainNewAppTileData); // Recherche du topic foreach (string line in favorisTopicNames) { if (favorisIsHot[i] == "On") { // Nombre de pages if (favorisTopicNumberOfPages[i] != " ") { numberOfPagesTopicLine = favorisTopicNumberOfPages[i]; } else { numberOfPagesTopicLine = "1"; } string topicCatId; int firstTopicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&cat=") + "&cat=".Length; int lastTopicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&", firstTopicCatId); topicCatId = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstTopicCatId, lastTopicCatId - firstTopicCatId); string topicId; int firstTopicId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&post=") + "&post=".Length; int lastTopicId = HttpUtility.HtmlDecode(favorisBalise[j]).LastIndexOf("&page"); topicId = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstTopicId, lastTopicId - firstTopicId); string reponseId; int firstReponseId = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("#t") + "#t".Length; int lastReponseId = HttpUtility.HtmlDecode(favorisBalise[j]).Length; reponseId = "rep" + HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstReponseId, lastReponseId - firstReponseId); string pageNumber; int firstPageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).IndexOf("&page=") + "&page=".Length; int lastPageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).LastIndexOf("&p="); pageNumber = HttpUtility.HtmlDecode(favorisBalise[j]).Substring(firstPageNumber, lastPageNumber - firstPageNumber); if (topicId == topicIdTile) { uriTopic = "/ReadTopic.xaml?idcat=" + topicCatId + "&idtopic=" + topicIdTile + "&topicname=" + HttpUtility.UrlEncode(line) + "&pagenumber=" + pageNumber + "&jump=" + reponseId + "&numberofpages=" + numberOfPagesTopicLine + "&back=fftt"; if (numberOfPagesTopicLine == pageNumber) { foreach (ShellTile tile in ShellTile.ActiveTiles) { if (tile.NavigationUri.ToString() != "/") { string tilePostId; int firstTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=") + "&idtopic=".Length; int lastTilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&topicname=", firstTilePostId); tilePostId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTilePostId, lastTilePostId - firstTilePostId)); string tileCatId; int firstTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("?idcat=") + "?idcat=".Length; int lastTileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString()).IndexOf("&idtopic=", firstTileCatId); tileCatId = HttpUtility.HtmlDecode(tile.NavigationUri.ToString().Substring(firstTileCatId, lastTileCatId - firstTileCatId)); if (tilePostId == topicId) { StandardTileData NewTileData = new StandardTileData { BackContent = "Pas de nouveaux messages", BackgroundImage = new Uri("Images/tiles/" + HFRClasses.GetCatName.ShortNameFromId(tileCatId) + ".png", UriKind.Relative), BackBackgroundImage = new Uri("Images/tiles/read.png", UriKind.Relative) }; tile.Update(NewTileData); } } } } } j++; } i++; } if (uriTopic == null) { uriTopic = "/ReadTopic.xaml?idcat=" + idCatTile + "&idtopic=" + topicIdTile + "&topicname=" + topicNameTile + "&pagenumber=" + pageNumberTile + "&jump=bas&numberofpages=" + numberOfPagesTile + "&page=" + numberOfPagesTile + "&back=fftt"; } Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri(uriTopic, UriKind.Relative))); } }); }