public async Task FileExclusion() { // Arrange // Prepare DB & files Assert.IsTrue(PrepareDirectories()); Assert.IsTrue(await ResetDatabase(), "Could not create database"); var targetDir = Path.Combine(testDirD, "dir1"); var targetDir2 = Path.Combine(testDirD, @"dir2\subdir1"); // should be scanned File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "KeyMap.txt")), Path.Combine(targetDir, "KeyMap.txt")); // should not be scanned File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "randomExe.exe")), Path.Combine(targetDir, "randomExe.exe")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "0266554465.jpeg")), Path.Combine(targetDir2, "0266554465.jpeg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "Nikon-1-V3-sample-photo.jpg")), Path.Combine(targetDir2, "Nikon-1-V3-sample-photo.jpg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "umlaut_äü(&テスト.txt")), Path.Combine(targetDir2, "umlaut_äü(&テスト.txt")); // Act var diffFi = new FileIndex(); await diffFi.AddFileExclusionAsync(@"\.exe", true); await diffFi.AddFileExclusionAsync(@".*\\subdir1", true); await diffFi.CreateArchiveAsync(new DirectoryInfo(testDirD), new CancellationTokenSource().Token, new Progress <int>(), new Progress <string>(), "FileExclusionArchive"); // Assert Assert.AreEqual(1, diffFi.Hashes.Count, "FileHash count incorrect."); var hash = diffFi.Hashes.FirstOrDefault(); Assert.AreEqual(1, hash.NodeCount, "Node count incorrect."); var node = hash.Nodes.FirstOrDefault(); Assert.AreEqual(Path.Combine(targetDir, "KeyMap.txt"), node.FullSessionName, "Node count incorrect."); }
public async Task WriteToDatabase() { // Arrange // Prepare DB & files Assert.IsTrue(PrepareDirectories()); Assert.IsTrue(await ResetDatabase(), "Could not create database"); var targetDir = Path.Combine(testDirD, "dir1"); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "KeyMap.txt")), Path.Combine(targetDir, "KeyMap.txt")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "0266554465.jpeg")), Path.Combine(targetDir, "0266554465.jpeg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "Nikon-1-V3-sample-photo.jpg")), Path.Combine(targetDir, "Nikon-1-V3-sample-photo.jpg")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "randomExe.exe")), Path.Combine(targetDir, "randomExe.exe")); File.Copy(Path.GetFullPath(Path.Combine(testFileDir, "umlaut_äü(&テスト.txt")), Path.Combine(targetDir, "umlaut_äü(&テスト.txt")); var exclusionString1 = @"\.exe"; var exclusionString2 = @".*\subdir1"; // Act var refFi = new FileIndex(); await refFi.CreateArchiveAsync(new DirectoryInfo(targetDir), new CancellationTokenSource().Token, new Progress <int>(), new Progress <string>(), "testArchive"); await refFi.AddFileExclusionAsync(exclusionString1, true); await refFi.AddFileExclusionAsync(exclusionString2, true); var diffFi = new FileIndex(); await diffFi.LoadDataAsync(); // Assert Assert.AreEqual(refFi.Archives.Count, diffFi.Archives.Count, "Archive count incorrect."); foreach (var refArchive in refFi.Archives) { Assert.IsTrue(diffFi.Archives.Contains(refArchive), "Archive not found."); var diffArchive = diffFi.Archives.FirstOrDefault(x => x.Equals(refArchive)); Assert.AreEqual(refArchive.GetFileNodes().Count, diffArchive.GetFileNodes().Count, "FileNodes count incorrect."); foreach (var refNode in refArchive.GetFileNodes()) { Assert.IsTrue(diffArchive.GetFileNodes().Contains(refNode), "FileNode not found."); } Assert.AreEqual(refArchive.GetFileDirectories().Count, diffArchive.GetFileDirectories().Count, "FileDirectory count incorrect."); foreach (var refNode in refArchive.GetFileDirectories()) { Assert.IsTrue(diffArchive.GetFileDirectories().Contains(refNode), "FileDirectory not found."); } } Assert.AreEqual(refFi.LogicalVolumes.Count, diffFi.LogicalVolumes.Count, "LogicalVolume count incorrect."); foreach (var refVolume in refFi.LogicalVolumes) { Assert.IsTrue(diffFi.LogicalVolumes.Contains(refVolume), "LogicalVolume not found."); } Assert.AreEqual(refFi.Hashes.Count, diffFi.Hashes.Count, "FileHash count incorrect."); foreach (var refHash in refFi.Hashes) { Assert.IsTrue(diffFi.Hashes.Contains(refHash), "FileHash not found."); Assert.AreEqual(refHash, diffFi.Hashes.FirstOrDefault(x => x.Equals(refHash)), "FileHash not equal."); } Assert.IsTrue(diffFi.Exclusions.Contains(exclusionString1), "Exclusion not found."); Assert.IsTrue(diffFi.Exclusions.Contains(exclusionString2), "Exclusion not found."); }
/// <summary> /// Creates a new file exclusion which prevents files from being scanned if they match the provided string.</summary> /// <param name="exclusion">A regex string matching a file or path name.</param> public async Task AddFileExclusionAsync(string exclusion) { await index.AddFileExclusionAsync(exclusion, true); }