protected override void ScrapProductFromUrl(string url, HtmlNode HtmlNode, WebScrapperBaseProxyEntity proxyInfo)
 {
     if (!ReferenceEquals(HtmlNode, null))
     {
         var scrapper = new BaseScrapper(HtmlNode, proxyInfo, _l, url);
         try {
             AkeneoProduct product = scrapper.ScrappingInstance(requestScrappingSite);
             ShareSale.AddLinkToProcessing(product.productUrl);
             var  delay    = 1000;
             bool shouldGo = false;
             while (shouldGo)
             {
                 var _c = ShareSale.GetLinkSolution(product.productUrl);
                 if (!ReferenceEquals(_c, null))
                 {
                     product.productUrl = _c;
                     break;
                 }
                 Thread.Sleep(delay);
             }
             if (!ReferenceEquals(product, null))
             {
                 Akeneo.ProcessProduct(product);
             }
             else
             {
                 _l.error("Error in creating AkeneoProduct object, you can find more information in application error log");
             }
         } catch (Exception e) {
             _l.error($"Cannot create product from url {url} : {e.Message} -> {e.StackTrace}.");
         }
         return;
     }
 }
Exemple #2
0
 protected override void ScrapProductFromUrl(string url, HtmlNode htmlNode, WebScrapperBaseProxyEntity proxyInfo)
 {
     if (!ReferenceEquals(htmlNode, null))
     {
         new Thread(() => {
             try {
                 var scrapper          = new BaseScrapper(htmlNode, proxyInfo, _l, url);
                 AkeneoProduct product = scrapper.ScrappingInstance(requestScrappingSite);
                 if ((ReferenceEquals(product.productCategory, null)) &&
                     !ReferenceEquals(requestScrappingSite.CollectionsProcessor, null) &&
                     !ReferenceEquals(requestScrappingSite.CollectionsProcessor.Collections, null) &&
                     requestScrappingSite.CollectionsProcessor.Collections.Count > 0)
                 {
                     List <string> firstLevelMatches = new List <string>();
                     foreach (string collection in requestScrappingSite.CollectionsProcessor.Collections)
                     {
                         var c = collection.Trim().Remove(collection.Trim().Length - 1);
                         if (product.productName.Contains(c))
                         {
                             firstLevelMatches.Add(c);
                         }
                     }
                     int MaxCountOfMatches     = 0;
                     int CurrentCountOfMatches = 0;
                     foreach (var collection in firstLevelMatches)
                     {
                         CurrentCountOfMatches = 0;
                         var parts             = collection.Split(" ").ToList();
                         foreach (var part in parts)
                         {
                             if (product.productName.Contains(part))
                             {
                                 CurrentCountOfMatches++;
                             }
                         }
                         if (CurrentCountOfMatches > MaxCountOfMatches)
                         {
                             product.productCategory = collection;
                             MaxCountOfMatches       = CurrentCountOfMatches;
                         }
                     }
                     if (ReferenceEquals(product.productCategory, null))
                     {
                         var d = product.productName.Split(" ");
                         product.productCategory = String.Concat(d[d.Length - 2], " ", d[d.Length - 1]);
                     }
                 }
                 if (!product.isProductInStock)
                 {
                     Shopify.UpdateProduct(product.productName);
                 }
                 if (!ReferenceEquals(product, null))
                 {
                     Akeneo.ProcessProduct(product);
                 }
                 else
                 {
                     _l.error("Error in creating AkeneoProduct object, you can find more information in application error log");
                 }
             } catch (Exception e) {
                 _l.error($"Cannot create product from url {url} : {e.Message} -> {e.StackTrace}.");
             }
             return;
         }).Start();
     }
 }