public override async Task<IEnumerable<Domain.Tibia.KillStatistic>> LoadAsync(Domain.Tibia.World world) { List<string> filedata = new List<string>(); try { filedata = System.IO.File.ReadAllLines(Enum.GetName(typeof(World), World.Amera) + ".txt").ToList<string>(); } catch (System.IO.FileNotFoundException e) { } List<KillStatistic> data = new List<KillStatistic>(); for (int i = 0; i < filedata.Count; i = i + 2) { string[] strings = filedata[i + 1].Split(' '); foreach (var date in strings) { KillStatistic temp = new KillStatistic(); temp.Monster = filedata[i]; temp.Date = DateTime.Parse(date); data.Add(temp); } } return data; }
public static IEnumerable<KillStatistic> Parse(string htmlPage) { HtmlDocument page = new HtmlDocument(); page.LoadHtml(htmlPage); var tables = page.GetElementbyId("killstatistics").Descendants("table"); if (tables.Count() < 2) throw new ArgumentException("Page format not correct"); var statsTable = tables.Last(); var tableRows = statsTable.Descendants("tr").Skip(2); IList<KillStatistic> extractedStatistics = new List<KillStatistic>(); foreach(var row in tableRows) { var columns = row.Descendants("td"); KillStatistic stat = new KillStatistic { Monster = columns.First().InnerText.Replace(" ", ""), Date = DateTime.Now.AddDays(-1) }; stat.KilledPlayers = Convert.ToInt32(columns.ElementAt(1).InnerText.Replace(" ", "")); stat.KilledByPlayers = Convert.ToInt32(columns.ElementAt(2).InnerText.Replace(" ", "")); extractedStatistics.Add(stat); } return extractedStatistics; }