Exemple #1
0
        static int Main(string[] args)
        {
            var version = Assembly.GetEntryAssembly().GetName().Version;

            Console.WriteLine(
                "==================\n"
                + string.Format(" FatAntelope v{0}.{1}\n", version.Major, version.Minor)
                + "==================\n");

            if (args == null || args.Length < 3 || args.Length > 4)
            {
                Console.WriteLine(
                    "Error: Unexpected number of paramters.\n"
                    + "Usage: FatAntelope source-file target-file output-file [transformed-file]\n"
                    + "  source-file : (Input) The original config file\n"
                    + "  target-file : (Input) The final config file\n"
                    + "  output-file : (Output) The output config transform patch file\n"
                    + "  transformed-file : (Optional Output) The config file resulting from applying the output-file to the source-file\n"
                    + "                     This file should be semantically equal to the target-file.\n");
                return((int)ExitCode.InvalidParameters);
            }

            Console.WriteLine("- Building xml trees . . .\n");
            var tree1 = BuildTree(args[0]);
            var tree2 = BuildTree(args[1]);

            Console.WriteLine("- Comparing xml trees . . .\n");
            XDiff.Diff(tree1, tree2);
            if (tree1.Root.Match == MatchType.Match && tree2.Root.Match == MatchType.Match && tree1.Root.Matching == tree2.Root)
            {
                Console.WriteLine("Warning: No difference found!\n");
                return((int)ExitCode.NoDifference);
            }

            if (tree1.Root.Match == MatchType.NoMatch || tree2.Root.Match == MatchType.NoMatch)
            {
                Console.Error.WriteLine("Error: Root nodes must have the same name!\n");
                return((int)ExitCode.RootNodeMismatch);
            }

            Console.WriteLine("- Writing XDT transform . . .\n");
            var writer = new XdtDiffWriter();
            var patch  = writer.GetDiff(tree2);

            patch.Save(new FileStream(args[2], FileMode.Create));

            /*if (args.Length > 3)
             * {
             *  Console.WriteLine("- Applying transform to source . . .\n");
             *  var source = new XmlTransformation();
             *  source.Load(args[0]);
             *
             *  var transform = new XmlTransformation(patch.OuterXml, false, null);
             *  transform.Apply(source);
             *
             *  source.Save(args[3]);
             * }
             * Console.WriteLine("- Finished successfully!\n");*/
            return((int)ExitCode.Success);
        }
        private void AssertCanTransform(string sourceXml, string targetXml)
        {
            var doc1 = new XmlDocument();

            doc1.LoadXml(sourceXml);

            // reordered xml but same values
            var doc2 = new XmlDocument();

            doc2.LoadXml(targetXml);

            var tree1 = new XTree(doc1);
            var tree2 = new XTree(doc2);

            XDiff.Diff(tree1, tree2);

            var writer      = new XdtDiffWriter();
            var patch       = writer.GetDiff(tree2);
            var transformed = Transform(doc1, patch);

            var transformedTree = new XTree(transformed);

            Assert.IsFalse(Enumerable.SequenceEqual(tree1.Root.Hash, tree2.Root.Hash));
            Assert.IsTrue(Enumerable.SequenceEqual(transformedTree.Root.Hash, tree2.Root.Hash));
        }
Exemple #3
0
        private void diffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var source = new XmlDocument();
                source.LoadXml(fastColoredTextBoxSource.Text);
                var target = new XmlDocument();
                target.LoadXml(fastColoredTextBoxTarget.Text);

                var tree1 = new XTree(source);
                var tree2 = new XTree(target);


                XDiff.Diff(tree1, tree2);
                if (tree1.Root.Match == MatchType.Match && tree2.Root.Match == MatchType.Match && tree1.Root.Matching == tree2.Root)
                {
                    Message("Warning: No difference found!\n");
                }

                if (tree1.Root.Match == MatchType.NoMatch || tree2.Root.Match == MatchType.NoMatch)
                {
                    Message("Error: Root nodes must have the same name!\n");
                }

                var writer = new XdtDiffWriter();
                var patch  = writer.GetDiff(tree2);
                fastColoredTextBoxXDT.Text = PrettyXml(patch.OuterXml);
                tabControl1.SelectedIndex  = 2;
            }
            catch (Exception ex)
            {
                Message(ex.ToString());
            }
        }
Exemple #4
0
        public static string GenerateXdt(string newConfig)
        {
            var baseConfig = GetBaseConfig();

            if (string.IsNullOrEmpty(baseConfig) || string.IsNullOrEmpty(newConfig))
            {
                return("");
            }

            var baseTree = BuildTree(baseConfig);
            var newTree  = BuildTree(newConfig);

            XDiff.Diff(baseTree, newTree);

            var patch = new XdtDiffWriter().GetDiff(newTree);

            return(patch.ToFormattedString());
        }
        private XmlDocument GetPatch(string sourceXml, string targetXml)
        {
            var doc1 = new XmlDocument();

            doc1.LoadXml(sourceXml);

            // reordered xml but same values
            var doc2 = new XmlDocument();

            doc2.LoadXml(targetXml);

            var tree1 = new XTree(doc1);
            var tree2 = new XTree(doc2);

            XDiff.Diff(tree1, tree2);

            var writer = new XdtDiffWriter();

            return(writer.GetDiff(tree2));
        }