public ProductPage Build()
        {
            var web = new HtmlWeb();
            var doc = web.Load(_url);

            var maxPrice = Convert.ToDecimal(doc.DocumentNode
                                             .SelectNodes(
                                                 "//div[1]/div[@class=' margined' and 1]/div[@class='row column' and 2]/div[@class='row' and 1]/div[1]/table[@class='product_pane' and 1]/tbody[1]/tr[@class='highest_price' and 2]/td[2]")
                                             .Nodes().FirstOrDefault()?.InnerText?.Replace("$", ""));
            var minPrice = Convert.ToDecimal(doc.DocumentNode
                                             .SelectNodes(
                                                 "//div[1]/div[@class=' margined' and 1]/div[@class='row column' and 2]/div[@class='row' and 1]/div[1]/table[@class='product_pane' and 1]/tbody[1]/tr[@class='lowest_price' and 3]/td[2]")
                                             .Nodes().FirstOrDefault()?.InnerText?.Replace("$", ""));

            var startDateRaw = string.Join("", doc.DocumentNode
                                           .SelectNodes(
                                               "//div[1]/div[@class=' margined' and 1]/div[@class='row column' and 2]/div[@class='row' and 1]/div[1]/p[@class='grey' and 1]/small[1]")
                                           .Nodes().Select(x => x.InnerText).ToList());

            var startDate = DateTime.Parse(Regex
                                           .Match(startDateRaw, @"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sept|Oct|Nov|Dec) \d+\, \d+").Value);

            var graphParameters = new GraphParameters(startDate, DateTime.Now, 1000, 1000);
            var graph           = new Graph(_url, graphParameters, minPrice, maxPrice);

            return(new ProductPage {
                Url = _url, Graph = graph, MinPrice = minPrice, MaxPrice = maxPrice
            });
        }
Beispiel #2
0
 public Graph(string url, GraphParameters graphParameters, decimal minprice, decimal maxprice)
 {
     _url             = url;
     _graphParameters = graphParameters;
     MinPrice         = minprice;
     MaxPrice         = maxprice;
 }
Beispiel #3
0
        /// <summary>
        ///     Downloads a graph using specified graph parameters
        /// </summary>
        /// <param name="url">The product url to get the image from</param>
        /// <param name="parameters">A set of optional graph parameters</param>
        /// <returns>A new image</returns>
        private static Bitmap DownloadGraphImage(string url, GraphParameters parameters)
        {
            var imageUrl = ConvertWebpageUrlToImageUrl(url, parameters.Width, parameters.Height);

            return(HttpService.DownloadImage(imageUrl));
        }