private void loadFiles() { origfile = new InputFile(txtOrig.Text); newfile = new InputFile(txtNew.Text); lbxCols.DataSource = Differ.GetCommonColNames(origfile, newfile); for (int i = 0; i < lbxCols.Items.Count; i++) { lbxCols.SetSelected(i, true); } }
private void btnGo_Click(object sender, EventArgs e) { if (origfile == null || newfile == null || txtTol.Text == "" || lbxCols.SelectedItems.Count == 0) { MessageBox.Show("Invalid inputs, please make sure 2 files are specified, at least 1 column is selected and some kind of 'Tolerance' is specified"); return; } if (txtTol.Text == "0" && !radDP.Checked) { if (MessageBox.Show("Tolerance entered is exclusive upper bound, therefore entering a value of '0' may cause every single comparison to fail\r\nContinue?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } StringBuilder sb = new StringBuilder(); try { Differ.Diff( origfile, newfile, lbxCols.SelectedItems.Cast <string>().ToList(), decimal.Parse(txtTol.Text), radAbs.Checked ? DiffMethod.abs : radDP.Checked ? DiffMethod.dp : DiffMethod.pct, ref sb ); string[] s; rtxtOutput.Text = sb.ToString(); } catch (Exception ex) { MessageBox.Show("ERROR - Please check output text box for details"); rtxtOutput.Text = sb.ToString() + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace; } }
/// <summary> /// Actually run the Differ using the arguments provided to the constructor /// </summary> /// <returns>The number of files that failed diffs</returns> public int Run() { //load our inputs into Dictionairies. 'Key' is Path.FileNameWithoutExtension('Value') //'Pairify' matches the a and b dictionary keys up, returning a dictionary with 'b' keys as the 'Key's and 'a' keys as //the 'Value's (this is how we figure out which files to diff against) Dictionary <string, string> a = Dictionaryify(getFiles(args.A, args.Filter)), b = Dictionaryify(getFiles(args.B, args.Filter)), pairs = Pairify(a, b); int bad_result = 0; bool report_individually = report == null; //process the files foreach (KeyValuePair <string, string> pair in pairs) { bool reported = false; //stringbuilder used for reporting StringBuilder info = new StringBuilder(); try { //append file names in the order 'new' then 'orig' info.AppendFormat("{0}\t{1}\t", b[pair.Key], a[pair.Value]); //load our files into a form where the differ can recognise them InputFile f_orig = new InputFile(a[pair.Value]), f_new = new InputFile(b[pair.Key]); //diff the files, if there are any errors it will return 'false' (StringBuilder 'info' is passed in by ref here for reporting purposes) //note that all common columns will be diffed if (!Differ.Diff(f_orig, f_new, Differ.GetCommonColNames(f_orig, f_new), args.Tolerance, args.Method, ref info)) { //if we failed then increment our total fails bad_result++; //let 'finally' know we want to report a fail reported = true; } } catch (Exception e) { //if there was an exception for this file then report it as a failed diff bad_result++; info.AppendFormat("ERROR\t{0}\n{1}\n", e.Message, e.StackTrace); reported = true; } finally { //if reporting individually, only report if there was an error (easier to tell which files failed then becasue they will the the only ones with logs) if (report_individually && reported) { if (args.Output != null) { using (report = new StreamWriter(Path.Combine(args.Output, pair.Key + ".txt"))) report.Write(info.ToString()); } else { using (report = new StreamWriter(b[pair.Key] + ".txt")) report.Write(info.ToString()); } } //if not reporting individually the write 'info' to the log file regardless of whetehr it passed or failed else if (!report_individually) { report.WriteLine(info.ToString()); } } } report.Close(); return(bad_result); }