/// <summary>Run a backup</summary> /// <param name="simMode">flag for simulation mode</param> /// <param name="debugMode">flag for debug mode</param> /// <returns>an empty string for success. Otherwise, an error message for a fatal error encountered prior to the run.</returns> /// <remarks> /// Note: All I/O errors and anticipated exceptions encountered during the backup are captured in the error log. /// </remarks> public void Run(bool simMode, bool debugMode) { RanSuccessfully = false; SetupPrep(); if (Validate(simMode, debugMode) == false) { // a serious validation error occurred prior to job; we cannot continue nor can we log anything safely return; } dirSearch = new DirSearch(); AddSearchDelegates(); for (currentSrcNdx = 0; currentSrcNdx < sourcesToBackup.Count; currentSrcNdx++) { // process each backup source dirSearch.SearchMask = DirSearch.SearchMaskAllFilesAndFolders; dirSearch.BaseDir = sourcesToBackup[currentSrcNdx].StartingFolder; dirSearch.SearchType = AttrSearchType.IgnoreAttributeMatch; dirSearch.FileAttribs = DirSearch.AllAttributes; // not really needed currently as we are set to IgnoreAttributeMatch dirSearch.ProcessSubs = sourcesToBackup[currentSrcNdx].TraverseSubs; dirSearch.Execute(); if (CancelFlag) { break; } } RemoveSearchDelegates(); if (CancelFlag == false && TrackDeletes()) { CheckDeletes(); } Stats.DtTmEnded = DateTime.Now; WriteLogs(); RanSuccessfully = true; }
public RenameResults ProcessFiles() { string err = string.Empty; Results = new RenameResults(); batchNum = 0; script = ScriptRunner.CompileScript(RenameCode, out err); if (script == null) // could not compile { LogErr("Script code did not compile. Error: " + err); } else { dirSearch = new DirSearch(FileMask, StartingPath, AttrSearchType.AnyMatch, DirSearch.AllAttributesMinusSysAndHidden, ProcessSubFolders); dirSearch.OnFileMatch += DirSearch_OnFileMatch; dirSearch.OnFolderMatch += DirSearch_OnFolderMatch; dirSearch.OnFileExcept += DirSearch_OnFileExcept; dirSearch.OnFolderExcept += DirSearch_OnFolderExcept; dirSearch.Execute(); dirSearch.OnFileMatch -= DirSearch_OnFileMatch; dirSearch.OnFolderMatch -= DirSearch_OnFolderMatch; dirSearch.OnFileExcept -= DirSearch_OnFileExcept; dirSearch.OnFolderExcept -= DirSearch_OnFolderExcept; } OutputData(true); // write any residual data collected for specific output types return(Results); }
public void TopLevelAndSubsWithNoHitsReturnsNoFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(NoMatchFilePatttern, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.AreEqual(0, numFiles, "Number of files not 0"); }
public void NullPathUsesCurrentDir() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, null, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.AreEqual(Directory.GetCurrentDirectory(), searcher.BaseDir, "base dir != GetCurrentDirectory()"); }
public void FilesStartingWithRootReturnsFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch("Root*.*", RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.IsTrue(numFiles >= 3, "Number of files not >= 3"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
public void TopLevelReturnsFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, false); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.IsTrue(numFiles >= 7, "Number of files not >= 7"); Assert.IsTrue(numFolders >= 1, "Number of folders not >= 1"); }
public void CustomFolderFilterOnHiddenFolderReturnsOneHit() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.OnFolderFilter += (DirectoryInfo folder, ref bool skip, ref bool skipChildren) => { skip = ((folder.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden); }; searcher.Execute(); Assert.IsTrue(numFolders >= 1, "Number of folders not >= 1"); }
public void HiddenFilesAndSubsReturnsFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.AllMatchPlusAnyOthers, FileAttributes.Hidden, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.IsTrue(numFiles >= 3, "Number of Hidden files not >= 3"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
public void ROFilesAndSubsReturnsFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.AnyMatch, FileAttributes.ReadOnly, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.Execute(); Assert.IsTrue(numFiles >= 2, "Number of RO files not >= 2"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
public void CustomFileFilterOnSublevelWithNoMatchesReturnsZero() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(NoMatchFilePatttern, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.OnFileFilter += (FileInfo oneFile, ref bool skip) => { skip = oneFile.Name != "L2F1-1.txt"; }; searcher.Execute(); Assert.AreEqual(0, numFiles, "Number of files not 0"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
public void CustomFolderFilterWithChildFoldersOnWorks() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch("L3-L2F1*.*", RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.OnFolderFilter += (DirectoryInfo folder, ref bool skip, ref bool skipChildren) => { skip = (folder.Name == "L2F1"); skipChildren = false; }; searcher.Execute(); Assert.IsTrue(numFolders >= MinFolderTotal - 1, $"Number of folders not >= {MinFolderTotal - 1}"); Assert.IsTrue(numFiles >= 2, "Number of files not >= 1"); }
public void CustomFileFilterZeroByteFileslReturnsFiles() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.OnFileFilter += (FileInfo oneFile, ref bool skip) => { skip = oneFile.Length != 0; }; searcher.Execute(); Assert.IsTrue(numFiles >= 4, "Number of files not >= 4"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
public void CustomFileFilterOnAllFilesReturnsOneHit() { int numFolders = 0; int numFiles = 0; DirSearch searcher = new DirSearch(AllFiles, RootLoc, AttrSearchType.IgnoreAttributeMatch, 0, true); searcher.OnFolderMatch += (DirectoryInfo info, ref bool flag) => { numFolders++; }; searcher.OnFileMatch += (FileInfo info, ref bool flag) => { numFiles++; }; searcher.OnFileFilter += (FileInfo oneFile, ref bool skip) => { skip = oneFile.Name != "Root2.dat"; }; searcher.Execute(); Assert.AreEqual(1, numFiles, "Number of files not 1"); Assert.IsTrue(numFolders >= MinFolderTotal, $"Number of folders not >= {MinFolderTotal}"); }
/// <summary>Delete handling for destination folder where file is no longer on source</summary> /// <remarks> /// Reverse lookup for delete-detection using list of scanned files and destination folder /// - only called when settings for job require delete-detection /// - foldersToSkipForDeleteDetection contains the list of trash and History folders to be skipped. /// - a file filter is not used to skip BUM error and stat logs as it's done directly in OnDelFileInitialMatch() using prefixesToSkipForDeleteDetection /// </remarks> private void CheckDeletes() { DirSearch delSearch = new DirSearch("*.*", Stats.DestPathRoot, AttrSearchType.AnyMatch, DirSearch.AllAttributesMinusSysAndHidden, true); delSearch.OnFileMatch += OnDelFileInitialMatch; delSearch.OnFileExcept += OnDelFileException; delSearch.OnFolderExcept += OnDelFolderException; // Folder filtering is used to skip History and Trash folders delSearch.OnFolderFilter += OnDelFolderFilter; delSearch.Execute(); delSearch.OnFileMatch -= OnDelFileInitialMatch; delSearch.OnFileExcept -= OnDelFileException; delSearch.OnFolderExcept -= OnDelFolderException; delSearch.OnFolderFilter -= OnDelFolderFilter; processedFileDict.Clear(); // free memory as it can be substantial }