public void DoCompare(string file1, string file2) { try { MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 18; MainProBar.Value = 6; MainProBar.Step = 1; MainProBar.PerformStep(); //Convert HL7 to XML System.IO.StreamReader InputFile = new System.IO.StreamReader(file1); string InputHL7 = InputFile.ReadToEnd(); InputFile.Close(); InputHL7 = InputHL7.Replace((Char)127, (Char)13); String InputHL7asXml = HL7ToXmlConverter.ConvertToXml(InputHL7, ""); string myTempFile1 = Path.Combine(Path.GetTempPath(), "Input.xml"); System.IO.StreamWriter fileI = new System.IO.StreamWriter(myTempFile1); fileI.WriteLine(InputHL7asXml); fileI.Close(); file1 = myTempFile1; MainProBar.PerformStep(); System.IO.StreamReader OutputFile = new System.IO.StreamReader(file2); string OutputHL7 = OutputFile.ReadToEnd(); OutputFile.Close(); OutputHL7 = OutputHL7.Replace((Char)127, (Char)13); String OutputHL7asXml = HL7ToXmlConverter.ConvertToXml(OutputHL7, ""); string myTempFile2 = Path.Combine(Path.GetTempPath(), "Output.xml"); System.IO.StreamWriter fileO = new System.IO.StreamWriter(myTempFile2); fileO.WriteLine(OutputHL7asXml); fileO.Close(); file2 = myTempFile2; MainProBar.PerformStep(); string startupPath = Application.StartupPath; //output diff file. diffFile = startupPath + Path.DirectorySeparatorChar + "vxd.out"; XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile)); tw.Formatting = Formatting.Indented; MainProBar.PerformStep(); //This method sets the diff.Options property. SetDiffOptions(); bool isEqual = false; //Now compare the two files. try { isEqual = diff.Compare(file1, file2, compareFragments, tw); } catch (XmlException xe) { xe.StackTrace.ToString(); //MessageBox.Show("An exception occured while comparing\n" + xe.StackTrace); } finally { tw.Close(); } MainProBar.PerformStep(); if (isEqual) { //This means the files were identical for given options. MessageBox.Show("Files Identical for the given options"); MainProBar.Value = 1; return; //dont need to show the differences. } MainProBar.PerformStep(); //Files were not equal, so construct XmlDiffView. XmlDiffView dv = new XmlDiffView(); //Load the original file again and the diff file. XmlTextReader orig = new XmlTextReader(file1); XmlTextReader diffGram = new XmlTextReader(diffFile); dv.Load(orig, diffGram); MainProBar.PerformStep(); //Wrap the HTML file with necessary html and //body tags and prepare it before passing it to the GetHtml method. string tempFile = startupPath + Path.DirectorySeparatorChar + "Compare_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; StreamWriter sw1 = new StreamWriter(tempFile); MainProBar.PerformStep(); sw1.Write("<html><body><table width='100%'>"); //Write Legend. sw1.Write("<tr><td colspan='2' align='center'><b>Legend:</b> <font style='background-color: yellow'" + " color='black'>added</font> <font style='background-color: red'" + " color='black'>removed</font> <font style='background-color: " + "lightgreen' color='black'>changed</font> " + "<font style='background-color: red' color='blue'>moved from</font>" + " <font style='background-color: yellow' color='blue'>moved to" + "</font> <font style='background-color: white' color='#AAAAAA'>" + "ignored</font></td></tr>"); sw1.Write("<tr><td><b> File Name : "); sw1.Write(OriginalPath.Text); sw1.Write("</b></td><td><b> File Name : "); sw1.Write(ComparePath.Text); sw1.Write("</b></td></tr>"); MainProBar.PerformStep(); //This gets the differences but just has the //rows and columns of an HTML table dv.GetHtml(sw1); MainProBar.PerformStep(); //Finish wrapping up the generated HTML and complete the file. sw1.Write("</table></body></html>"); //Open the IE Control window and pass it the HTML file we created. ReportWindow.Navigate(new Uri(tempFile)); MainProBar.PerformStep(); //HouseKeeping...close everything we dont want to lock. dv = null; file1 = null; file2 = null; sw1.Close(); orig.Close(); diffGram.Close(); orig.Dispose(); diffGram.Dispose(); tw.Dispose(); sw1.Dispose(); fileI.Dispose(); fileO.Dispose(); File.Delete(diffFile); GC.Collect(); MainProBar.PerformStep(); MainProBar.PerformStep(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }