public void GetIMBDRating(BackgroundWorker worker) { rating_list.Clear(); int max = filterResult.Count; double one = 100 / max; int sum = 0; Parallel.ForEach(filterResult, movie => { worker.ReportProgress(sum); sum += Convert.ToInt32(one); string name = movie.Name.Trim(); //name = HttpUtility.HtmlEncode(name); name = name.Replace(' ', '+'); name = name.Replace(":", "%3A"); name = name.Replace("'", "%27"); string query = "http://www.omdbapi.com/?t=" + name + "&y=" + movie.Year + "&r=xml"; string webData = new WebClient().DownloadString(query); string pattern = "<a href(.*?)>"; var matches = Regex.Matches(webData, pattern); // Check for href-links in movies' plot texts if (matches.Count != 0) { foreach (Match m in matches) { webData = webData.Replace(m.ToString(), ""); } } var xmlMovie = new XmlDocument(); xmlMovie.LoadXml(webData); var deserializedMovie = deserializeFromXMLDoc(xmlMovie); string rating = string.Empty; string plot = string.Empty; string poster = string.Empty; if (deserializedMovie.response == "True") { var currentMovie = deserializedMovie.movie[0]; rating = currentMovie.imdbRating.ToString(); plot = currentMovie.plot; poster = currentMovie.poster; poster = Regex.Replace(poster, @"SX\d{3,}", "SX100"); // Get smaller poster to fit popup } else { rating = "N/A"; plot = "N/A"; poster = "N/A"; } rating_list.Add(new Movie { Name = movie.Name, Year = movie.Year, Rating = rating, Link = movie.Link, videoQuality = movie.videoQuality, audioQuality = movie.audioQuality, NameRussian = movie.NameRussian, Plot = plot, Poster = poster }); }); try { this.Dispatcher.Invoke((Action)(() => { final_list = rating_list; applyFilters(); })); } catch (Exception exceptionObject) { MessageBox.Show(exceptionObject.ToString()); } }
// // GET: /AsposeExporter/ public void Index(string Format="pdf") { string baseURL = Request.Url.Authority; if (Request.ServerVariables["HTTPS"] == "on") { baseURL = "https://" + baseURL; } else { baseURL = "http://" + baseURL; } // Check for license and apply if exists string licenseFile = Server.MapPath("~/App_Data/Aspose.Words.lic"); if (System.IO.File.Exists(licenseFile)) { License license = new License(); license.SetLicense(licenseFile); } string refURL = Request.UrlReferrer.AbsoluteUri; string html = new WebClient().DownloadString(refURL); // To make the relative image paths work, base URL must be included in head section html = html.Replace("</head>", string.Format("<base href='{0}'></base></head>", baseURL)); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(html)); Document doc = new Document(stream); string fileName = System.Guid.NewGuid().ToString() + "." + Format; doc.Save(System.Web.HttpContext.Current.Response, fileName, ContentDisposition.Inline, null); System.Web.HttpContext.Current.Response.End(); }
public static bool DownloadAndDeserialiseJSON(string url) { var json = new WebClient().DownloadString(url); // Fixup NAN -> NaN json = json.Replace("NAN", "NaN"); return DeserializeBeeJSON(json); }
private string urlToHtml; //url to html page where you want to take data from #endregion Fields #region Constructors // 2 arguments constructor, taking url and regex string, public GetDataFromWeb(string urlToHtml, string regexExpr) { this.urlToHtml = urlToHtml; this.regexExpr = regexExpr; htmlInString = new WebClient().DownloadString(urlToHtml); // getting data from http and save it like a string htmlInStringTmp = htmlInString.Replace('\n', ' '); // replacing '\n' on ' ' if necessary matchHtmlStr = Regex.Match(htmlInStringTmp, regexExpr, RegexOptions.IgnoreCase); // matching html file using regex expr ifMatchSuccess(matchHtmlStr); // call function to check if matching success, next save results to List<string>keys }
public string DownloadWeatherXML() { try { string xml = new WebClient().DownloadString(_url); string modifiedxml = xml.Replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n", ""); return modifiedxml; } catch (Exception e) { LogErrors LogObj = new LogErrors(); LogObj.InsertErrors(e.Message, e.Source, e.StackTrace, e.TargetSite.ToString()); return null; } }
/// <summary> /// Get a link to the 640x640 cover art image of a spotify album /// </summary> /// <param name="uri">The Spotify album URI</param> /// <returns></returns> public string getArt(string uri) { try { string raw = new WebClient().DownloadString("http://open.spotify.com/album/" + uri.Split(new string[] { ":" }, StringSplitOptions.None)[2]); raw = raw.Replace("\t", ""); ; string[] lines = raw.Split(new string[] { "\n" }, StringSplitOptions.None); foreach (string line in lines) { if (line.StartsWith("<meta property=\"og:image\"")) { string[] l = line.Split(new string[] { "/" }, StringSplitOptions.None); return "http://o.scdn.co/640/" + l[4].Replace("\"", "").Replace(">", ""); } } } catch { return ""; } return ""; }
/// <summary> /// Recieves a OAuth key from the Spotify site /// </summary> /// <returns></returns> public static string GetOAuth() { string raw = new WebClient().DownloadString("https://embed.spotify.com/openplay/?uri=spotify:track:5Zp4SWOpbuOdnsxLqwgutt"); raw = raw.Replace(" ", ""); string[] lines = raw.Split(new string[] { "\n" }, StringSplitOptions.None); foreach (string line in lines) { if (line.StartsWith("tokenData")) { string[] l = line.Split(new string[] { "'" }, StringSplitOptions.None); return l[1]; } } throw new Exception("Could not find OAuth token"); }
private void TimerPullJsonTick(object sender, EventArgs e) { Debug.WriteLine("Updating"); toolStripStatusLabel1.Text = "Updating"; Application.DoEvents(); try { // Grab data var json = new WebClient().DownloadString(_url); // Fixup NAN -> NaN json = json.Replace("NAN", "NaN"); // Deserialize data var collData = JsonConvert.DeserializeObject<List<BeeData>>(json); UpdateGraphSeries(collData); } catch (Exception ex) { toolStripStatusLabel1.Text = "Problem retrieving JSON:" + ex.Message; ButtonStopClick(this, null); return; } toolStripStatusLabel1.Text = "Done"; Application.DoEvents(); Debug.WriteLine("Update done"); }
/// <summary> /// Recieves a OAuth key from the Spotify site /// </summary> /// <returns></returns> public static string GetOAuth() { string text = new WebClient() { Headers = { "User-Agent: SpotifyAPI" } }.DownloadString("https://embed.spotify.com/openplay/?uri=spotify:track:6uQ192yNyZ4W8yoaL0Sb9p"); text = text.Replace(" ", ""); string[] array = text.Split(new string[] { "\n" }, StringSplitOptions.None); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text2 = array2[i]; bool flag = text2.StartsWith("tokenData"); if (flag) { string[] array3 = text2.Split(new string[] { "'" }, StringSplitOptions.None); return array3[1]; } } throw new Exception("Could not find OAuth token"); }
private void CreateGrubMenu() { var grubMenu = new StringBuilder(); grubMenu.Append("insmod password_pbkdf2" + NewLineChar); grubMenu.Append("insmod regexp" + NewLineChar); grubMenu.Append("set default=0" + NewLineChar); grubMenu.Append("set timeout=10" + NewLineChar); grubMenu.Append("set pager=1" + NewLineChar); if (!string.IsNullOrEmpty(GrubUserName) && !string.IsNullOrEmpty(GrubPassword)) { grubMenu.Append("set superusers=\"" + GrubUserName + "\"" + NewLineChar); string sha = null; try { sha = new WebClient().DownloadString( "http://docs.clonedeploy.org/grub-pass-gen/encrypt.php?password="******"\n \n\n\n", ""); } catch { Logger.Log("Could not generate sha for grub password. Could not contact http://clonedeploy.org"); } grubMenu.Append("password_pbkdf2 " + GrubUserName + " " + sha + "" + NewLineChar); grubMenu.Append("export superusers" + NewLineChar); grubMenu.Append("" + NewLineChar); } grubMenu.Append(@"regexp -s 1:b1 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 2:b2 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 3:b3 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 4:b4 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 5:b5 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 6:b6 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"mac=01-$b1-$b2-$b3-$b4-$b5-$b6" + NewLineChar); grubMenu.Append("" + NewLineChar); if (Type == "standard") { grubMenu.Append("if [ -s /pxelinux.cfg/$mac.cfg ]; then" + NewLineChar); grubMenu.Append("configfile /pxelinux.cfg/$mac.cfg" + NewLineChar); grubMenu.Append("fi" + NewLineChar); } else { grubMenu.Append("if [ -s /proxy/efi64/pxelinux.cfg/$mac.cfg ]; then" + NewLineChar); grubMenu.Append("configfile /proxy/efi64/pxelinux.cfg/$mac.cfg" + NewLineChar); grubMenu.Append("fi" + NewLineChar); } grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Boot To Local Machine\" --unrestricted {" + NewLineChar); grubMenu.Append("exit" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Client Console\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=debug consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"On Demand Imaging\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=ond consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Add Computer\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=register consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Diagnostics\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=diag consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); var path = Settings.TftpPath + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; new FileOps().WritePath(path, grubMenu.ToString()); }
public List<Company> GetCompaniesSymbols(string url) { int i = 0; List<Company> companies = new List<Company>(); string response = new WebClient().DownloadString(url); response = response.Replace(@"\", ""); JObject parsedResponse = JsonConvert.DeserializeObject<JObject>(response); foreach (var property in parsedResponse) { string key = property.Key; if (key == "searchresults") { JArray values = (JArray)property.Value; foreach (JObject property2 in values) { Company company = new Company(); foreach (var property3 in property2) { if (property3.Key == "title") { company.Name = property3.Value.ToString(); } else if (property3.Key == "ticker") { company.Symbol = property3.Value.ToString(); } } companies.Add(company); } } } return companies; }
public void GoogleDrive(string database) { // create the DatabaseClient passing my Gmail or Google Apps credentials IDatabaseClient client = new DatabaseClient(emailUsername, emailPassword); // get or create the database. This is the spreadsheet file IDatabase db = client.GetDatabase(database) ?? client.CreateDatabase(database); // get or create the table. This is a worksheet in the file // note I am using my Person object so it knows what my schema needs to be // for my data. It will create a header row with the property names System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo(); string monthName = d.MonthNames[DateTime.Now.Month - 1]; string worksheet = user.ToLower().Replace(" ", "").Replace("\r\n", "").Replace(System.Environment.NewLine, ""); ITable<CycleData> table = db.GetTable<CycleData>(worksheet) ?? db.CreateTable<CycleData>(worksheet); string IP = new WebClient().DownloadString("http://icanhazip.com/"); // now I can fill a Person object and add it var cycleData = new CycleData(); cycleData.Time = DateTime.Now.ToString("MM.dd.yy").Replace("\r\n", "").Replace(System.Environment.NewLine, ""); cycleData.killer = AvatarID.Text.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, ""); cycleData.ipAddress = IP.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, ""); IList<IRow<CycleData>> rows = table.FindStructured(string.Format("killer=\"{0}\"", cycleData.Time)); if (rows == null || rows.Count == 0) { // Email does not exist yet, add row table.Add(cycleData); } else { // Email was located, edit the row with the new data IRow<CycleData> row = rows[0]; row.Element = cycleData; row.Update(); } }