Exemplo n.º 1
0
        public static async Task <SummonerModel> FindSummoner(string Summoner)
        {
            try
            {
                SummonerModel model = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(GlobalClasses.GlobalProperties.UrlApi);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = await client.GetAsync($"/api/Summoner?Summonername={Summoner}");

                    if (response.IsSuccessStatusCode)
                    {
                        model = JsonConvert.DeserializeObject <SummonerModel>(await response.Content.ReadAsStringAsync());
                    }

                    return(model);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(SummonerModel model)
        {
            ViewModel = await CreateViewModelAsync();

            if (!ModelState.IsValid)
            {
                return(Error(ModelState));
            }

            // Rule: Summoner must not be registered to a User.
            if (await Summoners.IsSummonerRegistered(model.Region, model.SummonerName))
            {
                return(Error("Summoner is already registered."));
            }

            // Rule: Summoner must exist.
            var cacheKey = string.Concat(model.Region, ":", model.SummonerName).ToLowerInvariant();
            var summoner = await CacheUtil.GetItemAsync(cacheKey,
                                                        () => Riot.FindSummonerAsync(model.Region, model.SummonerName));

            if (summoner == null)
            {
                return(Error("Summoner not found."));
            }

            return(Success());
        }
Exemplo n.º 3
0
        private void RegisterHotkeyForRole(SummonerModel summoner)
        {
            var converter = new KeysConverter();

            try
            {
                var firstSpellKey = (Keys)converter.ConvertFromString(
                    Settings.Default[$"{summoner.Name}FirstSpellHotkey"].ToString());

                HotkeyManager.Current.AddOrReplace($"{summoner.Name}FirstSpell", firstSpellKey, delegate
                {
                    summoner.FirstSummonerSpell.SpellUsedTime = DateTime.Now;
                });


                var secondSpellKey = (Keys)converter.ConvertFromString(
                    Settings.Default[$"{summoner.Name}SecondSpellHotkey"].ToString());

                HotkeyManager.Current.AddOrReplace($"{ summoner.Name }SecondSpell", secondSpellKey, delegate
                {
                    summoner.SecondSummonerSpell.SpellUsedTime = DateTime.Now;
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MessageBox.Show(e.Message, @"Error while registering hotkey");
            }
        }
        public async Task <IHttpActionResult> DeleteSummoner(SummonerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = await _users.GetUserAsync();

            var summoner = user.Summoners.FirstOrDefault(DbUtil.CreateComparer(model.Region, model.SummonerName));

            if (summoner == null)
            {
                return(Conflict("Summoner not found."));
            }

            if (await _summoners.RemoveAsync(model.Region, model.SummonerName))
            {
                return(Ok());
            }

            if (!await _flair.SetUpdateFlagAsync(new[] { user }))
            {
                return(Conflict("Unable to remove summoner."));
            }
            return(Conflict("Unable to remove summoner."));
        }
Exemplo n.º 5
0
        public void SetUpData(SummonerModel summoner)
        {
            Summoner = summoner;

            roleNameLabel.Text = summoner.Name;
            firstSpellControl.SetUpData(summoner.FirstSummonerSpell);
            secondSpellControl.SetUpData(summoner.SecondSummonerSpell);
        }
 //constructor
 public SummonerViewModel(SummonerModel model)
 {
     Name          = model.Name;
     ProfileIconId = model.ProfileIconId;
     Level         = model.Level;
     //this.Matches = model.Matches;
     //RankedInfo = model.RankedInfo;
 }
Exemplo n.º 7
0
        public static SummonerModel ConvertSummonerInfoData(JsonSummonerModel.SummonerDTO rootModel)
        {
            SummonerModel model = new SummonerModel();

            model.Id            = rootModel.id;
            model.SummonerName  = rootModel.name;
            model.Level         = rootModel.summonerLevel;
            model.ProfileIconId = rootModel.profileIconId;

            return(model);
        }
Exemplo n.º 8
0
        public MainForm()
        {
            InitializeComponent();

            Match = new MatchModel()
            {
                TopSummoner     = SummonerModel.CreateDefaultSummoner("Top", "flash", "teleport"),
                JungleSummoner  = SummonerModel.CreateDefaultSummoner("Jungle", "flash", "smite"),
                MidSummoner     = SummonerModel.CreateDefaultSummoner("Mid", "flash", "barrier"),
                AdcSummoner     = SummonerModel.CreateDefaultSummoner("Adc", "flash", "heal"),
                SupportSummoner = SummonerModel.CreateDefaultSummoner("Support", "flash", "exhaust"),
            };

            UpdateForm();
        }
Exemplo n.º 9
0
        public async static Task <SummonerModel> LoadSummoner(string summonerName, string region)
        {
            string url = $"https://{region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/{summonerName}?api_key={ApiHelper.DeveloperKey}";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SummonerModel summoner = await response.Content.ReadAsAsync <SummonerModel>();

                    return(summoner);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
Exemplo n.º 10
0
        public static SummonerModel CreateDefaultSummoner(
            string name, string firstSpellName, string secondSpellName)
        {
            var summoner = new SummonerModel()
            {
                Name = name,
                FirstSummonerSpell = new SummonerSpellModel()
                {
                    Name = firstSpellName, Cooldown = SummonerSpellModel.SpellsCooldowns[firstSpellName]
                },
                SecondSummonerSpell = new SummonerSpellModel()
                {
                    Name = secondSpellName, Cooldown = SummonerSpellModel.SpellsCooldowns[secondSpellName]
                }
            };
            var val = SummonerSpellModel.SpellsCooldowns[secondSpellName];

            return(summoner);
        }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> Get(string SummonerName)
        {
            try
            {
                Summoner summoner = await WebApiApplication.api.GetSummonerAsync(RiotSharp.Region.br, SummonerName);

                SummonerModel model = new SummonerModel()
                {
                    SummonerName  = summoner.Name,
                    SummonerId    = summoner.Id,
                    SummonerIcon  = ReturnUrlChampion(summoner.ProfileIconId),
                    SummonerLevel = summoner.Level
                };

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> Register(SummonerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                // Summoner MUST exist.
                var summoner = await FindSummonerAsync(model.Region, model.SummonerName);

                if (summoner == null)
                {
                    return(Conflict("Summoner not found."));
                }

                // Summoner MUST NOT be registered.
                if (await Summoners.IsSummonerRegistered(model.Region, model.SummonerName))
                {
                    return(Conflict("Summoner is already registered."));
                }

                return(Ok(new
                {
                    code = RegistrationCode.Generate((await Users.GetUserAsync()).Name, summoner.Id, model.Region)
                }));
            }
            catch (RiotHttpException e)
            {
                switch ((int)e.StatusCode)
                {
                case 500:
                case 503:
                    return(Conflict("Error communicating with Riot (Service unavailable)"));
                }
                throw;
            }
        }
Exemplo n.º 13
0
        public JsonResult GetMatchInformation(int hours, int minutes, string date)
        {
            SummonerModel model = new SummonerModel();

            API riotApi = new API();


            DateTime parsedDate = DateTime.Parse(date);

            parsedDate = parsedDate.AddHours(hours);
            parsedDate = parsedDate.AddMinutes(minutes);

            List <long> gameIds = riotApi.GetUrfGames(parsedDate);

            if (gameIds.Count > 0)
            {
                var api       = RiotApi.GetInstance(riotApi.KeyOnly);
                var staticApi = StaticRiotApi.GetInstance(riotApi.KeyOnly);

                List <MatchDetail> matchDetails = new List <MatchDetail>();


                for (int i = 0; i < gameIds.Count; i++)
                {
                    matchDetails.Add(api.GetMatch(Region.euw, gameIds[i]));
                }

                ChampionListStatic championList = staticApi.GetChampions(Region.euw);


                ScoreCardCalculator scoreCalculator = new ScoreCardCalculator();

                model.ChampionScoreCards = scoreCalculator.CalculateChampionScores(matchDetails, riotApi.GetChampions());
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
0
        public ActionResult Index()
        {
            SummonerModel model = new SummonerModel();

            return(View(model));
        }
Exemplo n.º 15
0
        public async Task <IHttpActionResult> Validate(SummonerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                // Summoner MUST exist.
                var riotSummoner = await Riot.FindSummonerAsync(model.Region, model.SummonerName);

                var user = await Users.GetUserAsync();

                if (riotSummoner == null)
                {
                    return(Conflict("Summoner not found."));
                }

                // Summoner MUST NOT be registered.
                if (await Summoners.IsSummonerRegistered(model.Region, model.SummonerName))
                {
                    return(Conflict("Summoner is already registered."));
                }

                var runePages = await Riot.GetRunePagesAsync(model.Region, riotSummoner.Id);

                var code = RegistrationCode.Generate(user.Name, riotSummoner.Id, model.Region);

                if (!runePages.Any(page => string.Equals(page.Name, code, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(StatusCode(HttpStatusCode.ExpectationFailed));
                }

                // Create the data entity and associate it with the current user
                var currentSummoner =
                    await Summoners.AddSummonerAsync(user, riotSummoner.Id, model.Region, riotSummoner.Name);

                // If the user doesn't have an active summoner, assign the new summoner as active.
                if (await Summoners.GetActiveSummonerAsync(user) == null)
                {
                    await Summoners.SetActiveSummonerAsync(currentSummoner);
                }

                // Queue up the league update.
                var jobId = BackgroundJob.Enqueue <LeagueUpdateJob>(job => job.Execute(currentSummoner.Id));
                // Queue up flair update.
                BackgroundJob.ContinueWith <FlairUpdateJob>(jobId, job => job.Execute(user.Id));
                return(Ok());
            }
            catch (RiotHttpException e)
            {
                switch ((int)e.StatusCode)
                {
                case 500:
                case 503:
                    return(Conflict("Error communicating with Riot (Service unavailable)"));
                }
                throw;
            }
        }
Exemplo n.º 16
0
        public void PrepareSearchSummonerModel(SearchSummoner searchSummoner, Dictionary <string, SummonerDto> summonersDto, Dictionary <string, IEnumerable <LeagueDto> > summonerLeagues)
        {
            searchSummoner.SummonerModels = new List <SummonerModel>();

            var allChampionsKey = string.Format(CacheKeys.AllStaticChampionsByRegionKey, searchSummoner.Region);
            var allChampions    =
                _cacheManager.Get(allChampionsKey, DateTime.UtcNow.AddDays(1),
                                  () => _riotClient.LolStaticData.GetChampionList(searchSummoner.Region, champData: "all"));

            var ddragonKeyVersionsKey = string.Format(CacheKeys.DataDragonVersionByRegionKey, searchSummoner.Region);

            var ddragonVersions = _memoryCache.Get(ddragonKeyVersionsKey, DateTime.UtcNow.AddDays(1),
                                                   () => _riotClient.LolStaticData.GetVersionData(searchSummoner.Region));

            foreach (var key in summonersDto.Keys)
            {
                SummonerModel summonerModel = new SummonerModel();
                summonerModel.PlayedChampions = new List <SummonerModel.PlayedChampionModel>();
                var summonerDto = summonersDto[key];

                summonerModel.SummonerKey      = key;
                summonerModel.SummonerDto      = summonerDto;
                summonerModel.ProfileImagePath =
                    $"http://ddragon.leagueoflegends.com/cdn/{ddragonVersions.FirstOrDefault()}/img/profileicon/{summonerDto.ProfileIconId}.png";

                summonerModel.LeagueModels = new List <SummonerModel.LeagueModel>();
                if (summonerLeagues != null && summonerLeagues.Count > 0 && summonerLeagues.ContainsKey(summonerDto.Id.ToString()))
                {
                    var summonerLeagueDtos = summonerLeagues[summonerDto.Id.ToString()];
                    foreach (var summonerLeagueDto in summonerLeagueDtos)
                    {
                        SummonerModel.LeagueModel leagueModel = new SummonerModel.LeagueModel();
                        leagueModel.LeagueKey  = summonerDto.Id.ToString();
                        leagueModel.LeagueDto  = summonerLeagueDto;
                        leagueModel.LeagueName = RiotApiEnumsDisplay.GetDisplayForQueueType(summonerLeagueDto.Queue);

                        summonerModel.LeagueModels.Add(leagueModel);
                    }
                }

                //summoner spells
                var recentGamesKey = string.Format(CacheKeys.SummonerRecentGamesbyRegionAndIdCacheKey, searchSummoner.Region,
                                                   summonerDto.Id);
                var recentGames = _cacheManager.Get(recentGamesKey, DateTime.UtcNow.AddMinutes(60),
                                                    () => _riotClient.Game.GetRecentGamesBySummonerId(searchSummoner.Region, summonerDto.Id));
                var orderedRecentGames = recentGames.Games.OrderByDescending(x => x.CreateDate).ToList();
                summonerModel.RecentGames = orderedRecentGames;

                //summoner stats
                var playersStatskey = string.Format(CacheKeys.PlayerStatsByRegionAndIdCacheKey, searchSummoner.Region, summonerDto.Id);
                var playerStats     = _cacheManager.Get(playersStatskey, DateTime.UtcNow.AddMinutes(60),
                                                        () => _riotClient.Stats.GetPlayerStatsBySummonerId(searchSummoner.Region, summonerDto.Id));
                summonerModel.PlayerStats = playerStats;

                //summoner ranked stats
                RankedStatsDto rankedStats = null;
                try
                {
                    var rankedStatsKey = string.Format(CacheKeys.PlayerRankedStatsByRegionAndIdCacheKey, searchSummoner.Region, summonerDto.Id);
                    rankedStats = _cacheManager.Get(rankedStatsKey, DateTime.UtcNow.AddMinutes(60),
                                                    () => _riotClient.Stats.GetRankedStatsBySummonerId(searchSummoner.Region, summonerDto.Id));
                }
                catch (RiotExceptionRaiser.RiotApiException exception)
                {
                    if (exception.RiotErrorCode == RiotExceptionRaiser.RiotErrorCode.DATA_NOT_FOUND)
                    {
                        logger.Debug(
                            $"Stats.GetRankedStatsBySummonerId({searchSummoner.Region}, {summonerDto.Id}) - - {exception.RiotErrorCode}");
                    }
                }

                //champion data
                if (rankedStats != null)
                {
                    var mostPlayedChampions =
                        rankedStats.Champions.OrderByDescending(x => x.Stats.TotalSessionsPlayed).ToList();
                    foreach (var statChampion in mostPlayedChampions)
                    {
                        var staticChampion = allChampions.Data.Values.FirstOrDefault(x => x.Id == statChampion.Id);
                        if (staticChampion != null)
                        {
                            SummonerModel.PlayedChampionModel playedChampion = new SummonerModel.PlayedChampionModel();
                            playedChampion.StaticChampion      = staticChampion;
                            playedChampion.RankedStats         = statChampion.Stats;
                            playedChampion.ChampionSpriteImage =
                                $"http://ddragon.leagueoflegends.com/cdn/{ddragonVersions.FirstOrDefault()}/img/champion/{staticChampion.Image.Full}";
                            summonerModel.PlayedChampions.Add(playedChampion);
                        }
                    }
                }

                searchSummoner.SummonerModels.Add(summonerModel);
            }
        }
Exemplo n.º 17
0
        public ApiTest()
        {
            SummonerClass summonerClass = new SummonerClass("tr1");

            SummonerModel summoner = summonerClass.GetSummonerByName("MSTZTRK");
        }
Exemplo n.º 18
0
        public void SetSupportInfo(string userName = "******")
        {
            ApiCalls api = new ApiCalls();

            // Suppport
            if (userName == "default")
            {
                userName = supportTextBox.Text;
            }
            if (Helper.ValidateSummonerName(userName, REGION) == true)
            {
                SummonerModel summoner5             = api.getSummonerInfo(userName, REGION);
                long          supportId             = api.getSummonerInfo(userName, REGION).Id;
                List <SummonerRankedInfoModel> list = api.getSummonerRankedInfo(supportId, REGION);

                string supportSoloRank;
                string supportSoloDivision;

                string supportFlexRank;
                string supportFlexDivision;

                supportLvlLabel.Text                  = summoner5.Level.ToString();
                supportProfileIconImage.SizeMode      = PictureBoxSizeMode.StretchImage;
                supportProfileIconImage.ImageLocation = imageDefaultLibraryIcon + summoner5.ProfileIconId + ".png";


                foreach (var i in list)
                {
                    if (i.QueueType == "RANKED_FLEX_SR")
                    {
                        supportFlexDivision = i.Rank;
                        supportFlexRank     = i.Tier;

                        supportFlexRankLabel.Text          = supportFlexRank + " " + supportFlexDivision;
                        supportFlexRankImage.ImageLocation = SetImageRank(supportFlexRank);
                        supportFlexWinsLabel.Text          = i.Wins.ToString();
                        supportFlexLossesLabel.Text        = i.Losses.ToString();

                        if (i.HotStreak)
                        {
                            supportFlexHotSteak.Text = "(Hot Streak)";
                        }
                        supportFlexLeaguePointsLabel.Text = i.LeaguePoints.ToString() + " LP";
                    }
                    else if (i.QueueType == "RANKED_SOLO_5x5")
                    {
                        supportSoloRank     = i.Tier;
                        supportSoloDivision = i.Rank;

                        supportSoloRankLabel.Text          = supportSoloRank + " " + supportSoloDivision;
                        supportSoloRankImage.ImageLocation = SetImageRank(supportSoloRank);
                        supportSoloWinLabel.Text           = i.Wins.ToString();
                        supportSoloLossesLabel.Text        = i.Losses.ToString();

                        if (i.HotStreak)
                        {
                            supportSoloHotSteak.Text = "(Hot Streak)";
                        }
                        supportSoloLeaguePointsLabel.Text = i.LeaguePoints.ToString() + " LP";
                    }
                }
            }
            else
            {
                errorMessageLabel.Text = "Support Summoner name does't exist.";
            }
        }
 public SummonerViewModel(SummonerModel summoner)
 {
     this.summoner = summoner;
 }
 public SummonerViewModel()
 {
     summoner = new SummonerModel();
 }