Ejemplo n.º 1
0
        /// <summary>
        /// Compare two blocks of characters against each other.
        /// </summary>
        /// <param name="poAlpha">First block of characters.</param>
        /// <param name="poBeta">Second block of characters.</param>
        public override void Compare(Block poAlpha1, Block poBeta1)
        {
            Sections.OnAddSection += new Sections.AddSectionHandler(Sections_OnAddSection);

            BlockOfCharacters poAlpha = (BlockOfCharacters)poAlpha1;
            BlockOfCharacters poBeta  = (BlockOfCharacters)poBeta1;

            this.MinElements = this.MinChars;
            Analyse(1, poAlpha, 1, poBeta);

            //Add missing alpha segments.
            SegmentComparer oSegAComparer = new SegmentComparer();

            oSegAComparer.ComparisonMethod = SegmentComparer.ComparisonType.AlphaPosition;
            AddMissingSegments("A1", oSegAComparer, mcSegA, poAlpha);

            //Add missing beta segments.
            SegmentComparer oSegBComparer = new SegmentComparer();

            oSegBComparer.ComparisonMethod = SegmentComparer.ComparisonType.BetaPosition;
            AddMissingSegments("B1", oSegBComparer, mcSegB, poBeta);

            //Check if user has chosen to cancel run.
            if (Interrupt.Reason == "Cancel")
            {
                return;
            }

            //Merge into report.
            long   nCountA            = 0;
            long   nCountB            = 0;
            string sMatchIndent       = string.Empty;
            string sInsertIndent      = string.Empty;
            SegmentOfCharacters oSegA = new SegmentOfCharacters();
            SegmentOfCharacters oSegB = new SegmentOfCharacters();

            oSegA.Type = "X1";
            oSegA.Data = new BlockOfCharacters();
            oSegB.Type = "Z1";
            oSegB.Data = new BlockOfCharacters();
            SectionOfCharacters oSection = new SectionOfCharacters();

            while (nCountA < mcSegA.Count || nCountB < mcSegB.Count)
            {
                if (nCountA < mcSegA.Count)
                {
                    oSegA = (SegmentOfCharacters)mcSegA[(int)nCountA];
                }
                if (nCountB < mcSegB.Count)
                {
                    oSegB = (SegmentOfCharacters)mcSegB[(int)nCountB];
                }
                if (oSegA.Type.Substring(0, 1) == "M" && oSegB.Type.Substring(0, 1) == "M")
                {
                    if (!oSegA.Data.IsEmpty)
                    {
                        oSection             = new SectionOfCharacters();
                        oSection.Type        = oSegA.Type;
                        oSection.Position    = oSegA.PositionA;
                        oSection.PositionA   = oSegA.PositionA;
                        oSection.PositionB   = oSegB.PositionB;
                        oSection.Size        = oSegA.Size;
                        oSection.Data        = oSegA.Data;
                        oSection.Indentation = sInsertIndent;
                        Sections.Add(oSection);
                        oSegA.Display(sInsertIndent);
                        sMatchIndent  = oSegA.Indent;
                        sInsertIndent = oSegA.Indent;
                    }
                    nCountA++;
                    nCountB++;
                }
                else if (oSegA.Type.Substring(0, 1) == "M" && oSegB.Type.Substring(0, 1) != "M")
                {
                    if (!oSegB.Data.IsEmpty)
                    {
                        oSection             = new SectionOfCharacters();
                        oSection.Type        = oSegB.Type;
                        oSection.Position    = oSegB.PositionB;
                        oSection.PositionA   = oSegA.PositionA;
                        oSection.PositionB   = oSegB.PositionB;
                        oSection.Size        = oSegB.Size;
                        oSection.Data        = oSegB.Data;
                        oSection.Indentation = sMatchIndent;
                        Sections.Add(oSection);
                        oSegB.Display(sMatchIndent);
                    }
                    nCountB++;
                }
                else if (oSegA.Type.Substring(0, 1) != "M" && oSegB.Type.Substring(0, 1) == "M")
                {
                    if (!oSegA.Data.IsEmpty)
                    {
                        oSection             = new SectionOfCharacters();
                        oSection.Type        = oSegA.Type;
                        oSection.Position    = oSegA.PositionA;
                        oSection.PositionA   = oSegA.PositionA;
                        oSection.PositionB   = oSegB.PositionB;
                        oSection.Size        = oSegA.Size;
                        oSection.Data        = oSegA.Data;
                        oSection.Indentation = sMatchIndent;
                        Sections.Add(oSection);
                        oSegA.Display(sMatchIndent);
                        sInsertIndent = oSegA.Indent;
                    }
                    nCountA++;
                }
                else if (oSegA.Type.Substring(0, 1) != "M" && oSegB.Type.Substring(0, 1) != "M")
                {
                    if (oSegA.PositionA < oSegB.PositionB)
                    {
                        if (!oSegA.Data.IsEmpty)
                        {
                            oSection             = new SectionOfCharacters();
                            oSection.Type        = oSegA.Type;
                            oSection.Position    = oSegA.PositionA;
                            oSection.PositionA   = oSegA.PositionA;
                            oSection.PositionB   = oSegB.PositionB;
                            oSection.Size        = oSegA.Size;
                            oSection.Data        = oSegA.Data;
                            oSection.Indentation = sMatchIndent;
                            Sections.Add(oSection);
                            oSegA.Display(sMatchIndent);
                            sInsertIndent = oSegA.Indent;
                        }
                        if (!oSegB.Data.IsEmpty)
                        {
                            oSection             = new SectionOfCharacters();
                            oSection.Type        = oSegB.Type;
                            oSection.Position    = oSegB.PositionB;
                            oSection.PositionA   = oSegA.PositionA;
                            oSection.PositionB   = oSegB.PositionB;
                            oSection.Size        = oSegB.Size;
                            oSection.Data        = oSegB.Data;
                            oSection.Indentation = sMatchIndent;
                            Sections.Add(oSection);
                            oSegB.Display(sMatchIndent);
                        }
                    }
                    else
                    {
                        if (!oSegB.Data.IsEmpty)
                        {
                            oSection             = new SectionOfCharacters();
                            oSection.Type        = oSegB.Type;
                            oSection.Position    = oSegB.PositionB;
                            oSection.PositionA   = oSegA.PositionA;
                            oSection.PositionB   = oSegB.PositionB;
                            oSection.Size        = oSegB.Size;
                            oSection.Data        = oSegB.Data;
                            oSection.Indentation = sMatchIndent;
                            Sections.Add(oSection);
                            oSegB.Display(sMatchIndent);
                        }
                        if (!oSegA.Data.IsEmpty)
                        {
                            oSection             = new SectionOfCharacters();
                            oSection.Type        = oSegA.Type;
                            oSection.Position    = oSegA.PositionA;
                            oSection.PositionA   = oSegA.PositionA;
                            oSection.PositionB   = oSegB.PositionB;
                            oSection.Size        = oSegA.Size;
                            oSection.Data        = oSegA.Data;
                            oSection.Indentation = sMatchIndent;
                            Sections.Add(oSection);
                            oSegA.Display(sMatchIndent);
                            sInsertIndent = oSegA.Indent;
                        }
                    }
                    nCountA++;
                    nCountB++;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Build comparisons list.
 /// </summary>
 private void BuildComparisons()
 {
     mcComparisons = new List <Comparison>();
     for (int nCount = 0; nCount < Sections.Count; nCount++)
     {
         Section oSection = (Section)Sections[nCount];
         if (oSection is SectionOfLines)
         {
             SectionOfLines oSectionOfLines = (SectionOfLines)oSection;
             BlockOfLines   moBlock         = (BlockOfLines)oSectionOfLines.Data;
             if (oSectionOfLines.Type.Substring(0, 1) == "M")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfLines.PositionA + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Line, Comparison.MatchEnum.Match, position, sData, position, sData);
                     mcComparisons.Add(oComparison);
                 }
             }
             else if (oSectionOfLines.Type.Substring(0, 1) == "A")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfLines.PositionA + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Line, Comparison.MatchEnum.InsertNew, position, sData, -1, string.Empty);
                     mcComparisons.Add(oComparison);
                 }
             }
             else if (oSectionOfLines.Type.Substring(0, 1) == "B")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfLines.PositionB + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Line, Comparison.MatchEnum.DeleteOld, -1, string.Empty, position, sData);
                     mcComparisons.Add(oComparison);
                 }
             }
         }
         if (oSection is SectionOfCharacters)
         {
             SectionOfCharacters oSectionOfCharacters = (SectionOfCharacters)oSection;
             BlockOfCharacters   moBlock = (BlockOfCharacters)oSectionOfCharacters.Data;
             if (oSectionOfCharacters.Type.Substring(0, 1) == "M")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfCharacters.PositionA + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Character, Comparison.MatchEnum.Match, position, sData, position, sData);
                     mcComparisons.Add(oComparison);
                 }
             }
             else if (oSectionOfCharacters.Type.Substring(0, 1) == "A")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfCharacters.PositionA + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Character, Comparison.MatchEnum.InsertNew, position, sData, -1, string.Empty);
                     mcComparisons.Add(oComparison);
                 }
             }
             else if (oSectionOfCharacters.Type.Substring(0, 1) == "B")
             {
                 for (long nIndex = 0; nIndex < moBlock.Elements.Length; nIndex++)
                 {
                     long       position    = oSectionOfCharacters.PositionB + nIndex;
                     string     sData       = moBlock.Elements[nIndex].ToDisplay();
                     Comparison oComparison = new Comparison(Comparison.GranularityEnum.Character, Comparison.MatchEnum.DeleteOld, -1, string.Empty, position, sData);
                     mcComparisons.Add(oComparison);
                 }
             }
         }
     }
 }