Пример #1
0
        public void BrowseStoreTest()
        {
            StoreBrowser target = new StoreBrowser(); // TODO: Initialize to an appropriate value
            Parser parser = new  VerkkokauppaParser();
              var store = new Store() {MainPageUrl = "http://www.verkkokauppa.com", Name = "Verkkokauppa"};

            target.BrowseStore(parser,store );
        }
Пример #2
0
        public void CollectStoreData(Store store)
        {
            _currentSearch = new StoreSearch() { Categories = new List<string>(), Created = DateTime.Now, Store = store };
              _parser = new VerkkokauppaParser();

              _parser.ProductParsed +=new EventHandler<ParserEventArgs>(_parser_ProductParsed);

              _browser = new StoreBrowser();
              _browser.BrowseStore(_parser,store);
        }
Пример #3
0
        public void CollectStoreDataTest()
        {
            DataCollector target = new DataCollector();
              Store store = new Store() {MainPageUrl = "http://www.verkkokauppa.com", Name = "Verkkokauppa"};

              target.CollectStoreData(store);

              foreach (var product in target.Products)
              {
            Trace.WriteLine(product.ToString());
              }
        }
Пример #4
0
        public void BrowseStore(Parser parser, Store store)
        {
            _parser = parser;
            _parser.FoundCategory += new EventHandler<ParserEventArgs>(parser_FoundCategory);
            _parser.FoundProductLink += new EventHandler<ParserEventArgs>(_parser_FoundProduct);

            LimitedConcurrencyLevelTaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(LimitedConcurrencyLevelTaskScheduler_UnobservedTaskException);

            var document = _client.Load(store.MainPageUrl);

            if (document != null)
                parser.ParseMainpage(document);
            else
            {
                throw new InvalidOperationException(String.Format(@"Could not load main page from {0}", store.MainPageUrl));
            }

              var completedTasks = _tasks.Where(t => t.IsCompleted);

              foreach (Task completedTask in completedTasks)
              {
            completedTask.Dispose();
              }

            while (_tasks.Where(t => t.IsCompleted == false).Count() > 0)
            {
                try
                {
                    Task.WaitAll(_tasks.ToArray());
                    Thread.Sleep(5000);
                }
                catch (AggregateException ae)
                {

                    ae.Handle((x) =>
                                  {
                                      if (x is InvalidOperationException)
                                      {

                                          //TODO: add logging here
                                          Trace.WriteLine(x.Message);
                                          return true;
                                      }

                                      return false;
                                  });

                }

            }
        }
Пример #5
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();
        }