private static bool TestDownloadWallpaper() { rsEvent.Reset(); Console.WriteLine(@"[Downloading wallpapers(1 random wallpapers per parser) ]"); int thread = 0; int doneThread = 0; int maxThreads = 1; int downloaded = 0; foreach (var capsule in _capsuleList) { if (capsule.IsNotWorking) { PrintColoredTextOnce(@" " + capsule.Scraper.SiteName + @" isnt working.... move on"); continue; } Console.WriteLine(@" Now downloading at " + capsule.Scraper.SiteName); foreach (var list in capsule.ListOfResList) { thread++; for (int i = 0; i < 1; i++) //take 1 time each ResList { string wallpaperLink = list[Rnd.Next(list.Count)].ResolutionUrl; if (capsule.Scraper.IsJpgUrlNeedParsed) { var w = new WebDownload(); wallpaperLink = capsule.Scraper.JpgLink(w.DownloadString(new Uri(Extentions.HandleWeirdFormat(wallpaperLink)))); } var getData = new GetDataAsync(wallpaperLink); getData.DownloadComplete += (sender, e) => getData_DownloadWallpaperCompleted(sender, e, wallpaperLink, ref doneThread, maxThreads, ref downloaded); } if (thread != maxThreads) { continue; } rsEvent.WaitOne(); thread = 0; break; //rsEvent.WaitOne(); } } int numberOfInfoList = 0; _capsuleList.ForEach(a => numberOfInfoList += a.ListOfResList.Count); Console.WriteLine(@"Downloaded wallpapers: " + downloaded + "/" + numberOfInfoList); return(true); }
public static JsonUtils.JsonObject GetDynamicJsonObject(this Uri uri, string ProxyName, int ProxyPort) { using (var wc = new WebDownload()) { wc.Encoding = Encoding.UTF8; wc.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E)"; if (!ProxyName.Equals(String.Empty)) { var myproxy = new WebProxy(ProxyName, ProxyPort); myproxy.BypassProxyOnLocal = false; wc.Proxy = myproxy; } return(JsonUtils.JsonObject.GetDynamicJsonObject(wc.DownloadString(uri.ToString()))); } }
private static void CallEngine() { try { //WebRequest webRequest = WebRequest.Create(WebMonitoringEngineURL); //WebResponse webResp = webRequest.GetResponse(); var webpage = new WebDownload(); string s = webpage.DownloadString(new Uri(WebActionEngineURL)); s = s.Substring(0, s.Length - 9).Substring(68); Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Finished -> " + System.Net.WebUtility.HtmlDecode(s)); } catch (Exception ex) { Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Error -> " + ex.Message); new RMSAppException("CallEngine failed. WebActionEngineURL = " + WebActionEngineURL + ", " + ex.Message, ex, true); } }
static bool TestDownloadRndPage() { Console.WriteLine(@"[Dl rnd pages]"); foreach (var parser in Scraper.InstanciatedScrapers) { var webClient = new WebDownload(); var capsule = new DataCapsule(); string link = parser.GetRandomPageUrl(); string html = string.Empty; try { html = webClient.DownloadString(link); //if (parser.SiteName == "Goodfon") // html = string.Empty; if (string.IsNullOrEmpty(html)) { throw new Exception(@" html string is null or zero in length at: " + parser.SiteName); } } catch (Exception ex) { PrintColoredTextOnce(@" Site: " + parser.SiteName); if (ex.Message.Length > 0) { PrintColoredTextOnce(@" " + ex.Message); } else { PrintColoredTextOnce(@" Failed to download random page"); } continue; } capsule.Scraper = parser; capsule.RndPageHtml = html; _capsuleList.Add(capsule); } return(true); }
private static void CallMonitoringEngine() { try { //WebRequest webRequest = WebRequest.Create(monitoringEngineURL); //WebResponse webResp = webRequest.GetResponse(); Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Started Monitoring"); var webpage = new WebDownload(); string s = webpage.DownloadString(new Uri(monitoringEngineURL)); s = s.Substring(0, s.Length - 9).Substring(68); Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Finished Monitoring -> " + s); } catch (Exception ex) { Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Error Monitoring -> " + ex.Message); new RMSAppException("CallMonitoringEngine failed. monitoringEngineURL = " + monitoringEngineURL + ", " + ex.Message, ex, true); } }
private static void CallWebsiteMonitoringEngine() { try { if (ConfigurationManager.AppSettings["RMS.WebsiteMonitoringEnable"] == null || !Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.WebsiteMonitoringEnable"])) { return; } Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Started Website Monitoring"); var webpage = new WebDownload(); string s = webpage.DownloadString(new Uri(websiteMonitoringEngineURL)); s = s.Substring(0, s.Length - 9).Substring(68); Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Finished Website Monitoring -> " + s); } catch (Exception ex) { Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " : Error Website Monitoring -> " + ex.Message); new RMSAppException("CallWebsiteMonitoringEngine failed. websiteMonitoringEngineURL = " + websiteMonitoringEngineURL + ", " + ex.Message, ex, true); } }