Exemplo n.º 1
0
        protected static Dictionary <string, string[]> GetAttributes(IComparableNode left, IComparableNode right)
        {
            Dictionary <string, string[]> attributes = new Dictionary <string, string[]>();

            ExtractAttributes(left, attributes, 0);
            ExtractAttributes(right, attributes, 1);

            return(attributes);
        }
        public ComparableXmlFile(string fileName)
        {
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            doc.Load(fileName);

            rootNode = new RootNode(doc);
            rootNode.AnalyzeChildren();
        }
Exemplo n.º 3
0
        public override void AnalyzeChildren()
        {
            List <XmlNode> usefulChildren = BaseNode.UsefulChildren();

            Children.Add(ComparableNodeFactory.AnalyzeNode(usefulChildren.First()));
            foreach (XmlNode node in usefulChildren.Skip(1))
            {
                IComparableNode child = ComparableNodeFactory.AnalyzeNode(node);
                child.Name = "ITEM";
                Children.Add(child);
            }
        }
Exemplo n.º 4
0
        private static void ExtractAttributes(IComparableNode node, Dictionary <string, string[]> attributes, int position)
        {
            foreach (XmlAttribute attribute in node.BaseNode.Attributes)
            {
                if (!attributes.ContainsKey(attribute.Name))
                {
                    attributes[attribute.Name] = new string[2];
                }

                attributes[attribute.Name][position] = attribute.Value;
            }
        }
Exemplo n.º 5
0
        public virtual List <StructuredFileDiff.Lib.Result.Line> RenderAfter(INode rightNode)
        {
            IComparableNode left  = this;
            IComparableNode right = rightNode as IComparableNode;

            return(new List <StructuredFileDiff.Lib.Result.Line> {
                new StructuredFileDiff.Lib.Result.Line
                {
                    Left = "</" + left.BaseNode.Name + ">",
                    Right = "</" + right.BaseNode.Name + ">",
                },
            });
        }
        public static IComparableNode AnalyzeNode(XmlNode node)
        {
            foreach (IComparableNodeFactory factory in factories)
            {
                IComparableNode comparableNode = factory.TryCreate(node);

                if (comparableNode == null)
                {
                    continue;
                }

                comparableNode.AnalyzeChildren();
                return(comparableNode);
            }

            throw new Exception("Cannot convert node to IComparableNode");
        }
Exemplo n.º 7
0
        protected List <StructuredFileDiff.Lib.Result.Line> RenderDetailledBefore(IComparableNode right, Dictionary <string, string[]> attributes = null)
        {
            IComparableNode left = this;

            List <StructuredFileDiff.Lib.Result.Line> lines = ExpendedElementDiffLines(left, right, attributes);

            lines.Add(new StructuredFileDiff.Lib.Result.Line
            {
                Left  = left.BaseNode.InnerText,
                Right = right.BaseNode.InnerText,
            });
            lines.Add(new StructuredFileDiff.Lib.Result.Line
            {
                Left  = "</" + left.Name + ">",
                Right = "</" + right.Name + ">",
            });

            return(lines);
        }
Exemplo n.º 8
0
        public override List <StructuredFileDiff.Lib.Result.Line> RenderBefore(INode rightNode)
        {
            IComparableNode left  = this;
            IComparableNode right = rightNode as IComparableNode;

            List <StructuredFileDiff.Lib.Result.Line> lines = new List <StructuredFileDiff.Lib.Result.Line>();

            if (left.Name != right.Name)
            {
                return(RenderDetailledBefore(right));
            }

            Dictionary <string, string[]> attributes = GetAttributes(left, right);

            if (attributes.Any(x => x.Value.Any(y => y == null)))
            {
                return(RenderDetailledBefore(right, attributes));
            }

            string leftString  = "<" + left.Name;
            string rightString = "<" + right.Name;

            foreach (string key in attributes.Keys.OrderBy(x => x))
            {
                leftString += " " + RenderAttribute(key, attributes[key][0]);
                rightString = " " + RenderAttribute(key, attributes[key][1]);
            }

            leftString  += ">" + left.BaseNode.InnerText;
            rightString += ">" + right.BaseNode.InnerText;
            leftString  += "</" + left.Name + ">";
            rightString += "</" + right.Name + ">";

            return(new List <StructuredFileDiff.Lib.Result.Line> {
                new StructuredFileDiff.Lib.Result.Line
                {
                    Left = leftString,
                    Right = rightString,
                }
            });
        }
Exemplo n.º 9
0
        protected static List <StructuredFileDiff.Lib.Result.Line> ExpendedElementDiffLines(IComparableNode left, IComparableNode right, Dictionary <string, string[]> attributes = null)
        {
            List <StructuredFileDiff.Lib.Result.Line> lines = new List <StructuredFileDiff.Lib.Result.Line>();

            if (attributes == null)
            {
                attributes = GetAttributes(left, right);
            }

            lines.Add(new StructuredFileDiff.Lib.Result.Line
            {
                Left  = "<" + left.BaseNode.Name,
                Right = "<" + right.BaseNode.Name,
            });

            foreach (string key in attributes.Keys.OrderBy(x => x))
            {
                lines.Add(new StructuredFileDiff.Lib.Result.Line
                {
                    Left  = RenderAttribute(key, attributes[key][0]),
                    Right = RenderAttribute(key, attributes[key][1]),
                });
            }

            lines.Last().Left  += ">";
            lines.Last().Right += ">";

            return(lines);
        }