public void T001_RankingsParser() { var jsonData = System.IO.File.ReadAllText(@".\test_data\rankings.json"); var conv = new GameDataConverter(); var rankings = conv.GetRankings(jsonData); }
async public void rankings(string jsonData, string type, string continent) { try { log.InfoFormat("New rankings, type: {0}, continent: {1}, parsing...", type, continent); DoProgress(string.Format("New rankings, type:{0}, continent: {1}, parsing...", type, continent)); var conv = new GameDataConverter(); if (type == "0") { var ranks = conv.GetRankings(jsonData); log.InfoFormat("New empire rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New empire rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentEmpireRanking save = new SaveCurrentEmpireRanking(); save.Progress += (s, e) => DoProgress(e.Message); await Task.Run(() => { int c = int.Parse(continent); foreach (var r in ranks) { r.Continent = c; } save.CurrentRankings = ranks; Db.ExecuteWork(save); }); } else if (type == "5") { var ranks = conv.GetUnitsKills(jsonData); log.InfoFormat("New units kills rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New units kills rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentEmpireRanking save = new SaveCurrentEmpireRanking(); save.Progress += (s, e) => DoProgress(e.Message); await Task.Run(() => { foreach (var r in ranks) { r.Continent = 56; } save.CurrentRankings = ranks; Db.ExecuteWork(save); }); } else if (type == "1") { var ranks = conv.GetAliancesRanking(jsonData); log.InfoFormat("New aliances rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New aliances rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentAlianceRanking save = new SaveCurrentAlianceRanking(); int total = ranks.Count; int step = 0; await Task.Run(() => { foreach (var r in ranks) { r.Continent = int.Parse(continent); save.AlianceScore = r; Db.ExecuteWork(save); step++; DoProgress(string.Format("~Db updating.... {0}/{1}", step, total)); } }); } else if (type == "7") { var ranks = conv.GetCaverns(jsonData); log.InfoFormat("New caverns rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New caverns rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentEmpireRanking save = new SaveCurrentEmpireRanking(); save.Progress += (s, e) => DoProgress(e.Message); await Task.Run(() => { foreach (var r in ranks) { r.Continent = 56; } save.CurrentRankings = ranks; Db.ExecuteWork(save); }); } else if (type == "4") { //def rep var ranks = conv.GetDefReputation(jsonData); log.InfoFormat("New def reputation rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New def reputation rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentEmpireRanking save = new SaveCurrentEmpireRanking(); save.Progress += (s, e) => DoProgress(e.Message); await Task.Run(() => { foreach (var r in ranks) { r.Continent = 56; } save.CurrentRankings = ranks; Db.ExecuteWork(save); }); } else if (type == "3") { //off rep var ranks = conv.GetOffReputation(jsonData); log.InfoFormat("New off reputation rankings parsed, rows:{0}, updating database...", ranks.Count()); DoProgress(string.Format("New off reputation rankings parsed, rows:{0}, updating database...", ranks.Count())); SaveCurrentEmpireRanking save = new SaveCurrentEmpireRanking(); save.Progress += (s, e) => DoProgress(e.Message); await Task.Run(() => { foreach (var r in ranks) { r.Continent = 56; } save.CurrentRankings = ranks; Db.ExecuteWork(save); }); } log.Info("Database updated."); m_CurrentStep++; DoProgress("Database updated."); //pobieram następny z listy if (m_Continents.Count > 0) { var paramStr = m_Continents.Dequeue(); var b = paramStr.Split(':')[1]; var a = paramStr.Split(':')[0]; log.InfoFormat("Invoking CotGBrowser_GetRanks({0}, {1}), ...", a, b); DoProgress(string.Format("Invoking CotGBrowser_GetRanks({0}, {1}), ...", a, b)); m_Browser.ExecuteScriptAsync("CotGBrowser_GetRanks", a, b); } else { log.Info("All jobs finished."); DoProgress("All jobs finished."); m_CurrentStep = m_TotalSteps; DoJobFinished(); } } catch (Exception e) { log.Error(e.Message, e); DoProgress(e.Message); } }