private void DiffReader_OnProgressChanged(DiffReader sender, string message) { base.Invoke((Action) delegate { diffPreview.Add(message); if (diffPreview.Count > 10) { diffPreview.RemoveAt(0); } diffRichTextBox.Text = string.Join("\n", diffPreview.ToArray()); }); }
// Worker event handlers private void DiffReader_OnFinished(DiffReader sender, string message) { base.Invoke((Action) delegate { startButton.Enabled = true; pauseButton.Enabled = false; resumeButton.Enabled = false; cancelDiffButton.Enabled = false; diffFileButton.Enabled = true; diffFileTextBox.Enabled = true; firstHashButton.Enabled = true; secondHashButton.Enabled = true; noFileCheckBox.Enabled = true; diffStatusLabel.Text = message; if (windowClosing) { Close(); } }); }
// UI event handlers private void StartButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(file1TextBox.Text) || string.IsNullOrEmpty(file2TextBox.Text)) { diffStatusLabel.Text = "Input files are invalid."; return; } if (!noFileCheckBox.Checked && string.IsNullOrEmpty(diffFileTextBox.Text)) { diffStatusLabel.Text = "Output file is invalid."; return; } diffPreview.Clear(); startButton.Enabled = false; pauseButton.Enabled = true; cancelDiffButton.Enabled = true; firstHashButton.Enabled = false; secondHashButton.Enabled = false; diffFileButton.Enabled = false; diffFileTextBox.Enabled = false; noFileCheckBox.Enabled = false; diffStatusLabel.Text = "-"; diffReader = new DiffReader(); diffReader.File1 = file1TextBox.Text; diffReader.File2 = file2TextBox.Text; diffReader.WriteOutputToFile = !noFileCheckBox.Checked; diffReader.OnProgressChanged += DiffReader_OnProgressChanged; diffReader.OnFinished += DiffReader_OnFinished; diffReader.OutputFile = diffFileTextBox.Text; diffReader.Start(); }
private static DiffSet ReadDiff(string doc) { DiffSet diff; using (TextReader rdr = new StringReader(doc)) { diff = new DiffReader().Read(rdr); } return diff; }
static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { if (!File.Exists(options.DiffFile)) { Console.WriteLine("ERROR: diff file does not exist"); } if (options.Verbose) { Console.WriteLine("Processing {0}", options.DiffFile); } var reader = new DiffReader(options.DiffFile); var diff = reader.Read(); if (!String.IsNullOrEmpty(options.WordOutput)) { if (options.Verbose) { Console.WriteLine("Creating word output {0}", options.WordOutput); } var wordOutput = new WordFormatter(options.WordOutput) { Title = options.Title, Summary = options.Summary, ShowDeletedFileContents = options.ShowDeleteFileContents, ShowCreatedFileContents = options.ShowCreatedFileContents }; wordOutput.Execute(diff); } if (!String.IsNullOrEmpty(options.HtmlOutput)) { if (options.Verbose) { Console.WriteLine("Creating html output {0}", options.HtmlOutput); } var htmlOutput = new HtmlFormatter(options.HtmlOutput) { Title = options.Title, Summary = options.Summary, ShowDeletedFileContents = options.ShowDeleteFileContents, ShowCreatedFileContents = options.ShowCreatedFileContents }; htmlOutput.Execute(diff); } if (options.Verbose || (String.IsNullOrEmpty(options.WordOutput) && String.IsNullOrEmpty(options.HtmlOutput))) { var consoleOutput = new ConsoleFormatter(); consoleOutput.Execute(diff); } } if (options.Verbose) { Console.Write("Press enter to quit: "); Console.ReadKey(); } }