Ejemplo n.º 1
0
        /// <summary>
        /// Generates output data in html form when the node has not changed
        /// </summary>
        /// <param name="writer">output data stream</param>
        /// <param name="indent">size of indentation</param>
        internal void DrawHtmlNoChange(XmlWriter writer, int indent)
        {
            Debug.Assert(this.NodeType != XmlNodeType.Element && this.NodeType != XmlNodeType.Attribute);
            Debug.Assert(this.Operation != XmlDiffViewOperation.Change);
            XmlDiffView.HtmlStartRow(writer);
            this.DrawLinkNode(writer);

            for (int i = 0; i < 2; i++)
            {
                XmlDiffView.HtmlStartCell(writer, indent);
                if (XmlDiffView.HtmlWriteToPane[(int)this.Operation, i])
                {
                    bool closeElement = this.OutputNavigationHtml(writer);
                    XmlDiffView.HtmlWriteString(
                        writer,
                        this.Operation,
                        this.OuterXml);
                    if (closeElement)
                    {
                        writer.WriteEndElement();
                    }
                }
                else
                {
                    XmlDiffView.HtmlWriteEmptyString(writer);
                }
                XmlDiffView.HtmlEndCell(writer);
            }
            XmlDiffView.HtmlEndRow(writer);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Generates output data in text form for a difference due
 /// to adding data.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="typeOfDifference">type of difference</param>
 /// <param name="tagStart">xml tags at start of statement</param>
 /// <param name="tagEnd">xml tags at end of statement</param>
 private void DrawHtmlName(
     XmlWriter writer,
     XmlDiffViewOperation typeOfDifference,
     string tagStart,
     string tagEnd)
 {
     if (this.Prefix != string.Empty && this.ignorePrefixes)
     {
         XmlDiffView.HtmlWriteString(
             writer,
             typeOfDifference,
             tagStart);
         XmlDiffView.HtmlWriteString(
             writer,
             XmlDiffViewOperation.Ignore,
             this.Prefix + ":");
         XmlDiffView.HtmlWriteString(
             writer,
             typeOfDifference,
             this.LocalName + tagEnd);
     }
     else
     {
         XmlDiffView.HtmlWriteString(
             writer,
             typeOfDifference,
             tagStart + this.Name + tagEnd);
     }
 }
Ejemplo n.º 3
0
 internal override void DrawHtml(XmlWriter writer, int indent)
 {
     if (this._op == XmlDiffViewOperation.Change)
     {
         var op1 = this._name == this._changeInfo._localName ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change;
         var op2 = this._value == this._changeInfo._value ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change;
         XmlDiffView.HtmlStartRow(writer);
         XmlDiffView.HtmlStartCell(writer, indent);
         XmlDiffView.HtmlWriteString(writer, "<?");
         XmlDiffView.HtmlWriteString(writer, op1, this._name);
         XmlDiffView.HtmlWriteString(writer, " ");
         XmlDiffView.HtmlWriteString(writer, op2, this._value);
         XmlDiffView.HtmlWriteString(writer, "?>");
         XmlDiffView.HtmlEndCell(writer);
         XmlDiffView.HtmlStartCell(writer, indent);
         XmlDiffView.HtmlWriteString(writer, "<?");
         XmlDiffView.HtmlWriteString(writer, op1, this._changeInfo._localName);
         XmlDiffView.HtmlWriteString(writer, " ");
         XmlDiffView.HtmlWriteString(writer, op2, this._changeInfo._value);
         XmlDiffView.HtmlWriteString(writer, "?>");
         XmlDiffView.HtmlEndCell(writer);
         XmlDiffView.HtmlEndRow(writer);
     }
     else
     {
         this.DrawHtmlNoChange(writer, indent);
     }
 }
        internal static void Equal(string file1, string file2)
        {
            var diffFile = @"diff.xml";
            XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile));
            tw.Formatting = Formatting.Indented;
            var diff = new XmlDiff();
            diff.Options = XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl;
            var result = diff.Compare(file1, file2, false, tw);
            tw.Close();
            if (!result)
            {
                //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);
                string tempFile = "test.htm";

                StreamWriter sw1 = new StreamWriter(tempFile);
                //Wrapping
                sw1.Write("<html><body><table>");
                sw1.Write("<tr><td><b>");
                sw1.Write(file1);
                sw1.Write("</b></td><td><b>");
                sw1.Write(file2);
                sw1.Write("</b></td></tr>");

                //This gets the differences but just has the 
                //rows and columns of an HTML table
                dv.GetHtml(sw1);

                //Finish wrapping up the generated HTML and 
                //complete the file by putting legend in the end just like the 
                //online tool.

                sw1.Write("<tr><td><b>Legend:</b> <font style='background-color: yellow'" +
                " color='black'>added</font>&nbsp;&nbsp;<font style='background-color: red'" +
                "color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: " +
                "lightgreen' color='black'>changed</font>&nbsp;&nbsp;" +
                "<font style='background-color: red' color='blue'>moved from</font>" +
                "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to" +
                "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>" + "ignored</font></td></tr>");

                sw1.Write("</table></body></html>");

                //HouseKeeping...close everything we dont want to lock.
                sw1.Close();
                orig.Close();
                diffGram.Close();
                Process.Start("test.htm");
            }

            Assert.True(result);
        }
Ejemplo n.º 5
0
        private void DrawHtmlAttributes(XmlWriter writer, int paneNo)
        {
            if (this._attributes == null)
            {
                return;
            }
            var data = string.Empty;

            if (this._attributes._nextSibbling != null)
            {
                data = XmlDiffView.GetIndent(this._name.Length + 2);
            }
            var attr = this._attributes;

            while (attr != null)
            {
                if (XmlDiffView.HtmlWriteToPane[(int)attr._op, paneNo])
                {
                    if (attr == this._attributes)
                    {
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteRaw(data);
                    }
                    if (attr._op == XmlDiffViewOperation.Change)
                    {
                        if (paneNo == 0)
                        {
                            this.DrawHtmlAttributeChange(writer, attr, attr._localName, attr._prefix, attr._value);
                        }
                        else
                        {
                            this.DrawHtmlAttributeChange(writer, attr, attr._changeInfo._localName, attr._changeInfo._prefix, attr._changeInfo._value);
                        }
                    }
                    else
                    {
                        this.DrawHtmlAttribute(writer, attr, attr._op);
                    }
                }
                else
                {
                    XmlDiffView.HtmlWriteEmptyString(writer);
                }
                attr = (XmlDiffViewAttribute)attr._nextSibbling;
                if (attr != null)
                {
                    XmlDiffView.HtmlBr(writer);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Generate output text for a difference due to a change
        /// to the baseline data.
        /// </summary>
        /// <param name="writer">output data stream</param>
        /// <param name="indent">size of the indent</param>
        public void DrawTextNoChange(
            TextWriter writer,
            int indent)
        {
            Debug.Assert(this.NodeType != XmlNodeType.Element && this.NodeType != XmlNodeType.Attribute);
            Debug.Assert(this.Operation != XmlDiffViewOperation.Change);
            //bool closeElement = OutputNavigationHtml(writer);
            string xmlText = this.OuterXml;

            writer.Write(XmlDiffView.IndentText(indent) +
                         xmlText);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Generates atrributes' output data in text form
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="indent">number of indentations</param>
        private void DrawTextAttributes(
            TextWriter writer,
            int indent)
        {
            if (this.Attributes != null)
            {
                indent += Indent.IncrementSize;
                XmlDiffViewAttribute curAttr = this.Attributes;
                while (curAttr != null)
                {
                    if (curAttr == this.Attributes)
                    {
                        writer.Write(" ");
                    }
                    else
                    {  // put subsequent attributes on their own line
                        writer.Write(
                            writer.NewLine + XmlDiffView.IndentText(indent));
                    }

                    // The attributes could have their own
                    // 'add'/'remove'/'move from'/ 'move to'/match/ignore
                    // attribute operations so we check for that now
                    switch (curAttr.Operation)
                    {
                    case XmlDiffViewOperation.Change:
                        this.DrawTextAttributeChange(writer, curAttr);
                        break;

                    case XmlDiffViewOperation.Add:
                    case XmlDiffViewOperation.Ignore:
                    case XmlDiffViewOperation.MoveFrom:
                    case XmlDiffViewOperation.MoveTo:
                    case XmlDiffViewOperation.Remove:
                    case XmlDiffViewOperation.Match:
                        // for 'add'/'remove'/'move from'/'move to'/match
                        // operations write out the baseline attributes
                        // data.
                        this.DrawTextAttribute(writer, curAttr);
                        break;

                    default:
                        // raise exception for new type of
                        // difference created in XmlDiff object.
                        throw new ArgumentException(
                                  "Unrecognised type of difference",
                                  "Operation");
                    }
                    curAttr = (XmlDiffViewAttribute)curAttr.NextSibbling;
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Generates output data in text form for a difference due
 /// to deleting data.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="indent">number of indentations</param>
 /// <param name="tagStart">xml tags at start of statement</param>
 /// <param name="tagEnd">xml tags at end of statement</param>
 private void DrawTextNameDelete(
     TextWriter writer,
     int indent,
     string tagStart,
     string tagEnd)
 {
     writer.Write(XmlDiffView.IndentText(indent) +
                  tagStart);
     if (this.Prefix != string.Empty)
     {
         writer.Write(this.Prefix + ":");
     }
     writer.Write(this.LocalName + " " + Difference.Tag +
                  Difference.NodeDeleted);
     writer.Write(tagEnd);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates output data in html form for a difference due to
        /// a change in element name.
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="localName">name of the
        /// element (without the prefix)</param>
        /// <param name="prefix">prefix</param>
        private void DrawHtmlNameChange(
            XmlWriter writer,
            string localName,
            string prefix)
        {
            if (prefix != string.Empty)
            {
                XmlDiffView.HtmlWriteString(
                    writer,
                    this.ignorePrefixes ? XmlDiffViewOperation.Ignore : (prefix == ChangeInformation.Prefix) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                    prefix + ":");
            }

            XmlDiffView.HtmlWriteString(
                writer,
                (localName == ChangeInformation.LocalName) ? XmlDiffViewOperation.Match : XmlDiffViewOperation.Change,
                localName);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Generates  output data in text form
        /// </summary>
        /// <param name="writer">output stream</param>
        /// <param name="indent">number of indentations</param>
        internal override void DrawText(TextWriter writer, int indent)
        {
            Debug.Assert(XmlNodeType.Comment == NodeType ||
                         XmlNodeType.CDATA == NodeType ||
                         XmlNodeType.Text == NodeType);

            // indent the text.
            writer.Write(XmlDiffView.IndentText(indent));

            switch (Operation)
            {
            case XmlDiffViewOperation.Add:
                this.DrawTextAdd(writer);
                break;

            case XmlDiffViewOperation.Change:
                this.DrawTextChange(writer);
                break;

            case XmlDiffViewOperation.Ignore:
                // suppress the output
                break;

            case XmlDiffViewOperation.Match:
                DrawTextNoChange(writer, indent);
                break;

            case XmlDiffViewOperation.MoveFrom:
                Debug.Assert(false);
                break;

            case XmlDiffViewOperation.MoveTo:
                Debug.Assert(false);
                break;

            case XmlDiffViewOperation.Remove:
                this.DrawTextDelete(writer);
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Generates output data in text form for a difference due
 /// to moving data to a new location.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="indent">number of indentations</param>
 /// <param name="tagStart">xml tags at start of statement</param>
 /// <param name="tagEnd">xml tags at end of statement</param>
 private void DrawTextNameMoveTo(
     TextWriter writer,
     int indent,
     string tagStart,
     string tagEnd)
 {
     writer.Write(XmlDiffView.IndentText(indent) +
                  tagStart);
     if (this.Prefix == string.Empty)
     {
         writer.Write(this.Prefix + ":");
     }
     writer.Write(this.LocalName + " " +
                  Difference.Tag +
                  Difference.NodeMovedToBegin +
                  OperationId +
                  Difference.NodeMovedToEnd);
     writer.Write(tagEnd);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Generates output data in text form for a difference due
 /// to changing existing data.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="indent">number of indentations</param>
 /// <param name="tagStart">xml tags at start of statement</param>
 /// <param name="tagEnd">xml tags at end of statement</param>
 private void DrawTextNameChange(
     TextWriter writer,
     int indent,
     string tagStart,
     string tagEnd)
 {
     writer.Write(XmlDiffView.IndentText(indent) +
                  tagStart);
     if (this.Prefix != string.Empty)
     {
         writer.Write(this.Prefix + ":");
     }
     writer.Write(Difference.Tag +
                  Difference.ChangeBegin +
                  this.LocalName +
                  Difference.ChangeTo +
                  ChangeInformation.LocalName +
                  Difference.ChangeEnd);
     writer.Write(tagEnd);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Generates output data in text form for the name of the element.
 /// </summary>
 /// <param name="writer">output stream</param>
 /// <param name="indent">number of indentations</param>
 /// <param name="tagStart">xml tags at start of statement</param>
 /// <param name="tagEnd">xml tags at end of statement</param>
 private void DrawTextName(
     TextWriter writer,
     int indent,
     string tagStart,
     string tagEnd)
 {
     if (this.Prefix != string.Empty && this.ignorePrefixes)
     {
         writer.Write(
             XmlDiffView.IndentText(indent) +
             tagStart +
             this.Prefix + ":" +
             this.LocalName + tagEnd);
     }
     else
     {
         writer.Write(XmlDiffView.IndentText(indent) +
                      tagStart + this.Name + tagEnd);
     }
 }
Ejemplo n.º 14
0
        public void GrHtm(XmlDiffView dv, string Dts, string Srv, string Cls)
        {
            string msg;
            StringBuilder msgHtm = new StringBuilder();
            //
            HTMFile = startupPath + Path.DirectorySeparatorChar + Dts + "_" + Cls + "_" + Srv + "_diff" + r.Next() + ".htm";
            StreamWriter sw1 = new StreamWriter(HTMFile);

            // Escreve o HTML com as diferenças para analise do LeHtm...

            // Cabecalho
            msg = "<html><body><table width='100%'>";
            msgHtm.Append(msg);
            sw1.Write(msg);

            // Legenda
            msg =   "<tr><td colspan='2' align='center'><b>"    +   Cls     +   "_"     +   Srv         +
                    " - Legenda:</b> <font style='background-color: yellow'"                            +
                    " color='black'>adicionado</font>&nbsp;&nbsp;<font style='background-color: red'"   +
                    " color='black'>removido</font>&nbsp;&nbsp;<font style='background-color: "         +
                    "lightgreen' color='black'>alterado</font>&nbsp;&nbsp;"                             +
                    "<font style='background-color: red' color='blue'>movido Ini</font>"                +
                    "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>movido Fim"        +
                    "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>"         +
                    "ignorado</font></td></tr>";
            msgHtm.Append(msg);
            sw1.Write(msg);

            // Arquivos comparados...
            msg = "<tr><td><b> File Name : ";
            msgHtm.Append(msg);
            sw1.Write(msg);
            //
            msg = Dts.Substring(1,11);
            msgHtm.Append(msg);
            sw1.Write(msg);
            //
            msg = "</b></td><td><b> File Name : ";
            msgHtm.Append(msg);
            sw1.Write(msg);
            //
            msg = Dts.Substring(13,11);
            msgHtm.Append(msg);
            sw1.Write(msg);
            //
            msg = "</b></td></tr>";
            msgHtm.Append(msg);
            sw1.Write(msg);

            // This gets the differences but just has the
            //rows and columns of an HTML table
            dv.GetHtml(sw1);

            // Finaliza o HTML
            msg = "</table></body></html>";
            msgHtm.Append(msg);
            sw1.Write(msg);

            // Fecha arquivos
            sw1.Close();
            dv = null;
        }
Ejemplo n.º 15
0
        static void Main( string[] args )
        {
            try {

            int curArgIndex = 0;
            bool bFragment = false;

            // decode options
            XmlDiffOptions options = XmlDiffOptions.None;
            string optionsString = string.Empty;
            while ( curArgIndex < args.Length  &&
                    ( args[curArgIndex][0] == '/' || args[curArgIndex][0] == '-' ) ) {
                if ( args[curArgIndex].Length != 2 ) {
                    System.Console.Write( "Invalid option: " + args[curArgIndex] + "\n" );
                    return;
                }

                switch ( args[curArgIndex][1] ) {
                    case '?':
                        WriteUsage();
                        return;
                    case 'o':
                        options |= XmlDiffOptions.IgnoreChildOrder;
                        break;
                    case 'c':
                        options |= XmlDiffOptions.IgnoreComments;
                        break;
                    case 'p':
                        options |= XmlDiffOptions.IgnorePI;
                        break;
                    case 'w':
                        options |= XmlDiffOptions.IgnoreWhitespace;
                        break;
                    case 'n':
                        options |= XmlDiffOptions.IgnoreNamespaces;
                        break;
                    case 'r':
                        options |= XmlDiffOptions.IgnorePrefixes;
                        break;
                    case 'x':
                        options |= XmlDiffOptions.IgnoreXmlDecl;
                        break;
                    case 'd':
                        options |= XmlDiffOptions.IgnoreDtd;
                        break;
                    case 'f':
                        bFragment = true;
                        break;
                    default:
                        System.Console.Write( "Invalid option: " + args[curArgIndex] + "\n" );
                        return;
                }
                optionsString += args[curArgIndex][1];
                curArgIndex++;
            }

            if ( args.Length - curArgIndex < 3 ) {
                WriteUsage();
                return;
            }

            bool includeIngnore = (args.Length - curArgIndex > 3);

            string sourceXmlFile = args[curArgIndex];
            string changedXmlFile = args[curArgIndex+1];
            string resultHtmlViewFile = args[curArgIndex+2];
            string diffgramFile = args[curArgIndex + 3];
            string ignoreFile = includeIngnore ? args[curArgIndex + 4] : null;

            MemoryStream diffgram = new MemoryStream();
            XmlTextWriter diffgramWriter = new XmlTextWriter( new StreamWriter( diffgram ) );

            var msg = "Comparing " + sourceXmlFile + " to " + changedXmlFile + " using ignore config " + ignoreFile;
            log.Info(msg);
            Console.WriteLine(msg);

            XmlDiff xmlDiff = new XmlDiff( options );
            bool bIdentical = true;
            try
            {
                bIdentical = xmlDiff.Compare(sourceXmlFile, changedXmlFile, bFragment, diffgramWriter, ignoreFile);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                Console.WriteLine(e.Message);
                return;
            }

            msg = "Files compared " + (bIdentical ? "identical." : "different.");
            log.Info(msg);
            Console.WriteLine(msg);

            msg = "Generating " + resultHtmlViewFile + " view file";
            log.Info(msg);
            Console.WriteLine(msg);

            TextWriter resultHtml = new StreamWriter( new FileStream( resultHtmlViewFile, FileMode.Create, FileAccess.Write ));
            resultHtml.WriteLine( "<html><head>");
            resultHtml.WriteLine( "<style TYPE='text/css' MEDIA='screen'>");
            resultHtml.Write( "<!-- td { font-family: Courier New; font-size:14; } " +
                                "th { font-family: Arial; } " +
                                "p { font-family: Arial; } -->" );
            resultHtml.WriteLine( "</style></head>" );
            resultHtml.WriteLine( "<body><h3 style='font-family:Arial'>XmlDiff view</h3><table border='0'><tr><td><table border='0'>" );
            resultHtml.WriteLine( "<tr><th>" + sourceXmlFile + "</th><th>" +
                                            changedXmlFile + "</th></tr>" +
                                "<tr><td colspan=2><hr size=1></td></tr>" );
            if ( bIdentical ) {
                resultHtml.WriteLine( "<tr><td colspan='2' align='middle'>Files are identical.</td></tr>" );
            }
            else {
                resultHtml.WriteLine( "<tr><td colspan='2' align='middle'>Files are different.</td></tr>" );
            }

            diffgram.Seek( 0,SeekOrigin.Begin );
            Microsoft.XmlDiffPatch.XmlDiffView xmlDiffView = new Microsoft.XmlDiffPatch.XmlDiffView();
            XmlTextReader sourceReader;
            if ( bFragment ) {
                    NameTable nt = new NameTable();
                    sourceReader = new XmlTextReader( new FileStream( sourceXmlFile, FileMode.Open, FileAccess.Read ),
                                                      XmlNodeType.Element,
                                                      new XmlParserContext( nt, new XmlNamespaceManager( nt ),
                                                                            string.Empty, XmlSpace.Default ) );
            }
            else {
                sourceReader = new XmlTextReader( sourceXmlFile );
            }

            sourceReader.XmlResolver = null;
            xmlDiffView.Load( sourceReader, new XmlTextReader( diffgram ) );

            xmlDiffView.GetHtml( resultHtml );

            resultHtml.WriteLine( "</table></table></body></html>" );
            resultHtml.Close();

            msg = resultHtmlViewFile + " saved successfully.";
            log.Info(msg);
            Console.WriteLine(msg);

            msg = "saving diffgram file";
            log.Info(msg);
            Console.WriteLine(msg);

            using (FileStream file = new FileStream(diffgramFile, FileMode.Create, FileAccess.Write))
            {
                diffgram.WriteTo(file);
            }

            msg = "diffgram file saved to " + diffgramFile;
            log.Info(msg);
            Console.WriteLine(msg);
            }
            catch ( Exception e ) {
            log.Error(e.Message, e);
            Console.WriteLine( "Error: " + e.Message );
            }

            if ( System.Diagnostics.Debugger.IsAttached )
            {
            Console.Write( "\nPress enter...\n" );
            Console.Read();
            }
        }
Ejemplo n.º 16
0
        private static string GetHtmlDiff(string sourceXml, string diffgram)
        {
            var diffView = new XmlDiffView();
            diffView.Load(
                XmlReader.Create(new StringReader(sourceXml)),
                XmlReader.Create(new StringReader(diffgram)));

            var builder = new StringBuilder();
            builder.Append("<html><body><table>");
            diffView.GetHtml(new StringWriter(builder));
            builder.Append("</table></body></html>");
            return builder.ToString();
        }
Ejemplo n.º 17
0
        public bool XmlDiffHtm(string source, string target, string intervalo, string server, string classe)
        {
            // Randomiza para criar arquivos unicos de comparação
            r = new Random();
            bool isEqual = false;

            //Pega o usuário logado...
            MembershipUser currentUser = Membership.GetUser();

            //output diff file.
            startupPath = ConfigurationManager.AppSettings["XMLData"] + "\\RPTs";
            diffFile = startupPath + Path.DirectorySeparatorChar + "vxd" + r.Next() + ".out";
            //
            XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile));
            tw.Formatting = Formatting.Indented;

            try
            {
                XmlReader expected = XmlReader.Create(new StringReader(target));
                XmlReader actual = XmlReader.Create(new StringReader(source));

                XmlDiff diff = new XmlDiff( XmlDiffOptions.IgnoreChildOrder |
                                            XmlDiffOptions.IgnoreComments   |
                                            XmlDiffOptions.IgnoreXmlDecl    |
                                            XmlDiffOptions.IgnoreWhitespace);

                isEqual = diff.Compare(actual, expected, tw);
                tw.Close();

                //-----------------------------------------------------------------
                // Cria a comparação dos XMLs...
                XmlDiffView dv = new XmlDiffView();

                // Carrega o arquivo orig = source + o arquivo XML das Diff...
                XmlTextReader orig = new XmlTextReader(new StringReader(source)); //source
                XmlTextReader diffGram = new XmlTextReader(diffFile);
                dv.Load(orig,
                    diffGram);

                orig.Close();
                diffGram.Close();

                // Chama a função para gravar e formatar o conteudo + diff em HTM...
                if (!isEqual)
                { GrHtm(dv, intervalo, server, classe); }
                //
                return isEqual;
            }
            catch (XmlException xe)
            {
                divMessage.InnerHtml = "<span id='msg' style='color:#FF3300;font-size:Smaller;font-weight:bold;'>Ocorreu um erro de Comparação - " + xe.StackTrace + "</span>";
                return isEqual;
            }
        }
Ejemplo n.º 18
0
        private void DoCompare(string changed)
        {
            CleanupTempFiles();

            XmlDocument original = this.model.Document;
            XmlDocument doc = new XmlDocument();

            XmlReaderSettings settings = model.GetReaderSettings();
            using (XmlReader reader = XmlReader.Create(changed, settings)) {
                doc.Load(reader);
            }

            string startupPath = Application.StartupPath;
            //output diff file.
            string diffFile = Path.Combine(Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".xml");
            this.tempFiles.AddFile(diffFile, false);

            bool isEqual = false;
            XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
            diffWriter.Formatting = Formatting.Indented;
            using (diffWriter) {
                XmlDiff diff = new XmlDiff();
                isEqual = diff.Compare(original, doc, diffWriter);
                diff.Options = XmlDiffOptions.None;
            }

            if (isEqual) {
                //This means the files were identical for given options.
                MessageBox.Show(this, SR.FilesAreIdenticalPrompt, SR.FilesAreIdenticalCaption,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            string tempFile = Path.Combine(Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".htm");
            tempFiles.AddFile(tempFile, false);

            using (XmlReader diffGram = XmlReader.Create(diffFile, settings)) {
                XmlDiffView diffView = new XmlDiffView();
                diffView.Load(new XmlNodeReader(original), diffGram);
                using (TextWriter htmlWriter = new StreamWriter(tempFile)) {
                    SideBySideXmlNotepadHeader(this.model.FileName, changed, htmlWriter);
                    diffView.GetHtml(htmlWriter);
                }
            }

            /*
            Uri uri = new Uri(tempFile);
            WebBrowserForm browserForm = new WebBrowserForm(uri, "XmlDiff");
            browserForm.Show();
            */
        }
Ejemplo n.º 19
0
	public void GenerateOutput(BuildItem buildItem, Stream outputStream, IDictionary<string, Stream> inputFormatStreams, string defaultNamespace)
	{
		outputStream = new UncloseableStream(outputStream);
		Stream undeadOial = inputFormatStreams["UndeadOIAL"];
		Stream liveOial = inputFormatStreams["LiveOIAL"];

		XmlDiff xmlDiff = new XmlDiff(XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl | XmlDiffOptions.IgnorePrefixes);

		xmlDiff.Algorithm = XmlDiffAlgorithm.Precise;

		bool identical = false;

		MemoryStream diffgram = new MemoryStream(8192);

		using (XmlWriter diffgramWriter = XmlWriter.Create(diffgram))
		{
			try
			{
				using (XmlReader undeadReader = XmlReader.Create(undeadOial, XmlReaderSettings), liveReader = XmlReader.Create(liveOial, XmlReaderSettings))
				{
					identical = xmlDiff.Compare(undeadReader, liveReader, diffgramWriter);
				}
			}
			finally
			{
				undeadOial.Seek(0, SeekOrigin.Begin);
				liveOial.Seek(0, SeekOrigin.Begin);
			}
		}

		// Files have been compared, and the diff has been written to the diffgramwriter.

		TextWriter resultHtml = new StreamWriter(outputStream);
		resultHtml.WriteLine("<html><head>");
		resultHtml.WriteLine("<style TYPE='text/css' MEDIA='screen'>");
		resultHtml.Write("<!-- td { font-family: Courier New; font-size:14; } " +
							"th { font-family: Arial; } " +
							"p { font-family: Arial; } -->");
		resultHtml.WriteLine("</style></head>");
		resultHtml.WriteLine("<body><h3 style='font-family:Arial'>XmlDiff view</h3><table border='0'><tr><td><table border='0'>");
		resultHtml.WriteLine("<tr><th>Undead OIAL</th><th>Live OIAL</th></tr>" +
							"<tr><td colspan=2><hr size=1></td></tr>");

		if (identical)
		{
			resultHtml.WriteLine("<tr><td colspan='2' align='middle'>Files are identical.</td></tr>");
		}
		else
		{
			resultHtml.WriteLine("<tr><td colspan='2' align='middle'>Files are different.</td></tr>");
		}

		diffgram.Seek(0, SeekOrigin.Begin);
		XmlDiffView xmlDiffView = new XmlDiffView();

		XmlTextReader sourceReader = new XmlTextReader(undeadOial);

		sourceReader.XmlResolver = null;

		xmlDiffView.Load(sourceReader, new XmlTextReader(diffgram));

		xmlDiffView.GetHtml(resultHtml);

		resultHtml.WriteLine("</table></table></body></html>");

		resultHtml.Flush();
		resultHtml.Close();
	}
Ejemplo n.º 20
0
        /// <summary>
        /// compares two xml data sources as xml strings
        /// </summary>
        /// <param name="querySource">the SQL query text for the source</param>
        /// <param name="queryTarget">the SQL query text for the target</param>
        /// <param name="connectionSource">The sql connection object for the source</param>
        /// <param name="connectionTarget">The sql connection object for the target</param>
        /// <param name="asTextFile"></param>
        /// <returns></returns>
        public static string CompareData(string querySource, string queryTarget, SqlConnection connectionSource, SqlConnection connectionTarget, bool asTextFile)
        {
            bool isEqual = false;
            string tempFile = "TableDiffReport.html";
            string sourceName = querySource.Replace("select * from ", "").Split(' ')[0].Replace("\\", "_").Replace(":", "-") + ".xml";
            string targetName = queryTarget.Replace("select * from ", "").Split(' ')[0].Replace("\\", "_").Replace(":", "-") + ".xml";
            //output diff file.
            string diffFile = sourceName.Replace(".xml", "") + "_DIFF_" + targetName;
            XmlDiffOptions xdo = XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePI;

            XmlDocument original = new XmlDocument();
            original.LoadXml(GetXMLData(querySource, connectionSource));
            original.Save(sourceName);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(GetXMLData(queryTarget, connectionTarget));
            doc.Save(targetName);

            if (asTextFile)
            {
                XmlDiffView diffView = new XmlDiffView();
                diffView.DifferencesAsFormattedText(sourceName, targetName, diffFile.Replace(".xml", "") + ".txt", false, xdo);
                diffView = null;
                return diffFile.Replace(".xml", "") + ".txt";
            }
            else
            {

                XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
                diffWriter.Formatting = Formatting.Indented;
                using (diffWriter)
                {
                    XmlDiff diff = new XmlDiff();
                    isEqual = diff.Compare(original, doc, diffWriter);
                    diff.Options = xdo;
                }

                if (isEqual)
                {
                    //This means the files were identical for given options.
                    MessageBox.Show("Tables are identical", "Identical",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return string.Empty;
                }

                using (XmlReader diffGram = XmlReader.Create(diffFile))
                {
                    XmlDiffView diffView = new XmlDiffView();
                    diffView.Load(new XmlNodeReader(original), diffGram);
                    using (TextWriter htmlWriter = new StreamWriter(tempFile))
                    {
                        SideBySideXmlNotepadHeader(sourceName, targetName, htmlWriter);
                        diffView.GetHtml(htmlWriter);
                    }
                    diffView = null;
                }
            }
            return tempFile;
        }
Ejemplo n.º 21
0
        public void DoCompare(string file1, string file2)
        {
            Random r = new Random();
            //to randomize the output files and hence allow
            //us to generate multiple files for the same pair
            //of comparisons.

            string tempPath = Path.GetTempPath();
            //output diff file.
            diffFile = tempPath + Path.DirectorySeparatorChar + "vxd.out";
            XmlTextWriter tw = new XmlTextWriter( new StreamWriter( diffFile ) );
            tw.Formatting = Formatting.Indented;

            //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 )
            {
                MessageBox.Show( "An exception occured while comparing\n" + xe.StackTrace );
            }
            finally
            {
                tw.Close();
            }

            if (  isEqual )
            {
                //This means the files were identical for given options.
                MessageBox.Show ( "Files Identical for the given options");
                return; //dont need to show the differences.
            }

            //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 );

            //Wrap the HTML file with necessary html and
            //body tags and prepare it before passing it to the GetHtml method.

            string tempFile = tempPath + "diff" + r.Next() + ".htm";
            StreamWriter sw1 = new StreamWriter( tempFile );

            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>&nbsp;&nbsp;<font style='background-color: red'"+
                " color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: "+
                "lightgreen' color='black'>changed</font>&nbsp;&nbsp;"+
                "<font style='background-color: red' color='blue'>moved from</font>"+
                "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to"+
                "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>"+
                "ignored</font></td></tr>");

            sw1.Write("<tr><td><b> File Name : ");
            sw1.Write(textBox1.Text);
            sw1.Write("</b></td><td><b> File Name : ");
            sw1.Write(textBox2.Text);
            sw1.Write("</b></td></tr>");

            //This gets the differences but just has the
            //rows and columns of an HTML table
            dv.GetHtml( sw1 );

            //Finish wrapping up the generated HTML and complete the file.
            sw1.Write("</table></body></html>");

            //HouseKeeping...close everything we dont want to lock.
            sw1.Close();
            dv = null;
            orig.Close();
            diffGram.Close();
            File.Delete ( diffFile );

            //Open the IE Control window and pass it the HTML file we created.
            Browser b = new Browser( tempFile );
            b.Show(); //Display it!
            //Done!
        }
        private string CreateDiffAsHtml(string expectationFile, string diffFile)
        {
            var xmlDiffView = new XmlDiffView();
            using (var expectationFileReader = new XmlTextReader(expectationFile))
            using (var diffFileReader = new XmlTextReader(diffFile))
            {
                xmlDiffView.Load(expectationFileReader, diffFileReader);
            }

            var htmlContent = new StringBuilder();
            var xmlDiffWriter = new StringWriter(htmlContent);

            xmlDiffWriter.Write("<html><body><table width='100%'><tr><th>Expected</th><th>Actual</th></tr>");
            xmlDiffView.GetHtml(xmlDiffWriter);
            xmlDiffWriter.Write("</table></body></html>");

            return htmlContent.ToString();
        }