コード例 #1
0
        private HaloStatModel ParseHalo2StatsFromBungie(List <string> htmlStats)
        {
            HaloStatModel haloStatModel = new HaloStatModel();

            foreach (string stat in htmlStats)
            {
                if (stat.Contains(Constants.Halo2Constants.TotalGames, StringComparison.OrdinalIgnoreCase))
                {
                    haloStatModel.TotalGames = int.Parse(stat.Replace($"{Constants.Halo2Constants.TotalGames}:", ""));
                }
                else if (stat.Contains(Constants.Halo2Constants.LastPlayed, StringComparison.OrdinalIgnoreCase))
                {
                    haloStatModel.LastPlayed = (stat.Replace($"{Constants.Halo2Constants.LastPlayed}:", ""));
                }
                else if (stat.Contains(Constants.Halo2Constants.TotalKills, StringComparison.OrdinalIgnoreCase))
                {
                    haloStatModel.TotalKills = int.Parse(stat.Replace($"{Constants.Halo2Constants.TotalKills}:", ""));
                }
                else if (stat.Contains(Constants.Halo2Constants.TotalDeaths, StringComparison.OrdinalIgnoreCase))
                {
                    haloStatModel.TotalDeaths = int.Parse(stat.Replace($"{Constants.Halo2Constants.TotalDeaths}:", ""));
                }
                else if (stat.Contains(Constants.Halo2Constants.TotalAssists, StringComparison.OrdinalIgnoreCase))
                {
                    haloStatModel.TotalAssists = int.Parse(stat.Replace($"{Constants.Halo2Constants.TotalAssists}:", ""));
                }
            }

            return(haloStatModel);
        }
コード例 #2
0
        public async Task <HaloStatModel> GetHalo2StatsFromBungie(string gamerTag)
        {
            HaloStatModel haloStatModel = new HaloStatModel();

            if (string.IsNullOrWhiteSpace(gamerTag))
            {
                return(await Task.FromResult(haloStatModel));
            }
            else
            {
                WebClient client           = new WebClient();
                string    downloadedString = client.DownloadString("https://halo.bungie.net/stats/playerstatshalo2.aspx?player=" + gamerTag);

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(downloadedString);
                string whatUrLookingFor = doc.GetElementbyId("ctl00_mainContent_bnetpgl_identityStrip_div1").InnerHtml;

                HtmlNodeCollection childNodes = doc.DocumentNode.SelectNodes("//li");
                var result = childNodes.Single(x => x.InnerText.Contains("Total Games:") == true);

                List <string> cleanedResult = GetCleanAndSplitHalo2StatsFromBungie(result.InnerHtml);

                haloStatModel = ParseHalo2StatsFromBungie(cleanedResult);

                return(await Task.FromResult(haloStatModel));
            }
        }
コード例 #3
0
        /**
         * SageOfChaos : Total Halo 2 Games: Total Games: 5313 Last Played: 11/23/2009 4:10:18 PM Total Kills: 41131 Total Deaths: 28649 Total Assists: 9791
         */
        public async Task GetHalo2StatsFromBungie_Goldenflow(string gamerTag)
        {
            // Arrange
            // Do nothing

            // Act
            HaloStatModel result = await _sut.GetHalo2StatsFromBungie(gamerTag);

            // Assert
            Assert.IsTrue(result.TotalGames == 5313);
            Assert.IsTrue(result.LastPlayed.Equals("11/23/20094:10:18PM"));
            Assert.IsTrue(result.TotalKills == 41131);
            Assert.IsTrue(result.TotalDeaths == 28649);
            Assert.IsTrue(result.TotalAssists == 9791);
        }