Пример #1
0
        private static Nhl_Games_Rtss MapHtmlRowToModel(HtmlNode row, NhlSeasonType nhlSeasonType)
        {
            HtmlNodeCollection tdNodes = row.SelectNodes(@"./td");

            Nhl_Games_Rtss model = new Nhl_Games_Rtss();

            model.NhlSeasonType = nhlSeasonType;
            model.Date          = Convert.ToDateTime(tdNodes[0].InnerText.Replace("'", "/"));
            model.Year          = NhlModelHelper.GetSeason(model.Date).Item2;

            model.GameNumber = Convert.ToInt32(tdNodes[1].InnerText);
            model.Visitor    = tdNodes[2].InnerText;
            model.Home       = tdNodes[3].InnerText;

            model.RosterLink     = NhlGamesRtss.ParseLinkFromTd(tdNodes[4]);
            model.GameLink       = NhlGamesRtss.ParseLinkFromTd(tdNodes[5]);
            model.EventsLink     = NhlGamesRtss.ParseLinkFromTd(tdNodes[6]);
            model.FaceOffsLink   = NhlGamesRtss.ParseLinkFromTd(tdNodes[7]);
            model.PlayByPlayLink = NhlGamesRtss.ParseLinkFromTd(tdNodes[8]);
            model.ShotsLink      = NhlGamesRtss.ParseLinkFromTd(tdNodes[9]);
            model.HomeToiLink    = NhlGamesRtss.ParseLinkFromTd(tdNodes[10]);
            model.VistorToiLink  = NhlGamesRtss.ParseLinkFromTd(tdNodes[11]);
            model.ShootoutLink   = NhlGamesRtss.ParseLinkFromTd(tdNodes[12]);

            return(model);
        }
Пример #2
0
        private static List <Nhl_Games_Rtss> UpdateSeason(int year, NhlSeasonType nhlSeasonType, DateTime fromDate, bool saveToDb)
        {
            // Get HTML rows
            NhlGamesRtss    nhl  = new NhlGamesRtss();
            List <HtmlNode> rows = nhl.GetResultsForSeasonType(year, nhlSeasonType, fromDate);

            // Parse into a list
            List <Nhl_Games_Rtss> results = new List <Nhl_Games_Rtss>();

            foreach (HtmlNode row in rows)
            {
                Nhl_Games_Rtss result = NhlGamesRtss.MapHtmlRowToModel(row, nhlSeasonType);

                if (null != result)
                {
                    results.Add(result);
                }
            }

            // Update DB
            if (saveToDb)
            {
                NhlGamesRtss.AddOrUpdateDb(results);
            }

            return(results);
        }
Пример #3
0
        /// <summary>
        /// Get all the results starting from the last date of the data in the db. If a year is specified then only get latest for that year.
        /// </summary>
        /// <param name="year"></param>
        public static List <Nhl_Games_Rtss> GetNewResultsOnly([Optional] int year, [Optional] bool saveToDb)
        {
            DateTime latestResultDate;

            using (SportsDataContext db = new SportsDataContext())
            {
                latestResultDate = (from m in db.Nhl_Games_Rtss_DbSet
                                    orderby m.Date descending
                                    select m.Date).FirstOrDefault();
            }

            return(NhlGamesRtss.GetFullSeason(year, latestResultDate, saveToDb));
        }
Пример #4
0
        public static List <Nhl_Games_Rtss> GetFullSeason([Optional] int year, [Optional] DateTime fromDate, [Optional] bool saveToDb)
        {
            List <Nhl_Games_Rtss> results = new List <Nhl_Games_Rtss>();

            foreach (NhlSeasonType seasonType in Enum.GetValues(typeof(NhlSeasonType)))
            {
                if (seasonType == NhlSeasonType.None)
                {
                    continue;
                }

                List <Nhl_Games_Rtss> partialResults = NhlGamesRtss.UpdateSeason(year, seasonType, fromDate, saveToDb);
                if (null != partialResults)
                {
                    results.AddRange(partialResults);
                }
            }

            return(results);
        }
Пример #5
0
        private static List<Nhl_Games_Rtss> UpdateSeason(int year, NhlSeasonType nhlSeasonType, DateTime fromDate, bool saveToDb)
        {
            // Get HTML rows
            NhlGamesRtss nhl = new NhlGamesRtss();
            List<HtmlNode> rows = nhl.GetResultsForSeasonType(year, nhlSeasonType, fromDate);

            // Parse into a list
            List<Nhl_Games_Rtss> results = new List<Nhl_Games_Rtss>();
            foreach (HtmlNode row in rows)
            {
                Nhl_Games_Rtss result = NhlGamesRtss.MapHtmlRowToModel(row, nhlSeasonType);

                if (null != result)
                {
                    results.Add(result);
                }
            }

            // Update DB
            if (saveToDb)
            {
                NhlGamesRtss.AddOrUpdateDb(results);
            }

            return results;
        }