Пример #1
0
        public async void GetData()
        {
            try
            {
                var loginPacket = await Connection.GetLoginDataPacketForUser();

                if (loginPacket.AllSummonerData == null)
                {
                    Data.ErrorMessage = "Summoner not created.";
                    Data.State        = Account.Result.Error;

                    IsCompleted.TrySetResult(true);
                    return;
                }

                await GetChampions();

                GetRunes(loginPacket.AllSummonerData.Summoner.SumId);

                Data.Summoner  = loginPacket.AllSummonerData.Summoner.Name;
                Data.Level     = (int)loginPacket.AllSummonerData.SummonerLevel.Level;
                Data.RpBalance = (int)loginPacket.RpBalance;
                Data.IpBalance = (int)loginPacket.IpBalance;
                Data.Champions = Data.ChampionList.Count;
                Data.Skins     = Data.SkinList.Count;
                Data.RunePages = loginPacket.AllSummonerData.SpellBook.BookPages.Count;

                if (loginPacket.EmailStatus != null)
                {
                    var emailStatus = loginPacket.EmailStatus.Replace('_', ' ');
                    Data.EmailStatus = Char.ToUpper(emailStatus[0]) + emailStatus.Substring(1);
                }
                else
                {
                    Data.EmailStatus = "Unknown";
                }

                // Leagues
                if (Data.Level == 30)
                {
                    var myLeagues = await Connection.GetMyLeaguePositions();

                    var soloqLeague = myLeagues.SummonerLeagues.FirstOrDefault(l => l.QueueType == "RANKED_SOLO_5x5");
                    Data.SoloQRank = soloqLeague != null
                        ? string.Format(
                        "{0}{1} {2}", char.ToUpper(soloqLeague.Tier[0]), soloqLeague.Tier.Substring(1).ToLower(),
                        soloqLeague.Rank)
                        : "Unranked";
                }
                else
                {
                    Data.SoloQRank = "Unranked";
                }

                // Last Play
                var recentGames = await Connection.GetRecentGames(loginPacket.AllSummonerData.Summoner.AcctId);

                var lastGame = recentGames.GameStatistics.FirstOrDefault();

                if (lastGame != null)
                {
                    Data.LastPlay = lastGame.CreateDate;
                }

                Data.State = Account.Result.Success;
            }
            catch (Exception e)
            {
                Utils.ExportException(e);
                Data.ErrorMessage = string.Format("Exception found: {0}", e.Message);
                Data.State        = Account.Result.Error;
            }

            IsCompleted.TrySetResult(true);
        }
Пример #2
0
        public async void GetData()
        {
            var loginPacket = await Connection.GetLoginDataPacketForUser();

            if (loginPacket.AllSummonerData == null)
            {
                Data.ErrorMessage = "Summoner not created.";
                Data.Result       = Result.Error;

                IsCompleted.TrySetResult(true);
                return;
            }

            var champions = await Connection.GetAvailableChampions();

            Data.ChampionList = new List <ChampionData>();
            Data.SkinList     = new List <SkinData>();

            foreach (var champion in champions)
            {
                var cdata = LeagueData.Data.data.FirstOrDefault(c => Int32.Parse(c.key) == champion.ChampionId);

                if (cdata == null)
                {
                    continue; // champion not implemented in json file ?
                }

                if (champion.Owned)
                {
                    Data.ChampionList.Add(
                        new ChampionData
                    {
                        Name         = cdata.name,
                        PurchaseDate =
                            new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(
                                Math.Round(champion.PurchaseDate / 1000d))
                    });
                }

                foreach (var skin in champion.ChampionSkins.Where(skin => skin.Owned))
                {
                    var sdata = cdata.skins.FirstOrDefault(s => Int32.Parse(s.id) == skin.SkinId);

                    if (sdata == null)
                    {
                        continue; // skin not implemented in json file ?
                    }

                    Data.SkinList.Add(new SkinData {
                        Name = sdata.name, StillObtainable = skin.StillObtainable
                    });
                }
            }

            Data.Level     = (int)loginPacket.AllSummonerData.SummonerLevel.Level;
            Data.RpBalance = (int)loginPacket.RpBalance;
            Data.IpBalance = (int)loginPacket.IpBalance;
            Data.Champions = Data.ChampionList.Count;
            Data.Skins     = Data.SkinList.Count;
            Data.RunePages = loginPacket.AllSummonerData.SpellBook.BookPages.Count;
            Data.Summoner  = loginPacket.AllSummonerData.Summoner.Name;

            var emailStatus = loginPacket.EmailStatus.Replace('_', ' ');

            Data.EmailStatus = Char.ToUpper(emailStatus[0]) + emailStatus.Substring(1);


            // Leagues
            if (Data.Level == 30)
            {
                var myLeagues = await Connection.GetMyLeaguePositions();

                var soloqLeague = myLeagues.SummonerLeagues.FirstOrDefault(l => l.QueueType == "RANKED_SOLO_5x5");
                Data.SoloQRank = soloqLeague != null
                    ? string.Format(
                    "{0}{1} {2}", char.ToUpper(soloqLeague.Tier[0]), soloqLeague.Tier.Substring(1).ToLower(),
                    soloqLeague.Rank)
                    : "Unranked";
            }
            else
            {
                Data.SoloQRank = "Unranked";
            }

            // Last Play
            var recentGames = await Connection.GetRecentGames(loginPacket.AllSummonerData.Summoner.AcctId);

            var lastGame = recentGames.GameStatistics.FirstOrDefault();

            if (lastGame != null)
            {
                Data.LastPlay = lastGame.CreateDate;
            }

            Data.Result = Result.Success;

            IsCompleted.TrySetResult(true);
        }