Пример #1
0
 public static void ProcessModelAsync(ProductModel model)
 {
     modelsQueue.Enqueue(model);
 }
Пример #2
0
        public static IEnumerable<ProductModel> ExtractModels(string text)
        {
            List<ProductModel> models = new List<ProductModel>();

            Match m = reModels.Match(text);
            if (m.Success)
            {
                string allSubmittedModels = m.Groups[1].Value;
                var modelDescriptors = allSubmittedModels.Split(new char[] { ';' });
                foreach(var modelDescriptor in modelDescriptors)
                {

                    string[] modelDescriptorParts = modelDescriptor.Split(new char[] { '|' });
                    if (modelDescriptorParts.Length == 2)
                    {
                        int modelNumber = 0;
                        if (Int32.TryParse(modelDescriptorParts[0], out modelNumber))
                        {
                            ProductModel prodModel = new ProductModel(modelNumber, modelDescriptorParts[1]);
                            models.Add(prodModel);
                        }
                        else
                        {
                            throw new Exception(String.Format("{0} coul not be parsed as a integer", modelDescriptor));
                        }

                    }
                    else
                    {
                        throw new Exception(String.Format("Cannot use the '{0}' as a model's descriptor", modelDescriptor));
                    }
                }

            }

            return models;
        }
Пример #3
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;
        }