Пример #1
0
        public void FolderSizeIsZero()
        {
            var sut = new FileCrawler(new MemoryFileDatabase(), new SystemFileDescriptorProvider(), new StatSignatureGenerator(new SHA1HashGenerator()), new NullProgressTracker());
            var rootDescriptor = sut.ScanDirectory(TestResources.ResourcesPath);

            Assert.That(rootDescriptor.Size, Is.EqualTo(0));
        }
Пример #2
0
 public void ScanDirectoryAddsAllFilesAndFoldersToDatabase()
 {
     var database = new MemoryFileDatabase();
     var sut = new FileCrawler(database, new SystemFileDescriptorProvider(), new StatSignatureGenerator(new SHA1HashGenerator()), new NullProgressTracker());
     sut.ScanDirectory(TestResources.ResourcesPath);
     var expected = TestResources.AllPaths;
     var actual = database.GetAllDescriptors().Select(x => x.Path);
     Assert.That(actual, Is.EquivalentTo(expected));
 }
Пример #3
0
        public void ScanDirectoryReturnsRootFileDescriptor()
        {
            var database = new MemoryFileDatabase();
            var sut = new FileCrawler(database, new SystemFileDescriptorProvider(), new StatSignatureGenerator(new SHA1HashGenerator()), new NullProgressTracker());
            var rootDescriptor = sut.ScanDirectory(TestResources.ResourcesPath);

            Assert.That(rootDescriptor.Name, Is.EqualTo(TestResources.ResourcesPath));
            Assert.That(rootDescriptor.Children, Is.Not.Null, "Expected root descriptor to have child descriptors");
            Assert.That(rootDescriptor.Children.Select(x => x.Name), Is.EquivalentTo(new [] {"albert-einstein.jpg", "TextFile.txt", "Sub"}));
        }
Пример #4
0
 private static void UpdateContentSignatures(MemoryFileDatabase database, FileDescriptor rootDescriptor)
 {
     Console.WriteLine("Updating content signatures");
     var progressTracker = new ConsoleProgressTracker(database.GetAllDescriptors().Count());
     var contentCrawler = new FileCrawler(new NullFileDatabase(), new RevisitDescriptorProvider(),
                                          new SampleSignatureGenerator(new SHA1HashGenerator()), progressTracker);
     var contentTimer = Stopwatch.StartNew();
     contentCrawler.ScanDirectory(rootDescriptor);
     contentTimer.Stop();
     var descriptorCount = database.GetAllDescriptors().Count();
     //            PrintDescriptorTree(rootDescriptor, descriptor => descriptor.ContentHash);
     //            PrintDuplicates(database, descriptor => descriptor.ContentHash);
     Console.WriteLine("Calculated content signature for {0} entries in {1}. {2} files per second", descriptorCount,
                       contentTimer.Elapsed, 1000 * descriptorCount / contentTimer.ElapsedMilliseconds);
 }
Пример #5
0
 private static FileDescriptor StatScanFolder(MemoryFileDatabase database, string baseFolder)
 {
     var volumeInfo = new VolumeInfo(baseFolder);
     Console.WriteLine($"Name = {volumeInfo.VolumeName}, Serial = {volumeInfo.SerialNumber}");
     database.RootInfo = new RootInfo
     {
         RootPath = baseFolder,
         VolumeId = volumeInfo.SerialNumber,
         VolumeLabel = volumeInfo.VolumeName
     };
     var progressTracker = new ConsoleProgressTracker();
     var signatureGenerator = new StatSignatureGenerator(new SHA1HashGenerator());
     var crawler = new FileCrawler(database, new SystemFileDescriptorProvider(), signatureGenerator, progressTracker);
     var scanTimer = Stopwatch.StartNew();
     var rootDescriptor = crawler.ScanDirectory(baseFolder);
     scanTimer.Stop();
     var descriptorCount = database.GetAllDescriptors().Count();
     Console.WriteLine("Scanned {0} entries in {1}. {2} stat scans per second", descriptorCount, scanTimer.Elapsed,
         1000*descriptorCount/scanTimer.ElapsedMilliseconds);
     return rootDescriptor;
 }