示例#1
0
        private async Task StartSiteSpecificDownloaderAsync(QueueListItem queueListItem, PauseToken pt, CancellationToken ct)
        {
            IBlog blog = queueListItem.Blog;

            blog.Dirty = true;
            ProgressThrottler <DownloadProgress> progress = SetupThrottledQueueListProgress(queueListItem);

            ICrawler crawler = null;

            try
            {
                crawler = _crawlerFactory.GetCrawler(blog, progress, pt, ct);
                await crawler.CrawlAsync();

                blog.UpdateProgress(true);
            }
            finally
            {
                crawler?.Dispose();
            }

            Monitor.Enter(_lockObject);
            QueueOnDispatcher.CheckBeginInvokeOnUI(() => _crawlerService.RemoveActiveItem(queueListItem));
            Monitor.Exit(_lockObject);

            if (!ct.IsCancellationRequested)
            {
                Monitor.Enter(_lockObject);
                QueueOnDispatcher.CheckBeginInvokeOnUI(() => QueueManager.RemoveItem(queueListItem));
                Monitor.Exit(_lockObject);
            }
        }
示例#2
0
        private async Task StartSiteSpecificDownloaderAsync(QueueListItem queueListItem, PauseToken pt, CancellationToken ct)
        {
            IBlog blog = queueListItem.Blog;

            blog.Dirty = true;
            ProgressThrottler <DownloadProgress> progress = SetupThrottledQueueListProgress(queueListItem);

            ICrawler crawler = null;

            try
            {
                crawler = _crawlerFactory.GetCrawler(blog, progress, pt, ct);
                queueListItem.InterruptionRequested += crawler.InterruptionRequestedEventHandler;
                await crawler.CrawlAsync();

                blog.UpdateProgress(false);
            }
            catch (Exception e)
            {
                if (!ct.IsCancellationRequested)
                {
                    Logger.Error("CrawlerController.StartSiteSpecificDownloaderAsync: {0}", e);
                }
            }
            finally
            {
                if (crawler != null)
                {
                    queueListItem.InterruptionRequested -= crawler.InterruptionRequestedEventHandler;
                }
                crawler?.Dispose();
            }

            Monitor.Enter(_lockObject);
            QueueOnDispatcher.CheckBeginInvokeOnUI(() => _crawlerService.RemoveActiveItem(queueListItem));
            Monitor.Exit(_lockObject);

            if (!ct.IsCancellationRequested)
            {
                Monitor.Enter(_lockObject);
                QueueOnDispatcher.CheckBeginInvokeOnUI(() => QueueManager.RemoveItem(queueListItem));
                Monitor.Exit(_lockObject);
            }
        }
示例#3
0
        private async Task StartSiteSpecificDownloader(QueueListItem queueListItem, CancellationToken ct, PauseToken pt)
        {
            IBlog blog = queueListItem.Blog;

            blog.Dirty = true;
            ProgressThrottler <DownloadProgress> progress = SetupThrottledQueueListProgress(queueListItem);

            ICrawler crawler = crawlerFactory.GetCrawler(blog, ct, pt, progress);
            await crawler.CrawlAsync();

            if (ct.IsCancellationRequested)
            {
                Monitor.Enter(lockObject);
                QueueOnDispatcher.CheckBeginInvokeOnUI(() => crawlerService.RemoveActiveItem(queueListItem));
                Monitor.Exit(lockObject);
            }
            else
            {
                Monitor.Enter(lockObject);
                QueueOnDispatcher.CheckBeginInvokeOnUI(() => QueueManager.RemoveItem(queueListItem));
                QueueOnDispatcher.CheckBeginInvokeOnUI(() => crawlerService.RemoveActiveItem(queueListItem));
                Monitor.Exit(lockObject);
            }
        }
示例#4
0
 /// <summary>
 /// Start crawl process synchronously.
 /// </summary>
 /// <param name="crawler">Crawler for which start crawling.</param>
 public static void Crawl(this ICrawler crawler)
 {
     crawler.CrawlAsync().Wait();
 }