Exemplo n.º 1
0
 private void attachCrawlerJobPart(ICrawlerJobPart crawlerJobPart)
 {
     crawlerJobPart.crawlerJobContext                  = this.crawlerJobContext;
     crawlerJobPart.progressPercentageChangeEvent     += new CrawlerJobPartProgressUpdate(crawlerJobPart_ProgressPercentageChangeEvent);
     crawlerJobPart.crawlerJobPartImageRetrievedEvent += new CrawlerJobPartImageRetrievedEvent(crawlerJobPart_crawlerJobPartImageRetrievedEvent);
     crawlerJobPart.crawlerJobPartSuspendEvent        += new CrawlerJobPartSuspendEvent(crawlerJobPart_crawlerJobPartSuspendEvent);
 }
Exemplo n.º 2
0
        public ICrawlerJob addCrawlerJobPartAndSetPage(ICrawlerJobPart crawlerJobPart, Page page)
        {
            this.crawlerJobContext.page = page;

            if (crawlerJobPart != null && !this.crawlerJobPartList.Contains(crawlerJobPart))
            {
                this.crawlerJobPartList.Add(crawlerJobPart);
                this.attachCrawlerJobPart(crawlerJobPart);
            }

            //
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Runns the crawler job. You have to set an initial crawler job part before.
        /// </summary>
        public void run()
        {
            //
            this.isRunning = true;
            this.triggerProcessStateChangeEvent(CrawlerJobProcessState.Initialize);
            this.triggerProgressPercentageChangeEvent(0.00000);

            //
            while (this.crawlerJobPartList.Count > 0)
            {
                //
                this.currentlyActiveJobPart = this.crawlerJobPartList[0];
                this.crawlerJobPartList.RemoveAt(0);

                //
                if (this.isAborting)
                {
                    break;
                }

                //
                if (this.currentlyActiveJobPart != null)
                {
                    //
                    this.triggerProcessStateChangeEvent(this.currentlyActiveJobPart.getProcessState());

                    //
                    if (this.crawlerJobSuspendEvent != null)
                    {
                        this.crawlerJobSuspendEvent();
                    }

                    //run the job part workload
                    List <ICrawlerJobPart> followingJobPartList = null;
                    try
                    {
                        followingJobPartList = this.currentlyActiveJobPart.run();
                    }
                    catch (Exception e)
                    {
                        //
                        this.triggerProcessStateChangeEvent(CrawlerJobProcessState.Erroneous);
                        Thread.Sleep(1000); //Keep in error state for some time
                    }

                    //
                    if (followingJobPartList != null)
                    {
                        followingJobPartList.ForEach(crawlerJobPartItem => this.attachCrawlerJobPart(crawlerJobPartItem));
                        this.crawlerJobPartList.AddRange(followingJobPartList);
                    }
                }
            }

            //
            if (this.crawlerJobContext.page != null)
            {
                this.crawlerJobContext.page.isCompleted = true;
            }

            //
            this.isRunning = false;
            this.triggerProcessStateChangeEvent(CrawlerJobProcessState.Finished);
            this.triggerProgressPercentageChangeEvent(1.00000);
        }
Exemplo n.º 4
0
 ICrawlerJob ICrawlerJob.addCrawlerJobPartAndSetPage(ICrawlerJobPart crawlerJobPart, Page page)
 {
     return(this);
 }