Exemplo n.º 1
0
 public XmlDiff(XmlInput control, XmlInput test,
                DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
     _controlReader     = CreateXmlReader(control);
     if (control.Equals(test))
     {
         _testReader = _controlReader;
     }
     else
     {
         _testReader = CreateXmlReader(test);
     }
 }
Exemplo n.º 2
0
        public XmlDiff(XmlInput control, XmlInput test,
					   DiffConfiguration diffConfiguration)
        {
            _diffConfiguration = diffConfiguration;
            _controlReader = CreateXmlReader(control);
            if (control.Equals(test))
            {
                _testReader = _controlReader;
            }
            else
            {
                _testReader = CreateXmlReader(test);
            }
        }
Exemplo n.º 3
0
        private XmlReader CreateXmlReader(XmlInput forInput)
        {
            XmlReader xmlReader = forInput.CreateXmlReader();

            if (xmlReader is XmlTextReader)
            {
                ((XmlTextReader)xmlReader).WhitespaceHandling = _diffConfiguration.WhitespaceHandling;
            }

            if (_diffConfiguration.UseValidatingParser)
            {
#pragma warning disable 612,618
                XmlValidatingReader validatingReader = new XmlValidatingReader(xmlReader);
#pragma warning restore 612,618
                return(validatingReader);
            }

            return(xmlReader);
        }
Exemplo n.º 4
0
 public XmlDiff(XmlInput control, XmlInput test)
     : this(control, test, new DiffConfiguration())
 {
 }
Exemplo n.º 5
0
 public static bool AreXmlElementsEqual(XmlInput ours, XmlInput theirs)
 {
     // Must use 'config', or whitespace only differences will make the elements different.
     // cf. diffing changeset 240 and 241 in the Tok Pisin project for such whitespace differences.
     var config = new DiffConfiguration(WhitespaceHandling.None);
     var diff = new XmlDiff(ours, theirs, config);
     var diffResult = diff.Compare();
     return (diffResult == null || diffResult.Difference == null || !diffResult.Difference.MajorDifference);
 }
Exemplo n.º 6
0
		private void RunLoopClicked(object sender, EventArgs e)
		{
			var sb = new StringBuilder();
			const string data = "<element />";

			var bytesTimer = new Stopwatch();
			var ourBytes = Encoding.UTF8.GetBytes(data);
			var theirBytes = Encoding.UTF8.GetBytes(data);
			bytesTimer.Start();
			for (var i = 0; i < 100000; ++i)
			{
				XmlUtilities.AreXmlElementsEqual(ourBytes, theirBytes);
			}
			bytesTimer.Stop();
			sb.AppendFormat("Time to check (as bytes): {0}ms; {1}ticks.", bytesTimer.ElapsedMilliseconds, bytesTimer.ElapsedTicks);
			sb.AppendLine();

			var stringTimer = new Stopwatch();
			stringTimer.Start();
			for (var i = 0; i < 100000; ++i)
			{
				XmlUtilities.AreXmlElementsEqual(data, data);
			}
			stringTimer.Stop();
			sb.AppendFormat("Time to check (as string): {0}ms; {1}ticks.", stringTimer.ElapsedMilliseconds, stringTimer.ElapsedTicks);
			sb.AppendLine();

			var doc = new XmlDocument();
			var ourNode = XmlUtilities.GetDocumentNodeFromRawXml(data, doc);
			var theirNode = XmlUtilities.GetDocumentNodeFromRawXml(data, doc);
			var xmlNodeTimer = new Stopwatch();
			xmlNodeTimer.Start();
			for (var i = 0; i < 100000; ++i)
			{
				XmlUtilities.AreXmlElementsEqual(ourNode, theirNode);
			}
			xmlNodeTimer.Stop();
			sb.AppendFormat("Time to check (as XmlNode): {0}ms; {1}ticks.", xmlNodeTimer.ElapsedMilliseconds, xmlNodeTimer.ElapsedTicks);
			sb.AppendLine();

			var ourInput = new XmlInput(data);
			var theirInput = new XmlInput(data);
			var xmlInputTimer = new Stopwatch();
			xmlInputTimer.Start();
			for (var i = 0; i < 100000; ++i)
			{
				XmlUtilities.AreXmlElementsEqual(ourInput, theirInput);
			}
			xmlInputTimer.Stop();
			sb.AppendFormat("Time to check (as XmlInput): {0}ms; {1}ticks.", xmlInputTimer.ElapsedMilliseconds, xmlInputTimer.ElapsedTicks);

			MessageBox.Show(sb.ToString());
		}
Exemplo n.º 7
0
 public XmlDiff(XmlInput control, XmlInput test)
     : this(control, test, new DiffConfiguration())
 {
 }
Exemplo n.º 8
0
        private XmlReader CreateXmlReader(XmlInput forInput)
        {
            XmlReader xmlReader = forInput.CreateXmlReader();

            if (xmlReader is XmlTextReader)
            {
                ((XmlTextReader)xmlReader).WhitespaceHandling = _diffConfiguration.WhitespaceHandling;
            }

            if (_diffConfiguration.UseValidatingParser)
            {
            #pragma warning disable 612,618
                XmlValidatingReader validatingReader = new XmlValidatingReader(xmlReader);
            #pragma warning restore 612,618
                return validatingReader;
            }

            return xmlReader;
        }