예제 #1
0
        /// <summary>
        /// Gets the product asynchronous.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="url">The URL.</param>
        /// <param name="shop">The shop.</param>
        /// <returns>Wait-able task</returns>
        public static async Task <LRMProduct> GetProductAsync(
            HttpClient client, string url, LRMShop shop)
        {
            if (!url.Contains("leroymerlin.fr/v3/p/produits/"))
            {
                return(null);
            }

            string html = await ProcessUrlAsync(url, client).ConfigureAwait(false);

            if (html == null)
            {
                return(null);
            }

            int reference = GetReference(html);

            if (reference <= 0)
            {
                return(null);
            }

            LRMProduct product = new LRMProduct(reference, url);

            product.AddProductVarProp(shop, new LRMProductVarProp(GetPrice(html), GetStock(html)));

            return(product);
        }
예제 #2
0
        /// <summary>Adds the or update product.</summary>
        /// <param name="product">The product.</param>
        /// <param name="shop">The shop.</param>
        public void AddOrUpdateProduct(LRMProduct product, LRMShop shop)
        {
            if (product == null || shop == null)
            {
                return;
            }

            // No such product, simply add this definition
            if (!Products.ContainsKey(product.Reference))
            {
                Products[product.Reference] = product;
            }

            // Update existing definition
            else
            {
                var localProduct = Products[product.Reference];

                foreach (var url in product.Urls)
                {
                    localProduct.Urls.Add(url);
                }

                foreach (var productProductVarProp in product.ProductVarProps)
                {
                    localProduct.AddProductVarProp(
                        productProductVarProp.Key, productProductVarProp.Value);
                }
            }
        }
예제 #3
0
 /// <summary>Selects the shop.</summary>
 /// <param name="shop">The shop.</param>
 /// <returns>Wait-able task</returns>
 public async Task SelectShopAsync(LRMShop shop)
 {
     //cookieContainer.Add(baseUrl, new Cookie("tracking", "\"{\\\"x1\\\":\\\"142_Ivry_sur_Seine\\\",\\\"x11\\\":\\\"21_Vitry_sur_Seine\\\",\\\"x6\\\":\\\"1\\\",\\\"x10\\\":\\\"1\\\",\\\"x9\\\":null}\""));
     //cookieContainer.Add(baseUrl, new Cookie("store", "store=142|dateContext=20170219"));
     await
     HttpClient.GetStringAsync(
         "http://www.leroymerlin.fr/v3/contextualization/store/contextualize.do?storeId="
         + shop.Id).ConfigureAwait(false);
 }
예제 #4
0
        /// <summary>Crawls the shop asynchronous.</summary>
        /// <param name="shop">The shop.</param>
        /// <returns>Wait-able task</returns>
        private async Task <IEnumerable <LRMProduct> > CrawlShopAsync(LRMShop shop)
        {
            await SelectShopAsync(shop).ConfigureAwait(false);

            IEnumerable <Task <LRMProduct> > tasks =
                RequestedUrls.Select(
                    u => LRMProductCrawler.GetProductAsync(HttpClient, u, shop));

            // ReSharper disable once CoVariantArrayConversion
            Task.WaitAll(tasks.ToArray());

            return(tasks.Select(t => t.Result));
        }
예제 #5
0
        /// <summary>
        /// Creates the shop header.
        /// </summary>
        /// <param name="shopId">The shop identifier.</param>
        /// <returns>Csv Header</returns>
        private static string CreateShopHeader(LRMShop shop)
        {
            string shopName = shop.Name;

            return(shopName + " Price;" + shopName + " Stock");
        }