Пример #1
0
        private void RegisteredPlayersEnterTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            foundPlayers.Clear();

            using (StringReader reader = new StringReader(RegisteredPlayersEnterTextBox.Text))
            {
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    PlayerRanking player      = new PlayerRanking();
                    bool          bExactMatch = false;
                    if (NameFinder.GetClosestName(playerRankingData.playerRankings, line, ref player, ref bExactMatch))
                    {
                        if (bExactMatch)
                        {
                            foundPlayers.Add(new PotentialPlayer(player, true));
                        }
                        else
                        {
                            foundPlayers.Add(new PotentialPlayer(line));
                        }
                    }
                }
            }
        }
Пример #2
0
 public PotentialPlayer(PlayerRanking pr, bool inbExactMatch)
 {
     firstName   = pr.firstName;
     lastName    = pr.lastName;
     points      = pr.points;
     womenPoints = pr.womenPoints;
     rank        = pr.rank;
     bExactMatch = inbExactMatch;
 }
 public RegisteredPlayer(PlayerRanking player)
 {
     firstName   = player.firstName;
     lastName    = player.lastName;
     country     = player.country;
     points      = player.points;
     womenPoints = player.womenPoints;
     rank        = player.rank;
     isMale      = player.isMale;
 }
Пример #4
0
        private void AddNewName_Click(object sender, RoutedEventArgs e)
        {
            PlayerRanking pr = new PlayerRanking();

            pr.firstName    = FixBoxFirstName;
            pr.lastName     = FixBoxLastName;
            pr.points       = 0;
            pr.rank         = 0;
            pr.IsRegistered = true;

            AddRegisteredPlayer(pr);
        }
        private void RankingPlayer_Click(object sender, RoutedEventArgs e)
        {
            PlayerRanking player = (sender as Button).Tag as PlayerRanking;

            if (player.IsRegistered)
            {
                RemoveRegisteredPlayer(player.firstName, player.lastName);
            }
            else
            {
                AddRegisteredPlayer(player);
            }

            FillRankingsTextBox();
        }
        private void TeamsEnterTeamsTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            foundTeams.Clear();

            using (StringReader reader = new StringReader(TeamsEnterTeamsTextBox.Text))
            {
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    PotentialTeam newTeam = new PotentialTeam();

                    string[] names = line.Split(NameFinder.splitPlayerChars);
                    foreach (string nameLine in names)
                    {
                        PlayerRanking player      = new PlayerRanking();
                        bool          bExactMatch = false;
                        if (NameFinder.GetClosestName(playerRankingData.playerRankings, nameLine, ref player, ref bExactMatch))
                        {
                            if (bExactMatch)
                            {
                                newTeam.registeredPlayers.Add(new RegisteredPlayer(new PotentialPlayer(player, true)));
                            }
                            else
                            {
                                newTeam.potentialPlayers.Add(new PotentialPlayer(nameLine));
                            }
                        }
                    }

                    if (newTeam.potentialPlayers.Count > 0 || newTeam.RegisteredPlayers.Count > 0)
                    {
                        foundTeams.Add(newTeam);
                    }
                }
            }
        }
Пример #7
0
 public PlayerRankingSortData(PlayerRanking inPlayerRanking, float inRating)
 {
     playerRanking = inPlayerRanking;
     rating        = inRating;
 }
Пример #8
0
        public static bool GetClosestName(ObservableCollection <PlayerRanking> playerRankings, string name, ref PlayerRanking outPlayerRanking, ref bool outExactMatch)
        {
            string name1 = "";
            string name2 = "";

            GetValidNames(name, ref name1, ref name2);

            if (name1 == "")
            {
                return(false);
            }

            List <PlayerRankingSortData> sortedPlayers = GetFilteredNamesRaw(playerRankings, name1, name2);

            if (sortedPlayers.Count > 0)
            {
                outPlayerRanking = sortedPlayers[0].playerRanking;
                outExactMatch    = sortedPlayers[0].rating == EXACT_MATCH_RATING;

                return(true);
            }

            return(false);
        }
 private void AddRegisteredPlayer(PlayerRanking player)
 {
     registeredPlayers.Add(new RegisteredPlayer(player));
 }
        private void GetRankingsWorker_DoWork(string url, bool bIsOpenRankings)
        {
            using (WebClient client = new WebClient())
            {
                string htmlSource = client.DownloadString(url);

                if (htmlSource != null && htmlSource.Length > 0)
                {
                    playerRankingData.time = DateTime.Now;

                    string       line              = null;
                    StringReader textStream        = new StringReader(htmlSource);
                    bool         bFoundFirstPlayer = false;
                    string       rankTag           = "<td height=19 class=xl6330694 style='height:14.4pt'>";
                    string       nameClass         = "xl1530694";
                    string       countryClass      = "xl6619937";
                    string       pointsClass       = "xl6330694";
                    string       maleTag           = "<td class=xl6614882>m</td>";
                    while ((line = textStream.ReadLine()) != null)
                    {
                        line = line.Trim();

                        if (!bFoundFirstPlayer && line.Contains(">1<"))
                        {
                            bFoundFirstPlayer = true;

                            rankTag = line.Substring(0, line.IndexOf(">1<") + 1);

                            line      = textStream.ReadLine();
                            line      = textStream.ReadLine().Trim();
                            line      = line.Replace("<td class=", "");
                            nameClass = line.Substring(0, line.IndexOf(">"));

                            line         = textStream.ReadLine();
                            line         = line.Replace("<td class=", "").Trim();
                            countryClass = line.Substring(0, line.IndexOf(">"));

                            line        = textStream.ReadLine();
                            line        = textStream.ReadLine().Trim();
                            line        = line.Replace("<td class=", "");
                            pointsClass = line.Substring(0, line.IndexOf(">"));

                            textStream = new StringReader(htmlSource);
                        }
                        else if (line.StartsWith(rankTag))
                        {
                            PlayerRanking newPlayer = new PlayerRanking();
                            string        rankStr   = line.Trim().Replace(rankTag, "");
                            rankStr = rankStr.Replace("</td>", "").Replace("T", "");
                            int.TryParse(rankStr, out newPlayer.rank);
                            newPlayer.womenPoints = 0;
                            textStream.ReadLine();

                            string nameLine           = textStream.ReadLine().Trim().Replace("<td class=" + nameClass + ">", "");
                            int    nameLineCommaIndex = nameLine.IndexOf(',');
                            if (nameLineCommaIndex == -1)
                            {
                                continue;
                            }
                            string lastName  = nameLine.Substring(0, nameLineCommaIndex);
                            string firstName = nameLine.Substring(nameLineCommaIndex + 2, nameLine.IndexOf("</td>") - nameLineCommaIndex - 2);
                            newPlayer.firstName = firstName;
                            newPlayer.lastName  = lastName;

                            string countryLine = textStream.ReadLine().Trim().Replace("<td class=" + countryClass + ">", "").Replace("</td>", "");
                            newPlayer.country = countryLine;


                            if (bIsOpenRankings)
                            {
                                // Open rankings has extra line for gender
                                string genderStr = textStream.ReadLine().Trim();
                                newPlayer.isMale = genderStr == maleTag;
                            }
                            string pointsLine = textStream.ReadLine().Trim();
                            pointsLine = pointsLine.Replace("<td class=" + pointsClass + ">", "").Replace("</td>", "").Replace(",", ".");

                            float.TryParse(pointsLine,
                                           System.Globalization.NumberStyles.AllowDecimalPoint,
                                           System.Globalization.CultureInfo.CreateSpecificCulture("en-US"),
                                           out newPlayer.points);

                            if (bIsOpenRankings)
                            {
                                asyncRetrievedPlayerRankings.Add(newPlayer);
                            }
                            else
                            {
                                // Women points need to be queried after open
                                foreach (PlayerRanking pr in asyncRetrievedPlayerRankings)
                                {
                                    if (pr.FullName == newPlayer.FullName)
                                    {
                                        pr.womenPoints = newPlayer.points;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }