Exemplo n.º 1
0
        public List <Program> GetProgramsFromHtml(string htmlContent, DateTime baseday)
        {
            List <Program> programList  = new List <Program>();
            HtmlDocument   htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(htmlContent);
            HtmlNodeCollection htmlNodeCollection = htmlDocument.get_DocumentNode().SelectNodes("//section[@class='recipe-content']/a");

            if (htmlNodeCollection == null || htmlNodeCollection.get_Count() == 0)
            {
                return((List <Program>)null);
            }
            DateTime minValue = DateTime.MinValue;

            HtmlNodeCollection.HtmlNodeEnumerator enumerator = htmlNodeCollection.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Program programFromHtmlNode = this.CreateProgramFromHtmlNode(enumerator.get_Current(), baseday);
                    if (programFromHtmlNode.Start.HasValue)
                    {
                        DateTime?start    = programFromHtmlNode.Start;
                        DateTime dateTime = minValue;
                        if ((start.HasValue ? (start.GetValueOrDefault() < dateTime ? 1 : 0) : 0) != 0)
                        {
                            baseday = baseday.AddDays(1.0);
                        }
                        minValue = programFromHtmlNode.Start.Value;
                        programList.Add(programFromHtmlNode);
                    }
                }
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }
            return(programList);
        }