示例#1
0
        private IEnumerable <DiffContent> ChildsChanges(RealNode node)
        {
            var childs = Zip(node.Childs, Childs)
                         .Select(x => x.Result.CompareWith(x.Source))
                         .Where(x => x.IsChanged);

            return(childs);
        }
示例#2
0
        private IEnumerable <DiffContent> ValueChanges(RealNode node)
        {
            var pair = Pair.Create(node.Value, node.DefaultAction, Value, DefaultAction);

            return(pair.Apply((source, res, action) =>
            {
                return source != res && !string.IsNullOrEmpty(source)
                                                ? new DiffValue[] { new DiffValue(action, source) }
                                                : new DiffValue[0];
            }));
        }
示例#3
0
        private IEnumerable <DiffContent> AttributeChanges(RealNode node)
        {
            var pair = Pair.Create(node.Attributes, node.DefaultAction, Attributes, DefaultAction);

            return(pair.Apply((source, res, action) =>
            {
                return source
                .Where(x => !res.ContainsKey(x.Key) || res[x.Key].ToString() != x.Value.ToString())
                .Select(x => new DiffAttribute(action, x.Value));
            }));
        }
示例#4
0
        public DiffNode CompareWith(RealNode node)
        {
            //swap nodes to be sure that raw element with default action = Added comes first
            //since we are looking for a comparison against a current version
            if (DefaultAction == DiffAction.Removed)
            {
                return(node.CompareWith(this));
            }

            var contentChanges = AttributeChanges(node)
                                 .Concat(ValueChanges(node))
                                 .Concat(ChildsChanges(node));

            return(new DiffNode(Raw, contentChanges));
        }
示例#5
0
        /// <summary>
        /// Compare <paramref name="resultElement"/> with a <paramref name="sourceElement"/>
        /// Comparison is made only for XElement, XAttribute or XText elements
        /// All other xml elements such as XComment, CDATA etc would be ignored
        /// </summary>
        /// <param name="sourceElement">Source element</param>
        /// <param name="resultElement">Result element</param>
        /// <returns>
        /// Return value is build upon <paramref name="resultElement"/>
        /// In case of different root tags InvalidOperationException is throws
        /// </returns>
        public DiffNode Compare(XElement sourceElement, XElement resultElement)
        {
            if (sourceElement == null)
            {
                throw new ArgumentNullException(nameof(sourceElement));
            }
            if (resultElement == null)
            {
                throw new ArgumentNullException(nameof(resultElement));
            }
            if (sourceElement.Name != resultElement.Name)
            {
                throw new InvalidOperationException("Root elements are different");
            }

            RealNode parsedSource = Parse(sourceElement, DiffAction.Removed);
            RealNode parsedResult = Parse(resultElement, DiffAction.Added);

            return(parsedResult.CompareWith(parsedSource));
        }
示例#6
0
 public DiffNode CompareWith(RealNode node)
 {
     return(new DiffNode(node.DefaultAction, node.Raw));
 }