public void DeleteSummoner(long accountId) { Db_LccSummoner summoner = _lccDatabaseContext.Summoners.FirstOrDefault(x => x.AccountId == accountId); if (summoner != null) { _lccDatabaseContext.Summoners.Remove(summoner); } }
public void InsertSummoner(Db_LccSummoner summoner) { _lccDatabaseContext.Summoners.Add(summoner); }
public void UpdateSummoner(Db_LccSummoner summoner) { _lccDatabaseContext.Entry(summoner).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
// This task is not optmised in any way and has lots of code duplication protected override async Task ExecuteAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { _logging.LogEvent("MatchDataCollectionService started."); using (var scope = _serviceScopeFactory.CreateScope()) { using (var matchupInformationRepository = scope.ServiceProvider.GetRequiredService <IBasicMatchupInformationRepository>()) using (var summonerRepository = scope.ServiceProvider.GetRequiredService <ISummonerRepository>()) { try { _logging.LogEvent("Current matches count - " + matchupInformationRepository.GetAllMatchups().Count()); League challengerPlayers = await _throttledRequestHelper.SendThrottledRequest(async() => await _riotApi.League.GetChallengerLeagueAsync(Region.euw, LeagueQueue.RankedSolo)); League mastersPlayers = await _throttledRequestHelper.SendThrottledRequest(async() => await _riotApi.League.GetMasterLeagueAsync(Region.euw, LeagueQueue.RankedSolo)); IEnumerable <LeaguePosition> highEloPlayerEntires = challengerPlayers.Entries.Concat(mastersPlayers.Entries); int totalPlayers = highEloPlayerEntires.Count(); int currentCount = 0; foreach (var highEloPlayer in highEloPlayerEntires) { _logging.LogEvent(++currentCount + "/" + totalPlayers + " - " + highEloPlayer.PlayerOrTeamName); Summoner summoner = await _throttledRequestHelper.SendThrottledRequest(async() => await _riotApi.Summoner.GetSummonerBySummonerIdAsync(RiotSharp.Misc.Region.euw, Convert.ToInt64(highEloPlayer.PlayerOrTeamId))); Db_LccSummoner summonerInDatabase = summonerRepository.GetSummonerByAccountId(summoner.AccountId); if (summoner != null && summonerInDatabase == null) { summonerRepository.InsertSummoner( new Db_LccSummoner() { AccountId = summoner.AccountId, SummonerName = summoner.Name, LastUpdatedTime = DateTime.Now }); newSummonersAddedToDatabaseTotal++; newSummonersAddedThisSession++; MatchList matchList = await _throttledRequestHelper.SendThrottledRequest(async() => await _riotApi.Match.GetMatchListAsync(Region.euw, summoner.AccountId, null, null, null, null, null, 0, 75)); if (matchList != null && matchList?.Matches != null) { await GetRiotMatchupInformationAndAddIfNotExisting(matchupInformationRepository, matchList, highEloPlayerEntires); } } else { DateTime lastUpdatedDate = summonerInDatabase.LastUpdatedTime; DateTime lastRevisionDateFromRiot = summoner.RevisionDate; if (lastRevisionDateFromRiot > lastUpdatedDate) { summonerInDatabase.LastUpdatedTime = summoner.RevisionDate; summonerRepository.UpdateSummoner(summonerInDatabase); MatchList newMatches = await _throttledRequestHelper.SendThrottledRequest(async() => await _riotApi.Match.GetMatchListAsync(RiotSharp.Misc.Region.euw, summoner.AccountId, null, null, null, lastUpdatedDate, DateTime.Now, 0, 25)); if (newMatches != null && newMatches?.Matches != null) { await GetRiotMatchupInformationAndAddIfNotExisting(matchupInformationRepository, newMatches, highEloPlayerEntires); } } } summonerRepository.Save(); matchupInformationRepository.Save(); } } catch (RiotSharpException e) { _logging.LogEvent("RiotSharpException encountered - " + e.Message + "."); if (e.HttpStatusCode == (HttpStatusCode)429) { _logging.LogEvent("RateLimitExceeded exception - Sleeping for 50 seconds."); await Task.Run(() => Thread.Sleep(50 * 1000)); } } catch (Exception e) { _logging.LogEvent("Exception encountered - " + e.Message + "."); } } } PrintSummary(); matchesUpdatedThisSession = 0; newSummonersAddedThisSession = 0; _logging.LogEvent("MatchDataCollectionService finished, will wait 10 minutes and start again."); await Task.Run(() => Thread.Sleep(600000)); } }