コード例 #1
0
        private async Task ExecuteInternal(int summonerId)
        {
            var summoner = await _summoners.FindAsync(summonerId);

            if (summoner == null)
            {
                return;
            }

            var leagues = await _riot.GetLeaguesAsync(summoner.Region, summoner.SummonerId);

            var solo = leagues?.FirstOrDefault(league => league.Queue == QueueType.RANKED_SOLO_5x5);

            if (solo == null)
            {
                await _summoners.UpdateLeagueAsync(summoner, TierName.Unranked, 0);
            }
            else
            {
                var entry    = solo.Entries.First(e => e.PlayerOrTeamId == summoner.SummonerId.ToString());
                var division = (int)entry.Division;
                var tier     = (TierName)Enum.Parse(typeof(TierName), solo.Tier.ToString(), true);
                await _summoners.UpdateLeagueAsync(summoner, tier, division);
            }
        }
コード例 #2
0
        private async Task UpdateSummonerAsync(Summoner summoner)
        {
            if (summoner == null)
            {
                throw new ArgumentNullException("summoner");
            }

            if (summoner.LeagueInfo == null)
            {
                throw new InvalidOperationException("summoner.LeagueInfo is null");
            }

            var leagues = await _riot.GetLeaguesAsync(summoner.Region, summoner.SummonerId);

            var solo = leagues?.FirstOrDefault(league => league.Queue == QueueType.RANKED_SOLO_5x5);

            if (solo == null)
            {
                summoner.LeagueInfo.Division    = 0;
                summoner.LeagueInfo.Tier        = TierName.Unranked;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
            else
            {
                var entry = solo.Entries.First(e => e.PlayerOrTeamId == summoner.SummonerId.ToString());

                if (entry == null)
                {
                    throw new InvalidOperationException("Entry not found in league.");
                }

                var division = (int)entry.Division;
                var tier     = (TierName)Enum.Parse(typeof(TierName), solo.Tier.ToString(), true);
                summoner.LeagueInfo.Division    = division;
                summoner.LeagueInfo.Tier        = tier;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
        }