Пример #1
0
        /// <summary>
        /// Performs and records the specified routine and upon failure, retries with an exponentional backoff.
        /// </summary>
        /// <param name="retries">The number of times to retry.</param>
        /// <param name="intervalMin">The minimum interval to back off.</param>
        /// <param name="intervalMax">The maximum interval to back off.</param>
        /// <param name="request">The request to record for this operation.</param>
        /// <param name="routine">The procedure to execute.</param>
        public void Perform(int retries, int intervalMin, int intervalMax, BattleNetRequest request, Action routine)
        {
            int retryCount = retries;
            int maxInterval = intervalMax;
            int backOffInterval = intervalMin;
            int exponent = 2;
            int currentCount = 0;

            do
            {
                try
                {
                    var timer = new Stopwatch();
                    timer.Start();

                    routine();

                    timer.Stop();
                    data.BattleNetRequests.Attach(request);
                    request.Duration = timer.Elapsed.TotalSeconds;
                    data.SaveChanges();
                    break;
                }
                catch (Exception ex)
                {
                    var x = ex;
                    if (++currentCount >= retryCount) break;

                    Thread.Sleep(backOffInterval * Second);
                    backOffInterval = Math.Min(maxInterval, backOffInterval * exponent);
                }
            } while (true);


        }
        public ConquestCap GetConquestCap(BattleDotSwag.Region region, string host, BattleDotSwag.Game game, BattleDotSwag.Locale locale, int arenaRating, int bgRating)
        {
            var endpoint = new ConquestEndpoint(locale, arenaRating, bgRating);

            BattleNetRequest newRequest = new BattleNetRequest()
            {
                Locale = locale.ToString(),
                RegionID = (int)region,
                RequestDate = DateTime.Now,
                RequestType = "leaderboards",
                Bracket = "",
                Url = conquestCapService.GetUri(endpoint, region).ToString()
            };

           // BattleNetRequest request =
                data.BattleNetRequests.Add(newRequest);
            data.SaveChanges();
            ConquestCap cap = new ConquestCap();

            // TODO:  Fix Conquest Cap call.
            //requests.Perform(10, 2, 5, request, () =>
            //{
            //     cap = conquestCapService.Get(endpoint, host, region, game).Result;
            //});

            return cap;
        }
Пример #3
0
 public LadderEntry(BattleDotSwag.PVP.Row entry, BattleNetRequest request)
 {
     Request = request;
     Ranking = entry.Ranking;
     Rating = entry.Rating;
     Name = entry.Name;
     RealmID = entry.RealmID;
     RealmName = entry.RealmName;
     RealmSlug = entry.RealmSlug;
     RaceID = entry.RaceID;
     ClassID = entry.ClassID;
     SpecID = entry.SpecID;
     FactionID = entry.FactionID;
     GenderID = entry.GenderID;
     SeasonWins = entry.SeasonWins;
     SeasonLosses = entry.SeasonLosses;
     WeeklyWins = entry.WeeklyWins;
     WeeklyLosses = entry.WeeklyLosses;
 }
        public async Task GetRecentActivity(
            string bracket,
            BattleDotSwag.Locale locale,
            BattleDotSwag.Region region,
            string key,
            IMemoryCache cache,
            Func<string, Task> Send)
        {
            var endpoint = new LeaderboardEndpoint(bracket, locale, key);
            var requestor = new BattleNetService();
            var leaderboard = new List<LadderEntry>();
            var request = new QueueDodge.Models.BattleNetRequest()
            {
                Bracket = bracket,
                Locale = locale.ToString(),
                RegionID = (int)region,
                RequestDate = DateTime.Now,
                RequestType = "leaderboard",
                Url = requestor.GetUri(endpoint, region).ToString(),
                Duration = 0
            };

            var addedRequest = data.BattleNetRequests.Add(request).Entity;
            data.SaveChanges();

            var json = requestor.Get(endpoint, region).Result;

            var ladder = JsonConvert.DeserializeObject<Leaderboard>(json);



            foreach(var entry in ladder.Rows)
            {
                var ladderEntry = new LadderEntry(entry, addedRequest);
                leaderboard.Add(ladderEntry);
                CompareWithCache(ladderEntry, cache, Send);
            };

            cache.Set(region + ":" + bracket, leaderboard);
        }