protected override void OnAppearing()
        {
            base.OnAppearing();

            //if you use nested folders to help id your views, use: this.GetType().FullName
            _logging.LogEvent(AppLogLevel.Info, $"{this.GetType().Name} Appeared");
        }
        public async Task <T> SendThrottledRequest <T>(Func <Task <T> > action) where T : class
        {
            try
            {
                await Task.Run(() => Thread.Sleep(DelayBetweenRequestsAsSeconds));

                return(await action());
            }
            catch (RiotSharpException e)
            {
                _logging.LogEvent("######RiotSharpException encountered when sending throttle request - " + e.Message + ".");
                if (e.HttpStatusCode == (HttpStatusCode)429)
                {
                    _logging.LogEvent("Sleeping for 50 seconds.");
                    await Task.Run(() => Thread.Sleep(50 * 1000));
                }
            }
            catch (Exception e)
            {
                _logging.LogEvent("######Exception encountered when trying to send throttled request - " + e.Message + ". Action: " + action.ToString());
            }


            return(await Task.FromResult <T>(null));
        }
示例#3
0
        public async Task <bool> AddItemAsync(Item item)
        {
            items.Add(item);

            _logging.LogEvent(AppLogLevel.Debug, "Item Added");

            return(await Task.FromResult(true));
        }
示例#4
0
        // 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));
            }
        }