public Game(MatchSummary match, ChampionListStatic champions) { IIsolatedStorageManager storageService = SimpleIoc.Default.GetInstance<IIsolatedStorageManager>(); this.ID = match.MatchId; this.DatePlayed = match.MatchCreation; var participant = match.Participants.First(); var championID = participant.ChampionId; var championName = this.FindChampionName(championID, champions); var championImage = storageService.GetImageSource(IMGCHAMPIONPATH + championName + ".png"); this.Champion = new Champion(championID, championName, championImage); this.Lane = participant.Timeline.Lane; var stats = participant.Stats; this.Kda = this.CalculKda(stats.Kills, stats.Deaths, stats.Assists); this.Gold = stats.GoldEarned; this.Cs = (int)stats.MinionsKilled + (int)stats.NeutralMinionsKilled; this.CsPer10min = this.CalculCsPer10min(this.Cs, match.MatchDuration); this.Win = stats.Winner; this.Dammage = stats.TotalDamageDealtToChampions; this.Ward = stats.WardsPlaced; }
public static MatchDetail GetMatchDetailEventually(MatchSummary summary) { return GetMatchDetailEventually(summary.MatchId); }
/// <summary> /// Process a match. /// </summary> private async Task<MatchDetail> ConsumeMatch(MatchSummary match) { long matchId = match.MatchId; // Try to mark the match as being processed if (!TryLockMatch(matchId)) { // Another thread has already started processing this match, we don't need to do anything return null; } // Get the disk path and version of the match string matchPath = MatchDirectory.GetMatchPath(match); RiotVersion matchVersion = new RiotVersion(match.MatchVersion); // Check if the match version is older than the current realm version if (!StaticDataStore.Version.IsSamePatch(matchVersion)) { TryUnlockMatch(matchId); return null; } // Check if the match exists on disk if (MatchDirectory.MatchFileExists(match)) { // Match file loading will handle this TryUnlockMatch(matchId); return null; } // <TEST> download limiting long count = Interlocked.Read(ref testSynchronizer.Count); Interlocked.Increment(ref testSynchronizer.Count); if (count >= testSynchronizer.Limit) return null; // </TEST> MatchDetail matchData = null; int retriesLeft = 3; while (retriesLeft > 0) { try { // Get the match with full timeline data matchData = api.GetMatch(match.Region, matchId, true); // Verify the match if (matchData == null) throw new RiotSharpException("Null match: " + matchId); if (matchData.Timeline == null) throw new RiotSharpException("Null match timeline: " + matchId); // Save it to disk MatchDirectory.SaveMatch(matchData); // Success, don't retry anymore retriesLeft = 0; Console.WriteLine(count); } catch (RiotSharpException ex) { if (ex.IsRetryable()) --retriesLeft; else retriesLeft = 0; // Don't do anything with the exception yet // TODO: log exceptions Console.ForegroundColor = retriesLeft > 0 ? ConsoleColor.Yellow : ConsoleColor.Red; Console.WriteLine("{0}: Match Error ({1} retries left): {2}", count, retriesLeft, ex.Message); Console.ResetColor(); } } // Remove the match from current downloads TryUnlockMatch(matchId); return matchData; }
/// <summary> /// Check if a match file exists. /// </summary> public static bool MatchFileExists(MatchSummary match) { string filename = GetMatchPath(match); return File.Exists(filename); }
/// <summary> /// Load a match. /// </summary> public static MatchDetail LoadMatch(MatchSummary match) { string filename = GetMatchPath(match); return CompressedJson.ReadFromFile<MatchDetail>(filename); }
/// <summary> /// Get the path to a match file. /// </summary> public static string GetMatchPath(MatchSummary match) { return GetMatchPath(match.MatchVersion, match.MatchId); }