Ejemplo n.º 1
0
        public void GetLargeImage(string asin, MarketType market, string marketplaceId)
        {
            var  url                  = MarketUrlHelper.GetMarketUrl(asin, market, marketplaceId);
            var  imageService         = new ImageRequestingService(_log, _htmlScraper);
            var  webPageParserFactory = new WebPageParserFactory();
            var  pageParser           = webPageParserFactory.GetPageParser(market);
            long size                 = 0;
            var  image                = imageService.GetMainImageFromUrl(url, pageParser, out size);

            Console.WriteLine(image);
        }
Ejemplo n.º 2
0
        private IList <ImageInfo> UpdateForItems(IList <ItemDTO> items)
        {
            var imageService = new ImageRequestingService(_log, _htmlScraper);
            var resultList   = new List <ImageInfo>();

            foreach (var item in items)
            {
                var url = String.Empty;
                if (item.Market == (int)MarketType.Amazon || item.Market == (int)MarketType.AmazonEU || item.Market == (int)MarketType.AmazonAU)
                {
                    url = MarketUrlHelper.GetMarketUrl(item.ASIN, (MarketType)item.Market, item.MarketplaceId);
                }
                if (item.Market == (int)MarketType.Walmart ||
                    item.Market == (int)MarketType.WalmartCA ||
                    item.Market == (int)MarketType.Jet ||
                    item.Market == (int)MarketType.Shopify ||
                    item.Market == (int)MarketType.eBay)
                {
                    url = MarketUrlHelper.GetMarketUrl(item.SourceMarketId, (MarketType)item.Market, item.MarketplaceId);
                }

                long downloadedSize = 0;
                CallResult <IList <ImageInfo> > result = null;
                var pageParser = new WebPageParserFactory().GetPageParser((MarketType)item.Market);
                result = imageService.GetMainImageFromUrl(url, pageParser, out downloadedSize);

                var imageInfoList = result?.Data ?? new List <ImageInfo>();
                imageInfoList.ForEach(i =>
                {
                    i.Tag       = item.Id;
                    i.ImageType = (int)ProductImageType.Large;
                });

                if (imageInfoList.Any())
                {
                    _log.Info("Image updated, page size=" + downloadedSize + " asin=" + item.ASIN + ", market=" + item.Market + ", marketplaceId=" +
                              item.MarketplaceId + ", image=" + String.Join("; ", imageInfoList.Select(i => i.Image).ToList()));
                }
                else
                {
                    var image = new ImageInfo();
                    image.Tag = item.Id;

                    if (result.Exception != null &&
                        result.Exception.Message.Contains("404") &&
                        result.Exception.Message.IndexOf("Not Found", StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        image.UpdateFailAttempts = 100;
                    }
                    else
                    {
                        image.UpdateFailAttempts++;
                    }
                    _log.Info("Image update failed, page size=" + downloadedSize + ", asin=" + item.ASIN + ", market=" + item.Market + ", marketplaceId=" + item.MarketplaceId);

                    imageInfoList.Add(image);
                }

                resultList.AddRange(imageInfoList);


                Thread.Sleep(300);
            }

            return(resultList);
        }