コード例 #1
0
        private void Compare(DiffResult result)
        {
            _continueComparing = true;
            bool controlRead, testRead;

            // Yuck! (Says RandyR) Exceptions are too expensive to use to control program flow like this.
            // Compare these times with and without the exceptions:
            // ZPI data set, DM09->DM10
            // With 19K exceptions: RevisionInspector.GetChangeRecords: 00:02:31.5675604
            // Use bool (_continueComparing) to control it, not exception: RevisionInspector.GetChangeRecords: 00:00:30.9605999
            // The bool code is two minutes faster.
            //try
            //{
            do
            {
                controlRead = _controlReader.Read();
                try
                {
                    testRead = _testReader.Read();
                }
                catch (Exception e)
                {
                    throw e;                            //just need a place to put a breakpoint
                }
                Compare(result, ref controlRead, ref testRead);
            } while (_continueComparing && controlRead && testRead);
            //}
            //catch (FlowControlException e)
            //{
            //    //what is this? it's how this class stops looking for more differences,
            //    //by throwing this exception, making us jump back up here.
            //    //Console.Out.WriteLine(e.Message);
            //}
        }
コード例 #2
0
 private void DifferenceFound(DifferenceType differenceType,
                              XmlNodeType controlNodeType,
                              XmlNodeType testNodeType,
                              DiffResult result)
 {
     DifferenceFound(new Difference(differenceType, controlNodeType, testNodeType),
                     result);
 }
コード例 #3
0
ファイル: XmlDiff.cs プロジェクト: sillsdev/chorus
        private void CompareText(DiffResult result, DifferenceType type)
        {
            string controlText = _controlReader.Value;
            string testText    = _testReader.Value;

            if (!string.Equals(controlText, testText))
            {
                DifferenceFound(type, result);
            }
        }
コード例 #4
0
        private void CompareText(DiffResult result)
        {
            string controlText = _controlReader.Value;
            string testText    = _testReader.Value;

            if (!String.Equals(controlText, testText))
            {
                DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
            }
        }
コード例 #5
0
 private void DifferenceFound(Difference difference, DiffResult result)
 {
     result.DifferenceFound(this, difference);
     if (!ContinueComparison(difference))
     {
         // Don't even think of using exceptions to control program flow. They are too expensive!
         //throw new FlowControlException(difference);
         _continueComparing = false;
     }
 }
コード例 #6
0
 private void CheckEndElement(XmlReader reader, ref bool readResult, DiffResult result)
 {
     readResult = reader.Read();
     if (!readResult || reader.NodeType != XmlNodeType.EndElement)
     {
         DifferenceFound(
             reader.NodeType == XmlNodeType.Text
                                         ? DifferenceType.TEXT_VALUE_ID
                                         : DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
     }
 }
コード例 #7
0
        private void CompareAttributes(DiffResult result, int controlAttributeCount)
        {
            string controlAttrValue, controlAttrName;
            string testAttrValue, testAttrName;

            var movedToControlAttr = _controlReader.MoveToFirstAttribute();
            var movedToTestAttr    = _testReader.MoveToFirstAttribute();

            for (int i = 0; _continueComparing && i < controlAttributeCount; ++i)
            {
                controlAttrName = _controlReader.Name;
                testAttrName    = _testReader.Name;

                controlAttrValue = _controlReader.Value;
                testAttrValue    = _testReader.Value;



                if (!String.Equals(controlAttrName, testAttrName))
                {
                    DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID, result);

                    if (!_testReader.MoveToAttribute(controlAttrName))
                    {
                        DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
                    }
                    testAttrValue = _testReader.Value;
                }

                //Hatton hack for LIFT: this is just not enough reason to tell the user there  was a change,
                //since it's basically a bug in the LIFT edittor, if it's the only change, and this diff
                //framework doesn't report *what* changed, so we can't filter it out later.
                if (!string.Equals(controlAttrName, "dateModified"))
                {
                    if (!String.Equals(controlAttrValue, testAttrValue))
                    {
                        DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
                    }
                }
                _controlReader.MoveToNextAttribute();
                _testReader.MoveToNextAttribute();
            }
            if (movedToControlAttr)
            {
                _controlReader.MoveToElement();
            }
            if (movedToTestAttr)
            {
                _testReader.MoveToElement();
            }
        }
コード例 #8
0
        private void CompareNodes(DiffResult result)
        {
            XmlNodeType controlNodeType = _controlReader.NodeType;
            XmlNodeType testNodeType    = _testReader.NodeType;

            if (!controlNodeType.Equals(testNodeType))
            {
                CheckNodeTypes(controlNodeType, testNodeType, result);
            }
            else if (controlNodeType == XmlNodeType.Element)
            {
                CompareElements(result);
            }
            else if (controlNodeType == XmlNodeType.Text)
            {
                CompareText(result);
            }
        }
コード例 #9
0
 private void CheckEmptyOrAtEndElement(DiffResult result,
                                       ref bool controlRead, ref bool testRead)
 {
     if (_controlReader.IsEmptyElement)
     {
         if (!_testReader.IsEmptyElement)
         {
             CheckEndElement(_testReader, ref testRead, result);
         }
     }
     else
     {
         if (_testReader.IsEmptyElement)
         {
             CheckEndElement(_controlReader, ref controlRead, result);
         }
     }
 }
コード例 #10
0
 public DiffResult Compare()
 {
     if (_diffResult == null)
     {
         _diffResult = new DiffResult();
         if (!_controlReader.Equals(_testReader))
         {
             try
             {
                 Compare(_diffResult);
             }
             catch (Exception e)
             {
                 throw e;                        //just need a place to put a breakpoint
             }
         }
     }
     return(_diffResult);
 }
コード例 #11
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 public DiffResult Compare()
 {
     if (_diffResult == null)
     {
         _diffResult = new DiffResult();
         if (!_controlReader.Equals(_testReader))
         {
             try
             {
                 Compare(_diffResult);
             }
             catch(Exception e)
             {
                 throw e;//just need a place to put a breakpoint
             }
         }
     }
     return _diffResult;
 }
コード例 #12
0
 private void Compare(DiffResult result, ref bool controlRead, ref bool testRead)
 {
     if (controlRead)
     {
         if (testRead)
         {
             CompareNodes(result);
             CheckEmptyOrAtEndElement(result, ref controlRead, ref testRead);
         }
         else
         {
             if (_testReader.NodeType == XmlNodeType.None && _controlReader.NodeType == XmlNodeType.EndElement)
             {
                 DifferenceFound(DifferenceType.EMPTY_NODE_ID, result);
             }
             else
             {
                 DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
             }
             return;
         }
     }
     //jh added this; under a condition I haven't got into an xdiff test yet, the
     // 'test' guy still had more children, and this fact was being missed by the above code
     // I (RBR) discovered the context in which this happens. it is:
     // Control: <Run />
     // Test:    <Run></Run>
     // At this point Control is at node type 'none', while test is at EndElement.
     if (controlRead != testRead)
     {
         if (_controlReader.NodeType == XmlNodeType.None && _testReader.NodeType == XmlNodeType.EndElement)
         {
             DifferenceFound(DifferenceType.EMPTY_NODE_ID, result);
         }
         else
         {
             DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
         }
     }
 }
コード例 #13
0
        private void CompareElements(DiffResult result)
        {
            string controlTagName = _controlReader.Name;
            string testTagName    = _testReader.Name;

            if (!String.Equals(controlTagName, testTagName))
            {
                DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
            }
            else
            {
                int controlAttributeCount = _controlReader.AttributeCount;
                int testAttributeCount    = _testReader.AttributeCount;
                if (controlAttributeCount != testAttributeCount)
                {
                    DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
                }
                else
                {
                    CompareAttributes(result, controlAttributeCount);
                }
            }
        }
コード例 #14
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void Compare(DiffResult result)
 {
     _continueComparing = true;
     bool controlRead, testRead;
     // Yuck! (Says RandyR) Exceptions are too expensive to use to control program flow like this.
     // Compare these times with and without the exceptions:
     // ZPI data set, DM09->DM10
     // With 19K exceptions: RevisionInspector.GetChangeRecords: 00:02:31.5675604
     // Use bool (_continueComparing) to control it, not exception: RevisionInspector.GetChangeRecords: 00:00:30.9605999
     // The bool code is two minutes faster.
     //try
     //{
         do
         {
             controlRead = _controlReader.Read();
             try
             {
                 testRead = _testReader.Read();
             }
             catch(Exception e)
             {
                 throw e;//just need a place to put a breakpoint
             }
             Compare(result, ref controlRead, ref testRead);
         } while (_continueComparing && controlRead && testRead);
     //}
     //catch (FlowControlException e)
     //{
     //    //what is this? it's how this class stops looking for more differences,
     //    //by throwing this exception, making us jump back up here.
     //    //Console.Out.WriteLine(e.Message);
     //}
 }
コード例 #15
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void CompareElements(DiffResult result)
 {
     string controlTagName = _controlReader.Name;
     string testTagName = _testReader.Name;
     if (!String.Equals(controlTagName, testTagName))
     {
         DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
     }
     else
     {
         int controlAttributeCount = _controlReader.AttributeCount;
         int testAttributeCount = _testReader.AttributeCount;
         if (controlAttributeCount != testAttributeCount)
         {
             DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
         }
         else
         {
             CompareAttributes(result, controlAttributeCount);
         }
     }
 }
コード例 #16
0
 private void DifferenceFound(DifferenceType differenceType, DiffResult result)
 {
     DifferenceFound(new Difference(differenceType), result);
 }
コード例 #17
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void CompareNodes(DiffResult result)
 {
     XmlNodeType controlNodeType = _controlReader.NodeType;
     XmlNodeType testNodeType = _testReader.NodeType;
     if (!controlNodeType.Equals(testNodeType))
     {
         CheckNodeTypes(controlNodeType, testNodeType, result);
     }
     else if (controlNodeType == XmlNodeType.Element)
     {
         CompareElements(result);
     }
     else if (controlNodeType == XmlNodeType.Text)
     {
         CompareText(result);
     }
 }
コード例 #18
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void CompareText(DiffResult result)
 {
     string controlText = _controlReader.Value;
     string testText = _testReader.Value;
     if (!String.Equals(controlText, testText))
     {
         DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
     }
 }
コード例 #19
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void DifferenceFound(Difference difference, DiffResult result)
 {
     result.DifferenceFound(this, difference);
     if (!ContinueComparison(difference))
     {
         // Don't even think of using exceptions to control program flow. They are too expensive!
         //throw new FlowControlException(difference);
         _continueComparing = false;
     }
 }
コード例 #20
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
        private void CompareAttributes(DiffResult result, int controlAttributeCount)
        {
            string controlAttrValue, controlAttrName;
            string testAttrValue, testAttrName;

            var movedToControlAttr = _controlReader.MoveToFirstAttribute();
            var movedToTestAttr = _testReader.MoveToFirstAttribute();
            for (int i = 0; _continueComparing && i < controlAttributeCount; ++i)
            {

                controlAttrName = _controlReader.Name;
                testAttrName = _testReader.Name;

                controlAttrValue = _controlReader.Value;
                testAttrValue = _testReader.Value;

                    if (!String.Equals(controlAttrName, testAttrName))
                    {
                        DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID, result);

                        if (!_testReader.MoveToAttribute(controlAttrName))
                        {
                            DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
                        }
                        testAttrValue = _testReader.Value;
                    }

                //Hatton hack for LIFT: this is just not enough reason to tell the user there  was a change,
                //since it's basically a bug in the LIFT edittor, if it's the only change, and this diff
                //framework doesn't report *what* changed, so we can't filter it out later.
                if (!string.Equals(controlAttrName, "dateModified"))
                {
                   if (!String.Equals(controlAttrValue, testAttrValue))
                    {
                        DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
                    }
                }
                _controlReader.MoveToNextAttribute();
                _testReader.MoveToNextAttribute();
            }
            if (movedToControlAttr)
                _controlReader.MoveToElement();
            if (movedToTestAttr)
                _testReader.MoveToElement();
        }
コード例 #21
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
        private void CheckNodeTypes(XmlNodeType controlNodeType, XmlNodeType testNodeType, DiffResult result)
        {
            XmlReader readerToAdvance = null;
            if (controlNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = _controlReader;
            }
            else if (testNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = _testReader;
            }

            if (readerToAdvance != null)
            {
                DifferenceFound(DifferenceType.HAS_XML_DECLARATION_PREFIX_ID,
                                controlNodeType, testNodeType, result);
                readerToAdvance.Read();
                CompareNodes(result);
            }
            else
            {
                DifferenceFound(DifferenceType.NODE_TYPE_ID, controlNodeType,
                                testNodeType, result);
            }
        }
コード例 #22
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
        private void CheckEmptyOrAtEndElement(DiffResult result,
											  ref bool controlRead, ref bool testRead)
        {
            if (_controlReader.IsEmptyElement)
            {
                if (!_testReader.IsEmptyElement)
                {
                    CheckEndElement(_testReader, ref testRead, result);
                }
            }
            else
            {
                if (_testReader.IsEmptyElement)
                {
                    CheckEndElement(_controlReader, ref controlRead, result);
                }
            }
        }
コード例 #23
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
        private void DifferenceFound(DifferenceType differenceType,
									 XmlNodeType controlNodeType,
									 XmlNodeType testNodeType,
									 DiffResult result)
        {
            DifferenceFound(new Difference(differenceType, controlNodeType, testNodeType),
                            result);
        }
コード例 #24
0
        private void CheckNodeTypes(XmlNodeType controlNodeType, XmlNodeType testNodeType, DiffResult result)
        {
            XmlReader readerToAdvance = null;

            if (controlNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = _controlReader;
            }
            else if (testNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = _testReader;
            }

            if (readerToAdvance != null)
            {
                DifferenceFound(DifferenceType.HAS_XML_DECLARATION_PREFIX_ID,
                                controlNodeType, testNodeType, result);
                readerToAdvance.Read();
                CompareNodes(result);
            }
            else
            {
                DifferenceFound(DifferenceType.NODE_TYPE_ID, controlNodeType,
                                testNodeType, result);
            }
        }
コード例 #25
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void DifferenceFound(DifferenceType differenceType, DiffResult result)
 {
     DifferenceFound(new Difference(differenceType), result);
 }
コード例 #26
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void CheckEndElement(XmlReader reader, ref bool readResult, DiffResult result)
 {
     readResult = reader.Read();
     if (!readResult || reader.NodeType != XmlNodeType.EndElement)
     {
         DifferenceFound(
             reader.NodeType == XmlNodeType.Text
                 ? DifferenceType.TEXT_VALUE_ID
                 : DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
     }
 }
コード例 #27
0
ファイル: XmlDiff.cs プロジェクト: JessieGriffin/chorus
 private void Compare(DiffResult result, ref bool controlRead, ref bool testRead)
 {
     if (controlRead)
     {
         if (testRead)
         {
             CompareNodes(result);
             CheckEmptyOrAtEndElement(result, ref controlRead, ref testRead);
         }
         else
         {
             if (_testReader.NodeType == XmlNodeType.None && _controlReader.NodeType == XmlNodeType.EndElement)
             {
                 DifferenceFound(DifferenceType.EMPTY_NODE_ID, result);
             }
             else
             {
                 DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
             }
             return;
         }
     }
     //jh added this; under a condition I haven't got into an xdiff test yet, the
     // 'test' guy still had more children, and this fact was being missed by the above code
     // I (RBR) discovered the context in which this happens. it is:
     // Control: <Run />
     // Test:    <Run></Run>
     // At this point Control is at node type 'none', while test is at EndElement.
     if (controlRead != testRead)
     {
         if (_controlReader.NodeType == XmlNodeType.None && _testReader.NodeType == XmlNodeType.EndElement)
         {
             DifferenceFound(DifferenceType.EMPTY_NODE_ID, result);
         }
         else
         {
             DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
         }
     }
 }