public static Summoner GetSummoner(string name) { string json; try { json = new WebClient().DownloadString(HTTPBuilder(_summonerBasePath + "/summoners/by-name/" + name + "?api_key=" + _api)); } catch (Exception) { Console.WriteLine("Nie znaleziono"); return(null); } Console.WriteLine(json); Summoner summoner = JsonConvert.DeserializeObject <Summoner>(json); SaveJson(json); return(summoner); }
private string GetResult(Summoner summoner, Match match, int j) { string matchResult = null; for (int i = 0; i < 10; i++) { try { if (summoner.AccountId == match.participantIdentities[i].player.accountId) { if (match.participants[i].teamId == 200 && match.teams[1].win == "Win") { matchResult = "Wygrana"; } else if (match.participants[i].teamId == 200 && match.teams[1].win == "Fail") { matchResult = "Porażka"; } else if (match.participants[i].teamId == 100 && match.teams[1].win == "Win") { matchResult = "Wygrana"; } else if (match.participants[i].teamId == 100 && match.teams[1].win == "Fail") { matchResult = "Porażka"; } } } catch (Exception e) { Console.WriteLine(e); //throw; } } return(matchResult); }
public async void SearchButton_Click(object sender, EventArgs e) { nickname = SearchText.Text; Task <Summoner> taskGetSummoner = new Task <Summoner>(() => WebServiceHandler.GetSummoner(StringNameToURLCode())); taskGetSummoner.Start(); ResultLabel.Text = "Oczekiwanie..."; Summoner summoner = await taskGetSummoner; if (summoner == null) { ResultLabel.Text = "Nie znaleziono przywoływacza"; return; } ResultLabel.Text = nickname; LevelLabel.Text = "Poziom: " + summoner.SummonerLevel; Task <Tuple <LeagueTT, LeagueFlex, LeagueSolo> > taskGetLeague = new Task <Tuple <LeagueTT, LeagueFlex, LeagueSolo> >(() => WebServiceHandler.GetLeague(summoner.Id)); taskGetLeague.Start(); Tuple <LeagueTT, LeagueFlex, LeagueSolo> tuple = await taskGetLeague; string iconId = summoner.ProfileIconId; Image image = DownloadImageFromUrl("http://ddragon.leagueoflegends.com/cdn/8.24.1/img/profileicon/" + iconId + ".png"); IconBox.Image = image; try { TTImage.Image = SetImage(tuple.Item1.Tier); TTLabel.Text = tuple.Item1.Tier + " " + tuple.Item1.Rank; } catch (Exception) { TTImage.Image = SetImage("unranked"); TTLabel.Text = "UNRANKED"; } try { FlexImage.Image = SetImage(tuple.Item2.Tier); FlexLabel.Text = tuple.Item2.Tier + " " + tuple.Item2.Rank; } catch (Exception) { FlexImage.Image = SetImage("unranked"); FlexLabel.Text = "UNRANKED"; } try { SoloImage.Image = SetImage(tuple.Item3.Tier); SoloLabel.Text = tuple.Item3.Tier + " " + tuple.Item3.Rank; } catch (Exception) { SoloImage.Image = SetImage("unranked"); SoloLabel.Text = "UNRANKED"; } Task <List <GameIds> > taskGetList = new Task <List <GameIds> >(() => WebServiceHandler.GetMatchesId(summoner.AccountId.ToString())); taskGetList.Start(); List <GameIds> list = await taskGetList; for (int i = 0; i < 20; i++) { Task <Match> taskGetMatch = new Task <Match>(() => WebServiceHandler.GetMatch(list[i].GameId)); taskGetMatch.Start(); Match match = await taskGetMatch; for (int j = 0; j < 10; j++) { if (summoner.AccountId == match.participantIdentities[j].player.accountId) { string score = match.participants[j].stats.kills.ToString() + " / " + match.participants[j].stats.deaths.ToString() + " / " + match.participants[j].stats.assists.ToString(); content[i].SetPanel(match.participants[j].stats.item0, match.participants[j].stats.item1, match.participants[j].stats.item2, match.participants[j].stats.item3, match.participants[j].stats.item4, match.participants[j].stats.item5, match.participants[j].championId, GetResult(summoner, match, i), score); } } } PanelTimer.Start(); }