private dynamic ParseInsert(string statement) { dynamic insert = new ExpandoObject(); insert.Type = "INSERT"; var tableName = SubstringExtensions.Between(statement, "INSERT INTO", "(", true); insert.Table = tableName.Trim(); var columnstText = SubstringExtensions.Between(statement, "(", ")", true); var columnsArray = columnstText.Split(','); var valuesText = SubstringExtensions.Between(statement, "VALUES (", ");", true); var valuesArray = valuesText.Split(','); dynamic columns = new ExpandoObject(); //Statement validation if (string.IsNullOrEmpty(tableName) || string.IsNullOrWhiteSpace(tableName) || (columnsArray.Length != valuesArray.Length) || (columnsArray.Length == 0) || (valuesArray.Length == 0)) { insert.Error = "Invalid statement"; return(insert); } for (int i = 0; i < columnsArray.Length; i++) { dynamic column = new ExpandoObject(); column.Name = columnsArray[i]; column.Value = valuesArray[i]; AddProperty(columns, i.ToString(), column); } AddProperty(insert, "Columns", columns); return(insert); }
private dynamic ParseDelete(string statement) { dynamic delete = new ExpandoObject(); delete.Type = "DELETE"; if (!statement.Contains("WHERE")) { var tableName = SubstringExtensions.Between(statement, "DELETE FROM", ";", true); delete.Table = tableName; } else { var tableName = SubstringExtensions.Between(statement, "DELETE FROM", "WHERE", true); delete.Table = tableName; dynamic wherExpandoObject = new ExpandoObject(); var whereText = SubstringExtensions.Between(statement, "WHERE", ";", true); int counter = 0; foreach (var oper in ComparisonOperators) { if (whereText.Contains(oper)) { dynamic critera = new ExpandoObject(); critera.Left = SubstringExtensions.Before(whereText, oper); critera.Operator = oper; critera.Right = SubstringExtensions.After(whereText, oper); AddProperty(wherExpandoObject, counter++.ToString(), critera); } } AddProperty(delete, "Where", wherExpandoObject); } return(delete); }
public async Task <IActionResult> Thumbnail(ThumbnailRequest model) { if (!ModelState.IsValid) { return(View(model)); } else { var absolutePath = AppDomain.CurrentDomain.BaseDirectory; var path = absolutePath + "\\" + model.Prefix; bool folderExists = Directory.Exists(path); if (!folderExists) { Directory.CreateDirectory(path); } // Setup the configuration to support document loading var config = Configuration.Default.WithDefaultLoader(); var address = model.Link; // Asynchronously get the document in a new context using the configuration var document = await BrowsingContext.New(config).OpenAsync(address); // This CSS selector gets the desired content var cellSelector = "a"; // Perform the query to get all cells with the content var cells = document.QuerySelectorAll(cellSelector); // We are only interested in the text - select it with LINQ var titles = cells.Select(m => m.TextContent); var links = cells.Select(m => m.GetAttribute("href")).ToList(); var sortedLinks = links.Where(x => x.Contains("/watch?v")).ToList(); sortedLinks = sortedLinks.Select(x => SubstringExtensions.BeforeIfContains(SubstringExtensions.BeforeIfContains(SubstringExtensions.After(x, "/watch?v="), "&index="), "&list=")).ToList(); var tasks = sortedLinks.Select(link => Task.Factory.StartNew(() => { using (WebClient webClient = new WebClient()) { string thumbnailLink = string.Format("https://img.youtube.com/vi/{0}/maxresdefault.jpg", link); try { webClient.DownloadFile(thumbnailLink, string.Format(path + "\\{0}.jpg", link)); webClient.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } })).ToArray(); Task.WaitAll(tasks); return(RedirectToAction("Results", new { prefix = model.Prefix })); } }
private dynamic ParseUse(string statement) { dynamic use = new ExpandoObject(); use.Type = "USE"; var databaseName = SubstringExtensions.Between(statement, "USE", ";", true); use.Database_Name = databaseName; return(use); }
/// <summary> /// Clears and re-creates the dropdown selection of League of Legends versions /// </summary> internal void UpdateMainTopBarVersions() { try { //Get current selected verions string currentVersion = ""; if (dropDownButtonRiotVersion.Text.Contains(" ")) { currentVersion = SubstringExtensions.Before(dropDownButtonRiotVersion.Text, " "); } else { currentVersion = dropDownButtonRiotVersion.Text; } //If the selected version is still current then add back in the " Current LoL" if (currentVersion == form1.getAllVersionAvailable.realm.V) { currentVersion += " Current LoL"; } popupMenuVersions.ItemLinks.Clear(); foreach (string s in form1.getAllVersionAvailable.versions) { BarButtonItem barButtonItemNew = new BarButtonItem(); if (form1.getAllVersionAvailable.realm.V == s) { barButtonItemNew.Caption = s + " Current LoL"; if (currentVersion.Length < 2) { dropDownButtonRiotVersion.Text = barButtonItemNew.Caption; } else { dropDownButtonRiotVersion.Text = currentVersion; } } else { barButtonItemNew.Caption = s; } barButtonItemNew.ItemClick += barButtonItemVersionList_ItemClick; barButtonItemNew.Name = s; popupMenuVersions.AddItem(barButtonItemNew); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SetupItemInformation(ItemStatic inputItem, string version, ItemStatic enchantBaseItem = null) { thisVersion = version; thisID = inputItem.Id; //Filter Out Items if (inputItem.Name.Contains("Enchantment:")) { filteredOut = true; } if (inputItem.Gold.Purchasable == false) { filteredOut = true; } if (inputItem.Name.Contains("Bonetooth Necklace")) { filteredOut = true; } // store tags for this item if (inputItem.Tags != null) { foreach (string tag in inputItem.Tags) { thisTags += " " + tag; } if (!inputItem.Tags.Contains("stealth") && (inputItem.Name.Contains("Greater Vision Totem") || inputItem.Name.Contains("Oracle's Lens"))) { thisTags += " " + "Stealth"; } if (!inputItem.Tags.Contains("stealth") && (inputItem.Description.Contains("stealth-detecting"))) { thisTags += " " + "Stealth"; } } if (thisTags == null) { //If there are no tags then store this information thisTags += " " + "noTag"; } //Select the appropriate image for the item string imageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/{0}/img/sprite/item0.png", thisVersion);; switch (inputItem.Image.Sprite) { case "item0.png": imageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/{0}/img/sprite/item0.png", thisVersion); break; case "item1.png": imageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/{0}/img/sprite/item1.png", thisVersion);; break; case "item2.png": imageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/{0}/img/sprite/item2.png", thisVersion);; break; } //Fix enchantment description and name thisItemDisplayName = inputItem.Name; string ItemDesc = inputItem.Description.ToString(); if (enchantBaseItem != null) { if (enchantBaseItem.Tags.Contains("Boots")) { ItemDesc = enchantBaseItem.Description + "<br/><br/>" + ItemDesc; } else { ItemDesc += "<br/><br/>" + enchantBaseItem.Description; } //Todo, inputItem.Description = ItemDesc; inputItem.Name = enchantBaseItem.Name + " - " + thisItemDisplayName.After("Enchantment: "); thisItemDisplayName = enchantBaseItem.Name + " - " + thisItemDisplayName.After("Enchantment: "); } //Update description to include if requires a champion or if requires a map if (inputItem.RequiredChampion != null) { ItemDesc += string.Format(@"<br/><br/> <font color=""#780000""> This item is only available on {0} </font>", inputItem.RequiredChampion); } if (inputItem.Maps != null) { string tempDescMaps = ""; foreach (KeyValuePair <string, bool> map in inputItem.Maps) { if (map.Value == false) { string mapName = ""; foreach (KeyValuePair <string, string> mapID in PublicStaticVariables.StaticMapIDNames) { if (mapID.Key == map.Key) { mapName = mapID.Value; } } tempDescMaps += string.Format(@" {0} <br/>", mapName); } } if (tempDescMaps != "") { tempDescMaps = tempDescMaps.Substring(0, tempDescMaps.Length - 6); ItemDesc += "<br/><br/> <font color=\"#B69B30\"> This item is not available on the following maps: <br/>" + tempDescMaps + "</font>"; } } //Stores the new Item Description while (ItemDesc.EndsWith("<br/>") || ItemDesc.EndsWith("<br>")) { if (ItemDesc.EndsWith("<br/>")) { ItemDesc = ItemDesc.Substring(0, ItemDesc.Length - 5); } else { ItemDesc = ItemDesc.Substring(0, ItemDesc.Length - 4); } } NewDesc = ItemDesc + "<br/>"; //Only actually render the item if it has not been filtered out string ItemID = "Item" + inputItem.Id; //This section is the item image. A border around the image can be added by adding a border style to the div below. string divOfItem = string.Format(@" <span class=""tooltipWrapper{0}""> <a href=""#"" class=""tooltip""> <div ID=""{2}"" onmouseover=""OnHoverDiv('{1}')"" class=""itemImage"" style=""background-image: url('{3}'); background-position: -{4}px -{5}px;""> </div>" , thisTags //0 , inputItem.Id //1 , ItemID //2 , imageUrl //3 , inputItem.Image.X //4 , inputItem.Image.Y //5 ); //This section is the tooltip image and information. tooltipOfItem = string.Format(@" <span class=""itemToolTip""> <div class=""itemImage"" style=""background-image: url('{0}'); background-position: -{1}px -{2}px;""> </div> <div class=""itemToolTipSpacer""> </div> <span class=""itemToolTipTitle"">{3}</span> <br/> <br /> Cost: <span class=""itemToolTipGold"">{4}</span> <br /> <br /> {5} </i></i></i> </span>" //Note: The </i></i></i> above is a percaution because I found unclosed <i> in Descriptions that broke everything if not closed. , imageUrl //0 , inputItem.Image.X //1 , inputItem.Image.Y //2 , thisItemDisplayName //3 , inputItem.Gold.TotalPrice.ToString() //4 , ItemDesc //5 ); string tempDescription = NewDesc; tempDescription = tempDescription.Replace("<consumable>", "<span style='color:#CC3300;'>"); //"<font color='#CC3300'>"); //dark-ish red tempDescription = tempDescription.Replace("</consumable>", "</span>"); //"</font>"); tempDescription = tempDescription.Replace("<groupLimit>", "<span style='color:#FFFFFF;'>"); //"<font color='#FFFFFF'>"); //white tempDescription = tempDescription.Replace("</groupLimit>", "</span>"); //"</font>"); tempDescription = tempDescription.Replace("<stats>", "<span style='color:#66FF99;'>"); //"<font color='#66FF99'>"); //Light green tempDescription = tempDescription.Replace("</stats>", "</span>"); //"</font>"); tempDescription = tempDescription.Replace("<unique>", "<span style='color:#E6E600;'>"); //dull yellow tempDescription = tempDescription.Replace("</unique>", "</span>"); tempDescription = tempDescription.Replace("<active>", "<span style='color:#E6E600;'>"); //dull yellow tempDescription = tempDescription.Replace("</active>", "</span>"); tempDescription = tempDescription.Replace("<passive>", "<span style='color:#E6E600;'>"); //dull yellow tempDescription = tempDescription.Replace("</passive>", "</span>"); tempDescription = tempDescription.Replace("<aura>", "<span style='color:#E6E600;'>"); //dull yellow tempDescription = tempDescription.Replace("</aura>", "</span>"); tempDescription = tempDescription.Replace("<mana>", ""); tempDescription = tempDescription.Replace("</mana>", ""); if (Regex.Matches(tempDescription, "<span>").Count != Regex.Matches(tempDescription, "</span>").Count) { tempDescription = SpanFixer(tempDescription); } //Fix all of Riot's ill-formaed html tempDescription = tempDescription.Replace("<br>", "<br/>"); int iCount = Regex.Matches(tempDescription, "<i>").Count; while (Regex.Matches(tempDescription, "</i>").Count < iCount) { tempDescription += "</i>"; } if (Regex.Matches(tempDescription, "</i>").Count > iCount) { tempDescription = SubstringExtensions.ReplaceLastOccurrence(tempDescription, "</i>", ""); } //This had to be done on one line or else it causes problems htmlToolTipOfItem = string.Format(@"<html><head></head><body>{0}</body></html>", tempDescription); DivText = StringExtensions.BrWrapper(tempDescription); aItem = inputItem; }
private void button1_Click(object sender, EventArgs e) { if (vars.agreeeula == true) { try { if (textBox1.Text.StartsWith(@"http://")) { textBox1.Text = textBox1.Text.Replace(@"http://", ""); } if (textBox1.Text.StartsWith(@"https://")) { textBox1.Text = textBox1.Text.Replace(@"https://", ""); } if (textBox1.Text.StartsWith(@"ssh://")) { textBox1.Text = textBox1.Text.Replace(@"ssh://", ""); } if (textBox1.Text.StartsWith(@"www")) { textBox1.Text = textBox1.Text.Replace(@"www", ""); } WebRequest req = WebRequest.Create(@"http://" + textBox1.Text + @"/config.txt"); WebResponse response = req.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); config = reader.ReadToEnd(); if (!(config == "")) { panel1.Visible = true; button1.Enabled = false; textBox1.Enabled = false; if (Boolean.Parse(SubstringExtensions.Between(config, "<synclibrary>", @"</synclibrary>"))) { checkBox1.Checked = true; } else { checkBox1.Checked = false; checkBox1.Enabled = false; } if (Boolean.Parse(SubstringExtensions.Between(config, "<syncmedia>", @"</syncmedia>"))) { checkBox2.Checked = true; } else { checkBox2.Checked = false; checkBox2.Enabled = false; } if (Boolean.Parse(SubstringExtensions.Between(config, "<syncpref>", @"</syncpref>"))) { checkBox3.Checked = true; } else { checkBox3.Checked = false; checkBox3.Enabled = false; } if (Boolean.Parse(SubstringExtensions.Between(config, "<automode>", @"</automode>"))) { checkBox4.Checked = true; } else { checkBox4.Checked = false; checkBox4.Enabled = false; } vars.libraryrepo = SubstringExtensions.Between(config, "<libraryrepo>", @"</libraryrepo>"); vars.mediarepo = SubstringExtensions.Between(config, "<mediarepo>", @"</mediarepo>"); vars.prefrepo = SubstringExtensions.Between(config, "<prefrepo>", @"</prefrepo>"); vars.dns = SubstringExtensions.Between(config, "<dns>", @"</dns>"); } } catch (Exception ex) { MessageBox.Show("There was an error connecting to the server. Please check the URL and your connection and try again. Technical details: " + Environment.NewLine + ex.Message.ToString()); } } else { MessageBox.Show("Please agree to the EULA first."); } }
private dynamic ParseSelect(string statement) { dynamic select = new ExpandoObject(); select.Type = "SELECT"; dynamic columns = new ExpandoObject(); //Split statement to words var words = SubstringExtensions.Between(statement, "SELECT", "FROM").Trim().Replace(" ", ""); var columnNames = words.Split(','); if (string.IsNullOrWhiteSpace(words) || columnNames == null || columnNames.Length == 0 || !statement.Contains("FROM")) { select.Error = "Invalid statement"; return(select); } //Column names foreach (var colName in columnNames) { dynamic col1 = new ExpandoObject(); col1.Type = "Column"; col1.Name = colName.Replace(",", "").ToLower(); AddProperty(columns, columnNames.IndexOf(colName).ToString(), col1); } AddProperty(select, "Columns", columns); //Table name and aliases dynamic table = new ExpandoObject(); var tableNameAndAliases = SubstringExtensions.Between(statement, "FROM", "WHERE").Trim(); if (tableNameAndAliases.Contains("AS")) { var tableName = SubstringExtensions.Between(statement, "FROM", "AS").Trim(); var alises = SubstringExtensions.Between(statement, "AS", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); table.Alises = alises.ToLower(); } else { var tableName = SubstringExtensions.Between(statement, "FROM", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); } AddProperty(select, "From", table); //Criteria without order by if (statement.Contains("WHERE") && !statement.Contains("ORDER BY")) { dynamic where = new ExpandoObject(); var wherePhrase = SubstringExtensions.Between(statement, "WHERE", ";").Trim(); var whereArray = wherePhrase.Split(' '); int counter = 0; foreach (var oper in ComparisonOperators) { for (int i = 0; i < whereArray.Length; i++) { if (oper == whereArray[i]) { dynamic crit = new ExpandoObject(); crit.Left = whereArray[i - 1]; crit.Operator = oper; crit.Right = SubstringExtensions.After(wherePhrase, oper).Trim(); AddProperty(where, counter++.ToString(), crit); } } } if (tableNameAndAliases.Contains("AS")) { var tableName = SubstringExtensions.Between(statement, "FROM", "AS").Trim(); var alises = SubstringExtensions.Between(statement, "AS", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); table.Alises = alises.ToLower(); } else { var tableName = SubstringExtensions.Between(statement, "FROM", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); } AddProperty(select, "Where", where); } else if (statement.Contains("WHERE") && statement.Contains("ORDER BY")) { dynamic where = new ExpandoObject(); var wherePhrase = SubstringExtensions.Between(statement, "WHERE", "ORDER BY").Trim(); var whereArray = wherePhrase.Split(' '); int counter = 0; foreach (var oper in ComparisonOperators) { for (int i = 0; i < whereArray.Length; i++) { if (oper == whereArray[i]) { dynamic crit = new ExpandoObject(); crit.Left = whereArray[i - 1]; crit.Operator = oper; crit.Right = SubstringExtensions.After(wherePhrase, oper).Trim(); AddProperty(where, counter++.ToString(), crit); } } } if (tableNameAndAliases.Contains("AS")) { var tableName = SubstringExtensions.Between(statement, "FROM", "AS").Trim(); var alises = SubstringExtensions.Between(statement, "AS", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); table.Alises = alises.ToLower(); } else { var tableName = SubstringExtensions.Between(statement, "FROM", "WHERE").Trim(); table.Type = "Table"; table.Name = tableName.ToLower(); } AddProperty(select, "Where", where); //Order by var orderPhrase = SubstringExtensions.Between(statement, "ORDER BY", ";").Trim(); dynamic orderBy = new ExpandoObject(); orderBy.Type = "Order by"; orderBy.column = orderPhrase; AddProperty(select, "Where", orderBy); } return(select); }
private static void ItemCorrection(ItemStatic temp) { string descriptionMain; List <string> uniqueDescriptions = new List <string>(); if (temp.SanitizedDescription.Contains("UNIQUE")) { descriptionMain = SubstringExtensions.Before(temp.SanitizedDescription, "UNIQUE"); int i = 0; while ((i = temp.Description.IndexOf("UNIQUE", i)) != -1) { int j = temp.Description.IndexOf("<br>", i); if (j == -1) { j = temp.Description.Length; } string uniqueDescription = temp.Description.Substring(i, j - i); if (!uniqueDescription.Contains("UNIQUE Active") && //Todo: All of these should instead of being ignored should be filtered on the Stats Tab and Activatable Items or On/Off !uniqueDescription.Contains("UNIQUE Passive - Point Runner:") && !uniqueDescription.Contains("UNIQUE Passive - Furor:") && !uniqueDescription.Contains("UNIQUE Passive - Captain:") && !uniqueDescription.Contains("UNIQUE Passive - Spellblade:") && !uniqueDescription.Contains("Falling below 50% Health grants")) { uniqueDescriptions.Add(uniqueDescription); } i++; } } else { descriptionMain = temp.SanitizedDescription; } StatCorrection(descriptionMain, temp.Stats); int ind = 0; temp.UniqueStats = new List <KeyValuePair <string, StatsStatic> >(); foreach (string s in uniqueDescriptions) { if (s.Contains("UNIQUE Passive:") || s.Contains("UNIQUE Aura:")) { if (temp.Name.Contains("Ionia")) { string tempNametest = SubstringExtensions.Before(temp.Name, " - "); } else { string tempNametest = temp.Name; } string tempName = (temp.Name.Contains(" - ")) ? SubstringExtensions.Before(temp.Name, " - ") : temp.Name; temp.UniqueStats.Add(new KeyValuePair <string, StatsStatic>(tempName + "~" + s, new StatsStatic())); } else if (s.Contains("UNIQUE Passive - Enhanced Movement")) { temp.UniqueStats.Add(new KeyValuePair <string, StatsStatic>(SubstringExtensions.Before(s, ":"), new StatsStatic())); temp.UniqueStats[ind].Value.FlatMovementSpeedMod = temp.Stats.FlatMovementSpeedMod; temp.Stats.FlatMovementSpeedMod = 0.0; } else { temp.UniqueStats.Add(new KeyValuePair <string, StatsStatic>(SubstringExtensions.Before(s, ":"), new StatsStatic())); } StatCorrection(s, temp.UniqueStats[ind].Value); ind++; } }