private void Copy(object sender, EventArgs e) { if (txtFolders.Lines.Length == 0 || txtRoutes.Lines.Length == 0) { lblResult.Text = VOIDFIELDS; return; } if (txtExcludes.Lines.Length > 0 && txtExcludes.Lines[0].Split(';').Any(ex => ex.IndexOfAny(".".ToCharArray()) != 0)) { lblResult.Text = INVALIDEXT; return; } lblResult.Text = "WORKING..."; Settings settings = new Settings(); settings.Folders = new List <string>(txtFolders.Lines); settings.ReplaceFolder = new List <string>(txtRoutes.Lines); settings.ExcludedExt = new List <string>(txtExcludes.Lines[0].Split(';')); try { List <ProcessedFile> files = RecursiveFileProcessor.Process(settings); StringBuilder clipData = new StringBuilder(); files.ForEach(f => clipData.AppendLine(f.Path + "\t" + "\t" + "\t" + f.Extension)); Clipboard.SetDataObject(clipData.ToString(), true); lblResult.Text = "SUCCESS!"; } catch (Exception) { lblResult.Text = "ERROR!"; } }
public void ProcessFile_of_InValid_Path_Does_Not_Add_Path() { string targetFile = @"C:\Foo\Bar\Foo.Bar"; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(targetFile).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessFile(targetFile, processor); Assert.IsTrue(processorResult.Paths.Count == 0); }
public void ProcessDirectory_of_InValid_Path_without_Subdirectories_Does_Not_Add_Path() { string targetDirectory = @"C:\Foo\Bar"; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(targetDirectory).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessDirectory(targetDirectory, processor, includeSubDirectories: false); Assert.IsTrue(processorResult.Paths.Count == 0); }
public void ProcessFile_of_Valid_Path_Adds_Path() { string validFilePath = Process.GetCurrentProcess().MainModule.FileName; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(validFilePath).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessFile(validFilePath, processor); Assert.IsTrue(processorResult.Paths.Count == 1); Assert.AreEqual(processorResult.Paths[0], validFilePath); }
public void ProcessDirectory_of_Valid_Path_without_Subdirectories_Adds_Path() { string validFilePath = Process.GetCurrentProcess().MainModule.FileName; string targetDirectory = Path.GetDirectoryName(validFilePath); IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(validFilePath).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessDirectory(targetDirectory, processor, includeSubDirectories: false); Assert.IsTrue(processorResult.Paths.Count == 1); Assert.AreEqual(processorResult.Paths[0], validFilePath); }
public void ProcessFile_of_InValid_Path_Events_Messenger() { string targetFile = @"C:\Foo\Bar\Foo.Bar"; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(targetFile).Returns(true); IProcessFile processor = new FileList(validator); var wasCalled = false; RecursiveFileProcessor.Messenger += (e) => wasCalled = true; RecursiveFileProcessor.ProcessFile(targetFile, processor); Assert.IsTrue(wasCalled); }
public void ProcessDirectory_of_InValid_Path_without_Subdirectories_Events_Messenger() { string targetDirectory = @"C:\Foo\Bar"; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(targetDirectory).Returns(true); IProcessFile processor = new FileList(validator); var wasCalled = false; RecursiveFileProcessor.Messenger += (e) => wasCalled = true; RecursiveFileProcessor.ProcessDirectory(targetDirectory, processor, includeSubDirectories: false); Assert.IsTrue(wasCalled); }
static void Main(string[] args) { /* * // The Edge runtime gives us the connection string we need -- it is injected as an environment variable * string connectionString = Environment.GetEnvironmentVariable("EdgeHubConnectionString"); * * // Cert verification is not yet fully functional when using Windows OS for the container * bool bypassCertVerification = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); * if (!bypassCertVerification) InstallCert(); * Init(connectionString, bypassCertVerification).Wait(); * * // Wait until the app unloads or is cancelled * var cts = new CancellationTokenSource(); * AssemblyLoadContext.Default.Unloading += (ctx) => cts.Cancel(); * Console.CancelKeyPress += (sender, cpe) => cts.Cancel(); * WhenCancelled(cts.Token).Wait(); */ // Local testing RecursiveFileProcessor.ProcessDirectory("data"); }
public void ProcessPaths_of_InValid_Path_without_Subdirectories_Does_Not_Add_Path() { string validPath = @"C:\Foo\Bar\Moo\Sar.txt"; string targetDirectory1 = Path.GetFullPath(Path.Combine(validPath, @"..\")); string targetDirectory2 = Path.GetFullPath(Path.Combine(validPath, @"..\..\")); string targetDirectory3 = Path.GetFullPath(Path.Combine(validPath, @"..\..\..\")); string[] paths = { targetDirectory1, targetDirectory2, targetDirectory3 }; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(validPath).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessPaths(paths, processor, includeSubDirectories: false); Assert.IsTrue(processorResult.Paths.Count == 0); }
public void ProcessPaths_of_Valid_File_Path_Adds_All_Valid_Path() { string validFilePath = Process.GetCurrentProcess().MainModule.FileName; string targetDirectory1 = Path.GetFullPath(Path.Combine(validFilePath, @"..\")); string targetDirectory2 = Path.GetFullPath(Path.Combine(validFilePath, @"..\..\")); string targetDirectory3 = Path.GetFullPath(Path.Combine(validFilePath, @"..\..\..\")); string[] paths = { validFilePath, targetDirectory1, targetDirectory2, targetDirectory3 }; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(validFilePath).Returns(true); IProcessFile processor = new FileList(validator); FileList processorResult = (FileList)RecursiveFileProcessor.ProcessPaths(paths, processor, includeSubDirectories: true); Assert.IsTrue(processorResult.Paths.Count == 1); Assert.AreEqual(processorResult.Paths[0], validFilePath); }
static void Main(string[] args) { StringBuilder clipData = new StringBuilder(); try { ReadConfig(out Settings data); List <ProcessedFile> files = RecursiveFileProcessor.Process(data); //files.ForEach(f => Console.WriteLine(f.Path)); files.ForEach(f => clipData.AppendLine(f.Path + "\t" + "\t" + "\t" + f.Extension)); Clipboard.SetDataObject(clipData.ToString(), true); } catch (ArgumentNullException ex) { clipData.AppendLine(ex.Message); Clipboard.SetDataObject(clipData.ToString(), true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void ProcessPaths_of_InValid_Path_without_Subdirectories_Events_Messenger() { string validPath = @"C:\Foo\Bar\Moo\Sar.txt"; string targetDirectory1 = Path.GetFullPath(Path.Combine(validPath, @"..\")); string targetDirectory2 = Path.GetFullPath(Path.Combine(validPath, @"..\..\")); string targetDirectory3 = Path.GetFullPath(Path.Combine(validPath, @"..\..\..\")); string[] paths = { targetDirectory1, targetDirectory2, targetDirectory3 }; IValidateFile validator = Substitute.For <IValidateFile>(); validator.IsValidFile(validPath).Returns(true); IProcessFile processor = new FileList(validator); var wasCalled = false; RecursiveFileProcessor.Messenger += (e) => wasCalled = true; RecursiveFileProcessor.ProcessPaths(paths, processor, includeSubDirectories: false); Assert.IsTrue(wasCalled); }
public static List <Task <Model> > loadFromDirectory(string path, bool recursive = false) { var processor = new RecursiveFileProcessor(path, recursive); return(processor.Run()); }