Exemple #1
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);
        }
Exemple #2
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;
                                  });

                }

            }
        }