public static Match GetMatch(string id) { int retries = 0; while (retries < 3) { try { string urlRequest = string.Format("https://{0}.api.pvp.net/api/lol/{0}/v2.2/match/{1}?includeTimeline={2}&api_key={3}", region, id, "true", apikey); WebRequest request = WebRequest.Create(urlRequest); request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us"); request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8"); string textResponse = string.Empty; Match m; using (WebResponse response = request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { textResponse = reader.ReadToEnd(); dynamic dynObject = JsonConvert.DeserializeObject(textResponse); m = new Match(dynObject); if (m.QueueType != QueueType.RANKED_SOLO_5x5) return null; } } return m; } catch (Exception ex) { LogHelper.Logger(string.Format("Warn - MatchId: {0}, ex: {1}", id, ex.Message) ); System.Threading.Thread.Sleep(2000); retries++; } } LogHelper.Logger(string.Format("Error - MatchId: {0}", id)); return null; }
public static Match Mapper(MySqlDataReader reader) { var m = new Match(); m.Id = reader.GetInt32("Id"); return m; }
public void SaveRunePage(Match m) { foreach (var t in m.Teams) { foreach (var p in t.Players) { MySqlCommand cmd = new MySqlCommand("insert_runepage", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("pParticipantId", p.ParticipantId)); cmd.Parameters.Add(new MySqlParameter("pMatchId", m.Id)); cmd.Parameters.Add(new MySqlParameter("pRunes", string.Join("|",p.Runes.Select(r=>r.Id)))); cmd.ExecuteNonQuery(); } } }
public void SaveMatch(Match m) { MySqlCommand cmd = new MySqlCommand("insert_match", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("pId", m.Id)); cmd.Parameters.Add(new MySqlParameter("pRegion", m.Region)); cmd.Parameters.Add(new MySqlParameter("pDuration", m.Duration.TotalSeconds)); cmd.Parameters.Add(new MySqlParameter("pMapId", m.MapId)); cmd.Parameters.Add(new MySqlParameter("pMatchMode", m.QueueType.ToString())); cmd.Parameters.Add(new MySqlParameter("pPatch", m.Patch)); cmd.ExecuteNonQuery(); }
public void SaveFinalStats(Match m, string patch) { foreach (var t in m.Teams) { foreach (var p in t.Players) { MySqlCommand cmd = new MySqlCommand("insert_endgamestats", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("pParticipantId", p.ParticipantId)); cmd.Parameters.Add(new MySqlParameter("pMatchId", m.Id)); cmd.Parameters.Add(new MySqlParameter("pRank", p.Rank)); cmd.Parameters.Add(new MySqlParameter("pTeamId", t.TeamId)); cmd.Parameters.Add(new MySqlParameter("pChampionId", p.SelectedChampion.Id)); cmd.Parameters.Add(new MySqlParameter("pRole", p.Role.ToString())); cmd.Parameters.Add(new MySqlParameter("pLane", p.Lane.ToString())); cmd.Parameters.Add(new MySqlParameter("pMagicDamageDealtToChampions", p.Finalstats.MagicDamageDealtToChampions)); cmd.Parameters.Add(new MySqlParameter("pPhysicalDamageDealtToChampions", p.Finalstats.PhysicalDamageDealtToChampions)); cmd.Parameters.Add(new MySqlParameter("pTrueDamageDealtToChampions", p.Finalstats.TrueDamageDealtToChampions)); cmd.Parameters.Add(new MySqlParameter("pTotalAP", p.Finalstats.TotalAp)); cmd.Parameters.Add(new MySqlParameter("pTotalMR", p.Finalstats.TotalMr)); cmd.Parameters.Add(new MySqlParameter("pWinner", t.Winner)); cmd.Parameters.Add(new MySqlParameter("pItemsIds", string.Join("|", p.Finalstats.Items.Select(i=>i.Id)))); cmd.Parameters.Add(new MySqlParameter("pPatch", patch)); cmd.ExecuteNonQuery(); } } }
public void SaveApTimeline(Match m, string patch) { foreach (var t in m.Teams) { foreach (var p in t.Players) { IList<ApTimeLine> timelines = ApTimeLine.GetPlayerApTimeline(p, m.Patch, m.Id, t.TeamId); foreach (var time in timelines) { MySqlCommand cmd = new MySqlCommand("insert_timeline", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("pMatchId", time.MatchId)); cmd.Parameters.Add(new MySqlParameter("pParticipantId", time.PlayerId)); cmd.Parameters.Add(new MySqlParameter("pRank", p.Rank)); cmd.Parameters.Add(new MySqlParameter("pChampionId", p.SelectedChampion.Id)); cmd.Parameters.Add(new MySqlParameter("pRole", p.Role.ToString())); cmd.Parameters.Add(new MySqlParameter("pLane", p.Lane.ToString())); cmd.Parameters.Add(new MySqlParameter("pTeamId", time.TeamId)); cmd.Parameters.Add(new MySqlParameter("pTotalAP", time.TotalAp)); cmd.Parameters.Add(new MySqlParameter("pTotalMR", time.TotalMr)); cmd.Parameters.Add(new MySqlParameter("pMinute", time.Minute)); cmd.Parameters.Add(new MySqlParameter("pWinner", t.Winner)); cmd.Parameters.Add(new MySqlParameter("pCurrentGold", time.CurrentGold)); cmd.Parameters.Add(new MySqlParameter("pGoldSpent", time.GoldSpent)); cmd.Parameters.Add(new MySqlParameter("pItemsIds", string.Join("|", time.Items.Select(i=>i.Id)))); cmd.Parameters.Add(new MySqlParameter("pPatch", patch)); cmd.ExecuteNonQuery(); } } } }