public static OnGoingMatchup Create(MatchStartedEvent matchStartedEvent) { var match = matchStartedEvent.match; var startTime = DateTimeOffset.FromUnixTimeMilliseconds(match.startTime); var result = new OnGoingMatchup() { Id = matchStartedEvent.Id, Map = new MapName(match.map).Name, MatchId = match.id, GateWay = match.gateway, GameMode = match.gameMode, StartTime = startTime, }; result.SetServerInfo(match); var teamGroups = SplitPlayersIntoTeams(match.players, match.gameMode); foreach (var team in teamGroups) { result.Teams.Add(CreateTeam(team.Value)); } SetTeamPlayers(result); return(result); }
public async Task Update() { var nextEvents = await _eventRepository.LoadStartedMatches(); while (nextEvents.Any()) { foreach (var nextEvent in nextEvents) { var matchup = OnGoingMatchup.Create(nextEvent); foreach (var team in matchup.Teams) { foreach (var player in team.Players) { var foundMatchForPlayer = await _matchRepository.LoadOnGoingMatchForPlayer(player.BattleTag); if (foundMatchForPlayer != null) { await _matchRepository.DeleteOnGoingMatch(foundMatchForPlayer.MatchId); } } } await _matchRepository.InsertOnGoingMatch(matchup); await _eventRepository.DeleteStartedEvent(nextEvent.Id); } nextEvents = await _eventRepository.LoadStartedMatches(); } }
public void Upsert(OnGoingMatchup matchup) { lock (_lock) { var orderByDescending = _values.Where(m => m.MatchId != matchup.MatchId); _values = orderByDescending.Append(matchup).OrderByDescending(s => s.Id).ToList(); } }
public async Task Update() { var nextEvents = await _eventRepository.LoadStartedMatches(); while (nextEvents.Any()) { foreach (var nextEvent in nextEvents) { if (nextEvent.match.gameMode != CommonValueObjects.GameMode.CUSTOM) { var matchup = OnGoingMatchup.Create(nextEvent); foreach (var team in matchup.Teams) { foreach (var player in team.Players) { var foundMatchForPlayer = await _matchRepository.LoadOnGoingMatchForPlayer(player.BattleTag); if (foundMatchForPlayer != null) { await _matchRepository.DeleteOnGoingMatch(foundMatchForPlayer.MatchId); } var personalSettings = await _personalSettingsRepository.Load(player.BattleTag); if (personalSettings != null) { player.CountryCode = personalSettings.CountryCode; } } } await _matchRepository.InsertOnGoingMatch(matchup); } await _eventRepository.DeleteStartedEvent(nextEvent.Id); } nextEvents = await _eventRepository.LoadStartedMatches(); } }
public Task InsertOnGoingMatch(OnGoingMatchup matchup) { _cache.Upsert(matchup); return(Upsert(matchup, m => m.MatchId == matchup.MatchId)); }