Exemple #1
0
        public void startCrawlingFtdTest()
        {
            Page page = new Page();

            page.urlStr = "http://www.ftd.de";
            CrawlerController crawlerController = new CrawlerController();
            ICrawlerJobView   crawlerJobView    = crawlerController.getCrawlerJobView();

            //
            int peekProcessInformationCount = 0;
            int updateEventCounter          = 0;
            int imageEventCounter           = 0;

            int    trackedProcessInformationUpdateCounter      = 0;
            int    trackedProcessInformationImageUpdateCounter = 0;
            double trackedProcessInformationPercentagePeek     = 0.0000;

            //
            CrawlerProcessInformation trackedProcessInformation = null;

            crawlerJobView.updateProcessInformationEvent += new CrawlerJobViewUpdateEventProcessInformation(delegate(CrawlerProcessInformation crawlerProcessInformation)
            {
                List <CrawlerProcessInformation> crawlerProcessInformationList = crawlerJobView.getActiveCrawlerProcessInformationList();
                peekProcessInformationCount = Math.Max(peekProcessInformationCount, crawlerProcessInformationList.Count);
                updateEventCounter++;

                //
                if (trackedProcessInformation == null && crawlerProcessInformation != null)
                {
                    trackedProcessInformation = crawlerProcessInformation;
                    trackedProcessInformation.crawlerProcessInformationUpdateEvent += new CrawlerProcessInformationUpdateEvent(delegate(CrawlerProcessInformation information)
                    {
                        trackedProcessInformationUpdateCounter++;
                        trackedProcessInformationPercentagePeek = Math.Max(trackedProcessInformationPercentagePeek, information.progressPercentage);
                    });
                    trackedProcessInformation.crawlerProcessInformationNewImageEvent += new CrawlerProcessInformationNewImageEvent(delegate(CrawlerImage image)
                    {
                        trackedProcessInformationImageUpdateCounter++;
                    });
                }
            });
            crawlerJobView.updateImageEvent += new CrawlerJobViewUpdateEventImage(delegate(CrawlerImage crawlerImage)
            {
                imageEventCounter++;
            });

            //
            crawlerController.startCrawling(page);
            crawlerController.getFinishedEvent().WaitOne(System.TimeSpan.FromSeconds(5), false);

            //
            Assert.IsTrue(peekProcessInformationCount > 0);
            Assert.IsTrue(updateEventCounter > 10);

            Assert.IsTrue(trackedProcessInformationUpdateCounter > 10);
            Assert.IsTrue(trackedProcessInformationPercentagePeek > 0.3);
        }
Exemple #2
0
        public static void NullCollectionThrows()
        {
            // Arrange
            var mockRepo   = new Mock <ICrawlerService>();
            var controller = new CrawlerController(mockRepo.Object);

            //Act
            var result = controller.GetAsync("wiprodigital.com");

            Assert.NotNull(result);
            Assert.NotEmpty((System.Collections.IEnumerable)result);
        }
Exemple #3
0
        public void HasContainOtherUrls()
        {
            var domain = "wiprodigital.com";
            // Arrange
            var mockRepo   = new Mock <ICrawlerService>();
            var controller = new CrawlerController(mockRepo.Object);

            //Act
            var result = controller.GetAsync(domain);
            var items  = ((System.Collections.IEnumerable)result).Cast <string>().ToArray();

            //Assert
            Assert.All(items, x => Assert.Contains(domain, x));
        }
Exemple #4
0
            public List <ICrawlerJobPart> run()
            {
                //
                List <ICrawlerJobPart> crawlerJobPartList = new List <ICrawlerJobPart>();

                //
                if (this.jobPartCounter > 1)
                {
                    crawlerJobPartList.Add(new CrawlerJobPartMock(this.jobPartCounter - 1, 0));
                }

                //
                for (int ii = 1; ii <= 10; ii++)
                {
                    if (this.progressPercentageChangeEvent != null)
                    {
                        this.progressPercentageChangeEvent(ii * 0.1);
                    }

                    if (ii == 9)
                    {
                        if (this.crawlerJobPartImageRetrievedEvent != null)
                        {
                            CrawlerImage crawlerImage = new CrawlerImage();
                            crawlerImage.image = new Bitmap(10, 10);
                            this.crawlerJobPartImageRetrievedEvent(crawlerImage);
                        }
                    }
                }

                for (int ii = 1; ii <= this.spawnJobsCounter; ii++)
                {
                    CrawlerController crawlerController = (CrawlerController)this.crawlerJobContext.crawlerController;
                    crawlerController.setInitialJobFactory(new InitialJobFactoryMock(0, this.jobPartCounter));
                    crawlerController.addPage(new Page("http://www.google.de/" + ii));
                }

                //
                return(crawlerJobPartList);
            }
Exemple #5
0
        public static void Main(string[] args)
        {
            if (args.Length == 2 && args[0] != null && new DirectoryInfo(args[0]).Exists)
            {
                //
                ICrawlerController crawlerController = new CrawlerController();
                crawlerController.setImageLoggingFolder(args[0]);

                //
                crawlerController.startCrawling(new Page(args[1]));

                //
                Console.WriteLine("Crawling process is running. Press any key to stop crawling...");
                Console.ReadLine();

                //
                crawlerController.stopCrawling();
            }
            else
            {
                Program.renderHelp();
            }
        }
Exemple #6
0
        public static T GetControllerInstance <T>()
        {
            if (typeof(T) == typeof(IClipperUserAPI) ||
                typeof(IClipperSystemAdministratorAPI) == typeof(T) ||
                typeof(IClipperStaffChiefAPI) == typeof(T))
            {
                return((T)(object)new UserController());
            }

            if (typeof(T) == typeof(IClipperDatabase))
            {
                return((T)DatabaseAdapterFactory.GetControllerInstance <IClipperDatabase>());
            }

            if (typeof(T) == typeof(IClipperService))
            {
                return((T)(object)new StatusController());
            }

            if (typeof(T) == typeof(IClipperOrganizationalUnitAPI))
            {
                return((T)(object)new OrganizationalUnitController());
            }

            if (typeof(T) == typeof(ICrawlerController))
            {
                return((T)(object)CrawlerController.GetCrawlerController());
            }

            if (typeof(T) == typeof(INotificationController))
            {
                return((T)(object)new NotificationControllerWrapper());
            }

            throw new ArgumentOutOfRangeException(nameof(T));
        }
 /// <summary>
 /// Changes the source.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="updatedSource">The updated source.</param>
 /// <returns>MethodResult indicating success</returns>
 public MethodResult ChangeSource(User user, Source updatedSource)
 {
     Factory.GetControllerInstance <IClipperDatabase>().UpdateSource(updatedSource);
     CrawlerController.GetCrawlerController().Restart();
     return(new MethodResult());
 }
 /// <summary>
 /// Deletes the given source.
 /// </summary>
 /// <param name="user">The user who requests the deletion.</param>
 /// <param name="toDelete">The source to delete.</param>
 /// <returns>MethodResult indicating success</returns>
 public MethodResult DeleteSource(User user, Guid toDelete)
 {
     Factory.GetControllerInstance <IClipperDatabase>().DeleteSource(toDelete);
     CrawlerController.GetCrawlerController().Restart();
     return(new MethodResult());
 }
 /// <summary>
 /// Adds the given source.
 /// </summary>
 /// <param name="user">The user who requests the addition.</param>
 /// <param name="toAdd">The source to add.</param>
 /// <returns>MethodResult indicating success</returns>
 public MethodResult AddSource(User user, Source toAdd)
 {
     Factory.GetControllerInstance <IClipperDatabase>().AddSource(toAdd);
     CrawlerController.GetCrawlerController().Restart();
     return(new MethodResult());
 }
Exemple #10
0
        public void startCrawlingTest()
        {
            //
            Page page = new Page();

            page.urlStr = "http://www.google.de";
            CrawlerController crawlerController = new CrawlerController();
            ICrawlerJobView   crawlerJobView    = crawlerController.getCrawlerJobView();

            //
            Assert.IsNotNull(crawlerJobView);

            //
            int peekProcessInformationCount = 0;
            int updateEventCounter          = 0;
            int imageEventCounter           = 0;

            int    trackedProcessInformationUpdateCounter      = 0;
            int    trackedProcessInformationImageUpdateCounter = 0;
            double trackedProcessInformationPercentagePeek     = 0.0000;
            //
            CrawlerProcessInformation trackedProcessInformation = null;

            crawlerJobView.updateProcessInformationEvent += new CrawlerJobViewUpdateEventProcessInformation(delegate(CrawlerProcessInformation crawlerProcessInformation)
            {
                List <CrawlerProcessInformation> crawlerProcessInformationList = crawlerJobView.getActiveCrawlerProcessInformationList();
                peekProcessInformationCount = Math.Max(peekProcessInformationCount, crawlerProcessInformationList.Count);
                updateEventCounter++;

                //
                if (trackedProcessInformation == null && crawlerProcessInformation != null)
                {
                    trackedProcessInformation = crawlerProcessInformation;
                    trackedProcessInformation.crawlerProcessInformationUpdateEvent += new CrawlerProcessInformationUpdateEvent(delegate(CrawlerProcessInformation information) {
                        trackedProcessInformationUpdateCounter++;
                        trackedProcessInformationPercentagePeek = Math.Max(trackedProcessInformationPercentagePeek, information.progressPercentage);
                    });
                    trackedProcessInformation.crawlerProcessInformationNewImageEvent += new CrawlerProcessInformationNewImageEvent(delegate(CrawlerImage image){
                        trackedProcessInformationImageUpdateCounter++;
                    });
                }
            });
            crawlerJobView.updateImageEvent += new CrawlerJobViewUpdateEventImage(delegate(CrawlerImage crawlerImage){
                imageEventCounter++;
            });

            //
            int crawlerJobCount     = 100;
            int crawlerJobPartCount = 10;

            crawlerController.setInitialJobFactory(new InitialJobFactoryMock(crawlerJobCount, crawlerJobPartCount));
            crawlerController.setMaximumCrawlerJobThreadCount(20);
            crawlerController.startCrawling(page);
            crawlerController.getFinishedEvent().WaitOne(Timeout.Infinite, false);

            //
            Assert.IsTrue(peekProcessInformationCount > 1);
            Assert.IsTrue(updateEventCounter > crawlerJobCount * 10);
            Assert.AreEqual(crawlerJobCount * crawlerJobPartCount, imageEventCounter);

            Assert.IsTrue(trackedProcessInformationUpdateCounter > 10);
            Assert.IsTrue(trackedProcessInformationPercentagePeek > 0.3);
            Assert.AreEqual(crawlerJobPartCount, trackedProcessInformationImageUpdateCounter);
        }
Exemple #11
0
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            if (isAiming == false)
            {
                isAiming    = true;
                aim.enabled = true;
            }
        }

        if (isAiming == true)
        {
            if (isAutoTargetingModeOn == false)
            {
                aim.transform.position = Input.mousePosition;

                if (Input.GetMouseButtonDown(0))
                {
                    muzzleFlash.Play();

                    var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (!Physics.Raycast(ray, out hit, 150))
                    {
                        return;
                    }

                    string targetName = hit.transform.name;
                    //Debug.Log(targetName);

                    if (hit.collider.name == "CopZombie")
                    {
                        copZombieController = hit.collider.gameObject.GetComponent <CopZombieController>();
                        //bombZombieController = hit.collider.gameObject.GetComponent<BombZombieController>();
                        copZombieController.IsBeingDamaged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                        //bombZombieController.IsBeingDamged(10);
                    }

                    if (hit.collider.name == "BombZombie")
                    {
                        bombZombieController = hit.collider.gameObject.GetComponent <BombZombieController>();
                        bombZombieController.IsBeingDamged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }

                    if (hit.collider.name == "HalfZombie")
                    {
                        halfZombieController = hit.collider.gameObject.GetComponent <HalfZombieController>();
                        halfZombieController.IsBeingDamaged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }

                    if (hit.collider.name == "Crawler")
                    {
                        crawlerController = hit.collider.gameObject.GetComponent <CrawlerController>();
                        crawlerController.IsBeingDamaged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }

                    //if(hit.collider)
                    //{
                    //    Debug.Log(targetName);
                    //}
                }
            }


            if (isAutoTargetingModeOn == true)
            {
                zombiePositionToWorld = Camera.main.WorldToScreenPoint(GameObject.Find("CopZombie").transform.position + new Vector3(0, 0.4f, 0));

                aim.transform.position = zombiePositionToWorld;

                if (Input.GetMouseButtonDown(0))
                {
                    var        ray = Camera.main.ScreenPointToRay(zombiePositionToWorld);
                    RaycastHit hit;

                    if (!Physics.Raycast(ray, out hit, 150))
                    {
                        return;
                    }

                    if (hit.collider.name == "CopZombie")
                    {
                        copZombieController = hit.collider.gameObject.GetComponent <CopZombieController>();
                        Instantiate(bloodEffectOnEnemy, hit.point, Quaternion.identity);
                        copZombieController.IsBeingDamaged(5);
                    }

                    if (hit.collider.name == "BombZombie")
                    {
                        bombZombieController = hit.collider.gameObject.GetComponent <BombZombieController>();
                        bombZombieController.IsBeingDamged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }

                    if (hit.collider.name == "HalfZombie")
                    {
                        halfZombieController = hit.collider.gameObject.GetComponent <HalfZombieController>();
                        halfZombieController.IsBeingDamaged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }

                    if (hit.collider.name == "Crawler")
                    {
                        crawlerController = hit.collider.gameObject.GetComponent <CrawlerController>();
                        crawlerController.IsBeingDamaged(10);
                        CreateBloodEffectOnEnemy(hit.point);
                    }
                }
            }

            if (Input.GetMouseButtonUp(1))
            {
                isAiming    = false;
                aim.enabled = false;
            }
        }
    }