/// <summary> /// Prepares script with user-defined providers. /// </summary> protected void SetProviders() { // Set default value for providers string providers = null; if (!String.IsNullOrEmpty(Providers)) { // Split providers by rows string[] rows = Providers.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); // Create javascript variable providers = "var providers = ["; int i = 1; foreach (string row in rows) { string rowValue = row.Trim(); if (i != 1) { providers += ", "; } providers += "{"; var parts = rowValue.Split('|'); var part0 = string.Empty; var part1 = string.Empty; // Check if providers are filled in correctly if (parts.Length >= 2) { part0 = parts[0]; part1 = parts[1]; } // Split URL to get suffix and prefix string url_prefix = null; var url_suffix = part1; var customusername = false; // Check if URL contains macro for custom username if (part1.ToLowerCSafe().Contains(USERNAME_MACRO.ToLowerCSafe())) { var urlParts = part1.Split(new[] { USERNAME_MACRO }, StringSplitOptions.None); url_prefix = urlParts[0]; url_suffix = urlParts[1]; customusername = true; } // long name + short name providers += " longname: \"" + part0 + "\", shortname: \"" + part0 + "\","; // url prefix providers += " url_prefix: \"" + url_prefix + "\","; // url suffix providers += " url_suffix: \"" + url_suffix + "\","; // usercalled (blog name, user name, user id) which will be displayed before username textbox providers += " usercalled: \"username\","; // website url providers += " website: \"" + url_suffix + "\","; // icon if ((parts.Length > 2) && !String.IsNullOrEmpty(parts[2])) { providers += " icon: \"" + URLHelper.GetAbsoluteUrl(PROVIDERS_LOCATION + parts[2].ToLowerCSafe()) + "\","; } else { providers += " icon: \"" + URLHelper.GetAbsoluteUrl(PROVIDERS_LOCATION + "openid.png") + "\","; } // id (used to determine cookie) providers += " id: " + i + ","; // enable username input (openid1 = FALSE means no username input) providers += " openid1: " + customusername.ToString().ToLowerCSafe() + ","; // openid2 providers += " openid2: true"; providers += " }"; i++; } providers += "];"; } providers += "\n"; providers += "var iconlocation = \"" + URLHelper.GetAbsoluteUrl(GetImageUrl("CMSModules/CMS_OpenID/")) + "\"; \n"; providers += "var providerlocation = \"" + URLHelper.GetAbsoluteUrl(PROVIDERS_LOCATION) + "\";\n"; if (DisplayTextbox) { providers += "var idselector_input_id = \"" + txtInput.ClientID + "\";\n"; } else { providers += "var idselector_input_id = \"" + hdnValue.ClientID + "\";\n"; } providers += "var displaytextbox = " + DisplayTextbox.ToString().ToLowerCSafe() + ";\n"; providers += "var otheropenid = \"" + GetString("mem.openid.other") + "\";\n"; providers += "var clicktosignin = \"" + GetString("mem.openid.click") + "\";\n"; ltlProvidersVariables.Text = ScriptHelper.GetScript(providers); }
private void ClearText_Click(object sender, RoutedEventArgs e) { DisplayTextbox.Clear(); }
private void button1_Click(object sender, EventArgs e) { DisplayTextbox displayTextBox = new DisplayTextbox(textBox2); displayTextBox.Clear(); var reddit = new Reddit(); Post giveawayPost = null; int? randomNumber = null; Regex numberPost = new Regex(@"(\d{1,6})"); try { displayTextBox.Write("Getting giveaway post..."); giveawayPost = reddit.GetPost(new Uri(textBox1.Text)); } catch (Exception ex) { displayTextBox.Write("Failed getting giveaway post", "You sure that's the right URI (alsomake sure to get the full uri from the address bar)"); return; } displayTextBox.Write("Post title: ", giveawayPost.Title, "Comment count: ", giveawayPost.CommentCount); try { displayTextBox.Write("Getting random number from random.org..."); WebRequest randomDotOrgRequest = WebRequest.Create(string.Format(RANDOM_ORG_URI, decimal.Round(randomMin.Value, 0), decimal.Round(randomMax.Value, 0))); using (WebResponse resp = randomDotOrgRequest.GetResponse()) { using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { randomNumber = int.Parse(sr.ReadToEnd()); } } } catch (Exception ex) { displayTextBox.Write("Failed getting giveaway post", ex); return; } displayTextBox.Write("Random Number: ", randomNumber, "Getting winning comment...", "This might take a while..."); Dictionary <string, int> nums = giveawayPost.Comments.Where(c => c.Body != null && numberPost.IsMatch(c.Body)).ToDictionary(k => k.Shortlink, elementSelector: x => int.Parse(numberPost.Match(x.Body).Captures[0].Value)); string winningNumKey = null; int? winningNumVal = null; int? diff = null; for (int i = 0; (winningNumKey == null && winningNumVal == null) && (randomNumber + i < decimal.Round(randomMax.Value, 0) || randomNumber - i > 0); i++) { foreach (var x in nums) { if ((x.Value == randomNumber + i && randomNumber + i < decimal.Round(randomMax.Value, 0)) || (x.Value == randomNumber - i && randomNumber - i > decimal.Round(randomMin.Value, 0))) { winningNumKey = x.Key; winningNumVal = x.Value; diff = i; break; } //stop if we're out of range if (randomNumber + i > decimal.Round(randomMax.Value, 0) && randomNumber - i < decimal.Round(randomMin.Value, 0)) { break; } } } if (!string.IsNullOrEmpty(winningNumKey) && winningNumVal.HasValue) { Comment winningComment = giveawayPost.Comments.FirstOrDefault(w => w.Shortlink == winningNumKey); displayTextBox.Write("Winning comment (link): ", winningNumKey, "Winning comment (body): ", winningComment.Body, "Winning comment (commenter): ", winningComment.Author, "Diff: ", diff ); } else { displayTextBox.Write("What the heck?? not one post in the range? you sure you have that range right?"); } }
private void button1_Click(object sender, EventArgs e) { DisplayTextbox displayTextBox = new DisplayTextbox(textBox2); displayTextBox.Clear(); var reddit = new Reddit(); Post giveawayPost = null; int? randomNumber = null; Regex numberPost = new Regex(@"(\d{1,6})"); try { displayTextBox.Write("Getting giveaway post..."); giveawayPost = reddit.GetPost(new Uri(textBox1.Text)); } catch (Exception ex) { displayTextBox.Write("Failed getting giveaway post", "You sure that's the right URI (alsomake sure to get the full uri from the address bar)"); return; } displayTextBox.Write("Post title: ", giveawayPost.Title, "Comment count: ", giveawayPost.CommentCount); try { displayTextBox.Write("Getting random number from random.org..."); WebRequest randomDotOrgRequest = WebRequest.Create(string.Format(RANDOM_ORG_URI, decimal.Round(randomMin.Value, 0), decimal.Round(randomMax.Value, 0))); using (WebResponse resp = randomDotOrgRequest.GetResponse()) { using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { randomNumber = int.Parse(sr.ReadToEnd()); } } } catch (Exception ex) { displayTextBox.Write("Failed getting giveaway post", ex); return; } displayTextBox.Write("Random Number: ", randomNumber, "Getting winning comment...", "This might take a while..."); Dictionary<string, int> nums = giveawayPost.Comments.Where(c => c.Body != null && numberPost.IsMatch(c.Body)).ToDictionary(k => k.Shortlink, elementSelector: x => int.Parse(numberPost.Match(x.Body).Captures[0].Value)); string winningNumKey = null; int? winningNumVal = null; int? diff = null; for (int i = 0; (winningNumKey == null && winningNumVal == null) && (randomNumber + i < decimal.Round(randomMax.Value, 0) || randomNumber - i > 0); i++) { foreach (var x in nums) { if ((x.Value == randomNumber + i && randomNumber + i < decimal.Round(randomMax.Value, 0)) || (x.Value == randomNumber - i && randomNumber - i > decimal.Round(randomMin.Value, 0))) { winningNumKey = x.Key; winningNumVal = x.Value; diff = i; break; } //stop if we're out of range if (randomNumber + i > decimal.Round(randomMax.Value, 0) && randomNumber - i < decimal.Round(randomMin.Value, 0)) break; } } if (!string.IsNullOrEmpty(winningNumKey) && winningNumVal.HasValue) { Comment winningComment = giveawayPost.Comments.FirstOrDefault(w => w.Shortlink == winningNumKey); displayTextBox.Write("Winning comment (link): ", winningNumKey, "Winning comment (body): ", winningComment.Body, "Winning comment (commenter): ", winningComment.Author, "Diff: ", diff ); } else { displayTextBox.Write("What the heck?? not one post in the range? you sure you have that range right?"); } }