Beispiel #1
0
        private static ExportItem CreateExportItem(
            ProductModel model, 
            ProductStyle style, 
            IEnumerable<string> additionalDirs, 
            string imagesPath, 
            float priceMultiple, 
            float priceAdd)
        {
            ExportItem prod = new ExportItem();
            prod.Sku = style.Sku;
            prod.Name = model.Name;
            prod.Description = model.Description;

            prod.Price = BuildPrice(style.DiscountPrice, priceMultiple, priceAdd);
            if (style.DiscountPrice < style.Price)
            {
                prod.OldPrice = BuildPrice(style.Price, priceMultiple, priceAdd);
            }

            // we use a single size list for all styles in a model, so I create the list in the caller function
            //prod.Size = BuildSize(style.Sizes.ToArray());

            prod.MoreCategories = string.Join<string>(",", additionalDirs);
            prod.SizeChartType = model.GenderAge;

            int imageCount = 0;
            foreach (ProductImage pi in style.Images.FindAll(p => p.Downloaded))
            {
                string pathSource = Path.Combine(Constants.DownloadsDir, pi.Name + ".jpg");
                if (File.Exists(pathSource))
                {
                    if (imageCount == 10) break; // up to 10 images

                    ThumbnailInfo tiInfo = new ThumbnailInfo()
                    {
                        Name = pi.Name + "_info.jpg",
                        Width = 300,
                        Height = 300
                    };
                    ThumbnailInfo tiThumbnail = new ThumbnailInfo()
                    {
                        Name = pi.Name + "_th.jpg",
                        Width = 150,
                        Height = 150
                    };
                    ThumbnailInfo tiLarge = new ThumbnailInfo()
                    {
                        Name = pi.Name + "_large.jpg",
                        Width = 1000,
                        Height = 1000
                    };
                    ThumbnailInfo[] thumbnails = new ThumbnailInfo[] { tiInfo, tiThumbnail, tiLarge };

                    if (MakeJpegThumbnails(pathSource, imagesPath, thumbnails))
                    {
                        prod.SetPhoto(imageCount++, tiInfo.Name + "," + tiThumbnail.Name + "," + tiLarge.Name);
                    }
                }
            }

            return prod;
        }
Beispiel #2
0
        public void Process()
        {
            // download a the main page
            string url = String.Format("http://www.champssports.com/product/model:{0}/sku:{1}/", Number, initialSku);
            Console.WriteLine("Downloading a model: " + url);
            string mainPage = Web.DownloadString(url, 5);
            if (String.IsNullOrEmpty(mainPage))
            {
                Status = ModelStatus.Failed;
                return;
            }
            Console.WriteLine("Parsing data...");

            string rawModel = RX.ExtractModelInfo(mainPage);
            string rawStyles = RX.ExtractStylesInfo(mainPage);

            jsModel = JsonConvert.DeserializeObject<JsModel>(rawModel);

            Dictionary<string, JArray> jStyles =
                JsonConvert.DeserializeObject<Dictionary<string, JArray>>(rawStyles);

            foreach (string sku in jsModel.ALLSKUS)
            {
                JArray rawStyle = jStyles[sku];
                ProductStyle stl = new ProductStyle(sku, rawStyle);
                Styles.Add(stl);
            }

            Parallel.ForEach(Styles, _ =>
            {
                _.Process();
            });

            Status = ModelStatus.Processed;
        }