示例#1
0
        void LoadPlayerUIFinish(PlayerCache ply, PlayerControl control)
        {
            FInvoke(delegate
            {
                //Now that we are back on the UI thread.
                //Lets check to make sure the control still wants this specific data.
                //if (control.Tag == null || ((PlayerParticipant)control.Tag).SummonerId != ply.Summoner.SummonerId)
                if (control.Tag == null || ((PlayerParticipant)control.Tag).InternalName != ply.Summoner.InternalName)
                {
                    return;
                }
                control.SetRankedStats(ply.Summoner, ply.RankedStats);
                control.SetLeagueInfo(ply.Summoner, ply.LeagueInfo);
                control.DefaultGameTab = Settings.DefaultGameTab;
                control.SetPlayer(ply.Player);

                /*if (ply.Stats != null)
                 *                  control.SetStats(ply.Summoner, ply.Stats);
                 * if (ply.RecentChamps != null)
                 *                  control.SetChamps(ply.RecentChamps);
                 * if (ply.Games != null)
                 *                  control.SetGames(ply.Games);*/
                control.SetLoading(false);
            });
        }
示例#2
0
        /// <summary>
        /// Query and cache player data
        /// </summary>
        /// <param name="player">Player to load</param>
        /// <param name="control">Control to update</param>
        void LoadPlayer(PlayerParticipant player, PlayerControl control)
        {
            PlayerCache existing;
            var         ply = new PlayerCache();

            try
            {
                lock (PlayersCache)
                {
                    //Clear the cache every 50000 players to prevent crashing afk lobbies.
                    if (PlayersCache.Count > 50000)
                    {
                        PlayersCache.Clear();
                    }

                    //Does the player already exist in the cache?
                    if ((existing = PlayersCache.Find(p => p.Player != null && p.Player.Id == player.SummonerId)) == null)
                    {
                        PlayersCache.Add(ply);
                    }
                }

                //If another thread is loading the player data, lets wait for it to finish and use its data.
                if (existing != null)
                {
                    existing.LoadWait.WaitOne();
                    LoadPlayerUIFinish(existing, control);
                    return;
                }


                using (SimpleLogTimer.Start("Player query"))
                {
                    //var entry = Recorder.GetPlayer(player.SummonerId);
                    //ply.Player = entry ?? ply.Player;
                }

                using (SimpleLogTimer.Start("Stats query"))
                {
                    var cmd      = new PlayerCommands(Connection);
                    var summoner = cmd.GetPlayerByName(player.Name);
                    if (summoner != null)
                    {
                        ply.Summoner        = summoner;
                        ply.CurrentChampion = Convert.ToInt32(player.QueueRating);
                        ply.RankedStats     = cmd.GetAggregatedStatList(summoner.AccountId, "CLASSIC", "CURRENT");
                        ply.LeagueInfo      = cmd.GetLeagueInfo(summoner.SummonerId);

                        /*
                         * if ((Settings.LoadWhatData & LoadDataEnum.Stats) != 0)
                         *                          ply.Stats = cmd.RetrievePlayerStatsByAccountId(summoner.AccountId);
                         * if ((Settings.LoadWhatData & LoadDataEnum.TopChamps) != 0)
                         *  ply.RecentChamps = cmd.RetrieveTopPlayedChampions(summoner.AccountId, "CLASSIC");
                         * if ((Settings.LoadWhatData & LoadDataEnum.RecentGames) != 0)
                         *  ply.Games = cmd.GetRecentGames(summoner.AccountId);
                         * */
                    }
                    else
                    {
                        StaticLogger.Debug(string.Format("Player {0} not found", player.Name));
                        ply.LoadWait.Set();
                        return;
                    }
                }

                using (SimpleLogTimer.Start("Seen query"))
                {
                    if (SelfSummoner != null && SelfSummoner.SummonerId != ply.Summoner.SummonerId && ply.Games != null)
                    {
                        ply.SeenCount = ply.Games.GameStatistics.Count(pgs => pgs.FellowPlayers.Any(fp => fp.SummonerId == SelfSummoner.SummonerId));
                    }
                }

                ply.LoadWait.Set();
                LoadPlayerUIFinish(ply, control);
            }
            catch (Exception ex)
            {
                ply.LoadWait.Set();                 //
                StaticLogger.Warning(ex);
            }
        }