Exemplo n.º 1
0
        void IJob.Execute(IJobExecutionContext context)
        {
            Trace.TraceInformation("MS.DHC.Scheduling.Amazon starting");

            try
            {
                //var repeatCount = int.Parse(CloudConfigurationManager.GetSetting("MS.DHC.Scheduling.Amazon.RepeatCount"), CultureInfo.InvariantCulture);
                var repeatCount = int.Parse(ConfigurationManager.AppSettings["MS.DHC.Scheduling.Amazon.RepeatCount"], CultureInfo.InvariantCulture);

                using (var db = new DB(Database.WorkerConnection))
                {
                    for (int i = 1; i <= repeatCount; i++)
                    {
                        Service.Enrich(db);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new JobExecutionException(e);
            }

            Trace.TraceInformation("MS.DHC.Scheduling.Amazon complete");
        }
Exemplo n.º 2
0
        public bool TestOuput()
        {
            using (var db = new DB(MS_Config.Database.WorkerConnection))
            {
                db.Database.ExecuteSqlCommand("DELETE FROM [dbo].Product");
            }

            return true;
        }
Exemplo n.º 3
0
        public bool TestOuput()
        {
            var repeatCount = int.Parse(ConfigurationManager.AppSettings["MS.DHC.Scheduling.Amazon.RepeatCount"], CultureInfo.InvariantCulture);

            using (var db = new DB(Database.WorkerConnection))
            {
                for (int i = 1; i <= repeatCount; i++)
                {
                    Service.Enrich(db);
                }

                db.SaveChanges();
            }
            return true;
        }
Exemplo n.º 4
0
        private static void UpdateModified(DB db, Product[] products)
        {
            foreach (var item in products)
            {
                item.Modified = DateTime.UtcNow;
            }

            db.SaveChanges();
        }
Exemplo n.º 5
0
        private static void ParseParentAttributes(DB db, Mapping.Product amazonProduct, Product product)
        {
            // title
            product.Title = amazonProduct.Attributes.Title;

            // description
            product.Description = Strip(amazonProduct.Attributes.Description);

            // bullets
            Service.ParseBullets(db, amazonProduct, product.ID);

            // main and part images
            var imageRelations = new Mapping.Relation[]
            {
                Mapping.Relation.Part1,
                Mapping.Relation.Part2,
                Mapping.Relation.Part3,
                Mapping.Relation.Part4,
                Mapping.Relation.Part5,
                Mapping.Relation.Part6,
                Mapping.Relation.Part7
            };

            Service.ParseAssets(db, amazonProduct.Assets, product.ID, imageRelations);
        }
Exemplo n.º 6
0
        private static void ParseChildAttributes(DB db, Mapping.Product amazonProduct, Product product)
        {
            // sku
            product.SKU = amazonProduct.Identifier.MerchantSku.Sku;

            // merchantid
            product.Merchant = amazonProduct.Identifier.MerchantSku.MerchantId;

            // url
            product.HREF = amazonProduct.HREF();

            Service.ParseOffer(amazonProduct.Offers, product);

            // db.SaveChanges();

            // swatch
            var imageRelations = new Mapping.Relation[]
            {
                Mapping.Relation.Main,
                Mapping.Relation.Swatch
            };

            Service.ParseAssets(db, amazonProduct.Assets, product.ID, imageRelations);

            foreach (var item in amazonProduct.Attributes.Fabrics)
            {
                var fabric = db.Fabrics.Where(f => f.Name == item.Value).SingleOrDefault();
                if (fabric == null)
                {
                    fabric = new Fabric() { Name = item.Value };

                    db.Fabrics.Add(fabric);
                    db.SaveChanges();
                }

                var productFabric = db.ProductFabrics.Where(pf => pf.ProductID == product.ID && pf.FabricID == fabric.ID).SingleOrDefault();
                if (productFabric == null)
                {
                    db.ProductFabrics.Add(new ProductFabric() { ProductID = product.ID, FabricID = fabric.ID });
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 7
0
        private static void ParseBullets(DB db, Mapping.Product amazonProduct, int product)
        {
            foreach (var item in amazonProduct.Attributes.BulletPoints)
            {
                var text = Strip(item);

                if (!string.IsNullOrWhiteSpace(text))
                {
                    Service.AddBullet(db, product, text);
                }
            }
        }
Exemplo n.º 8
0
        private static void ParseAssets(DB db, Collection<Mapping.Link> assets, int product, Mapping.Relation[] relations)
        {
            foreach (var asset in assets.Where(a => relations.Contains(a.Relation)))
            {
                var type = Service.CreateAndGetImageType(db, asset.Relation.ToString());

                Service.CreateImage(db, product, asset.Href, type);
            }
        }
Exemplo n.º 9
0
        private static Product GetOrCreateProductFromAsin(DB db, string asin)
        {
            var product = db.Products.Where(p => p.Asin == asin).SingleOrDefault();
            if (product == null)
            {
                product = new Product()
                {
                    Asin = asin,
                    Modified = DateTime.UtcNow
                };

                db.Products.Add(product);
                db.SaveChanges();
            }

            return product;
        }
Exemplo n.º 10
0
        private static void CreateVariantIfRequired(DB db, Product product, Product variation, Mapping.Direction direction, Dictionary<Mapping.DimensionType, string> dimensions)
        {
            Product parent;
            Product child;

            if (direction == Mapping.Direction.Parent)
            {
                child = product;
                parent = variation;
            }
            else
            {
                child = variation;
                parent = product;
            }

            child.Parent = parent;

            foreach (var dimension in dimensions)
            {
                // Get ID of type of current dimension, create if doesn't exist
                var type = Service.CreateAndGetDimensionType(db, dimension.Key.ToString());

                // Get value of current dimension, create if doesn't exist
                var value = Service.CreateAndGetDimensionValue(db, dimension.Value, type);

                // Get all dimensions for current product (child)
                var existingDimensions = db.Dimensions.Where(dt => dt.ProductID == child.ID);

                // Delete dimensions other then the current
                foreach (var item in existingDimensions.Where(d => d.Value.TypeID == type && d.ValueID != value.ID))
                {
                    db.Dimensions.Remove(item);
                }

                // Add current dimension if it doesn't exist
                if (!existingDimensions.Any(d => d.ValueID == value.ID))
                {
                    var newDimension = new Dimension() { Product = child, Value = value };

                    db.Dimensions.Add(newDimension);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 11
0
        private static void CreateImage(DB db, int product, string href, int type)
        {
            var image = db.Images.Where(i => i.ProductID == product && i.TypeID == type).Any();
            if (!image)
            {
                var newImage = new Image() { ProductID = product, TypeID = type, URL = href };

                db.Images.Add(newImage);
                db.SaveChanges();
            }
        }
Exemplo n.º 12
0
        private static int CreateAndGetImageType(DB db, string name)
        {
            var type = db.ImageTypes.Where(dt => dt.Name == name).SingleOrDefault();
            if (type == null)
            {
                type = new ImageType() { Name = name };

                db.ImageTypes.Add(type);
                db.SaveChanges();
            }

            return type.ID;
        }
Exemplo n.º 13
0
        private static DimensionValue CreateAndGetDimensionValue(DB db, string name, int type)
        {
            var value = db.DimensionValues.Where(dt => dt.Name == name).SingleOrDefault();
            if (value == null)
            {
                value = new DimensionValue() { Name = name, TypeID = type };

                db.DimensionValues.Add(value);
                db.SaveChanges();
            }

            return value;
        }
Exemplo n.º 14
0
 private static void AddBullet(DB db, int product, string text)
 {
     var bullet = db.Bullets.Where(b => b.ProductID == product && b.Body == text).Any();
     if (!bullet)
     {
         db.Bullets.Add(new Bullet() { ProductID = product, Body = text });
         db.SaveChanges();
     }
 }