Example #1
0
        public async Task <IEnumerable <TeamParticipants> > GetAllTeam()
        {
            var teams = _team.GetAll("Team").Result;

            var teamPlayers = _teamPlayers.GetAll("TeamPlayers").Result;

            var query = teams.GroupJoin(teamPlayers, tp => tp.TeamId, t => t.TeamIdShort, (t, tp) => new
            {
                teamid = t.TeamId,

                TeamName = t.Name,

                ShortName = t.ShortName,

                TeamPlayers = tp.Select(s => new { s.TeamIdShort, s.PlayerName, s.PlayerId }).Distinct()
            });

            var teamLineUpCollections = new List <TeamParticipants>();

            foreach (var obj in query)
            {
                var teamlineup = new TeamParticipants();

                teamlineup.TeamId = obj.teamid;

                teamlineup.TeamName = obj.TeamName;

                teamlineup.ShortName = obj.ShortName;

                var teamplayer = new List <Participants>();

                foreach (var players in obj.TeamPlayers)
                {
                    teamplayer.Add(new Participants()
                    {
                        PlayerName = players.PlayerName, PlayerId = players.PlayerId
                    });
                }

                teamlineup.TeamPlayer = teamplayer;

                teamLineUpCollections.Add(teamlineup);
            }
            return(await Task.FromResult(teamLineUpCollections));
        }
Example #2
0
        public void GameLobbyUpdate(GameDTO lobby)
        {
            //StaticLogger.Info("Game Mode: " + lobby.GameMode);
            //StaticLogger.Info("Game Type: " + lobby.GameType);

            //StaticLogger.Info("Pre InvokeRequired");

            if (InvokeRequired)
            {
                BeginInvoke(new Action <GameDTO>(GameLobbyUpdate), lobby);
                return;
            }
            //StaticLogger.Info("Game State: " + lobby.GameState);

            if (CurrentGame == null || CurrentGame.Id != lobby.Id)
            {
                //StaticLogger.Info("CurrentGame is null OR the Ids don't match.");
                teammates      = new List <string>();
                bans           = new List <int>();
                APIRequestMade = false;
                CurrentGame    = lobby;
            }

            //CurrentGame.QueueTypeName.Equals("RANKED_SOLO_5x5")
            //StaticLogger.Info("Pre main IF");
            //StaticLogger.Info("Teammates count: " + teammates.Count);
            //StaticLogger.Info("Current Game State: " + CurrentGame.GameState);
            if (lobby.QueueTypeName.Equals("RANKED_SOLO_5x5") && lobby.GameState.Equals("PRE_CHAMP_SELECT") && teammates.Count == 0)
            {
                //StaticLogger.Info("Inside main if");
                IncludeBans.Enabled = false;

                int teamNumber = 0;
                List <TeamParticipants> teams = new List <TeamParticipants> {
                    lobby.TeamOne, lobby.TeamTwo
                };

                // Determine what team we're on
                for (int i = 0; i < teams.Count; i++)
                {
                    TeamParticipants team = teams[i];
                    for (int j = 0; j < team.Count; j++)
                    {
                        PlayerParticipant player = team[j] as PlayerParticipant;
                        if (player != null && player.SummonerId != 0)
                        {
                            if (player.SummonerId == SelfSummoner.SummonerId)
                            {
                                teamNumber = i;
                            }
                        }
                    }
                }

                TeamParticipants myTeam = teams[teamNumber];
                for (int i = 0; i < myTeam.Count; i++)
                {
                    PlayerParticipant player = myTeam[i] as PlayerParticipant;
                    teammates.Add(player.Name);
                }
                SummonerNamesLabel.Visible = true;
                //StaticLogger.Info("Team: " + string.Join(", ", teammates));
            }
            else if (lobby.QueueTypeName.Equals("RANKED_SOLO_5x5") && lobby.GameState.Equals("TERMINATED") || lobby.GameState.Equals("START_REQUESTED") || lobby.GameState.Equals("POST_CHAMP_SELECT"))
            {
                IncludeBans.Enabled        = true;
                SummonerNamesLabel.Visible = false;
                BansLabel.Visible          = false;
                GenRecLabel.Visible        = false;
                CopyURLButton.Visible      = false;
                OpenURLinBrowser.Visible   = false;
            }

            //StaticLogger.Info("Pre POST Ifs");
            if (lobby.QueueTypeName.Equals("RANKED_SOLO_5x5") && lobby.GameState.Equals("PRE_CHAMP_SELECT") && !IncludeBans.Checked && !APIRequestMade)
            {
                GenRecLabel.Visible = true;
                //StaticLogger.Info("Not including bans...");
                using (WebClient wb = new WebClient())
                {
                    NameValueCollection data = new NameValueCollection();
                    data["call"]          = "generateRecommendations";
                    data["region"]        = Settings.Region.ToString().ToLower();
                    data["summonerNames"] = string.Join(",", teammates);
                    data["bans"]          = "";

                    //StaticLogger.Info("Generating recommendations: " + data.ToString());

                    Byte[] response = wb.UploadValues(@"http://www.elophant.com/api.aspx", "POST", data);

                    TeamIdJson = System.Text.Encoding.UTF8.GetString(response);

                    //StaticLogger.Info("Response: " + TeamIdJson);
                    APIRequestMade = true;
                }
                CopyURLButton.Visible    = true;
                OpenURLinBrowser.Visible = true;
            }
            else if (lobby.QueueTypeName.Equals("RANKED_SOLO_5x5") && lobby.GameState.Equals("CHAMP_SELECT") && IncludeBans.Checked && !APIRequestMade)
            {
                //StaticLogger.Info("Including bans...");
                foreach (var ban in lobby.BannedChampions)
                {
                    bans.Add(ban.ChampionId);
                }
                BansLabel.Visible   = true;
                GenRecLabel.Visible = true;

                using (WebClient wb = new WebClient())
                {
                    NameValueCollection data = new NameValueCollection();
                    data["call"]          = "generateRecommendations";
                    data["region"]        = Settings.Region.ToString().ToLower();
                    data["summonerNames"] = string.Join(",", teammates);
                    data["bans"]          = string.Join(",", bans);

                    //StaticLogger.Info("region: " + Settings.Region.ToString().ToLower() + " summonerNames: " + string.Join(",", teammates) + " bans: " + string.Join(",", bans));

                    Byte[] response = wb.UploadValues(@"http://www.elophant.com/api.aspx", "POST", data);

                    TeamIdJson = System.Text.Encoding.UTF8.GetString(response);

                    //StaticLogger.Info("Response: " + TeamIdJson);

                    APIRequestMade = true;
                }
                CopyURLButton.Visible    = true;
                OpenURLinBrowser.Visible = true;
            }
        }