/// <summary>
        /// Throws 429 To Many Requests exception if the rate limit is exceeded.
        /// Consider then specifiying the endIndex to receive less matches results
        /// </summary>
        /// <param name="seasonId"> Season which has the matches you want </param>
        /// <param name="queue"> Ladder from which the matches were played </param>
        /// <returns></returns>
        public async Task <List <MatchResult> > GetMatchesBySeasonAsync(int seasonId, string queue, int beginIndex = 0, int endIndex = 100, bool tooManyRequestsThrowException = true)
        {
            await RiotApiUtils.FetchSummonerData();

            ConcurrentBag <MatchResult> results = new ConcurrentBag <MatchResult>();

            if (String.IsNullOrEmpty(RiotApiUtils.AccountId))
            {
                throw new Exception("AccountId cannot be null or empty");
            }

            try
            {
                long seasonTimestamp = Utils.GetSeasonTimestamp(seasonId) * 1000; // to ms

                Url request = RiotApiUtils.Api
                              .AppendPathSegment(matchListEndpoint)
                              .AppendPathSegment(RiotApiUtils.AccountId)
                              .SetQueryParam("beginTime", seasonTimestamp)
                              .SetQueryParam("api_key", RiotApiUtils.ApiKey)
                              .SetQueryParam("queue", RiotApiUtils.GetQueueID(queue))
                              .SetQueryParam("beginIndex", beginIndex)
                              .SetQueryParam("endIndex", endIndex);

                Console.WriteLine(request.ToString());

                MatchlistDto dto = await request.GetJsonAsync <MatchlistDto>();

                try
                {
                    await dto.Matches.ParallelForEachAsync(async match =>
                    {
                        var detail = await GetMatchResultAsync(match.GameId);
                        results.Add(detail);
                    }, maxDegreeOfParallelism : 10);

                    return(results.ToList());
                }
                catch (FlurlHttpException e)
                {
                    if (e.Call.HttpStatus == ((System.Net.HttpStatusCode) 429))
                    {
                        if (tooManyRequestsThrowException)
                        {
                            throw e;
                        }
                        else
                        {
                            return(results.ToList());
                        }
                    }

                    // Propagate any other type of exception other than 429
                    throw e;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #2
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            await RiotApiUtils.FetchSummonerData();

            // Max bar height 500
            int    maxBarHeight     = 500;
            double increaseSizeRate = (double)maxBarHeight / MyViewModel.TotalGamesPlayed;
            var    barChart         = this.FindByName <Grid>("Barchart");

            // Prepare animations

            Label []   counters = { Adc_Bar_Counter, Jungle_Bar_Counter, Mid_Bar_Counter, Support_Bar_Counter, Top_Bar_Counter };
            BoxView [] bars     = { Adc_Bar, Jungle_Bar, Mid_Bar, Support_Bar, Top_Bar };

            await MyViewModel.Init(counters, bars, barChart);

            //var lanes = MyViewModel.MatchList.Matches.GroupBy(m => m.Position).Where(g => g.Key != "UNKNOWN").OrderBy(x => x.Key);
            //var totalLanes = lanes.Count();

            //for (int i = 0; i < totalLanes; ++i)
            //{
            //    var lane = lanes.ElementAt(i).ToList();
            //    var laneSize = lane.Count();

            //    animations.Add(new Animation(
            //         callback: (h) =>
            //         {
            //             bars[i].HeightRequest = Increase(h, increaseSizeRate);
            //         },
            //         start: 0,
            //         end: (laneSize * increaseSizeRate) - increaseSizeRate,
            //         easing: Easing.Linear
            //         )
            //         );

            //    animations.Add(new Animation(
            //        callback: (l) =>
            //        {
            //            counters[i].Text = IncreaseCounter((int)l).ToString();
            //        },
            //        start: 0,
            //        end: laneSize - 1,
            //        easing: Easing.Linear
            //        ));
            //}

            //for (int i = 0; i < animations.Count; ++i)
            //{
            //    var currentAnimation = animations[i];
            //    try
            //    {

            //        if (i % 2 == 0)
            //        {
            //            currentAnimation.Commit(owner: barChart, name: "Grow" + i, rate: 30, length: 1500);
            //        }
            //        else
            //        {
            //            currentAnimation.Commit(owner: barChart, name: "Counter" + i, rate: 6, length: 1500);
            //        }

            //    }
            //    catch(Exception e)
            //    {

            //    }

            //}
        }