public override Exception Run(CancellationToken token) { LoadConfig("~/.config/taa/config.yml"); InputFiles = InputFiles.Any() ? InputFiles : Directory.EnumerateFiles(TargetDirectory); Logger.Info("Vtn:"); Logger.Info($"\tVoltage: {VtnVoltage}"); Logger.Info($"\tSigma: {VtnSigma}"); Logger.Info($"\tDeviation: {VtnDeviation}"); Logger.Info("Vtp:"); Logger.Info($"\tVoltage: {VtpVoltage}"); Logger.Info($"\tSigma: {VtpSigma}"); Logger.Info($"\tDeviation: {VtpDeviation}"); Logger.Info($"Total Files: {InputFiles.Count()}"); Logger.Info("Start push"); using (var bar = new ProgressBar(2, "Master", new ProgressBarOptions { ForegroundColor = ConsoleColor.DarkGreen, BackgroundCharacter = '-', ProgressCharacter = '>', CollapseWhenFinished = false })) { var opt = new ProgressBarOptions { ForegroundColor = ConsoleColor.DarkYellow, ProgressCharacter = '=', CollapseWhenFinished = false }; using (var pushBar = bar.Spawn(0, "Pushing...", opt)) using (var parseBar = bar.Spawn(InputFiles.Count(), "Parsing...", opt)) return(PushFiles(token, bar, parseBar, pushBar)); } }
public void ValidateArguments() { if (argsCount % 2 != 0) { throw new Exception("Invalid number of arguments."); } if (!InputFiles.Any()) { throw new Exception("No input file specified."); } if (string.IsNullOrWhiteSpace(OutputFile)) { throw new Exception("No output file specified."); } foreach (var file in InputFiles) { if (!File.Exists(file)) { throw new Exception($"File [{file}] does not exist."); } } }
public override bool IsValid() { if (!base.IsValid()) { return(false); } if (InputFiles == null || !InputFiles.Any()) { ValidationFailureList.Add("No input files found in report settings"); return(false); } if (Operations == null || !Operations.Any()) { ValidationFailureList.Add("No operations found in report settings"); return(false); } if (OutputFiles == null || !OutputFiles.Any()) { ValidationFailureList.Add("No output files found in report settings"); return(false); } return(true); }
/// <summary> /// Executes the concatenate command. /// </summary> /// <param name="fileSystem">The file system on which the command is going to be executed.</param> public override void Execute(Models.FileSystem fileSystem) { var hasInputFiles = InputFiles.Any(); var hasOutputFile = !string.IsNullOrWhiteSpace(OutputFile); if (hasInputFiles && hasOutputFile) { try { var concatenatedContent = ConcatenateFiles(fileSystem); fileSystem.CreateContentFile(OutputFile, concatenatedContent); } catch (InvalidOperationException operationException) { Console.WriteLine(operationException.Message); } catch (ArgumentException argumentException) { Console.WriteLine(argumentException.Message); } } else if (hasInputFiles) { try { var concatenatedContent = ConcatenateFiles(fileSystem); Console.Write(concatenatedContent); } catch (InvalidOperationException operationException) { Console.WriteLine(operationException.Message); } } else if (hasOutputFile) { var userInput = ReadUserInput(); try { fileSystem.CreateContentFile(OutputFile, userInput); } catch (InvalidOperationException operationException) { Console.WriteLine(operationException.Message); } catch (ArgumentException argumentException) { Console.WriteLine(argumentException.Message); } } else { Console.WriteLine("Couldn't execute cat command. Please check the validity of the passed parameters."); } }
/// <summary> /// Returns a list of absolute file paths of all matching input files. /// </summary> /// <param name="notifyOnPatternMiss">Writes to the Console if any input file is missing on disk.</param> public List <string> GetAbsoluteInputFiles(bool notifyOnPatternMiss = false) { List <string> files = new List <string>(); if (!InputFiles.Any()) { return(files); } string folder = new DirectoryInfo(Path.GetDirectoryName(FileName)).FullName; string ext = Path.GetExtension(InputFiles.First()); Options options = new Options { AllowWindowsPaths = true }; foreach (string inputFile in InputFiles.Where(f => !f.StartsWith("!", StringComparison.Ordinal))) { int globIndex = inputFile.IndexOf('*'); if (globIndex > -1) { string relative = string.Empty; int last = inputFile.LastIndexOf('/', globIndex); if (last > -1) { relative = inputFile.Substring(0, last + 1); } var output = GetAbsoluteOutputFile(); var outputMin = BundleMinifier.GetMinFileName(output); string searchDir = new FileInfo(Path.Combine(folder, relative).NormalizePath()).FullName; var allFiles = Directory.EnumerateFiles(searchDir, "*" + ext, SearchOption.AllDirectories).Select(f => f.Replace(folder + FileHelpers.PathSeparatorChar, "")); var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f)); matches = matches.Where(match => match != output && match != outputMin).ToList(); if (notifyOnPatternMiss && !matches.Any()) { Console.WriteLine($" No files matched the pattern {inputFile}".Orange().Bright()); } files.AddRange(matches.Where(f => !files.Contains(f))); } else { string fullPath = Path.Combine(folder, inputFile.NormalizePath()); if (Directory.Exists(fullPath)) { DirectoryInfo dir = new DirectoryInfo(fullPath); SearchOption search = SearchOption.TopDirectoryOnly; var dirFiles = dir.GetFiles("*" + Path.GetExtension(OutputFileName), search); var collected = dirFiles.Select(f => f.FullName).Where(f => !files.Contains(f)).ToList(); if (notifyOnPatternMiss && collected.Count == 0) { Console.WriteLine($" No files were found in {inputFile}".Orange().Bright()); } files.AddRange(collected); } else { files.Add(fullPath); if (notifyOnPatternMiss && !File.Exists(fullPath)) { Console.WriteLine($" {inputFile} was not found".Orange().Bright()); } } } } // Remove files starting with a ! foreach (string inputFile in InputFiles) { int globIndex = inputFile.IndexOf('!'); if (globIndex == 0) { var allFiles = files.Select(f => f.Replace(folder + FileHelpers.PathSeparatorChar, "")); var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f)); files = matches.ToList(); } } return(files); }
public bool BuildLibrary(IProgressMonitor progress) { _ambiguousMatches = null; IProgressStatus status = new ProgressStatus(Resources.BiblioSpecLiteBuilder_BuildLibrary_Preparing_to_build_library); progress.UpdateProgress(status); if (InputFiles.Any(f => f.EndsWith(EXT_PILOT))) { try { InputFiles = VendorIssueHelper.ConvertPilotFiles(InputFiles, progress, status); if (progress.IsCanceled) { return(false); } } catch (Exception x) { progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } } string message = string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Building__0__library, Path.GetFileName(OutputPath)); progress.UpdateProgress(status = status.ChangeMessage(message)); string redundantLibrary = BiblioSpecLiteSpec.GetRedundantName(OutputPath); var blibBuilder = new BlibBuild(redundantLibrary, InputFiles, TargetSequences) { IncludeAmbiguousMatches = IncludeAmbiguousMatches, CutOffScore = CutOffScore, Id = Id, }; try { if (!blibBuilder.BuildLibrary(Action, progress, ref status, out _ambiguousMatches)) { return(false); } } catch (IOException x) { progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } catch (Exception x) { Console.WriteLine(x.Message); progress.UpdateProgress(status.ChangeErrorException( new Exception(string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Failed_trying_to_build_the_redundant_library__0__, redundantLibrary)))); return(false); } var blibFilter = new BlibFilter(); status = new ProgressStatus(message); progress.UpdateProgress(status); // Write the non-redundant library to a temporary file first try { using (var saver = new FileSaver(OutputPath)) { if (!blibFilter.Filter(redundantLibrary, saver.SafeName, progress, ref status)) { return(false); } saver.Commit(); } } catch (IOException x) { progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } catch { progress.UpdateProgress(status.ChangeErrorException( new Exception(string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Failed_trying_to_build_the_library__0__, OutputPath)))); return(false); } finally { if (!KeepRedundant) { FileEx.SafeDelete(redundantLibrary, true); } } return(true); }
public bool BuildLibrary(IProgressMonitor progress) { _ambiguousMatches = null; IProgressStatus status = new ProgressStatus(Resources.BiblioSpecLiteBuilder_BuildLibrary_Preparing_to_build_library); progress.UpdateProgress(status); if (InputFiles.Any(f => f.EndsWith(EXT_PILOT))) { try { InputFiles = VendorIssueHelper.ConvertPilotFiles(InputFiles, progress, status); if (progress.IsCanceled) { return(false); } } catch (Exception x) { progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } } string message = string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Building__0__library, Path.GetFileName(OutputPath)); progress.UpdateProgress(status = status.ChangeMessage(message)); string redundantLibrary = BiblioSpecLiteSpec.GetRedundantName(OutputPath); var blibBuilder = new BlibBuild(redundantLibrary, InputFiles, TargetSequences) { IncludeAmbiguousMatches = IncludeAmbiguousMatches, CutOffScore = CutOffScore, Id = Id, PreferEmbeddedSpectra = PreferEmbeddedSpectra, DebugMode = DebugMode, }; bool retry = true; do { try { if (!blibBuilder.BuildLibrary(Action, progress, ref status, out _buildCommandArgs, out _buildOutput, out _ambiguousMatches)) { return(false); } retry = false; } catch (IOException x) { if (IsLibraryMissingExternalSpectraError(x, out string spectrumFilename, out string resultsFilepath)) { // replace the relative path to the results file (e.g. msms.txt) with the absolute path string fullResultsFilepath = InputFiles.SingleOrDefault(o => o.EndsWith(resultsFilepath)) ?? throw new InvalidDataException(@"no results filepath from BiblioSpec error message", x); // TODO: this will break if BiblioSpec output is translated to other languages string messageWithFullFilepath = x.Message.Replace(@"search results file '" + resultsFilepath, @"search results file '" + fullResultsFilepath); var response = progress.UpdateProgress( status.ChangeErrorException(new IOException(messageWithFullFilepath, x))); if (response == UpdateProgressResponse.cancel) { return(false); } else if (response == UpdateProgressResponse.normal) { blibBuilder.PreferEmbeddedSpectra = true; } continue; } progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } catch (Exception x) { Console.WriteLine(x.Message); progress.UpdateProgress(status.ChangeErrorException( new Exception(string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Failed_trying_to_build_the_redundant_library__0__, redundantLibrary)))); return(false); } } while (retry); var blibFilter = new BlibFilter(); status = new ProgressStatus(message); progress.UpdateProgress(status); // Write the non-redundant library to a temporary file first try { using (var saver = new FileSaver(OutputPath)) { if (!blibFilter.Filter(redundantLibrary, saver.SafeName, progress, ref status)) { return(false); } saver.Commit(); } } catch (IOException x) { progress.UpdateProgress(status.ChangeErrorException(x)); return(false); } catch { progress.UpdateProgress(status.ChangeErrorException( new Exception(string.Format(Resources.BiblioSpecLiteBuilder_BuildLibrary_Failed_trying_to_build_the_library__0__, OutputPath)))); return(false); } finally { if (!KeepRedundant) { FileEx.SafeDelete(redundantLibrary, true); } } return(true); }
internal List <string> GetAbsoluteInputFiles() { List <string> files = new List <string>(); if (!InputFiles.Any()) { return(files); } string folder = new DirectoryInfo(Path.GetDirectoryName(FileName)).FullName; string ext = Path.GetExtension(InputFiles.First()); Options options = new Options { AllowWindowsPaths = true }; foreach (string inputFile in InputFiles.Where(f => !f.StartsWith("!", StringComparison.Ordinal))) { int globIndex = inputFile.IndexOf('*'); if (globIndex > -1) { string relative = string.Empty; int last = inputFile.LastIndexOf('/', globIndex); if (last > -1) { relative = inputFile.Substring(0, last + 1); } var output = GetAbsoluteOutputFile(); var outputMin = BundleFileProcessor.GetMinFileName(output); string searchDir = new FileInfo(Path.Combine(folder, relative).Replace("/", "\\")).FullName; var allFiles = Directory.EnumerateFiles(searchDir, "*" + ext, SearchOption.AllDirectories).Select(f => f.Replace(folder + "\\", "")); var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f)); matches = matches.Where(match => match != output && match != outputMin); files.AddRange(matches.Where(f => !files.Contains(f))); } else { string fullPath = Path.Combine(folder, inputFile).Replace("/", "\\"); if (Directory.Exists(fullPath)) { DirectoryInfo dir = new DirectoryInfo(fullPath); SearchOption search = SearchOption.TopDirectoryOnly; var dirFiles = dir.GetFiles("*" + Path.GetExtension(OutputFileName), search); files.AddRange(dirFiles.Select(f => f.FullName).Where(f => !files.Contains(f))); } else { files.Add(fullPath); } } } // Remove files starting with a ! foreach (string inputFile in InputFiles) { int globIndex = inputFile.IndexOf('!'); if (globIndex == 0) { var allFiles = files.Select(f => f.Replace(folder + "\\", "")); var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f)); files = matches.ToList(); } } return(files); }