private async void button1_Click_1(object sender, EventArgs e) { //TODO: // DataGridView has memory leak // need to optimize string season_id = this.GetProperSeasonName(this.comboBoxSeason.SelectedItem.ToString()); string platform = this.comboBoxPlatform.SelectedItem.ToString(); string mode = this.comboBoxMode.SelectedItem.ToString(); RootLeaderboard leaderboard = await Task.Run(() => this.GetLeaderboard(platform, season_id, mode)); this.dataGridView1.Rows.Clear(); this.dataGridView1.Refresh(); if (leaderboard != null) { await Task.Run(() => this.PopulateNameDatabase(leaderboard)); this.PopulateGrid(await Task.Run(() => this.SortPlayersByAttribute(leaderboard))); this.PostGridPopulationSetup(); List <LeaderboardRow> list = this.ExtractDataGrid(); this.LeaderboardClicked(list, null); } }
private async Task PopulateNameDatabase(RootLeaderboard leaderboard) { if (leaderboard != null) { List <Person> list = new List <Person>(); foreach (Included player in leaderboard.included) { list.Add(new Person() { name_ = player.attributes.name, accountid_ = player.id, lowercasename_ = player.attributes.name.ToLower() }); } await Task.Run(() => SqliteDataAccess.SavePlayers(list)); list = null; } }
public static Tuple <RootLeaderboard, int> ParseLeaderboard(Tuple <string, int> pair) { if (pair == null) { return(null); } else if (pair.Item1 == null) { Tuple <RootLeaderboard, int> error = Tuple.Create <RootLeaderboard, int>(null, pair.Item2); return(error); } if (pair != null) { RootLeaderboard obj = JsonConvert.DeserializeObject <RootLeaderboard>(pair.Item1); Tuple <RootLeaderboard, int> response = Tuple.Create(obj, pair.Item2); return(response); } else { return(null); } }
private async Task <List <Included> > SortPlayersByAttribute(RootLeaderboard leaderboard) { List <Included> sortedList = await Task.Run(() => leaderboard.included.OrderBy(obj => obj.attributes.rank).ToList()); return(sortedList); }