public Report CompareFiles(Log log, CsvFile csvBase, ref Options options) { if (null != _fileName) if (Path.GetDirectoryName(_fileName).Length > 0) return CompareFiles(log, csvBase, string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}_report.html", Path.GetDirectoryName(_fileName), Path.DirectorySeparatorChar, Path.GetFileNameWithoutExtension(csvBase.ToString())), ref options); else return CompareFiles(log, csvBase, Path.GetFileNameWithoutExtension(_fileName) + ".html", ref options); else return CompareFiles(log, csvBase, null, ref options); }
public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Options options) { int iInvalids = 0; Report rep = new Report(sReportPath); log.WriteLine("Comparing \"{0}\" to \"{1}\"", _fileName, csvBase.ToString()); rep.BaseFile = csvBase.ToString(); rep.CompareFile = _fileName; Curve reference = new Curve(); Curve compareCurve = new Curve(); TubeReport tubeReport = new TubeReport(); TubeSize size = null; Tube tube = new Tube(size); IOptions tubeOptions = new Options1(_dRangeDelta, Axes.X); foreach (KeyValuePair<string, List<double>> res in csvBase.Results) { if (!this.Results.ContainsKey(res.Key)) log.WriteLine(LogLevel.Warning, "{0} not found in \"{1}\", skipping checks.", res.Key, this._fileName); else { compareCurve = new Curve(res.Key, this.XAxis.ToArray<double>(), this.Results[res.Key].ToArray<double>()); if (res.Value.Count == 0) { log.Error("{0} has no y-Values! Maybe error during parsing? Skipping", res.Key); continue; } reference = new Curve("Reference ", csvBase.XAxis.ToArray(), csvBase.Results[res.Key].ToArray()); if (!reference.ImportSuccessful) { log.Error("Error in the calculation of the tubes. Skipping {0}", res.Key); rep.Chart.Add(new Chart() { Title = res.Key, Errors = 1 }); continue; } if (reference.X.Length < compareCurve.X.Length) log.WriteLine(LogLevel.Warning, "The resolution of the base x-axis is smaller than the compare x-axis. The better the base resolution is, the better the validation result will be!"); else log.WriteLine(LogLevel.Debug, "The resolution of the base x-axis is good."); size = new TubeSize(reference, true); size.Calculate(_dRangeDelta, Axes.X, Relativity.Relative); tube = new Tube(size); tubeReport = tube.Calculate(reference); tube.Validate(compareCurve); if (tubeReport.Valid == Validity.Valid) log.WriteLine(res.Key + " is valid"); else { log.WriteLine(LogLevel.Warning, "{0} is invalid! {1} errors have been found during validation.", res.Key, (null != tube.Report.Errors && null != tube.Report.Errors.X) ? tube.Report.Errors.X.Length : 0); iInvalids++; Environment.ExitCode = 1; } } if (null != tube.Report)//No charts for missing reports PrepareCharts(reference, compareCurve, tube.Report.Errors, rep, tubeReport, res, options.UseBitmapPlots); } rep.Tolerance = _dRangeDelta; string sResult = "na"; if (rep.TotalErrors == 0) sResult = "passed"; else sResult = "failed"; if (options.ComparisonFlag) using (TextWriter writer = File.CreateText(string.Format("{0}{1}compare_{2}.log", Path.GetDirectoryName(_fileName), Path.DirectorySeparatorChar, sResult))) { //Content needs to be defined writer.WriteLine("CSV Compare Version {0} ({1})", Info.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); writer.WriteLine("Comparison result file for {0}", _fileName); writer.WriteLine(". Time: {0:o}", DateTime.Now); writer.WriteLine(". Operation: {0}", options.Mode); writer.WriteLine(". Tolerance: {0}", options.Tolerance); writer.WriteLine(". Result: {0}", sResult); if (rep.TotalErrors > 0) { Chart pairMax = rep.Chart.Aggregate((l, r) => l.DeltaError > r.DeltaError ? l : r); writer.WriteLine(". Biggest error: {0}=>{1}", pairMax.Title, pairMax.DeltaError); writer.WriteLine(". Failed values:"); foreach (Chart c in (from r in rep.Chart where r.DeltaError > 0 select r).OrderByDescending(er => er.DeltaError)) writer.WriteLine("{0}=>{1}", c.Title, c.DeltaError); } } rep.WriteReport(log, (!string.IsNullOrEmpty(options.ReportDir)) ? options.ReportDir : string.Empty, options); GC.Collect();//immediately forget big charts and data return rep; }
private static void Run(string[] cmdArgs) { var options = new Options(); Parser parser = new Parser(); if (parser.ParseArguments(cmdArgs, options)) { if (options.Verbosity > 0) _log.Verbosity = (LogLevel)options.Verbosity; else #if DEBUG _log.Verbosity = LogLevel.Debug; #endif _log.WriteLine(LogLevel.Debug, "Using CSV Compare Version {0} ({1})", Info.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); _log.WriteLine(LogLevel.Debug, "Starting new result check @{0}", DateTime.Now); _log.WriteLine(LogLevel.Debug, "Parsing commandline options: {0} * {1}", Environment.NewLine, string.Join(" ", cmdArgs)); _log.WriteLine(LogLevel.Debug, "Successfully parsed the following options:"); _log.WriteLine(LogLevel.Debug, "Operation mode is {0}", options.Mode); _log.WriteLine(LogLevel.Debug, "Tolerance is {0}", options.Tolerance); if (options.Delimiter == 0) { _log.WriteLine(LogLevel.Debug, "Delimiter is not explicitly set, so I am using \";\""); options.Delimiter = ';'; } else _log.WriteLine(LogLevel.Debug, "Delimiter to be used to parse csv has been explicitly set and is \"{0}\"", options.Delimiter); if (null == options.Logfile) _log.WriteLine(LogLevel.Debug, "Logfile is empty"); else { if (!options.OverrideOutput && File.Exists(options.Logfile)) { options.Logfile = Path.Combine(Path.GetDirectoryName(options.Logfile), string.Format(CultureInfo.CurrentCulture, "{0:yyyy-MM-ddTHH-mm-ss}_log.txt", DateTime.Now)); _log.WriteLine(LogLevel.Warning, "Logfile already exists and --override has been set to false. Changed log file name to \"{0}\"", options.Logfile); } else _log.WriteLine(LogLevel.Debug, "Logfile is {0}", options.Logfile); _log.SetLogFile(new FileInfo(options.Logfile)); } if (options.Items.Count == 0) { _log.Error("No files or directories to be compared have been given."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } MetaReport meta = new MetaReport(); if (String.IsNullOrEmpty(options.ReportDir))//report to directory of compare file if no report directory has been set { FileAttributes attr = File.GetAttributes(options.Items[0]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) options.ReportDir = Path.GetFullPath(options.Items[0]); else options.ReportDir = Path.GetDirectoryName(options.Items[0]); _log.WriteLine(LogLevel.Warning, "No report directory has been set, using \"{0}\"", options.ReportDir); } else { meta.ReportDirSet = true; options.ReportDir = Path.GetFullPath(options.ReportDir);//normalize report dir (i.e. make absolut if relative) if (!Directory.Exists(options.ReportDir)) Directory.CreateDirectory(options.ReportDir); } meta.FileName = new FileInfo(Path.Combine(options.ReportDir, string.Format(CultureInfo.CurrentCulture, "{0:yyyy-MM-dd}-index.html", DateTime.Now))); switch (options.Mode) { case OperationMode.CsvFileCompare://compare the file given as option 1 with the file given as option 2 if (options.Items.Count != 2) { _log.Error("Not enough arguments have been given. Please specify base and compare file."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } Report rep = CheckFiles(options); if (null != rep && !options.NoMetaReport) { meta.Reports.Add(rep);//Return "1" on invalid testresults meta.WriteReport(_log, options); } break; case OperationMode.CsvTreeCompare://compare files in the dirctory option 1 with the files in directory option 2 if (options.Items.Count != 2) { _log.Error("Not enough arguments have been given. Please specify base and compare directory."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } CheckTrees(meta, options); if(!options.NoMetaReport) meta.WriteReport(_log, options); break; case OperationMode.FmuChecker://run FMU checker on all fmus in directory given via option 1 and compare the result to CSVs in the source directory if (options.Items.Count != 1) { if (options.Items.Count == 0) _log.Error("Not enough arguments have been given. Please specify a compare directory with FMUs."); else _log.Error("Too many arguments have been given. Please specify a compare directory with FMUs only."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } if (string.IsNullOrEmpty(options.CheckerPath)) { _log.Error("No path to FMU Checker binary given."); Console.WriteLine(options.GetUsage()); } else { CheckFMUTree(ref meta, options); meta.WriteReport(_log, options); } break; case OperationMode.PlotOnly: foreach (string item in options.Items) using (CsvFile file = new CsvFile(item, options, _log)) { meta.Reports.Add(file.PlotCsvFile(null, _log)); } meta.WriteReport(_log, options); break; default://Invalid mode Console.WriteLine(options.GetUsage()); break; } } else Console.WriteLine(options.GetUsage()); #if DEBUG //Keep window open in debug mode _log.WriteLine(LogLevel.Debug, "Done."); Console.ReadLine(); #endif }
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; } } }
public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Options options) { int iInvalids = 0; Report rep = new Report(sReportPath); log.WriteLine("Comparing \"{0}\" to \"{1}\"", _fileName, csvBase.ToString()); rep.BaseFile = csvBase.ToString(); rep.CompareFile = _fileName; Curve reference = new Curve(); Curve compareCurve = new Curve(); TubeReport tubeReport = new TubeReport(); TubeSize size = null; Tube tube = new Tube(size); IOptions tubeOptions = new Options1(_dRangeDelta, Axes.X); foreach (KeyValuePair <string, List <double> > res in csvBase.Results) { if (!this.Results.ContainsKey(res.Key)) { log.WriteLine(LogLevel.Warning, "{0} not found in \"{1}\", skipping checks.", res.Key, this._fileName); } else { compareCurve = new Curve(res.Key, this.XAxis.ToArray <double>(), this.Results[res.Key].ToArray <double>()); if (res.Value.Count == 0) { log.Error("{0} has no y-Values! Maybe error during parsing? Skipping", res.Key); continue; } reference = new Curve("Reference ", csvBase.XAxis.ToArray(), csvBase.Results[res.Key].ToArray()); if (!reference.ImportSuccessful) { log.Error("Error in the calculation of the tubes. Skipping {0}", res.Key); rep.Chart.Add(new Chart() { Title = res.Key, Errors = 1 }); continue; } if (reference.X.Length < compareCurve.X.Length) { log.WriteLine(LogLevel.Warning, "The resolution of the base x-axis is smaller than the compare x-axis. The better the base resolution is, the better the validation result will be!"); } else { log.WriteLine(LogLevel.Debug, "The resolution of the base x-axis is good."); } size = new TubeSize(reference, true); size.Calculate(_dRangeDelta, Axes.X, Relativity.Relative); tube = new Tube(size); tubeReport = tube.Calculate(reference); tube.Validate(compareCurve); if (tubeReport.Valid == Validity.Valid) { log.WriteLine(res.Key + " is valid"); } else { log.WriteLine(LogLevel.Warning, "{0} is invalid! {1} errors have been found during validation.", res.Key, (null != tube.Report.Errors && null != tube.Report.Errors.X) ? tube.Report.Errors.X.Length : 0); iInvalids++; Environment.ExitCode = 1; } } if (null != tube.Report)//No charts for missing reports { PrepareCharts(reference, compareCurve, tube.Report.Errors, rep, tubeReport, res, options.UseBitmapPlots); } } rep.Tolerance = _dRangeDelta; string sResult = "na"; if (rep.TotalErrors == 0) { sResult = "passed"; } else { sResult = "failed"; } if (options.ComparisonFlag) { using (TextWriter writer = File.CreateText(string.Format("{0}{1}compare_{2}.log", Path.GetDirectoryName(_fileName), Path.DirectorySeparatorChar, sResult))) { //Content needs to be defined writer.WriteLine("CSV Compare Version {0} ({1})", Info.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); writer.WriteLine("Comparison result file for {0}", _fileName); writer.WriteLine(". Time: {0:o}", DateTime.Now); writer.WriteLine(". Operation: {0}", options.Mode); writer.WriteLine(". Tolerance: {0}", options.Tolerance); writer.WriteLine(". Result: {0}", sResult); if (rep.TotalErrors > 0) { Chart pairMax = rep.Chart.Aggregate((l, r) => l.DeltaError > r.DeltaError ? l : r); writer.WriteLine(". Biggest error: {0}=>{1}", pairMax.Title, pairMax.DeltaError); writer.WriteLine(". Failed values:"); foreach (Chart c in (from r in rep.Chart where r.DeltaError > 0 select r).OrderByDescending(er => er.DeltaError)) { writer.WriteLine("{0}=>{1}", c.Title, c.DeltaError); } } } } rep.WriteReport(log, (!string.IsNullOrEmpty(options.ReportDir)) ? options.ReportDir : string.Empty, options); GC.Collect();//immediately forget big charts and data return(rep); }
private static void Run(string[] cmdArgs) { var options = new Options(); Parser parser = new Parser(); if (parser.ParseArguments(cmdArgs, options)) { if (options.Verbosity > 0) { _log.Verbosity = (LogLevel)options.Verbosity; } else #if DEBUG { _log.Verbosity = LogLevel.Debug; } #endif { _log.WriteLine(LogLevel.Debug, "Using CSV Compare Version {0} ({1})", Info.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); } _log.WriteLine(LogLevel.Debug, "Starting new result check @{0}", DateTime.Now); _log.WriteLine(LogLevel.Debug, "Parsing command line options: {0} * {1}", Environment.NewLine, string.Join(" ", cmdArgs)); _log.WriteLine(LogLevel.Debug, "Successfully parsed the following options:"); _log.WriteLine(LogLevel.Debug, "Operation mode is {0}", options.Mode); _log.WriteLine(LogLevel.Debug, "Tolerance is {0}", options.Tolerance); if (options.Delimiter == 0) { _log.WriteLine(LogLevel.Debug, "Delimiter is not explicitly set, so I am using \";\""); options.Delimiter = ';'; } else { _log.WriteLine(LogLevel.Debug, "Delimiter to be used to parse CSV has been explicitly set and is \"{0}\"", options.Delimiter); } if (null == options.Logfile) { _log.WriteLine(LogLevel.Debug, "Logfile is empty"); } else { if (!options.OverrideOutput && File.Exists(options.Logfile)) { options.Logfile = Path.Combine(Path.GetDirectoryName(options.Logfile), string.Format(CultureInfo.CurrentCulture, "{0:yyyy-MM-ddTHH-mm-ss}_log.txt", DateTime.Now)); _log.WriteLine(LogLevel.Warning, "Logfile already exists and --override has been set to false. Changed log file name to \"{0}\"", options.Logfile); } else { _log.WriteLine(LogLevel.Debug, "Logfile is {0}", options.Logfile); } _log.SetLogFile(new FileInfo(options.Logfile)); } if (options.Items.Count == 0) { _log.Error("No files or directories to be compared have been given."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } MetaReport meta = new MetaReport(); if (String.IsNullOrEmpty(options.ReportDir))//report to directory of compare file if no report directory has been set { FileAttributes attr = File.GetAttributes(options.Items[0]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { options.ReportDir = GetFullPathWithEndingSlashes(options.Items[0]); } else { options.ReportDir = GetFullPathWithEndingSlashes(Path.GetDirectoryName(options.Items[0])); } _log.WriteLine(LogLevel.Warning, "No report directory has been set, using \"{0}\"", options.ReportDir); } else { meta.ReportDirSet = true; options.ReportDir = GetFullPathWithEndingSlashes(options.ReportDir);//normalize report dir (i.e. make absolut if relative) if (!Directory.Exists(options.ReportDir)) { Directory.CreateDirectory(options.ReportDir); } } meta.FileName = new FileInfo(Path.Combine(options.ReportDir, string.Format(CultureInfo.CurrentCulture, "{0:yyyy-MM-dd}-index.html", DateTime.Now))); switch (options.Mode) { case OperationMode.CsvFileCompare: //compare the file given as option 1 with the file given as option 2 if (options.Items.Count != 2) { _log.Error("Not enough arguments have been given. Please specify base and compare file."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } Report rep = CheckFiles(options); if (null != rep && !options.NoMetaReport) { meta.Reports.Add(rep); //Return "1" on invalid testresults meta.WriteReport(_log, options); } break; case OperationMode.CsvTreeCompare: //compare files in the dirctory option 1 with the files in directory option 2 if (options.Items.Count != 2) { _log.Error("Not enough arguments have been given. Please specify base and compare directory."); Console.WriteLine(options.GetUsage()); Environment.Exit(2); } options.Items[0] = GetFullPathWithEndingSlashes(options.Items[0]); options.Items[1] = GetFullPathWithEndingSlashes(options.Items[1]); CheckTrees(meta, options); if (!options.NoMetaReport) { meta.WriteReport(_log, options); } break; case OperationMode.FmuChecker: //run FMU checker on all FMUs in directory given via option 1 and compare the result to CSVs in the source directory if (options.Items.Count != 1) { if (options.Items.Count == 0) { _log.Error("Not enough arguments have been given. Please specify a compare directory with FMUs."); } else { _log.Error("Too many arguments have been given. Please specify a compare directory with FMUs only."); } Console.WriteLine(options.GetUsage()); Environment.Exit(2); } if (string.IsNullOrEmpty(options.CheckerPath)) { _log.Error("No path to FMU Checker binary given."); Console.WriteLine(options.GetUsage()); } else { CheckFMUTree(ref meta, options); meta.WriteReport(_log, options); } break; case OperationMode.PlotOnly: foreach (string item in options.Items) { using (CsvFile file = new CsvFile(item, options, _log)) { meta.Reports.Add(file.PlotCsvFile(_log)); } } foreach (Report r in meta.Reports) { if (!r.WriteReport(_log, options.NoMetaReport ? null : meta.FileName.FullName, options)) { _log.Error("Error writing report to {0}", r.FileName); } } if (!options.NoMetaReport) { meta.WriteReport(_log, options); } break; default: //Invalid mode Console.WriteLine(options.GetUsage()); break; } } else { Console.WriteLine(options.GetUsage()); } #if DEBUG //Keep window open in debug mode _log.WriteLine(LogLevel.Debug, "Done."); Console.ReadLine(); #endif }
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; } } }