Esempio n. 1
0
        private bool FindGameId()
        {
            NHLDotComFetch fetch = new NHLDotComFetch();
            String         xml   = NHLDotComFetch.GetPageString(gameListPath);

            if (xml != null && xml.IndexOf("<?xml") >= 0)
            {
                xml = xml.Substring(xml.IndexOf("<?xml"));

                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);

                XmlNodeList nodes = document.SelectNodes("//home-tab/schedule/category[@type=\"NHL\"]/game");
                foreach (XmlNode node in nodes)
                {
                    string   time = node.Attributes["date"].Value;
                    DateTime date = DateTime.Parse(time);

                    if ((date.Year == DateTime.Now.Year && date.Month == DateTime.Now.Month && date.Day == DateTime.Now.Day))
                    {
                        XmlNode homeTeam = node.SelectNodes("home-team")[0];
                        XmlNode awayTeam = node.SelectNodes("visiting-team")[0];

                        if (homeTeam.Attributes["name"].Value.ToLower().CompareTo(homeTeamName) == 0 &&
                            awayTeam.Attributes["name"].Value.ToLower().CompareTo(awayTeamName) == 0)
                        {
                            gameId = Convert.ToInt32(node.Attributes["eventId"].Value);
                            break;
                        }
                    }
                }
            }
            else
            {
                System.Console.WriteLine("Couldn't find game id");
            }

            return(gameId != null);
        }
Esempio n. 2
0
        private bool FindGameId()
        {
            NHLDotComFetch fetch = new NHLDotComFetch();
            String xml = NHLDotComFetch.GetPageString(gameListPath);

            if (xml != null && xml.IndexOf("<?xml") >= 0)
            {
                xml = xml.Substring(xml.IndexOf("<?xml"));

                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);

                XmlNodeList nodes = document.SelectNodes("//home-tab/schedule/category[@type=\"NHL\"]/game");
                foreach (XmlNode node in nodes)
                {
                    string time = node.Attributes["date"].Value;
                    DateTime date = DateTime.Parse(time);

                    if ((date.Year == DateTime.Now.Year && date.Month == DateTime.Now.Month && date.Day == DateTime.Now.Day))
                    {
                        XmlNode homeTeam = node.SelectNodes("home-team")[0];
                        XmlNode awayTeam = node.SelectNodes("visiting-team")[0];

                        if (homeTeam.Attributes["name"].Value.ToLower().CompareTo(homeTeamName) == 0 &&
                            awayTeam.Attributes["name"].Value.ToLower().CompareTo(awayTeamName) == 0)
                        {
                            gameId = Convert.ToInt32(node.Attributes["eventId"].Value);
                            break;
                        }
                    }
                }
            }
            else
                System.Console.WriteLine("Couldn't find game id");

            return gameId != null;
        }
Esempio n. 3
0
        private void FetchGameList()
        {     
            if ((DateTime.Now.Hour > 1 && DateTime.Now.Hour < 9) && games.Count > 0)
            {
                System.Console.WriteLine("Flushing games and downloading new schedule...");

                foreach (NHLGame game in games)
                {
                    game.Shutdown();
                }

                games.Clear();
                stats.UpdateSchedule();
            }
            else
            {
                NHLDotComFetch fetch = new NHLDotComFetch();

                DateTime cStart = DateTime.Now;
                List<int> gameIds = fetch.FetchGameIndex(DateTime.Now);
                TimeSpan cDiff = DateTime.Now - cStart;
                System.Console.WriteLine(String.Format("Took {0} s for FetchGameIndex download", cDiff.TotalSeconds));

                foreach (int i in gameIds)
                {
                    NHLGame game = null;
                    bool gameAlreadyExists = false;

                    foreach (NHLGame existingGame in games)
                    {
                        if (existingGame.GameId == i)
                        {
                            gameAlreadyExists = true;
                            break;
                        }
                    }

                    if (!gameAlreadyExists)
                    {
                        game = new NHLGame(i);
                        games.Add(game);
                        game.StartMonitoring(stats);
                        System.Console.WriteLine("Adding game {0}", i);
                    }
                }
            }

        }