Esempio n. 1
0
        public bool AddProduct(Product product, string categoryName)
        {
            var cat = FindCategory(categoryName);

              if (cat != null) {
            if (cat.Products == null)
              cat.Products = new List<Product>();
            cat.Products.Add(product);
            Trace.WriteLine(string.Format("Product {0} added to tree", product.Name));
            return true;

              }
              else {
            Trace.WriteLine(string.Format("Could not find category {0} for product {1}", categoryName, product.Name));
            return false;
              }
        }
Esempio n. 2
0
        //public static void FetchTestStoreDataToDb(IDocumentSession session)
        //{
        //    var browser = new StoreBrowser();
        //    browser.BrowseStore(new VerkkokauppaParser(), new Store() { MainPageUrl = @"http://www.verkkokauppa.com", Name = "Verkkokauppa" });
        //    //session.Store(browser.SearchResult);
        //}
        //public static void CreateTestStoreSearchesDataToDb(IDocumentSession session) {
        //  var fakeStore = new Store() { Id = "Verkkokauppa", MainPageUrl = "http://www.verkkokauppa.com", Name = "Verkkokauppa" };
        //  var fakeStore2 = new Store() { Id = "Gigantti", MainPageUrl = "http://www.gigantti.fi", Name = "Gigantti" };
        //  var fakeProd1 = new Product() {
        //    Id = "Vekkokauppa/Tietokoneet/Kannettavat/1",
        //    Name = "Acer Aspire 8920 ",
        //    Price = 400,
        //    Created = DateTime.Now
        //  };
        //  var fakeProd2 = new Product() {
        //    Id = "Vekkokauppa/Tietokoneet/Kannettavat/2",
        //    Name = "Acer ICONIA",
        //    Price = 600,
        //    Created = DateTime.Now
        //  };
        //  var fakeProd3 = new Product() {
        //    Id = "Vekkokauppa/Kannettavat/3",
        //    Name = "HP Compaq 620",
        //    Price = 200,
        //    Created = DateTime.Now
        //  };
        //  var fakeProd4 = new Product() {
        //    Id = "Gigantti/Tietokoneet/Kannettavat/2",
        //    Name = "Acer ICONIA",
        //    Price = 800,
        //    Created = DateTime.Now
        //  };
        //  fakeStore.Products = new List<Product> {fakeProd1, fakeProd2, fakeProd3};
        //  fakeStore2.Products = new List<Product> {fakeProd4};
        //  session.Store(fakeStore);
        //  session.Store(fakeStore2);
        //  session.SaveChanges();
        //}
        public static void CreateTestStoreSearchesDataToDb(IDocumentSession session)
        {
            var fakeStore = new Store() { Id = "Verkkokauppa", MainPageUrl = "http://www.verkkokauppa.com", Name = "Verkkokauppa" };

              var fakeStore2 = new Store() { Id = "Gigantti", MainPageUrl = "http://www.gigantti.fi", Name = "Gigantti" };

              var fakeProd1 = new Product() {
            Id = "Vekkokauppa20110801/Tietokoneet/Kannettavat/1",
            Name = "Acer Aspire 8920 ",
            Store = fakeStore,
            Price = 400,
            Created = DateTime.Now

              };

              var fakeProd2 = new Product() {
            Id = "Vekkokauppa20110801/Tietokoneet/Kannettavat/2",
            Name = "Acer ICONIA",
            Store = fakeStore,
            Price = 600,
            Created = DateTime.Now
              };
              var fakeProd3 = new Product() {
            Id = "Vekkokauppa20110801/Kannettavat/3",
            Name = "HP Compaq 620",
            Store = fakeStore,
            Price = 200,
            Created = DateTime.Now
              };

              var fakeProd4 = new Product() {
            Id = "Gigantti20110801/Tietokoneet/Kannettavat/2",
            Name = "Acer ICONIA",
            Store = fakeStore2,
            Price = 800,
            Created = DateTime.Now
              };

              session.Store(fakeProd1);
              session.Store(fakeProd2);
              session.Store(fakeProd3);
              session.Store(fakeProd4);

              session.SaveChanges();
        }
Esempio n. 3
0
        public override void ParseProductPage(HtmlDocument document, string parentCategoryId)
        {
            var prod = new Product();
            Trace.WriteLine(String.Format("Thread {0}: Parsing productpage", Thread.CurrentThread.ManagedThreadId));

            if(document==null)
                throw  new ArgumentNullException("Parser was given an empty product page");

              var nameNode = document.DocumentNode.SelectSingleNode(@"//h1[@id='productName']");

              if (nameNode != null)
            prod.Name = nameNode.InnerText;
              else
              {
              //TODO: add irregular product link handling here
              }

              var priceNode = document.DocumentNode.SelectSingleNode(@"//span[@class='hintabig']");

              if (priceNode != null)
              {
            var priceStr = priceNode.InnerText;

            var match = Regex.Match(priceStr, @"\d+[,.]\d+");

            if (match.Success)
            {
              priceStr = match.Value;
              double price;

              if (!Double.TryParse(priceStr, NumberStyles.Currency, CultureInfo.CurrentCulture, out price))
                if (!Double.TryParse(priceStr, NumberStyles.Any, CultureInfo.InvariantCulture, out price))
                  price = Double.NaN;

              prod.Price = price;

            }
            else
            {
              prod.Price = double.NaN;

            }
              }
              else
              {
            prod.Price = double.NaN;
              }

              OnProductParsed(new ParserEventArgs(){ParentCategoryId = parentCategoryId, Product = prod});
        }