Esempio n. 1
0
        public async Task <IEnumerable <Game> > GetGamesOdds()
        {
            var oddSource = new LiveBetSource
            {
                Name = "Odds",
                Url  = "http://www.goalserve.com/getfeed/d1aa4f5599064db8b343090338221a49/lines/soccer-inplay"
            };

            _gamesforLiveOdds.Clear();
            var req    = (HttpWebRequest)WebRequest.Create(oddSource.Url);
            var res    = (HttpWebResponse)req.GetResponse();
            var stream = res.GetResponseStream();
            var xmldoc = new XmlDocument();

            if (stream == null)
            {
                return(_gamesforLiveOdds.Values);                // if the stream is null return the games the way they are
            }
            // Get a UTF-32 encoding by name.
            Encoding encoding = Encoding.GetEncoding("utf-8");

            using (var str = new StreamReader(stream, encoding))
            {
                try
                {
                    xmldoc.Load(str);
                }
                catch (Exception)
                {
                    // continue;
                }
            }

            // check the url that has been loaded
            var categoryList = xmldoc.SelectNodes("/scores/category");

            if (categoryList != null)
            {
                //get the odds from the xml
                foreach (XmlNode category in categoryList)
                {
                    var testGame = new Game();
                    var match    = category.ChildNodes[0];
                    if (match.Attributes != null)
                    {
                        testGame.MatchNo   = match.Attributes["id"].InnerText;
                        testGame.StartDate = match.Attributes["formatted_date"].InnerText;
                        testGame.StartTime = match.Attributes["time"].InnerText;
                        testGame.League    = match.Attributes["league"] != null || match.Attributes["league"].InnerText == ""
                                   ? match.Attributes["league"].InnerText
                                   : "FailedLeague";

                        var odds = match.LastChild;
                        foreach (XmlNode odd in odds)
                        {
                            if (odd.Attributes != null)
                            {
                                switch (odd.Attributes["name"].InnerText)
                                {
                                case "Fulltime Result":
                                    testGame.FullTimeOdds = new FullTimeOdds();
                                    foreach (XmlNode FTO in odd.ChildNodes)
                                    {
                                        if (FTO.Attributes != null)
                                        {
                                            if (FTO.Attributes["extravalue"].InnerText == "1")
                                            {
                                                var homeWin = FTO.Attributes["odd"].InnerText;
                                                testGame.FullTimeOdds.HomeWins = homeWin;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "X")
                                            {
                                                var draw = FTO.Attributes["odd"].InnerText;
                                                testGame.FullTimeOdds.Draw = draw;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "2")
                                            {
                                                var awayWin = FTO.Attributes["odd"].InnerText;
                                                testGame.FullTimeOdds.AwayWins = awayWin;
                                            }
                                        }
                                    }
                                    break;

                                case "Match Goals":
                                    testGame.UnderOverOdds = new UnderOverOdds();
                                    foreach (XmlNode game in odd.ChildNodes)
                                    {
                                        if (game.Attributes != null)
                                        {
                                            if (game.Attributes["name"].InnerText.Contains("Over"))
                                            {
                                                var over = game.Attributes["odd"].InnerText;
                                                testGame.UnderOverOdds.Over       = over;
                                                testGame.UnderOverOdds.ExtraValue = game.Attributes["extravalue"].InnerText;
                                            }
                                            if (game.Attributes["name"].InnerText.Contains("Under"))
                                            {
                                                var under = game.Attributes["odd"].InnerText;
                                                testGame.UnderOverOdds.Under      = under;
                                                testGame.UnderOverOdds.ExtraValue = game.Attributes["extravalue"].InnerText;
                                            }
                                        }
                                    }
                                    break;

                                case "Next Goal":
                                    testGame.NextGoal = new NextGoal();
                                    foreach (XmlNode FTO in odd.ChildNodes)
                                    {
                                        if (FTO.Attributes != null)
                                        {
                                            if (FTO.Attributes["extravalue"].InnerText == "1")
                                            {
                                                var homeScores = FTO.Attributes["odd"].InnerText;
                                                testGame.NextGoal.HomeScores = homeScores;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "X")
                                            {
                                                var draw = FTO.Attributes["odd"].InnerText;
                                                testGame.NextGoal.Draw = draw;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "2")
                                            {
                                                var awayScores = FTO.Attributes["odd"].InnerText;
                                                testGame.NextGoal.AwayScores = awayScores;
                                            }
                                        }
                                    }
                                    break;

                                case "Double Chance":
                                    testGame.DoubleChance = new DoubleChance();
                                    foreach (XmlNode FTO in odd.ChildNodes)
                                    {
                                        if (FTO.Attributes != null)
                                        {
                                            if (FTO.Attributes["extravalue"].InnerText == "1X")
                                            {
                                                var homeWinsOrDraw = FTO.Attributes["odd"].InnerText;
                                                testGame.DoubleChance.HomeWinsOrDraw = homeWinsOrDraw;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "12")
                                            {
                                                var homeOrAwayWins = FTO.Attributes["odd"].InnerText;
                                                testGame.DoubleChance.HomeWinsOrAwayWins = homeOrAwayWins;
                                            }
                                            if (FTO.Attributes["extravalue"].InnerText == "X2")
                                            {
                                                var awayWinsOrDraw = FTO.Attributes["odd"].InnerText;
                                                testGame.DoubleChance.AwayWinsOrDraw = awayWinsOrDraw;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }

                            _gamesforLiveOdds.TryAdd(testGame.MatchNo, testGame);
                        }
                    }
                }
            }
            return(_gamesforLiveOdds.Values);
        }
Esempio n. 2
0
        public async Task <IEnumerable <Game> > GetGamesScores()
        {
            var scoresUrl = new LiveBetSource
            {
                Name = "Scores",
                Url  = "http://www.goalserve.com/getfeed/d1aa4f5599064db8b343090338221a49/soccernew/inplay"
            };

            _gamesforLiveScore.Clear();
            var req    = (HttpWebRequest)WebRequest.Create(scoresUrl.Url);
            var res    = (HttpWebResponse)req.GetResponse();
            var stream = res.GetResponseStream();
            var xmldoc = new XmlDocument();

            if (stream == null)
            {
                return(_gamesforLiveScore.Values);                // if the stream is null return the games the way they are
            }
            // Get a UTF-32 encoding by name.
            Encoding encoding = Encoding.GetEncoding("utf-8");

            using (var str = new StreamReader(stream, encoding))
            {
                try
                {
                    xmldoc.Load(str);
                }
                catch (Exception)
                {
                    // continue;
                }
            }

            // check the url that has been loaded
            var categoryList = xmldoc.SelectNodes("/scores/match");

            if (categoryList != null)
            {
                foreach (XmlNode category in categoryList)
                {
                    var match    = category;
                    var teams    = match.ChildNodes;
                    var testGame = new Game();

                    if (match.Attributes != null)
                    {
                        testGame.MatchNo = match.Attributes["id"].InnerText;
                        testGame.Minutes = match.Attributes["minute"].InnerText;//.Substring(0, 2) + "'";
                        // testGame.StartDate = DateTime.Now.Date.ToString();
                    }

                    foreach (XmlNode team in teams)
                    {
                        var local = team.Name;
                        if (team.Name == "localteam")
                        {
                            var localTeamAttributes = team.Attributes;
                            if (localTeamAttributes != null)
                            {
                                testGame.LocalTeam      = localTeamAttributes["name"].InnerText;
                                testGame.LocalTeamScore = localTeamAttributes["score"].InnerText == "" ? "?" : localTeamAttributes["score"].InnerText;
                            }
                        }
                        if (team.Name == "awayteam")
                        {
                            var awayTeamattributes = team.Attributes;
                            if (awayTeamattributes != null)
                            {
                                testGame.AwayTeam      = awayTeamattributes["name"].InnerText;
                                testGame.AwayTeamScore = awayTeamattributes["score"].InnerText == "" ? "?" : awayTeamattributes["score"].InnerText;
                            }
                        }

                        _gamesforLiveScore.TryAdd(testGame.MatchNo, testGame);
                    }
                }
            }
            return(_gamesforLiveScore.Values);
        }