public string Run(IParser parser, IFileInspector fileInspector, string[] args) { var options = parser.Parse(args); if (options.ShowUsage) { //We could be more specific about what was missing, but most command line apps just show you the general usage instructions. return("FileData.exe (-s | -v) filenane"); } var fileInfo = fileInspector.InspectFile(options); //Format the resuls for the user var result = new List <string>(); if (fileInfo.Size.HasValue) { result.Add($"Size: {fileInfo.Size.Value}"); } if (!string.IsNullOrEmpty(fileInfo.Version)) { result.Add($"Version: {fileInfo.Version}"); } return(result.Count() > 0 ? string.Join(", ", result.ToArray()) : "No file information"); }
private void mainBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var dir = new DirectoryInfo(pathTextBox.Text); var files = dir.EnumerateFiles().Where(f => (f.Name.Contains(".txt")) || (f.Name.Contains(".bin"))).ToArray(); mainBackgroundWorker.ReportProgress(0); // using parenthesees to make loop stop condition clear for (var i = 1; i < (files.Length + 1); i++) { var start = DateTime.Now.Millisecond; var file = files[i - 1]; var progressVal = (int)((double)i / (double)files.Length * 100.00); var result = _inspector.InspectFile(file, lookupStringTextBox.Text); var stop = DateTime.Now.Millisecond; var lookupTime = stop - start; var msg = $"In a file : {file.Name} Pattern: {lookupStringTextBox.Text} occured: {result} times. " + $"Lookup took: {lookupTime}ms{Environment.NewLine}"; mainBackgroundWorker.ReportProgress(progressVal, msg); } }