Example #1
0
        public void CanCrawl()
        {
            const string path           = @".\Files";
            const int    timeoutSeconds = 60;
            const int    mediaCount     = 39;
            const int    fileCount      = 28;

            var directory = new DirectoryInfo(path);

            Assert.IsTrue(directory.Exists);
            System.Diagnostics.Debug.WriteLine("CanCrawl() directory path=" + directory.FullName);

            var fileTally = 0;

            foreach (var file in System.IO.Directory.GetFiles(path))
            {
                fileTally++;
            }

            Assert.AreEqual(fileCount, fileTally);

            var target = new Uri(directory.FullName);

            Assert.IsTrue(target.IsFile);

            var media = new List <IMedia>();

            var task = spider.Crawl(target);

            task.AddResultsCallback(results => media.AddRange(results));
            task.AddProgressCallback(progress => logger.Info(string.Format("PROGRESS: {0} {1}", progress.Count, progress.Description)));
            //task.AddFailedCallback(

            task.StartSynchronously(TimeSpan.FromSeconds(timeoutSeconds));

            Assert.AreEqual(mediaCount, media.Count);

            foreach (var medium in media)
            {
                logger.Info(medium.Type.ToString() + " " + medium.Location.ToString());
            }
        }
 public ITask <IEnumerable <IMedia> > BuildCatalog(Uri location)
 {
     return(spider.Crawl(location));
 }