Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="region"></param>
        /// <returns>The ID of a Summoner from their name and region.</returns>
        public async Task <Summoner> FromNameAsync(string name, eRegion region)
        {
            string requestPath = string.Format("summoner/by-name/{0}", name);
            string url         = BuildURL(region, requestPath);

            using (HttpClient client = new HttpClient())
                using (HttpResponseMessage response = await client.GetAsync(url))
                    using (HttpContent content = response.Content)
                    {
                        string contentStr = await content.ReadAsStringAsync();

                        var result = await JsonConvert.DeserializeObjectAsync <Dictionary <string, SummonerDTO> >(contentStr);

                        SummonerDTO summonerDTO = result.Select(x => x.Value).FirstOrDefault();

                        if (summonerDTO == null)
                        {
                            return(null);
                        }
                        //todo: cache summoners.
                        Summoner summoner = new Summoner(summonerDTO);
                        summoner.Region = region;
                        return(summoner);
                    }
        }
Esempio n. 2
0
        private void SetRankingInformation(LeagueSummoner summoner, SummonerDTO summonerDto)
        {
            ICollection <LeagueDTO> leagueDtos = _leagueRequestService.GetLeagues(summonerDto.Id);

            if (leagueDtos == null)
            {
                summoner.Tier     = "Unranked";
                summoner.Division = "";
                return;
            }

            LeagueDTO rankedSoloLeagueDto = leagueDtos.FirstOrDefault(l => l.Queue == _rankedSolo);

            if (rankedSoloLeagueDto == null)
            {
                summoner.Tier     = "Unranked";
                summoner.Division = "";
            }
            else
            {
                summoner.Tier = rankedSoloLeagueDto.Tier.ToCapitalized();

                //For solo queue there's only one entry, so we can just get it
                LeagueEntryDTO entryDto = rankedSoloLeagueDto.Entries.First();

                summoner.Division     = IsDivisionRequired(summoner.Tier) ? entryDto.Division : "";
                summoner.LeaguePoints = entryDto.LeaguePoints;
            }
        }
Esempio n. 3
0
        public async Task FetchPlayerIdSucces()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName = "TestingPlayer";
                var regionName = "eune";
                var player     = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);

                //Act

                var result = await riotApiService.FetchPlayerId(playerName, regionName);

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);
                Assert.Equal(player.Id, result);
            }
        }
        /// <summary>
        /// get summoner information based on region and summoner name
        /// </summary>
        /// <param name="region"></param>
        /// <param name="SummonerName"></param>
        /// <returns></returns>
        public static async Task <SummonerDTO> LoadSummoner(string region, string SummonerName)
        {
            string url = "";

            if (!string.IsNullOrEmpty(SummonerName))
            {
                url = $"https://{region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/{SummonerName}?api_key={key}";
            }
            else
            {
                url = $"https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/shirtzoo?api_key={key}";
            }

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

                    return(summoner);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
Esempio n. 5
0
        // Pego os historicos de partida
        private MatchDTO GetMatch(SummonerDTO summoner)
        {
            Match_V4 matchs   = new Match_V4(Constants.Region);
            var      mhistory = matchs.GetMatchHistoryByAccount(summoner.accountId, Constants.CurrentyChampionId);

            return(mhistory ?? new MatchDTO());
        }
Esempio n. 6
0
        public LeagueEntryDTO GetEntry(SummonerDTO summoner)
        {
            LeagueAPI leagueAPI = new LeagueAPI(Summoner.Reg);
            var       entrys    = leagueAPI.GetEntrys(summoner.Id)
                                  .Where(x => x.QueueType.Equals("RANKED_SOLO_5x5")).First();

            return(entrys);
        }
Esempio n. 7
0
        private PositionDTO GetPosition(SummonerDTO summoner)
        {
            League_V4 league = new League_V4(Constant.Region);

            var position = league.GetPositions(summoner.Id).Where(p => p.QueueType.Equals("RANKED_SOLO_5x5")).FirstOrDefault();

            return(position ?? new PositionDTO());
        }
Esempio n. 8
0
        // GET: Summoner
        public ActionResult Index(string name)
        {
            Dictionary <string, SummonerDTO> p = APICalls.CallApi <Dictionary <string, SummonerDTO> >("https://na.api.pvp.net", "/api/lol/na/v1.4/summoner/by-name/" + name + "?api_key=");
            SummonerDTO play  = p.First().Value;
            var         model = APICalls.CallApi <RankedStatsDTO>("https://na.api.pvp.net", "/api/lol/na/v1.3/stats/by-summoner/" + play.id.ToString() + "/ranked?season=SEASON2016&api_key=");

            return(View(model));
        }
Esempio n. 9
0
        //Get a summoner by account ID
        public async Task <SummonerDTO> GetSummonerByAccountAsync(long accountID)
        {
            SummonerDTO summoner = null;
            string      request  = "/lol/summoner/" + SM_VERSION + "/summoners/by-account/" + accountID;
            string      response = await GET(request);

            summoner = JsonConvert.DeserializeObject <SummonerDTO>(response);
            return(summoner);
        }
Esempio n. 10
0
        //Get a summoner by summoner name
        public async Task <SummonerDTO> GetSummonerByNameAsync(string summonerName)
        {
            SummonerDTO summoner = null;
            string      request  = "/lol/summoner/" + SM_VERSION + "/summoners/by-name/" + summonerName;
            string      response = await GET(request);

            summoner = JsonConvert.DeserializeObject <SummonerDTO>(response);
            return(summoner);
        }
Esempio n. 11
0
        public async Task <InvocadorModel> GetAsync(string nomeInvocador)
        {
            Consulta    consulta = new Consulta();
            SummonerDTO summoner = await consulta.summonerDtoAsync(nomeInvocador);

            List <LeagueEntryDTO> leagueEntryDTOs = await consulta.leagueEntryDTO(summoner.id);

            List <ChampionMasteryDTO> championMasteryDTOs = await consulta.championMasteryAsync(summoner.id);

            return(new InvocadorModel(summoner, leagueEntryDTOs, championMasteryDTOs));
        }
Esempio n. 12
0
        // Pego as informações do ranking e fila
        private TFTLeagueDTO GetPosition(SummonerDTO summoner)
        {
            LeagueTFT1 league = new LeagueTFT1(Constants.Region);

            var position = league.GetPositions(summoner.Id).Where(p => p.QueueType.Equals("RANKED_TFT")).FirstOrDefault();

            //var position = league.GetPositions(summoner.Id);

            return(position ?? new TFTLeagueDTO());
            //return null;
        }
Esempio n. 13
0
        public async Task <FullSummonerDTO> GetSummonerData(string name)
        {
            SummonerDTO summonerData = await getSummonerData.ExecuteAsync(name);

            MatchListDTO matchesData = await getMatches.ExecuteAsync(summonerData.accountId.ToString());

            return(new FullSummonerDTO()
            {
                summoner = summonerData,
                matches = matchesData
            });
        }
Esempio n. 14
0
        public SummonerDTO GetSummoner(string summonerName)
        {
            string resource = GetLeagueResourceUri("v1.4/summoner/by-name/" + summonerName);

            SummonerDTO summonerDto = Get(resource, () => GetSummoner(summonerName));

            if (summonerDto == null)
            {
                throw new DataNotFoundException("Player could not be found");
            }

            return(summonerDto);
        }
Esempio n. 15
0
        public async Task GetMasterySuccess()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName   = "TestingPlayer";
                var regionName   = "eune";
                var championName = "Test";
                var championId   = 10;
                var player       = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var championDTOs = new ChampionDTO[]
                {
                    new ChampionDTO
                    {
                        Name = "Test",
                        Id   = championId
                    }
                };
                var championMasteryDTO = new ChampionMasteryDTO
                {
                    ChampionLevel  = 1,
                    ChampionPoints = "2000"
                };
                var memoryCache       = new MemoryCache(new MemoryCacheOptions());
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(memoryCache, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(championDTOs, 200);
                httpTest.RespondWithJson(championMasteryDTO, 200);

                //Act

                var result = await riotApiService.GetMastery(playerName, regionName, championName);

                //Assert
                httpTest.ShouldHaveCalled($"http://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{player.Id}/by-champion/{championId}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                Assert.Equal($"Champion level {championMasteryDTO.ChampionLevel} with {championName} ({championMasteryDTO.ChampionPoints ?? "0"} points)", result);
            }
        }
Esempio n. 16
0
        public LeagueSummoner GetSummoner(string summonerName)
        {
            SummonerDTO summonerDto = _leagueRequestService.GetSummoner(summonerName);

            LeagueSummoner summoner = new LeagueSummoner()
            {
                Id    = summonerDto.Id,
                Name  = summonerDto.Name,
                Level = summonerDto.SummonerLevel
            };

            SetRankingInformation(summoner, summonerDto);

            return(summoner);
        }
Esempio n. 17
0
        public async Task GetWinRatioSuccess()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName = "TestingPlayer";
                var regionName = "eune";
                var wins       = 10;
                var losses     = 10;
                var player     = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var LeagueEntryDTOs = new LeagueEntryDTO[]
                {
                    new LeagueEntryDTO
                    {
                        QueueType = "RANKED_SOLO_5x5",
                        Wins      = wins,
                        Losses    = losses
                    }
                };
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(LeagueEntryDTOs, 200);

                //Act

                var result = await riotApiService.GetWinRatio(playerName, regionName);

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/league/v4/entries/by-summoner/{player.Id}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                var winRatio = 100 * wins / (wins + losses);
                Assert.Equal($"Solo Win Ratio: {winRatio}%\r\n", result);
            }
        }
Esempio n. 18
0
        public async Task <SummonerDTO> GetSummonerByNameNA(string path)
        {
            using (HttpResponseMessage response = await client.GetAsync(path).ConfigureAwait(false))
            {
                if (response.IsSuccessStatusCode)
                {
                    string jsonResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    SummonerDTO summoner = JsonConvert.DeserializeObject <SummonerDTO>(jsonResponse);

                    return(summoner);
                }
            }

            return(null);
        }
Esempio n. 19
0
        public InvocadorModel(SummonerDTO summonerDTO, List <LeagueEntryDTO> leagueEntryDTO, List <ChampionMasteryDTO> championMasteryDTOs)
        {
            nomeInvocador = summonerDTO.name;
            level         = summonerDTO.summonerLevel;
            accountId     = summonerDTO.accountId;
            icone         = summonerDTO.profileIconId;
            filas         = new List <Fila>();
            foreach (var item in leagueEntryDTO)
            {
                filas.Add(new Fila(item));
            }

            melhoresCampeoes = new List <MelhoresCampeoes>();
            foreach (var item in championMasteryDTOs)
            {
                melhoresCampeoes.Add(new MelhoresCampeoes(item));
            }
        }
Esempio n. 20
0
        public ProfileViewModel(MainViewModel mainViewModel, String region)
        {
            this._mainViewModel = mainViewModel;
            Menu         = new RelayCommand(GoToMenu);
            MatchHistory = new RelayCommand(ShowMatchHistory);
            this._region = region;

            SummonerDTO       summoner       = SummonerDTO.Instance;
            SummonerLeagueDTO summonerLeague = SummonerLeagueDTO.Instance;

            SummonerName   = summoner.name;
            SummonerIcon   = summoner.profileIconId.ToString();
            Wins           = summonerLeague.wins.ToString();
            WinRate        = (((double)summonerLeague.wins / (summonerLeague.wins + summonerLeague.losses) * 100)).ToString() + "%";
            Played         = (summonerLeague.wins + summonerLeague.losses).ToString();
            RankBorderIcon = new BitmapImage(new Uri("pack://application:,,,/Resources/" + summonerLeague.tier + ".png"));
            Tier           = summonerLeague.tier;
            LeaguePoints   = summonerLeague.leaguePoints + " LP";
        }
Esempio n. 21
0
        // Precisa do spectator funcionando
        private SpectatorDTO GetChampion(SummonerDTO summoner)
        {
            try
            {
                Spectator_V4 spectator    = new Spectator_V4(Constants.Region);
                var          spectatorVar = spectator.GetSpectator(summoner.Id);

                for (int i = 0; i < spectatorVar.Participants.Count; i++)
                {
                    if (summoner.Id == spectatorVar.Participants[i].SummonerId)
                    {
                        Constants.CurrentyChampionId = spectatorVar.Participants[i].ChampionId;
                    }
                }
                return(spectatorVar ?? new SpectatorDTO());
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 22
0
        public async Task FetchPlayerIdPlayerNotFound()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName        = "TestingPlayer";
                var regionName        = "eune";
                var player            = new SummonerDTO();
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 404);

                //Act
                await Assert.ThrowsAsync <PlayerNotFoundException>(() => riotApiService.FetchPlayerId(playerName, regionName));

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Esempio n. 23
0
        public async Task GetMasteryNull()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName   = "TestingPlayer";
                var regionName   = "eune";
                var championName = "Unexisting Champion";
                var player       = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var championDTOs = new ChampionDTO[]
                {
                    new ChampionDTO
                    {
                        Name = "Test"
                    }
                };
                var memoryCache       = new MemoryCache(new MemoryCacheOptions());
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(memoryCache, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(championDTOs, 200);

                //Act

                await Assert.ThrowsAsync <ChampionNotFoundException>(() => riotApiService.GetMastery(playerName, regionName, championName));

                //Assert
                httpTest.ShouldHaveCalled($"http://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json")
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Esempio n. 24
0
        public object GetContext(SummonerDTO summoner)
        {
            var position = GetPosition(summoner);

            return(null);
        }
Esempio n. 25
0
        public async Task <GameResponse> Post()
        {
            List <Request> requests      = new List <Request>();
            List <Game>    gamesToReturn = new List <Game>();
            GameResponse   gameResponse  = new GameResponse
            {
                StatusCode   = HttpStatusCode.OK,
                ErrorMessage = "",
                Games        = gamesToReturn
            };

            __req = await GetHelper.ReadFromBody <Request>(Request.Body);

            __req.ApiKey = GetApiKey();


            if (__req.ApiKey == null)
            {
                // Handle non-existent API-Key
                gameResponse.StatusCode   = HttpStatusCode.NotFound;
                gameResponse.ErrorMessage = "No API key provided";

                return(gameResponse);
            }

            GetHelper getHelper = new GetHelper(__req.Region.ToLower(), __req.ApiKey);

            // Using https://developer.riotgames.com/apis

            /**
             * (1) Get {encryptedAccountId}
             */
            //TODO: Move these gets into a helper class and have them return an HttpGetRespone
            HttpGetResponse summonerGet = await getHelper.GetAsyncFromRiotApi <SummonerDTO>(".api.riotgames.com/lol/summoner/v4/summoners/by-name/" + __req.SummonerName);

            if (summonerGet.Ex != null)
            {
                return(GetHelper.HandleBadRequest(summonerGet.Ex, GetRequest.Summoner));
            }
            __summoner = summonerGet.Value as SummonerDTO;

            /**
             * (2) Use that information to get the match-lists
             *
             */
            HttpGetResponse matchesGet = await getHelper.GetAsyncFromRiotApi <MatchlistDto>(".api.riotgames.com/lol/match/v4/matchlists/by-account/" + __summoner.AccountId,
                                                                                            new List <Filter>
            {
                new Filter
                {
                    PropertyName = "endIndex",
                    Value        = "10"
                }
            }
                                                                                            );

            if (matchesGet.Ex != null)
            {
                return(GetHelper.HandleBadRequest(matchesGet.Ex, GetRequest.Matches));
            }
            __matches = matchesGet.Value as MatchlistDto;

            // Get Queue.json data - TODO: Maybe only need to do this one time
            HttpGetResponse versionsGet = await GetHelper.GetAsync <List <string> >("https://ddragon.leagueoflegends.com/api/versions.json");

            if (versionsGet.Ex != null)
            {
                return(GetHelper.HandleBadRequest(versionsGet.Ex, GetRequest.Versions));
            }
            __version = (versionsGet.Value as List <string>).First();

            // Get Champs data - TODO: Maybe only need to do this one time
            HttpGetResponse championsGet = await GetHelper.GetAsync <ChampionsJson>("http://ddragon.leagueoflegends.com/cdn/" + __version + "/data/en_US/champion.json");

            if (championsGet.Ex != null)
            {
                return(GetHelper.HandleBadRequest(championsGet.Ex, GetRequest.Champions));
            }
            __champsJson = (championsGet.Value as ChampionsJson);

            foreach (MatchReferenceDto matchRef in __matches.Matches)
            {
                /**
                 * Player stats:
                 *  - 1) Win/Loss = matchId -> MatchDto get request -> get index in partipiantIndentities -> get ParticipantDto from participants via the participantId + 1 ->
                 *       get ParticipantStatsDto -> get win boolean value
                 *  2) Queue type = Queue from MatchRferenceDto -> (TODO: map to the queue json)
                 *  3) Date - get timestamp long from MatchReferenceDto.cs and compare it to epoch in order to get date
                 *  4) ChampionName - for now just return return champion int from MatchReferenceDto (TODO: Also return the image eventually)
                 *  5) ChampionImage - The href link
                 *  6) GameLength - natchId -> MatchDto get request -> gameDuration
                 *  7) Kills
                 *  8) Deaths
                 *  9) Assists
                 *
                 *  TODO:
                 *  1) Items built (w/ icons)
                 *
                 *  Player card:
                 *  1) Overall KDA
                 *  2) Summoner Level
                 *  3) Win rate
                 *  4) Profile icon
                 *  5) Custom report card rating
                 */
                Game            currGame = new Game();
                MatchDto        match    = new MatchDto();
                HttpGetResponse matchGet = await getHelper.GetAsyncFromRiotApi <MatchDto>(".api.riotgames.com/lol/match/v4/matches/" + matchRef.GameId);

                if (matchGet.Ex != null)
                {
                    return(GetHelper.HandleBadRequest(matchGet.Ex, GetRequest.Match));
                }
                match = matchGet.Value as MatchDto;

                ParticipantIdentityDto participantId = match.ParticipantIdentities.Find(IsSummonerMatch);
                ParticipantDto         participant   = match.Participants[participantId.ParticipantId - 1];

                if (participant.Stats.Win) // (1) Result
                {
                    currGame.Result = "Win";
                    __totalWins++;
                }
                else
                {
                    currGame.Result = "Loss";
                }

                // TODO: Maybe actually map to http://http://static.developer.riotgames.com/docs/lol/queues.json
                currGame.QueueType = GetQueueStringMapping(matchRef.Queue); // (2) QueueType

                long timeStamp = matchRef.Timestamp;
                currGame.Date = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(timeStamp - 86400000).ToShortDateString(); // (3) Date

                __currentChampId = matchRef.Champion;
                Tuple <string, string> champTuple = GetChampMappings();
                currGame.ChampionName  = champTuple.Item1;            // (4) ChampionName
                currGame.ChampionImage = champTuple.Item2;            // (5) ChampionImage

                currGame.GameLength = (int)(match.GameDuration / 60); // (6) GameLength

                currGame.Kills   = participant.Stats.Kills;           // (7) Kills
                __totalKills    += currGame.Kills;
                currGame.Deaths  = participant.Stats.Deaths;          // (8) Deaths
                __totalDeaths   += currGame.Deaths;
                currGame.Assists = participant.Stats.Assists;         // (9) Assists
                __totalAssists  += currGame.Assists;

                gamesToReturn.Add(currGame); // Woohoo
            }

            double kda     = (__totalKills + __totalAssists) / (__totalDeaths * 1.0);
            double winRate = (double)__totalWins / gameResponse.Games.Count() * 100;

            gameResponse.CardStats = GetSummonerCardInfo(kda, winRate);

            return(gameResponse);
        }
Esempio n. 26
0
 public Summoner(SummonerDTO summoner)
 {
     ID    = summoner.id;
     Name  = summoner.name;
     Level = summoner.summonerLevel;
 }
Esempio n. 27
0
        private async void General_Click(object sender, RoutedEventArgs e)
        {
            ChampionButton.Foreground = Brushes.MediumPurple;
            MatchButton.Foreground    = Brushes.MediumPurple;
            GeneralButton.Foreground  = Brushes.Purple;
            LiveButton.Foreground     = Brushes.MediumPurple;

            summoner_handler = new SummonerHandler(viewProfile.Region);
            SummonerDTO summoner = await summoner_handler.GetSummoner(viewProfile.SummonerName);

            if (summoner == null)
            {
                Console.WriteLine("Summoner was null...");
                Show_Notification(summoner_handler.ErrorMsg);
                return;
            }
            viewProfile.SummonerEntry   = summoner;
            viewProfile.ProfileIconPath = "http://ddragon.leagueoflegends.com/cdn/10.4.1/img/profileicon/" + (summoner.ProfileIconId).ToString() + ".png";

            league_entry_handler = new LeagueEntryHandler(viewProfile.Region);
            List <LeagueEntryDTO> league_entries = await league_entry_handler.GetLeagueEntry(summoner.Id);

            if (league_entry_handler.ErrorMsg != "")
            {
                Show_Notification(league_entry_handler.ErrorMsg);
                return;
            }
            if (league_entries == null)
            {
                Show_Notification("No league data to display");
                return;
            }
            LeagueEntryDTO league_entry = league_entries.Where(p => p.QueueType.Equals("RANKED_SOLO_5x5")).FirstOrDefault();

            if (league_entry == null)
            {
                league_entry              = new LeagueEntryDTO();
                league_entry.MiniSeries   = null;
                league_entry.HotStreak    = false;
                league_entry.FreshBlood   = false;
                league_entry.Veteran      = false;
                league_entry.Wins         = 0;
                league_entry.Losses       = 0;
                league_entry.Rank         = "";
                league_entry.Tier         = "Unranked";
                league_entry.LeaguePoints = 0;
                viewProfile.Winrate       = "0";
            }
            else
            {
                viewProfile.Winrate = (100 * league_entry.Wins / (league_entry.Losses + league_entry.Wins)).ToString();
            }

            viewProfile.LeagueEntry = league_entry;
            viewProfile.EmblemPath  = "pack://application:,,,/Assets/Emblem/Emblem_" + league_entry.Tier + ".png";

            champion_data_handler = new ChampionInfoHandler();
            ChampionInfo champData = await champion_data_handler.GetChampionData();

            viewProfile.FullChampionNames = champion_data_handler.ParseChampionData(champData.Data);

            MenuBar.Visibility = Visibility.Visible;
            Main.Content       = new General(viewProfile);
        }
 public SummonerDetailViewModel(SummonerDTO summoner)
 {
     Summoner = summoner;
 }
Esempio n. 29
0
        // 非同期させたい(重たい)処理
        private LoginState LoginDelegatingMethod(string reg, string summName, bool loginTypeFlg)
        {
            LoginState loginStateRet = new LoginState();

            loginStateRet.LoginTypeFlg = loginTypeFlg;

            try
            {
                Region region = (Region)Enum.Parse(typeof(Region), reg);

                RiotSharp.Misc.Language language = RiotSharp.Misc.Language.en_US;
                if (region == Region.jp)
                {
                    language = RiotSharp.Misc.Language.ja_JP;
                }

                if (m_Region == region)
                {
                    if (!LoLStaticData.LoLStaticDataAlreadyLoaded())
                    {
                        //LoLStaticData.ItemsStaticData = m_StaticRiotApi.GetStaticItems(region, ItemData.all, language);
                        //LoLStaticData.ChampionsStaticData = m_StaticRiotApi.GetStaticChampions(region, ChampionData.all, language);
                        //LoLStaticData.SummonerSpellsStaticData = m_StaticRiotApi.GetStaticSummonerSpells(region, SummonerSpellData.all, language);
                    }
                }
                else
                {
                    //LoLStaticData.ItemsStaticData = m_StaticRiotApi.GetStaticItems(region, ItemData.all, language);
                    //LoLStaticData.ChampionsStaticData = m_StaticRiotApi.GetStaticChampions(region, ChampionData.all, language);
                    //LoLStaticData.SummonerSpellsStaticData = m_StaticRiotApi.GetStaticSummonerSpells(region, SummonerSpellData.all, language);
                }

                m_Region = region;

                _loginSummoner = m_RiotApi.GetSummonerByName(region, summName);

                var matches   = m_RiotApi.GetMacthAllByAccountId(region, _loginSummoner.AccountId).Matches;
                var mrbListBk = new List <MatchReferenceBinding>();
                foreach (MatchReferenceDto mr in matches)
                {
                    var mrb = new MatchReferenceBinding();
                    mrb.MatchReference = mr;
                    mrbListBk.Add(mrb);
                }
                if (_viewModel.ListMatchReference != null)
                {
                    _viewModel.ListMatchReference.Clear();
                }
                if (_viewModel.ListMatchReferenceBK != null)
                {
                    _viewModel.ListMatchReferenceBK.Clear();
                }

                _viewModel.ListMatchReferenceBK = mrbListBk;
                _viewModel.ListMatchReference   = mrbListBk;

                var championMasteries = m_RiotApi.GetChampionMasteries(region, _loginSummoner.Id);
                var cmbList           = new List <ChampionMasteryBinding>();
                foreach (ChampionMasteryDTO cmDto in championMasteries)
                {
                    var cmb = new ChampionMasteryBinding(cmDto);
                    cmbList.Add(cmb);
                }

                for (int i = cmbList.Count - 1; i >= 0; i--)
                {
                    var existDto = _viewModel.ListMatchReferenceBK.Where(lmrBk => lmrBk.MatchReference.Champion == cmbList[i].ChampionMastery.ChampionId);

                    if (existDto == null || existDto.ToArray().Length == 0)
                    {
                        cmbList.RemoveAt(i);
                    }
                }
                if (_viewModel.ListChampionMasteries != null)
                {
                    _viewModel.ListChampionMasteries.Clear();
                }

                var cmbEmpty = new ChampionMasteryBinding(new ChampionMasteryDTO());
                cmbEmpty.ChampionMastery.ChampionId = -1;
                cmbList.Insert(0, cmbEmpty);

                _viewModel.ListChampionMasteries = cmbList;

                loginStateRet.LoginErrorFlg     = false;
                loginStateRet.LoginErrorMessage = string.Empty;
            }
            catch (RiotSharpException rsEx)
            {
                _viewModel.ListMatchReference = null;

                loginStateRet.LoginErrorFlg     = true;
                loginStateRet.LoginErrorMessage = rsEx.Message;
            }
            catch (Exception ex)
            {
                _viewModel.ListMatchReference = null;

                if (ex.InnerException != null && ex.InnerException is RiotSharpException)
                {
                    loginStateRet.LoginErrorMessage = ex.InnerException.Message;
                }
                else
                {
                    loginStateRet.LoginErrorMessage = ex.Message;
                }

                loginStateRet.LoginErrorFlg = true;
            }

            return(loginStateRet);
        }
Esempio n. 30
0
 private object GetPosition(SummonerDTO summoner)
 {
     throw new NotImplementedException();
 }