public List <MarioMakerLevel> ReadCSV(string path) { var items = new List <MarioMakerLevel>(); // Create list of items using (TextFieldParser parser = new TextFieldParser(path)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); var index = 0; while (!parser.EndOfData) // Check if we are not at the end of file { //Processing row string[] fields = parser.ReadFields(); // Get the row fields if (index > 0) { var item = new MarioMakerLevel(); // Create a new object var props = typeof(MarioMakerLevel).GetProperties(); // Get the properties of MarioMakerLevel var j = 0; foreach (var prop in props) // Loop through the properties { if (j < fields.Length) { typeof(MarioMakerLevel).GetProperty(prop.Name).SetValue(item, Convert.ChangeType(fields[j], prop.PropertyType)); // Set value of item property to fields[j] } j++; } items.Add(item); // Add item to list } index++; // Iterate } } return(items); // Return items }
private void SortingBox_SelectedIndexChanged(object sender, EventArgs e) { MarioMakerLevel item = new MarioMakerLevel(); ComboBox comboBox = (ComboBox)sender; // Create object using sender var sortingValue = (string)SortingBox.SelectedItem; // Turn the comboBox selected item into a string item.SortList(marioMakerLevels, sortingValue); // Sort the list by the sortingValue ResetShownLevels(pagenumber); ResetDataSource(); ResetPageBox(); }
private bool checkHasNull(MarioMakerLevel level) { foreach (var prop in typeof(MarioMakerLevel).GetProperties()) // Foreach property { if (prop.GetValue(level) == null) // Check if null { Console.WriteLine(prop.GetValue(level)); return(true); // If null return true } } return(false); // If none found null, return false }
public string ConvertItemToString(MarioMakerLevel item) { var final = ""; var props = typeof(MarioMakerLevel).GetProperties(); // Get the properties from the Item class using reflection foreach (var prop in props) { string str = prop.GetValue(item, null).ToString(); // Get the value of the property of item as a string str = str.Replace(",", ""); str = str.Replace(@"\", ""); str = str.Replace("'", ""); final += str; // Add each properties value to the final output final += ","; // Seperate each property } //final += "\n"; // End line of final string return(final.Substring(0, final.Length - 1)); // Return the final string with the last "," removed }
public List <MarioMakerLevel> GetLevels(int page, int gameStyle, int courseTheme, int region, int difficulty, int tag, int uploadDate) { List <MarioMakerLevel> marioMakerLevels = new List <MarioMakerLevel>(); // Get a new list of marioMakerLevels string finalTag = ""; // Create a finalTag variable if (tag != 0) // If the tag is not 0 { finalTag = tag.ToString(); // Then make the finalTag equal to the tag value } string startString = "https://supermariomakerbookmark.nintendo.net/search/result?"; // Starting string of website string pageString = $"page={page + 1}"; // Get website string for page string skinString = $"&q%5Bskin%5D={ gameStyles[gameStyle] }"; // Get website string for skin string sceneString = $"&q%5Bscene%5D={ courseThemes[courseTheme] }"; // Get website string for theme string areaString = $"&q%5Barea%5D={ regions[region] }"; // Get website string for region string difficultyString = $"&q%5Bdifficulty%5D={ difficulties[difficulty] }"; // Get website string for difficulty string tagString = $"&q%5Btag_id%5D={ finalTag }"; // Get website string for tag string createdAtString = $"&q%5Bcreated_at%5D={ uploadDates[uploadDate] }"; // Get website string for uploaddate string endString = $"&q%5Bsorting_item%5D=like_rate_desc"; // The ending string of website // Compile all these strings into one string variable string finalString = startString + pageString + skinString + sceneString + areaString + difficultyString + tagString + createdAtString + endString; HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb(); // Get a html web object HtmlAgilityPack.HtmlDocument doc = web.Load(finalString); // Create new doc object using web load of the string if (doc != null) // If the doc collected is not null { for (int i = 0; i < 10; i++) { MarioMakerLevel level = new MarioMakerLevel(); // Get level title try { level.Title = doc.DocumentNode.SelectNodes("//div[@class='course-title']")[i].InnerText; } catch { } // Get level author try { level.Author = doc.DocumentNode.SelectNodes("//div[@class='name']")[i].InnerText; } catch { } // Get level theme try { level.GameStyle = doc.DocumentNode.SelectNodes("//div[@class='gameskin-wrapper']")[i].FirstChild.Attributes[0].Value.Replace("gameskin bg-image common_gs_", ""); } catch { } // Get level difficulty try { level.Difficulty = doc.DocumentNode.SelectNodes("//div[@class='rank nonprize']")[i].NextSibling.InnerText; } catch { } // Get level clear rate (Redacted) //try { level.ClearRate = GetValueFromFont(doc.DocumentNode.SelectNodes("//div[@class='clear-rate']")[i]); } catch { } // Get level stars try { level.Stars = int.Parse(GetValueFromFont(doc.DocumentNode.SelectNodes("//div[@class='liked-count ']")[i])); } catch { } // Get level players played try { level.PlayersPlayed = int.Parse(GetValueFromFont(doc.DocumentNode.SelectNodes("//div[@class='played-count ']")[i])); } catch { } // Get level clears try { level.Clears = int.Parse(GetValueFromClears(doc.DocumentNode.SelectNodes("//div[@class='tried-count ']")[i])[0]); } catch { } // Get level rounds played try { level.RoundsPlayed = int.Parse(GetValueFromClears(doc.DocumentNode.SelectNodes("//div[@class='tried-count ']")[i])[1]); } catch { } // Get level clear rate try { level.ClearRate = GetValueFromClears(doc.DocumentNode.SelectNodes("//div[@class='tried-count ']")[i])[2]; } catch { } // Get level tag try { level.Tag = doc.DocumentNode.SelectNodes("//div[@class='course-tag radius5']")[i].InnerText; } catch { } // Get level flag try { level.Flag = doc.DocumentNode.SelectNodes("//div[@class='creator-info']")[i].FirstChild.Attributes[0].Value.Replace("flag ", ""); } catch { } // Get level date uploaded //level.DateUploaded = doc.DocumentNode.SelectNodes("//div[@class='created_at']")[i].InnerText; // Get level link try { level.Link = "https://supermariomakerbookmark.nintendo.net" + doc.DocumentNode.SelectNodes("//a[@class='button course-detail link']")[i].GetAttributeValue("href", "null"); } catch { } marioMakerLevels.Add(level); // Add the level to the list of levels } return(marioMakerLevels); // Return levels } return(null); // Otherwise return null }
public MarioMakerLevel ConvertStringToItem(string str) { MarioMakerLevel level = new MarioMakerLevel(); return(level); }