internal static int OrderSubTrees(XmlDiffElement elem1, XmlDiffElement elem2) { var node1_1 = elem1._attributes; var node2_1 = elem2._attributes; while (node1_1 != null && node1_1.NodeType == XmlDiffNodeType.Namespace) node1_1 = (XmlDiffAttributeOrNamespace) node1_1._nextSibling; while (node2_1 != null && node2_1.NodeType == XmlDiffNodeType.Namespace) node2_1 = (XmlDiffAttributeOrNamespace) node2_1._nextSibling; for (; node1_1 != null && node2_1 != null; node2_1 = (XmlDiffAttributeOrNamespace) node2_1._nextSibling) { int num; if ((num = XmlDiffDocument.OrderAttributesOrNamespaces(node1_1, node2_1)) != 0) return num; node1_1 = (XmlDiffAttributeOrNamespace) node1_1._nextSibling; } if (node1_1 == node2_1) { var node1_2 = elem1.FirstChildNode; XmlDiffNode node2_2; for (node2_2 = elem2.FirstChildNode; node1_2 != null && node2_2 != null; node2_2 = node2_2._nextSibling) { int num; if ((num = XmlDiffDocument.OrderChildren(node1_2, node2_2)) != 0) return num; node1_2 = node1_2._nextSibling; } if (node1_2 == node2_2) return 0; return node1_2 == null ? 1 : -1; } return node1_1 == null ? 1 : -1; }
internal ulong ComputeHashXmlDiffDocument( XmlDiffDocument doc ) { HashAlgorithm ha = new HashAlgorithm(); HashDocument( ha ); ComputeHashXmlDiffChildren( ha, doc ); return ha.Hash; }
public bool Compare(XmlNode sourceNode, XmlNode changedNode, XmlWriter diffgramWriter) { if (sourceNode == null) { throw new ArgumentNullException(nameof(sourceNode)); } if (changedNode == null) { throw new ArgumentNullException(nameof(changedNode)); } try { var xmlHash = new XmlHash(this); this._xmlDiffPerf.Clean(); var tickCount = Environment.TickCount; this._sourceDoc = new XmlDiffDocument(this); this._sourceDoc.Load(sourceNode, xmlHash); this._targetDoc = new XmlDiffDocument(this); this._targetDoc.Load(changedNode, xmlHash); this._fragments = sourceNode.NodeType != XmlNodeType.Document || changedNode.NodeType != XmlNodeType.Document ? TriStateBool.Yes : TriStateBool.No; this._xmlDiffPerf._loadTime = Environment.TickCount - tickCount; return(this.Diff(diffgramWriter)); } finally { this._sourceDoc = null; this._targetDoc = null; } }
internal static int OrderChildren(XmlDiffNode node1, XmlDiffNode node2) { var nodeType1 = (int) node1.NodeType; var nodeType2 = (int) node2.NodeType; if (nodeType1 < nodeType2) return -1; if (nodeType2 < nodeType1) return 1; switch (nodeType1) { case 1: return XmlDiffDocument.OrderElements(node1 as XmlDiffElement, node2 as XmlDiffElement); case 2: case 100: return 0; case 5: return XmlDiffDocument.OrderERs(node1 as XmlDiffER, node2 as XmlDiffER); case 7: return XmlDiffDocument.OrderPIs(node1 as XmlDiffPI, node2 as XmlDiffPI); case 101: if (((XmlDiffShrankNode) node1).MatchingShrankNode == ((XmlDiffShrankNode) node2).MatchingShrankNode) return 0; return node1.HashValue >= node2.HashValue ? 1 : -1; default: return XmlDiffDocument.OrderCharacterData(node1 as XmlDiffCharData, node2 as XmlDiffCharData); } }
public bool Compare(XmlReader sourceReader, XmlReader changedReader, XmlWriter diffgramWriter) { if (sourceReader == null) { throw new ArgumentNullException(nameof(sourceReader)); } if (changedReader == null) { throw new ArgumentNullException(nameof(changedReader)); } try { var xmlHash = new XmlHash(this); this._xmlDiffPerf.Clean(); var tickCount = Environment.TickCount; this._sourceDoc = new XmlDiffDocument(this); this._sourceDoc.Load(sourceReader, xmlHash); this._targetDoc = new XmlDiffDocument(this); this._targetDoc.Load(changedReader, xmlHash); if (this._fragments == TriStateBool.DontKnown) { this._fragments = this._sourceDoc.IsFragment || this._targetDoc.IsFragment ? TriStateBool.Yes : TriStateBool.No; } this._xmlDiffPerf._loadTime = Environment.TickCount - tickCount; return(this.Diff(diffgramWriter)); } finally { this._sourceDoc = null; this._targetDoc = null; } }
internal ulong ComputeHashXmlDiffDocument(XmlDiffDocument doc) { HashAlgorithm ha = new HashAlgorithm(); HashDocument(ha); ComputeHashXmlDiffChildren(ha, doc); return(ha.Hash); }
internal ulong ComputeHashXmlDiffDocument(XmlDiffDocument doc) { var ha = new HashAlgorithm(); this.HashDocument(ha); this.ComputeHashXmlDiffChildren(ha, (XmlDiffParentNode)doc); return(ha.Hash); }
private void PreprocessTree(XmlDiffDocument doc, ref XmlDiffNode[] postOrderArray) { postOrderArray = new XmlDiffNode[(int)checked ((uint)unchecked (doc.NodesCount + 1))]; postOrderArray[0] = null; var currentIndex = 1; this.PreprocessNode(doc, ref postOrderArray, ref currentIndex); doc._bKeyRoot = true; }
internal void InsertAttributeOrNamespace(XmlDiffAttributeOrNamespace newAttrOrNs) { newAttrOrNs._parent = (XmlDiffParentNode)this; var node1 = this._attributes; var attributeOrNamespace = (XmlDiffAttributeOrNamespace)null; for (; node1 != null && XmlDiffDocument.OrderAttributesOrNamespaces(node1, newAttrOrNs) <= 0; node1 = (XmlDiffAttributeOrNamespace)node1._nextSibling) { attributeOrNamespace = node1; } if (attributeOrNamespace == null) { newAttrOrNs._nextSibling = (XmlDiffNode)this._attributes; this._attributes = newAttrOrNs; } else { newAttrOrNs._nextSibling = attributeOrNamespace._nextSibling; attributeOrNamespace._nextSibling = (XmlDiffNode)newAttrOrNs; } this._allAttributesHash += newAttrOrNs.HashValue; char c; if (newAttrOrNs.NodeType == XmlDiffNodeType.Attribute) { c = newAttrOrNs.LocalName[0]; } else { var xmlDiffNamespace = (XmlDiffNamespace)newAttrOrNs; c = xmlDiffNamespace.Prefix == string.Empty ? 'A' : xmlDiffNamespace.Prefix[0]; } var upper = char.ToUpper(c); if (upper >= 'R') { this._attributesHashRZ += newAttrOrNs.HashValue; } else if (upper >= 'I') { this._attributesHashIQ += newAttrOrNs.HashValue; } else { this._attributesHashAH += newAttrOrNs.HashValue; } if (newAttrOrNs.NodeType != XmlDiffNodeType.Namespace) { return; } this._bDefinesNamespaces = true; }
private void InsertChild(XmlDiffParentNode parent, XmlDiffNode newChild) { if (this._XmlDiff.IgnoreChildOrder) { var node1 = parent.FirstChildNode; var childNode = (XmlDiffNode) null; for (; node1 != null && XmlDiffDocument.OrderChildren(node1, newChild) <= 0; node1 = node1._nextSibling) childNode = node1; parent.InsertChildNodeAfter(childNode, newChild); } else { parent.InsertChildNodeAfter(this._curLastChild, newChild); this._curLastChild = newChild; } }
internal void InsertAttributeOrNamespace(XmlDiffAttributeOrNamespace newAttrOrNs) { Debug.Assert(newAttrOrNs != null); newAttrOrNs._parent = this; XmlDiffAttributeOrNamespace curAttr = _attributes; XmlDiffAttributeOrNamespace prevAttr = null; while (curAttr != null && XmlDiffDocument.OrderAttributesOrNamespaces(curAttr, newAttrOrNs) <= 0) { prevAttr = curAttr; curAttr = (XmlDiffAttributeOrNamespace)curAttr._nextSibling; } if (prevAttr == null) { newAttrOrNs._nextSibling = _attributes; _attributes = newAttrOrNs; } else { newAttrOrNs._nextSibling = prevAttr._nextSibling; prevAttr._nextSibling = newAttrOrNs; } // hash Debug.Assert(newAttrOrNs.HashValue != 0); _allAttributesHash += newAttrOrNs.HashValue; char firstLetter; if (newAttrOrNs.NodeType == XmlDiffNodeType.Attribute) { firstLetter = ((XmlDiffAttribute)newAttrOrNs).LocalName[0]; } else { XmlDiffNamespace nsNode = (XmlDiffNamespace)newAttrOrNs; firstLetter = (nsNode.Prefix == string.Empty) ? 'A' : nsNode.Prefix[0]; } firstLetter = char.ToUpper(firstLetter); if (firstLetter >= 'R') { _attributesHashRZ += newAttrOrNs.HashValue; } else if (firstLetter >= 'I') { _attributesHashIQ += newAttrOrNs.HashValue; } else { _attributesHashAH += newAttrOrNs.HashValue; } if (newAttrOrNs.NodeType == XmlDiffNodeType.Namespace) { _bDefinesNamespaces = true; } }
private void PreprocessTree( XmlDiffDocument doc, ref XmlDiffNode[] postOrderArray ) { // allocate the array for post-ordered nodes. // The index 0 is not used; this is to have the consistent indexing of all arrays in the algorithm; postOrderArray = new XmlDiffNode[ doc.NodesCount + 1 ]; postOrderArray[0] = null; // recursivelly process all nodes int index = 1; PreprocessNode( doc, ref postOrderArray, ref index ); // root node is a 'key root' node doc._bKeyRoot = true; Debug.Assert( index - 1 == doc.NodesCount ); }
/// <include file='doc\XmlDiff.uex' path='docs/doc[@for="XmlDiff.Compare6"]/*' /> /// <summary> /// Compares two XML nodes. /// If the diffgramWriter parameter is not null it will contain the list of changes /// between the two XML documents/fragments (diffgram). /// </summary> /// <param name="sourceNode">Original XML node</param> /// <param name="changedNode">Changed XML node</param> /// <param name="diffgramWriter">XmlWriter object for returning the list of changes (diffgram).</param> /// <returns>True, if the documents/fragments are identical.</returns> public bool Compare( XmlNode sourceNode, XmlNode changedNode, XmlWriter diffgramWriter ) { if ( sourceNode == null ) throw new ArgumentNullException( "sourceNode" ); if ( changedNode == null ) throw new ArgumentNullException( "changedNode" ); try { XmlHash xmlHash = new XmlHash( this ); #if MEASURE_PERF _xmlDiffPerf.Clean(); int startTickCount = Environment.TickCount; #endif // load source document _sourceDoc = new XmlDiffDocument( this ); _sourceDoc.Load( sourceNode, xmlHash ); #if DEBUG Trace.WriteLineIf( T_Phases.Enabled, "* Source document loaded: " + _sourceDoc.NodesCount + " nodes." ); #endif // load target document _targetDoc = new XmlDiffDocument( this ); _targetDoc.Load( changedNode, xmlHash ); _fragments = ( sourceNode.NodeType != XmlNodeType.Document || changedNode.NodeType != XmlNodeType.Document ) ? TriStateBool.Yes : TriStateBool.No; #if DEBUG Trace.WriteLineIf( T_Phases.Enabled, "* Target document loaded: " + _targetDoc.NodesCount + " nodes." ); #endif #if MEASURE_PERF _xmlDiffPerf._loadTime = Environment.TickCount - startTickCount; #endif // compare return Diff( diffgramWriter ); } finally { _sourceDoc = null; _targetDoc = null; } }
internal static int OrderCharacterData(XmlDiffCharData t1, XmlDiffCharData t2) { return XmlDiffDocument.OrderStrings(t1.Value, t2.Value); }
internal static int OrderPIs(XmlDiffPI pi1, XmlDiffPI pi2) { int num; return (num = XmlDiffDocument.OrderStrings(pi1.Name, pi2.Name)) == 0 && (num = XmlDiffDocument.OrderStrings(pi1.Value, pi2.Value)) == 0 ? 0 : num; }
internal static int OrderERs(XmlDiffER er1, XmlDiffER er2) { return XmlDiffDocument.OrderStrings(er1.Name, er2.Name); }
internal static int OrderAttributesOrNamespaces( XmlDiffAttributeOrNamespace node1, XmlDiffAttributeOrNamespace node2) { int num; return node1.NodeType != node2.NodeType ? (node1.NodeType == XmlDiffNodeType.Namespace ? -1 : 1) : ((num = XmlDiffDocument.OrderStrings(node1.LocalName, node2.LocalName)) == 0 && (num = XmlDiffDocument.OrderStrings(node1.Prefix, node2.Prefix)) == 0 && ((num = XmlDiffDocument.OrderStrings(node1.NamespaceURI, node2.NamespaceURI)) == 0 && (num = XmlDiffDocument.OrderStrings(node1.Value, node2.Value)) == 0) ? 0 : num); }
internal static int OrderElements(XmlDiffElement elem1, XmlDiffElement elem2) { int num; return (num = XmlDiffDocument.OrderStrings(elem1.LocalName, elem2.LocalName)) == 0 && (num = XmlDiffDocument.OrderStrings(elem1.NamespaceURI, elem2.NamespaceURI)) == 0 ? XmlDiffDocument.OrderSubTrees(elem1, elem2) : num; }