Exemplo n.º 1
0
        private DiffResult PerformDiff(TextReader reader1, TextReader reader2)
        {
            _xmlDiff = new Palaso.Lift.Merging.XmlDiff.XmlDiff(reader1, reader2);
            DiffResult result = _xmlDiff.Compare();

            return(result);
        }
Exemplo n.º 2
0
		//was public, but jh didn't see why
		internal void DifferenceFound(XmlDiff inDiff, Difference difference) {
			_areIdentical = false;
			if (difference.HasMajorDifference) {
				_areEqual = false;
			}
			_difference = difference;
			if (_stringBuilder.Length == 0) {
				_stringBuilder.Append(inDiff.OptionalDescription);
			}
			_stringBuilder.Append(Environment.NewLine).Append(difference);
		}
Exemplo n.º 3
0
		private void ComputeDiff(TextReader original, TextReader modified, IProgress progress)
		{
			//enchance: just get a checksum for each entry in both files, use that to determine everything else

			_idsOfDeletedEntries = new List<string>();
			_idsOfAddedEntries = new List<string>();
			_idsOfEditedEntries = new List<string>();
			_idsInOriginal = new List<string>();

			XPathDocument modifiedDoc = new XPathDocument(modified);
			XPathNavigator modifiedNav = modifiedDoc.CreateNavigator();


			XPathDocument originalDoc = new XPathDocument(original);
			XPathNavigator originalNav = originalDoc.CreateNavigator();
			XPathNodeIterator liftElement = originalNav.SelectChildren(XPathNodeType.Element);
			liftElement.MoveNext();//move to the one and only <lift> element
			if (liftElement.Current == null)
				return;
			XPathNodeIterator originalChildren = liftElement.Current.SelectChildren(XPathNodeType.Element);
			StringDictionary idToContentsOfModifiedEntries = new StringDictionary();

			XPathNodeIterator liftOfModifiedFile = modifiedNav.SelectChildren(XPathNodeType.Element);
			liftOfModifiedFile.MoveNext();
			if (liftOfModifiedFile.Current != null)
			{
				XPathNodeIterator modifiedChildren = liftOfModifiedFile.Current.SelectChildren(XPathNodeType.Element);
				while (modifiedChildren.MoveNext())
				{
					//TODO: consider if there are benefits to using guid as the first key, then try id
					if (modifiedChildren.Current != null)
					{
						string id = modifiedChildren.Current.GetAttribute("id", string.Empty);
						idToContentsOfModifiedEntries.Add(id, modifiedChildren.Current.OuterXml);
					}
				}
			}

			while (originalChildren.MoveNext())
			{
				if (originalChildren.Current != null)
				{
					string id = originalChildren.Current.GetAttribute("id", string.Empty);
					_idsInOriginal.Add(id);

					if(!idToContentsOfModifiedEntries.ContainsKey(id))
					{
						_idsOfDeletedEntries.Add(id);
					}
					else
					{
						var diff = new XmlDiff.XmlDiff(originalChildren.Current.OuterXml, idToContentsOfModifiedEntries[id]);
						DiffResult result = diff.Compare();
						if (!result.AreEqual)
						{
							_idsOfEditedEntries.Add(id);
						}
					}
				}
			}
			foreach (string id in idToContentsOfModifiedEntries.Keys)
			{
				if(!_idsInOriginal.Contains(id))
					_idsOfAddedEntries.Add(id);
			}
		}
Exemplo n.º 4
0
		/// <summary>
		/// Check whether the two XML elements are equal.
		/// </summary>
		public static bool AreXmlElementsEqual(XmlNode ours, XmlNode theirs)
		{
			if (ours.NodeType == XmlNodeType.Text)
			{
				if (ours.NodeType != XmlNodeType.Text)
				{
					return false;
				}
				bool oursIsEmpty = (ours.InnerText.Trim() == string.Empty);
				bool theirsIsEmpty = (theirs.InnerText.Trim() == string.Empty);
				if(oursIsEmpty != theirsIsEmpty)
				{
					return false;
				}
				return ours.InnerText.Trim() == theirs.InnerText.Trim();
			}
		   // DiffConfiguration config = new DiffConfiguration(WhitespaceHandling.None);
			var diff = new XmlDiff(new XmlInput(ours.OuterXml), new XmlInput(theirs.OuterXml));//, config);
			DiffResult d = diff.Compare();
			return (d == null || d.Difference == null || !d.Difference.HasMajorDifference);
		}
Exemplo n.º 5
0
        private void ComputeDiff(TextReader original, TextReader modified, IProgress progress)
        {
            //enchance: just get a checksum for each entry in both files, use that to determine everything else

            _idsOfDeletedEntries = new List <string>();
            _idsOfAddedEntries   = new List <string>();
            _idsOfEditedEntries  = new List <string>();
            _idsInOriginal       = new List <string>();

            XPathDocument  modifiedDoc = new XPathDocument(modified);
            XPathNavigator modifiedNav = modifiedDoc.CreateNavigator();


            XPathDocument     originalDoc = new XPathDocument(original);
            XPathNavigator    originalNav = originalDoc.CreateNavigator();
            XPathNodeIterator liftElement = originalNav.SelectChildren(XPathNodeType.Element);

            liftElement.MoveNext();            //move to the one and only <lift> element
            if (liftElement.Current == null)
            {
                return;
            }
            XPathNodeIterator originalChildren = liftElement.Current.SelectChildren(XPathNodeType.Element);
            StringDictionary  idToContentsOfModifiedEntries = new StringDictionary();

            XPathNodeIterator liftOfModifiedFile = modifiedNav.SelectChildren(XPathNodeType.Element);

            liftOfModifiedFile.MoveNext();
            if (liftOfModifiedFile.Current != null)
            {
                XPathNodeIterator modifiedChildren = liftOfModifiedFile.Current.SelectChildren(XPathNodeType.Element);
                while (modifiedChildren.MoveNext())
                {
                    //TODO: consider if there are benefits to using guid as the first key, then try id
                    if (modifiedChildren.Current != null)
                    {
                        string id = modifiedChildren.Current.GetAttribute("id", string.Empty);
                        idToContentsOfModifiedEntries.Add(id, modifiedChildren.Current.OuterXml);
                    }
                }
            }

            while (originalChildren.MoveNext())
            {
                if (originalChildren.Current != null)
                {
                    string id = originalChildren.Current.GetAttribute("id", string.Empty);
                    _idsInOriginal.Add(id);

                    if (!idToContentsOfModifiedEntries.ContainsKey(id))
                    {
                        _idsOfDeletedEntries.Add(id);
                    }
                    else
                    {
                        var        diff   = new XmlDiff.XmlDiff(originalChildren.Current.OuterXml, idToContentsOfModifiedEntries[id]);
                        DiffResult result = diff.Compare();
                        if (!result.AreEqual)
                        {
                            _idsOfEditedEntries.Add(id);
                        }
                    }
                }
            }
            foreach (string id in idToContentsOfModifiedEntries.Keys)
            {
                if (!_idsInOriginal.Contains(id))
                {
                    _idsOfAddedEntries.Add(id);
                }
            }
        }