private static Report CheckFiles(Options options, string Compare = null, string Base = null) { //Check Arguments if (string.IsNullOrEmpty(Compare)) { if (options.Items.Count == 2) { Compare = options.Items[0]; } else { throw new ArgumentException("You have to set compare and base csv files!"); } } if (string.IsNullOrEmpty(Base)) { if (options.Items.Count == 2) { Base = options.Items[1]; } else { throw new ArgumentException("You have to set compare and base csv files!"); } } try { using (CsvFile csvCompare = new CsvFile(Compare, options, _log)) { csvCompare.ShowRelativeErrors = !options.AbsoluteError; try { using (CsvFile csvBase = new CsvFile(Base, options, _log)) { //#if DEBUG //Save csv files during DEBUG session // if (!string.IsNullOrEmpty(options.ReportDir)) // { // csvBase.Save(options.ReportDir, options); // csvCompare.Save(options.ReportDir, options); // } // else // { // csvBase.Save(options); // csvCompare.Save(options); // } //#endif _log.WriteLine(LogLevel.Debug, "Exiting with exit code \"{0}\".", Environment.ExitCode); return(csvCompare.CompareFiles(_log, csvBase, ref options)); } } catch (ArgumentException argEx) { _log.Error(argEx.Message); return(null); } catch (FileNotFoundException) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, "Base file \"{0}\" does not exist, exiting.", Base)); } } } catch (ArgumentException ex) { _log.Error("Nothing has been parsed; maybe wrong csv format?"); _log.Error("Exception said: {0}", ex.Message); Environment.ExitCode = 2; return(null); } catch (FileNotFoundException) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, "Compare file \"{0}\" does not exist, exiting.", Compare)); } }
private static Report CheckFiles(Options options, string Compare = null, string Base = null) { //Check Arguments if (string.IsNullOrEmpty(Compare)) if (options.Items.Count == 2) Compare = options.Items[0]; else throw new ArgumentException("You have to set compare and base csv files!"); if (string.IsNullOrEmpty(Base)) if (options.Items.Count == 2) Base = options.Items[1]; else throw new ArgumentException("You have to set compare and base csv files!"); try { using (CsvFile csvCompare = new CsvFile(Compare, options, _log)) { csvCompare.ShowRelativeErrors = !options.AbsoluteError; try { using (CsvFile csvBase = new CsvFile(Base, options, _log)) { //#if DEBUG //Save csv files during DEBUG session // if (!string.IsNullOrEmpty(options.ReportDir)) // { // csvBase.Save(options.ReportDir, options); // csvCompare.Save(options.ReportDir, options); // } // else // { // csvBase.Save(options); // csvCompare.Save(options); // } //#endif _log.WriteLine(LogLevel.Debug, "Exiting with exit code \"{0}\".", Environment.ExitCode); return csvCompare.CompareFiles(_log, csvBase, ref options); } } catch (ArgumentException argEx) { _log.Error(argEx.Message); return null; } catch (FileNotFoundException) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, "Base file \"{0}\" does not exist, exiting.", Base)); } } } catch (ArgumentException ex) { _log.Error("Nothing has been parsed; maybe wrong csv format?"); _log.Error("Exception said: {0}", ex.Message); Environment.ExitCode = 2; return null; } catch (FileNotFoundException) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, "Compare file \"{0}\" does not exist, exiting.", Compare)); } }
private static void CheckFMUTree(ref MetaReport meta, Options options) { DirectoryInfo dirCompare, dirBase; string sTempDir = string.Format(CultureInfo.CurrentCulture, "{0}CSV-Compare-{1:yyyyMMdd}", Path.GetTempPath(), DateTime.Now); dirBase = new DirectoryInfo(options.Items[0]); if (!dirBase.Exists) { _log.Error("The directory \"{0}\" containing fmu files does not exist.", dirBase.FullName); Environment.Exit(2); } string outFile = string.Empty; dirCompare = new DirectoryInfo(sTempDir); if (!dirCompare.Exists) { Directory.CreateDirectory(dirCompare.ToString()); } if (!String.IsNullOrEmpty(options.ReportDir)) { meta = new MetaReport(options.ReportDir); } else { meta = new MetaReport(); } foreach (FileInfo file in dirBase.GetFiles("*.fmu", SearchOption.AllDirectories)) { if (!RunFMUChecker(options, dirCompare, ref outFile, file))//Skip to next FMU on error { continue; } string sBase = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".csv"); _log.WriteLine(LogLevel.Debug, "Searching for csv {0} ", sBase); if (!File.Exists(sBase))//if $FILENAME$.csv could not be found search for protocol.csv { sBase = Path.Combine(file.Directory.FullName, "protocol.csv"); _log.WriteLine(LogLevel.Information, "Not found trying \"{0}\"", sBase); if (!File.Exists(sBase)) { _log.Error("Found nothing to compare with, skipping {0}", file.Name); continue; } } _log.WriteLine(LogLevel.Information, "Trying to compare with \"{0}\"", sBase); try { CsvFile csvCompare = new CsvFile(outFile, options, _log); try { meta.Reports.Add(csvCompare.CompareFiles(_log, new CsvFile(sBase, options, _log), Path.Combine(options.ReportDir, file.Name + ".html"), ref options)); } catch (ArgumentNullException ex) { _log.Error(ex.Message); } } catch (ArgumentException ex) { _log.Error(ex.Message); continue; } } }
private static void CheckFMUTree(ref MetaReport meta, Options options) { DirectoryInfo dirCompare, dirBase; string sTempDir = string.Format(CultureInfo.CurrentCulture, "{0}CSV-Compare-{1:yyyyMMdd}", Path.GetTempPath(), DateTime.Now); dirBase = new DirectoryInfo(options.Items[0]); if (!dirBase.Exists) { _log.Error("The directory \"{0}\" containing fmu files does not exist.", dirBase.FullName); Environment.Exit(2); } string outFile = string.Empty; dirCompare = new DirectoryInfo(sTempDir); if (!dirCompare.Exists) Directory.CreateDirectory(dirCompare.ToString()); if (!String.IsNullOrEmpty(options.ReportDir)) meta = new MetaReport(options.ReportDir); else meta = new MetaReport(); foreach (FileInfo file in dirBase.GetFiles("*.fmu", SearchOption.AllDirectories)) { if (!RunFMUChecker(options, dirCompare, ref outFile, file))//Skip to next FMU on error continue; string sBase = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".csv"); _log.WriteLine(LogLevel.Debug, "Searching for csv {0} ", sBase); if (!File.Exists(sBase))//if $FILENAME$.csv could not be found search for protocol.csv { sBase = Path.Combine(file.Directory.FullName, "protocol.csv"); _log.WriteLine(LogLevel.Information, "Not found trying \"{0}\"", sBase); if (!File.Exists(sBase)) { _log.Error("Found nothing to compare with, skipping {0}", file.Name); continue; } } _log.WriteLine(LogLevel.Information, "Trying to compare with \"{0}\"", sBase); try { CsvFile csvCompare = new CsvFile(outFile, options, _log); try { meta.Reports.Add(csvCompare.CompareFiles(_log, new CsvFile(sBase, options, _log), Path.Combine(options.ReportDir, file.Name + ".html"), ref options)); } catch (ArgumentNullException ex) { _log.Error(ex.Message); } } catch (ArgumentException ex) { _log.Error(ex.Message); continue; } } }