コード例 #1
0
        public Product GetDbProduct(OnlineShopModel.Product product)
        {
            var dbProduct = new Product
            {
                ProductName      = product.ProductName,
                AddedDate        = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                IsActive         = true,
                Url         = product.Url,
                ImageUrl    = product.ImageUrl,
                Description = product.Description
            };

            return(dbProduct);
        }
コード例 #2
0
        public Product GenerateProductDetails(Product product, ProductDetails specdetails, MobilesDbContext dbContext)
        {
            int index = 1;
            List <SpecifictionType>    specTypeList    = dbContext.SpecifictionTypes.ToList();
            List <SpecifictionHeading> specHeadingList = dbContext.SpecifictionHeadings.ToList();

            foreach (Specification specification in specdetails.Specifications)
            {
                SpecifictionType specType = specTypeList.Where(s => s.Name == specification.Type).FirstOrDefault();
                if (specType == null)
                {
                    specType = new SpecifictionType {
                        Name = specification.Type
                    };
                    dbContext.SpecifictionTypes.Add(specType);
                }


                var dbSpecifiction = new Specifiction {
                    Type = specType, Product = product
                };

                foreach (SpecificationDetail specDetail in specification.Details)
                {
                    SpecifictionHeading specHeading =
                        specHeadingList.Where(s => s.Name == specDetail.Key).FirstOrDefault();
                    if (specHeading == null)
                    {
                        specHeading = new SpecifictionHeading {
                            Name = specDetail.Key
                        };
                        dbContext.SpecifictionHeadings.Add(specHeading);
                    }

                    var dbSpecDetail = new SpecificatonDetail
                    {
                        Heading      = specHeading,
                        Specifiction = dbSpecifiction,
                        Value        = specDetail.Value
                    };
                    dbSpecifiction.SpecificatonDetails.Add(dbSpecDetail);
                }
                product.Specifictions.Add(dbSpecifiction);
            }
            return(product);
        }
コード例 #3
0
 public Product GetDbProduct(OnlineShopModel.Product product)
 {
     var dbProduct = new Product
                         {
                             ProductName = product.ProductName,
                             AddedDate = DateTime.Now,
                             LastModifiedDate = DateTime.Now,
                             IsActive = true,
                             Url = product.Url,
                             ImageUrl = product.ImageUrl,
                             Description = product.Description
                         };
     return dbProduct;
 }
コード例 #4
0
        public Product GenerateProductDetails(Product product, ProductDetails specdetails, MobilesDbContext dbContext)
        {
            int index = 1;
            List<SpecifictionType> specTypeList = dbContext.SpecifictionTypes.ToList();
            List<SpecifictionHeading> specHeadingList = dbContext.SpecifictionHeadings.ToList();

            foreach (Specification specification in specdetails.Specifications)
            {
                SpecifictionType specType = specTypeList.Where(s => s.Name == specification.Type).FirstOrDefault();
                if (specType == null)
                {
                    specType = new SpecifictionType {Name = specification.Type};
                    dbContext.SpecifictionTypes.Add(specType);
                }

                var dbSpecifiction = new Specifiction { Type = specType, Product = product };

                foreach (SpecificationDetail specDetail in specification.Details)
                {
                    SpecifictionHeading specHeading =
                        specHeadingList.Where(s => s.Name == specDetail.Key).FirstOrDefault();
                    if (specHeading == null)
                    {
                        specHeading = new SpecifictionHeading {Name = specDetail.Key};
                        dbContext.SpecifictionHeadings.Add(specHeading);
                    }

                    var dbSpecDetail = new SpecificatonDetail
                                           {
                                               Heading = specHeading,
                                               Specifiction = dbSpecifiction,
                                               Value = specDetail.Value
                                           };
                    dbSpecifiction.SpecificatonDetails.Add(dbSpecDetail);
                }
                product.Specifictions.Add(dbSpecifiction);
            }
            return product;
        }
コード例 #5
0
        public void PopulateBrandMobilePhones(IEnumerable <int> brandIdList)
        {
            Settings.AttachToBrowserTimeOut = 240;
            Settings.WaitUntilExistsTimeOut = 240;
            Settings.WaitForCompleteTimeOut = 240;
            using (var dbContext = new MobilesDbContext())
            {
                try
                {
                    List <BrandPage> brandPages =
                        dbContext.BrandPages.Include("Brand").Where(p => brandIdList.Contains(p.Brand.Id) && p.IsRead == false).ToList();
                    foreach (BrandPage brandPage in brandPages)
                    {
                        string url = brandPage.Url;
                        try
                        {
                            using (var browser = new IE(url, true))
                            {
                                browser.ShowWindow(NativeMethods.WindowShowStyle.Hide);
                                browser.WaitForComplete();

                                IEnumerable <Div> productsDivs =
                                    browser.Divs.Where(d => d.ClassName != null && d.ClassName.Contains("makers"));

                                var listOfProducts = new List <OnlineShopModel.Product>();
                                foreach (Div productDiv in productsDivs)
                                {
                                    List productsList = productDiv.Lists.First();

                                    if (productsList != null && productsList.Exists)
                                    {
                                        foreach (ListItem productListItem in productsList.ListItems)
                                        {
                                            Link    productLink = productListItem.Links.First();
                                            Element productName =
                                                productLink.Children().Where(c => c.TagName.ToUpper() == "STRONG").First();
                                            Image productImage = productLink.Images.First();
                                            listOfProducts.Add(new OnlineShopModel.Product
                                            {
                                                ProductName = productName.Text,
                                                Url         = productLink.Url,
                                                ImageUrl    = productImage.Src,
                                                Description = productImage.Title
                                            });
                                        }
                                    }
                                }

                                Database.SetInitializer(new CreateDatabaseIfNotExists <MobilesDbContext>());

                                List <Product> dbProductsList = dbContext.Products.ToList();

                                foreach (OnlineShopModel.Product product in listOfProducts)
                                {
                                    Product filterProduct = dbProductsList.Where(p => p.Url == product.Url).FirstOrDefault();
                                    if (filterProduct == null)
                                    {
                                        Product dbProduct = GetDbProduct(product);
                                        dbProduct.Brand = brandPage.Brand;
                                        dbContext.Products.Add(dbProduct);
                                    }
                                }

                                brandPage.IsRead = true;

                                dbContext.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                    //throw ex;
                }
            }
        }