Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
        // Loads the document from XmlReader
        internal virtual void Load(XmlReader reader, XmlHash xmlHash)
        {
            if (_bLoaded)
            {
                throw new InvalidOperationException("The document already contains data and should not be used again.");
            }

            try
            {
                _curLastChild = null;
                _xmlHash      = xmlHash;

                LoadChildNodes(this, reader, false);

                ComputeHashValue(_xmlHash);
                _bLoaded = true;

    #if DEBUG
                if (XmlDiff.T_LoadedDoc.Enabled)
                {
                    Trace.Write("\nLoaded document " + reader.BaseURI + ": \n");
                    Dump();
                }
    #endif
            }
            finally
            {
                _xmlHash = null;
            }
        }
Ejemplo n.º 3
0
 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;
     }
 }
    // Loads the document from XmlReader
    internal virtual void Load( XmlReader reader, XmlHash xmlHash ) 
    {
        if ( _bLoaded ) 
            throw new InvalidOperationException( "The document already contains data and should not be used again." );

        try 
        {
            _curLastChild = null;
            _xmlHash = xmlHash;

            LoadChildNodes( this, reader, false );

            ComputeHashValue( _xmlHash );
            _bLoaded = true;

    #if DEBUG
            if ( XmlDiff.T_LoadedDoc.Enabled )
            {
                Trace.Write( "\nLoaded document " + reader.BaseURI + ": \n" );
                Dump();
            }
    #endif
        }
        finally
        {
            _xmlHash = null;
        }
    }
Ejemplo n.º 5
0
        public static bool VerifySource(XmlNode node, ulong hashValue, XmlDiffOptions options)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            var hash = new XmlHash().ComputeHash(node, options);

            return((long)hashValue == (long)hash);
        }
Ejemplo n.º 6
0
        // Loads the document from XmlNode
        internal virtual void Load(XmlNode node, XmlHash xmlHash)
        {
            if (_bLoaded)
            {
                throw new InvalidOperationException("The document already contains data and should not be used again.");
            }

            if (node.NodeType == XmlNodeType.Attribute ||
                node.NodeType == XmlNodeType.Entity ||
                node.NodeType == XmlNodeType.Notation ||
                node.NodeType == XmlNodeType.Whitespace)
            {
                throw new ArgumentException("Invalid node type.");
            }

            try
            {
                _curLastChild = null;
                _xmlHash      = xmlHash;

                if (node.NodeType == XmlNodeType.Document || node.NodeType == XmlNodeType.DocumentFragment)
                {
                    LoadChildNodes(this, node);
                    ComputeHashValue(_xmlHash);
                }
                else
                {
                    int         childPos = 0;
                    XmlDiffNode rootNode = LoadNode(node, ref childPos);
                    if (rootNode != null)
                    {
                        InsertChildNodeAfter(null, rootNode);
                        _hashValue = rootNode.HashValue;
                    }
                }
                _bLoaded = true;

    #if DEBUG
                if (XmlDiff.T_LoadedDoc.Enabled)
                {
                    Trace.Write("\nLoaded document " + node.BaseURI + ": \n");
                    Dump();
                }
    #endif
            }
            finally
            {
                _xmlHash = null;
            }
        }
Ejemplo n.º 7
0
 internal virtual void Load(XmlReader reader, XmlHash xmlHash)
 {
   if (this._bLoaded)
     throw new InvalidOperationException("The document already contains data and should not be used again.");
   try
   {
     this._curLastChild = (XmlDiffNode) null;
     this._xmlHash = xmlHash;
     this.LoadChildNodes((XmlDiffParentNode) this, reader, false);
     this.ComputeHashValue(this._xmlHash);
     this._bLoaded = true;
   }
   finally
   {
     this._xmlHash = (XmlHash) null;
   }
 }
Ejemplo n.º 8
0
 internal virtual void Load(XmlNode node, XmlHash xmlHash)
 {
   if (this._bLoaded)
     throw new InvalidOperationException("The document already contains data and should not be used again.");
   if (node.NodeType != XmlNodeType.Attribute && node.NodeType != XmlNodeType.Entity && node.NodeType != XmlNodeType.Notation)
   {
     if (node.NodeType != XmlNodeType.Whitespace)
     {
       try
       {
         this._curLastChild = (XmlDiffNode) null;
         this._xmlHash = xmlHash;
         if (node.NodeType == XmlNodeType.Document || node.NodeType == XmlNodeType.DocumentFragment)
         {
           this.LoadChildNodes((XmlDiffParentNode) this, node);
           this.ComputeHashValue(this._xmlHash);
         }
         else
         {
           var childPosition = 0;
                         var newChildNode = this.LoadNode(node, ref childPosition);
           if (newChildNode != null)
           {
             this.InsertChildNodeAfter((XmlDiffNode) null, newChildNode);
             this._hashValue = newChildNode.HashValue;
           }
         }
         this._bLoaded = true;
         return;
       }
       finally
       {
         this._xmlHash = (XmlHash) null;
       }
     }
   }
   throw new ArgumentException("Invalid node type.");
 }
Ejemplo n.º 9
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashAttribute(_localName, _prefix, _ns, _value);
        }
Ejemplo n.º 10
0
// Methods
        // computes the hash value of the node and saves it into the _hashValue field
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashDocumentType(_name, _publicId, _systemId, _subset);
        }
Ejemplo n.º 11
0
// Methods
        // computes the hash value of the node and saves it into the _hashValue field
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(false, "This method should bever be called.");
        }
Ejemplo n.º 12
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
 }
Ejemplo n.º 13
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashAttribute( _localName, _prefix, _ns, _value );
 }
Ejemplo n.º 14
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashNamespace(this._prefix, this._namespaceURI);
 }
Ejemplo n.º 15
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashER(this._name);
 }
Ejemplo n.º 16
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
   this._hashValue = xmlHash.ComputeHashXmlDiffDocument(this);
 }
Ejemplo n.º 17
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashXmlDeclaration(this._value);
 }
Ejemplo n.º 18
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashER(_name);
        }
Ejemplo n.º 19
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashPI(this.Name, this.Value);
 }
Ejemplo n.º 20
0
    /// <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;
        }
    }
Ejemplo n.º 21
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal abstract void ComputeHashValue( XmlHash xmlHash );
    // Loads the document from XmlNode
    internal virtual void Load( XmlNode node, XmlHash xmlHash ) 
    {
        if ( _bLoaded ) 
            throw new InvalidOperationException( "The document already contains data and should not be used again." );

        if ( node.NodeType == XmlNodeType.Attribute ||
             node.NodeType == XmlNodeType.Entity || 
             node.NodeType == XmlNodeType.Notation || 
             node.NodeType == XmlNodeType.Whitespace ) {
            throw new ArgumentException( "Invalid node type." );
        }

        try 
        {
            _curLastChild = null;
            _xmlHash = xmlHash;

            if ( node.NodeType == XmlNodeType.Document || node.NodeType == XmlNodeType.DocumentFragment ) {
                LoadChildNodes( this, node );
                ComputeHashValue( _xmlHash );
            }
            else {
                int childPos = 0;
                XmlDiffNode rootNode = LoadNode( node, ref childPos );
                if ( rootNode != null ) {
                    InsertChildNodeAfter( null, rootNode );
                    _hashValue = rootNode.HashValue;
                }
            }
            _bLoaded = true;

    #if DEBUG
            if ( XmlDiff.T_LoadedDoc.Enabled )
            {
                Trace.Write( "\nLoaded document " + node.BaseURI + ": \n" );
                Dump();
            }
    #endif
        }
        finally
        {
            _xmlHash = null;
        }
    }
Ejemplo n.º 23
0
    /// <include file='doc\XmlDiff.uex' path='docs/doc[@for="XmlDiff.VerifySource"]/*' />
    /// <summary>
    ///    Given a diffgram, this method verifies whether the given document/node is the original
    ///    source document/node for the diffgram. 
    /// </summary>
    /// <param name="node">Document/node to be verified.</param>
    /// <param name="hashValue">Value of the 'srcDocHash' attribute of the 'xd:xmldiff' element in diffgram.
    /// This is the hash value of the original source document. The document/node is verified if it yields
    /// the same hash value.</param>
    /// <param name="options">XmlDiff options selected when the document/node was compared. The hash value 
    /// of the document/node depends on these options.</param>
    /// <returns>True if the given document is the original source document for the diffgram.</returns>
    static public bool VerifySource( XmlNode node, ulong hashValue, XmlDiffOptions options )
    {
        if ( node == null )
            throw new ArgumentNullException( "node" );

        ulong computedHashValue = new XmlHash().ComputeHash( node, options );
        return hashValue == computedHashValue;
    }
Ejemplo n.º 24
0
 // Methods
 // computes the hash value of the node and saves it into the _hashValue field
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( false, "This method should bever be called." );
 }
Ejemplo n.º 25
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashAttribute(this._localName, this._prefix, this._ns, this._value);
 }
Ejemplo n.º 26
0
 // Methods
 // computes the hash value of the node and saves it into the _hashValue field
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashXmlDeclaration( _value );
 }
Ejemplo n.º 27
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashCharacterNode( (XmlNodeType)(int)_nodeType, _value );
 }
Ejemplo n.º 28
0
 // Methods
 // computes the hash value of the node and saves it into the _hashValue field
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashDocumentType( _name, _publicId, _systemId, _subset );
 }
Ejemplo n.º 29
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal abstract void ComputeHashValue(XmlHash xmlHash);
Ejemplo n.º 30
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.ComputeHashXmlDiffElement( this );
 }
Ejemplo n.º 31
0
// Methods
        // computes the hash value of the node and saves it into the _hashValue field
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashXmlDeclaration(_value);
        }
Ejemplo n.º 32
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashER( _name );
 }
Ejemplo n.º 33
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.ComputeHashXmlDiffElement(this);
        }
Ejemplo n.º 34
0
 // Methods
 // computes hash value of the node and stores it in the _hashValue variable
 internal override void ComputeHashValue( XmlHash xmlHash )
 {
     Debug.Assert( _hashValue == 0 );
     _hashValue = xmlHash.HashNamespace( _prefix, _namespaceURI );
 }
Ejemplo n.º 35
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashNamespace(_prefix, _namespaceURI);
        }
Ejemplo n.º 36
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashDocumentType(this._name, this._publicId, this._systemId, this._subset);
 }
Ejemplo n.º 37
0
// Methods
        // computes hash value of the node and stores it in the _hashValue variable
        internal override void ComputeHashValue(XmlHash xmlHash)
        {
            Debug.Assert(_hashValue == 0);
            _hashValue = xmlHash.HashCharacterNode((XmlNodeType)(int)_nodeType, _value);
        }
Ejemplo n.º 38
0
 internal override void ComputeHashValue(XmlHash xmlHash)
 {
     this._hashValue = xmlHash.HashCharacterNode((XmlNodeType)this._nodeType, this._value);
 }