public async Task <Artifact> GetArtifact(Artifact.ArtifactStatic artifactStatic) { var version = GlobalSettings.FileVersions.Artifact; if (string.IsNullOrWhiteSpace(version)) { version = GlobalSettings.DefaultVersion; } var data = await WebClient.GetString(new Uri(GHStatic + version + ArtifactsPath)); if (data == null) { return(null); } var dataCSV = CsvReader.ReadFromText(data); ICsvLine artifactRow = dataCSV.SingleOrDefault(r => r[0].EndsWith("t" + artifactStatic.Id)); if (artifactRow == null) { return(null); } var image = await GetImage(artifactStatic.ImageUrl); return(BuildArtifact(artifactRow, artifactStatic, image, version)); }
public async Task <Equipment> GetEquipment(Equipment.EquipmentStatic equipmentStatic) { var version = GlobalSettings.FileVersions.Equipment; if (string.IsNullOrWhiteSpace(version)) { version = GlobalSettings.DefaultVersion; } var data = await WebClient.GetString(new Uri(GHStatic + version + EquipmentPath)); if (data == null) { return(null); } var dataCSV = CsvReader.ReadFromText(data); ICsvLine equipmentRow = dataCSV.SingleOrDefault(r => r[0] == equipmentStatic.Id); if (equipmentRow == null) { return(null); } var image = await GetImage(equipmentStatic.ImageUrl); return(BuildEquipment(equipmentRow, equipmentStatic, image, version)); }
public Order(ICsvLine line) { this.id = line["id"]; this.total = Convert.ToDecimal(line["total"], System.Globalization.CultureInfo.InvariantCulture); this.parent_id = Int32.Parse(line["category_id"]); this.created = DateTime.Parse(line["created"]); }
public async Task <Helper> GetHelper(Helper.HelperStatic helperStatic) { var version = GlobalSettings.FileVersions.Helper; if (string.IsNullOrWhiteSpace(version)) { version = GlobalSettings.DefaultVersion; } var data = await WebClient.GetString(new Uri(GHStatic + version + HelpersPath)); if (data == null) { return(null); } var dataCSV = CsvReader.ReadFromText(data); ICsvLine helperRow = dataCSV.SingleOrDefault(r => r[0] == "H" + helperStatic.Id.ToString("00")); if (helperRow == null) { return(null); } var image = await GetImage(helperStatic.ImageUrl); var skills = await GetAllHelperSkills(); return(BuildHelper(helperRow, skills, helperStatic, image, version)); }
internal static HighScoreUser FromCsv(ICsvLine data, HighScoreSettings settings) { int ranking; string userName; string clanName; string rankMs; string simMs; string rankRel; string totalRelics; string rawAd; string fullAd; if (!int.TryParse(data[settings.RankingCol].Trim(), out ranking)) { return(null); } userName = data[settings.NameCol].Trim(); clanName = data[settings.ClanCol].Trim(); rankMs = data[settings.RankMsCol].Trim(); simMs = data[settings.SimMSCol].Trim(); rankRel = data[settings.RankRelCol].Trim(); totalRelics = data[settings.TotalRelicsCol].Trim(); rawAd = data[settings.RawADCol].Trim(); fullAd = data[settings.FullADCol].Trim(); return(new HighScoreUser(ranking, userName, clanName, rankMs, simMs, rankRel, totalRelics, rawAd, fullAd)); }
public void AddValidElement(ICsvLine line) { try { if (String.IsNullOrWhiteSpace(line["total"]) || String.IsNullOrWhiteSpace(line["id"]) || String.IsNullOrWhiteSpace(line["category_id"])) { return; } Order ord = new Order(line); if (list.ContainsKey(Int32.Parse(line["category_id"]))) { list[Int32.Parse(line["category_id"])].total += ord.total; } else { list[Int32.Parse(line["category_id"])] = ord; } } catch (Exception e) { //do nothing, element is invalid return; } }
public async Task <Pet> GetPet(Pet.PetStatic petStatic) { var version = GlobalSettings.FileVersions.Pet; if (string.IsNullOrWhiteSpace(version)) { version = GlobalSettings.DefaultVersion; } var data = await WebClient.GetString(new Uri(GHStatic + version + PetsPath)); if (data == null) { return(null); } var dataCSV = CsvReader.ReadFromText(data); ICsvLine petRow = dataCSV.SingleOrDefault(r => r[0] == "Pet" + petStatic.Id); if (petRow == null) { return(null); } var image = await GetImage(petStatic.ImageUrl); return(BuildPet(petRow, petStatic, image, version)); }
public List <TaskEntry> GetRange(int offset, int count) { // Read entire CSV string contents = dbFile.DownloadTextAsync().Result; List <TaskEntry> tasks = new List <TaskEntry>(); int endOffset = offset + count; IEnumerable <ICsvLine> lines = CsvReader.ReadFromText(contents, this.csvOptions); // Check we have enough entries if (lines.Count() < endOffset) { endOffset = lines.Count(); } for (int i = offset; i < endOffset; i++) { ICsvLine line = lines.ElementAt(i); try { tasks.Add(new TaskEntry(Int32.Parse(line["id"]), line["title"], System.Convert.ToBoolean(line["isComplete"]))); } catch { // Unable to parse entry or final blank line in CSV } } return(tasks); }
public static bool IsValid(this ICsvLine line) { if (line.Headers.Contains("key") && line.Headers.Count() > 1) { return(true); } return(false); }
private Equipment BuildEquipment(ICsvLine serverData, Equipment.EquipmentStatic staticData, Bitmap image, string version) { Enum.TryParse(serverData[1], out EquipmentClass eClass); Enum.TryParse(serverData[2], out BonusType bonusType); Enum.TryParse(serverData[3], out EquipmentRarity rarity); double.TryParse(serverData[4], out double bonusBase); double.TryParse(serverData[5], out double bonusIncrease); Enum.TryParse(serverData[6], out EquipmentSource source); return(staticData.Build(eClass, bonusType, rarity, bonusBase, bonusIncrease, source, image ?? new Bitmap(1, 1), version)); }
private Helper BuildHelper(ICsvLine serverData, List <HelperSkill> helperSkills, Helper.HelperStatic staticData, Bitmap image, string version) { int.TryParse(serverData[0].Replace("H", ""), out int helperId); int.TryParse(serverData[1], out int order); Enum.TryParse(serverData[2], out HelperType type); double.TryParse(serverData[3], out double baseCost); int.TryParse(serverData[4], out int isInGame); var skills = helperSkills.Where(h => h.HelperId == helperId).ToList(); return(staticData.Build(type, order, baseCost, skills, isInGame > 0, image ?? new Bitmap(1, 1), version)); }
private HelperSkill BuildHelperSkill(ICsvLine serverData, string version) { int.TryParse(serverData[0], out int skillId); int.TryParse(serverData[1].Replace("H", ""), out int helperId); var name = serverData[2]; Enum.TryParse(serverData[3], out BonusType type); double.TryParse(serverData[4], out double magnitude); int.TryParse(serverData[5], out int requirement); return(new HelperSkill(skillId, helperId, name, type, magnitude, requirement, version)); }
private bool AddValue(PathSegment s, ICsvLine line, int index, string name) { double v; if (!Double.TryParse(line[index], out v)) { v = Double.NaN; } s.SetValue(name, v); return(true); }
public Boolean ToggleComplete(int id) { // Read entire CSV string contents = dbFile.DownloadTextAsync().Result; List <string> newLines = new List <string>(); newLines.Add("id,title,isComplete"); // Find the line to toggle IEnumerable <ICsvLine> lines = CsvReader.ReadFromText(contents, this.csvOptions); for (int i = 0; i < lines.Count(); i++) { ICsvLine line = lines.ElementAt(i); try { if (Int32.Parse(line["id"]) == id) { string lineStr = line.Raw; string[] lineCols = lineStr.Split(','); if (lineCols[2] == "True") { lineCols[2] = "False"; } else { lineCols[2] = "True"; } newLines.Add(string.Join(",", lineCols.ToArray())); } else { newLines.Add(line.Raw); } } catch { // Ignore lines which are not parsable } } string linesString = string.Join("\r\n", newLines.ToArray()); byte[] linesBytes = Encoding.ASCII.GetBytes(linesString); // overwrite db dbFile.UploadFromByteArray(linesBytes, 0, linesBytes.Length); return(true); }
public Category(ICsvLine line) { this.name = line["name"]; this.id = Int32.Parse(line["id"]); if (!String.IsNullOrWhiteSpace(line["category_id"])) { this.parent_id = Int32.Parse(line["category_id"]); } else { this.parent_id = 0; } }
private Artifact BuildArtifact(ICsvLine serverData, Artifact.ArtifactStatic staticData, Bitmap image, string version) { int.TryParse(serverData[1], out int maxLevel); string tt1 = serverData[2]; Enum.TryParse(serverData[3], out BonusType bonusType); double.TryParse(serverData[4], out double effectPerLevel); double.TryParse(serverData[5], out double damageBonus); double.TryParse(serverData[6], out double costCoef); double.TryParse(serverData[7], out double costExpo); string note = serverData[8]; string name = serverData[9]; return(staticData.Build(maxLevel == 0 ? (int?)null : maxLevel, tt1, bonusType, effectPerLevel, damageBonus, costCoef, costExpo, note, image ?? new Bitmap(1, 1), version)); }
bool TryGetLineValue(ICsvLine line, string columName, out string columValue) { columValue = ""; bool result = true; try { columValue = line[columName]; } catch { result = false; } result = string.IsNullOrEmpty(columValue) == false; return(result); }
private CellDefinition GetRow(ICsvLine line) { var cellDefinition = new CellDefinition { Key = line[0] }; foreach (var row in line.Headers.Skip(1)) { if (!cellDefinition.Columns.ContainsKey(row) && !string.IsNullOrEmpty(line[row])) { cellDefinition.Columns.Add(row, line[row]); } } return(cellDefinition); }
public async Task Check() { // Arrange var text = "foo"; var csvLineRule = new CsvLineRule(x => x["A"] == text ); var mock = new Mock <ICsvLine>(); mock.SetupGet(p => p[It.IsAny <string>()]).Returns(text); ICsvLine obj = mock.Object; // Act var result = await csvLineRule.Check(obj); // Assert Assert.True(result); }
public void AddValidElement(ICsvLine line) { try { if (String.IsNullOrWhiteSpace(line["name"]) || String.IsNullOrWhiteSpace(line["id"])) { return; } Category cat = new Category(line); list[Int32.Parse(line["id"])] = cat; } catch (Exception e) { // do nothing element is invalid return; } }
//adaugarea elementelor public void AddValidElement(ICsvLine line) { //parsarea categoriilor din CSV try { if (String.IsNullOrWhiteSpace(line["name"]) || String.IsNullOrWhiteSpace(line["id"])) { return; } Category cat = new Category(line); list[Int32.Parse(line["id"])] = cat; } catch (Exception e) { return; } }
private Pet BuildPet(ICsvLine serverData, Pet.PetStatic staticData, Bitmap image, string version) { var incrementRange = new Dictionary <int, double> { }; double.TryParse(serverData[1], out double damageBase); double.TryParse(serverData[2], out double inc1to40); double.TryParse(serverData[3], out double inc41to80); double.TryParse(serverData[4], out double inc80on); Enum.TryParse(serverData[5], out BonusType bonusType); double.TryParse(serverData[6], out double bonusBase); double.TryParse(serverData[7], out double bonusIncrement); incrementRange.Add(1, inc1to40); incrementRange.Add(41, inc41to80); incrementRange.Add(81, inc80on); return(staticData.Build(damageBase, incrementRange, bonusType, bonusBase, bonusIncrement, image ?? new Bitmap(1, 1), version)); }
public bool Insert(string title) { // Read entire CSV string contents = dbFile.DownloadTextAsync().Result; List <string> newLines = new List <string>(); newLines.Add("id,title,isComplete"); // Cycle through CSV lines and populate a new list IEnumerable <ICsvLine> lines = CsvReader.ReadFromText(contents, this.csvOptions); for (int i = 0; i < lines.Count(); i++) { ICsvLine line = lines.ElementAt(i); try { // Check id is parsable, otherwise remove the entry Int32.Parse(line["id"]); newLines.Add(line.Raw); } catch { // Ignore lines which are not parsable } } // Insert the new entry into the new list Random random = new Random(); int id = random.Next(); string[] lineCols = { id.ToString(), title, "false" }; newLines.Add(string.Join(",", lineCols.ToArray())); string linesString = string.Join("\r\n", newLines.ToArray()); byte[] linesBytes = Encoding.ASCII.GetBytes(linesString); // overwrite db dbFile.UploadFromByteArray(linesBytes, 0, linesBytes.Length); return(true); }
private static async Task <Img> GetImageFromFile(Project project, ICsvLine line, string resourcesPath) { Img img = new Img(); string imgpath = ""; string tags = ""; try { imgpath = line["sourcefile"]; img.filepath = Path.GetFullPath(resourcesPath + "/trainingImages/" + imgpath); tags = line["tags"]; } catch (Exception e) { Console.WriteLine($"\n{e.GetType().Name}: Could not get source file name and tags from csv file."); throw; } string[] tagsList = tags.Split(','); foreach (string t in tagsList) { try { Tag tag = await GetTag(project, t); img.tags.Add(tag); } catch (Exception e) { Console.WriteLine($"\n{e.GetType().Name}: Could not get tag from project."); throw; } } return(img); }
private static async Task <Img> GetImageFromURL(Project project, ICsvLine line, CloudFileShare share) { Img img = new Img(); string url = ""; string tags = ""; try { url = line["sourcefile"]; img.url = AzureStorageHelpers.GetFileURL(url, share); tags = line["tags"]; } catch (Exception e) { Console.WriteLine($"\n{e.GetType().Name}: Could not get source file name and tags from csv file."); throw; } string[] tagsList = tags.Split(','); foreach (string t in tagsList) { try { Tag tag = await GetTag(project, t); img.tags.Add(tag); } catch (Exception e) { Console.WriteLine($"\n{e.GetType().Name}: Could not get tag from project."); throw; } } return(img); }
public VehicleFromCsvLineFactorySettings(int siteId, ICsvLine csvLine, IDictionary <string, string> propertyMapping) { SiteId = siteId; CsvLine = csvLine; PropertyMapping = propertyMapping; }
public static T?TryParseColumn <T>(this ICsvLine csvLine, String columnName, TryParseDelegate <T> tryParse) where T : struct => !csvLine.HasColumn(columnName) ? null : csvLine[columnName]?.TryParse(tryParse);
string GetLineValue(ICsvLine line, int index, EColumnName columnName) { string columnNameString = GetColumnName(index, columnName); return(line[columnNameString]); }
bool TryGetLineValue(ICsvLine line, int index, EColumnName columnName, out string columnValue) { string columnNameString = GetColumnName(index, columnName); return(TryGetLineValue(line, columnNameString, out columnValue)); }
private TEntity Build(ICsvLine row, string version) => Build(new Iterable <string>(Enumerable.Range(0, row.ColumnCount).Select(i => row[i])), version);