/// <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++;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Add missing alpha or beta segments to alpha or beta ArrayList.
        /// </summary>
        /// <param name="psMissingType">Missing segment type for all missing segments to be added.</param>
        /// <param name="poSegComparer">Segment comparar for alpha or beta segment ArrayList.</param>
        /// <param name="pcSegments">Alpha or beta segment ArrayList.</param>
        /// <param name="poFullBlock">Full alpha or beta block read in from original file.</param>
        protected void AddMissingSegments(string psMissingType, SegmentComparer poSegComparer, Segments pcSegments, Block poFullBlock)
        {
            pcSegments.Sort(poSegComparer);
            long    nCount   = 0;
            long    nPrevPos = 1;
            long    nPrevLen = 0;
            long    nPrevEnd = 0;
            long    nThisPos = 1;
            long    nThisLen = 0;
            Segment oSegment = null;
            Segment oMissing = null;

            while (nCount < pcSegments.Count)
            {
                oSegment = (Segment)pcSegments[(int)nCount];
                if (oSegment.Type.Substring(0, 1) == "M")
                {
                    if (psMissingType == "A1")
                    {
                        nThisPos = oSegment.PositionA;
                    }
                    if (psMissingType == "B1")
                    {
                        nThisPos = oSegment.PositionB;
                    }
                    nThisLen = oSegment.Size;
                    if (nThisPos - nPrevEnd > 1)
                    {
                        oMissing           = AllocateSegment();
                        oMissing.Type      = psMissingType;
                        oMissing.PositionA = nPrevEnd + 1;
                        oMissing.PositionB = nPrevEnd + 1;
                        oMissing.Data      = poFullBlock.Extract(nPrevEnd + 1, nThisPos - (nPrevEnd + 1));
                        oMissing.Size      = oMissing.Data.Length;
                        SignalBeginSegment(oMissing.Data.ContentsLength);
                        pcSegments.Add(oMissing);
                        SignalEndOfSegment();
                    }
                    nPrevPos = nThisPos;
                    nPrevLen = nThisLen;
                    nPrevEnd = nPrevPos + nPrevLen - 1;
                }
                else
                {
                    break;
                }
                nCount++;
            }
            if (nPrevEnd < poFullBlock.Length)
            {
                nThisPos           = poFullBlock.Length + 1;
                oMissing           = AllocateSegment();
                oMissing.Type      = psMissingType;
                oMissing.PositionA = nPrevEnd + 1;
                oMissing.PositionB = nPrevEnd + 1;
                oMissing.Data      = poFullBlock.Extract(nPrevEnd + 1, nThisPos - (nPrevEnd + 1));
                oMissing.Size      = oMissing.Data.Length;
                SignalBeginSegment(oMissing.Data.ContentsLength);
                pcSegments.Add(oMissing);
                SignalEndOfSegment();
            }
            pcSegments.Sort(poSegComparer);
        }
Exemple #3
0
        /// <summary>
        /// Compare two blocks of lines against each other.
        /// </summary>
        /// <param name="poAlpha">First block of lines.</param>
        /// <param name="poBeta">Second block of lines.</param>
        public override void Compare(Block poAlpha1, Block poBeta1)
        {
            Sections.OnAddSection += new Sections.AddSectionHandler(Sections_OnAddSection);

            BlockOfLines      poAlpha     = (BlockOfLines)poAlpha1;
            BlockOfLines      poBeta      = (BlockOfLines)poBeta1;
            BlockOfCharacters oAlphaChars = null;
            BlockOfCharacters oBetaChars  = null;

            if (poAlpha.ContentsLength >= poBeta.ContentsLength)
            {
                mcSegA.ProgressOn = Segments.ProgressOnEnum.Alpha;
                mcSegB.ProgressOn = Segments.ProgressOnEnum.Alpha;
                SignalBeginCompare(poAlpha.ContentsLength);
            }
            else
            {
                mcSegA.ProgressOn = Segments.ProgressOnEnum.Beta;
                mcSegB.ProgressOn = Segments.ProgressOnEnum.Beta;
                SignalBeginCompare(poBeta.ContentsLength);
            }

            this.MinElements = this.MinLines;
            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);

            SignalEndOfCompare();

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

            //Report.
            if (poAlpha.ContentsLength >= poBeta.ContentsLength)
            {
                Sections.ProgressOn = Sections.ProgressOnEnum.Alpha;
                SignalBeginReport(poAlpha.ContentsLength);
            }
            else
            {
                Sections.ProgressOn = Sections.ProgressOnEnum.Beta;
                SignalBeginReport(poBeta.ContentsLength);
            }

            //Merge into report.
            long           nCountA = 0;
            long           nCountB = 0;
            SegmentOfLines oSegA   = new SegmentOfLines();
            SegmentOfLines oSegB   = new SegmentOfLines();

            oSegA.Type = "X1";
            oSegA.Data = new BlockOfLines();
            oSegB.Type = "Z1";
            oSegB.Data = new BlockOfLines();
            SectionOfLines oSection = new SectionOfLines();

            while (nCountA < mcSegA.Count || nCountB < mcSegB.Count)
            {
                if (nCountA < mcSegA.Count)
                {
                    oSegA = (SegmentOfLines)mcSegA[(int)nCountA];
                }
                if (nCountB < mcSegB.Count)
                {
                    oSegB = (SegmentOfLines)mcSegB[(int)nCountB];
                }
                if (oSegA.Type.Substring(0, 1) == "M" && oSegB.Type.Substring(0, 1) == "M")
                {
                    if (!oSegA.Data.IsEmpty)
                    {
                        oSegA.Display();
                        oSection           = new SectionOfLines();
                        oSection.Type      = oSegA.Type;
                        oSection.Position  = oSegA.PositionA;
                        oSection.PositionA = oSegA.PositionA;
                        oSection.PositionB = oSegB.PositionB;
                        oSection.Size      = oSegA.Size;
                        oSection.Data      = oSegA.Data;
                        Sections.Add(oSection);
                    }
                    nCountA++;
                    nCountB++;
                }
                else if (oSegA.Type.Substring(0, 1) == "M" && oSegB.Type.Substring(0, 1) != "M")
                {
                    if (!oSegB.Data.IsEmpty)
                    {
                        oSegB.Display();
                        oSection           = new SectionOfLines();
                        oSection.Type      = oSegB.Type;
                        oSection.Position  = oSegB.PositionB;
                        oSection.PositionA = oSegA.PositionA;
                        oSection.PositionB = oSegB.PositionB;
                        oSection.Size      = oSegB.Size;
                        oSection.Data      = oSegB.Data;
                        Sections.Add(oSection);
                    }
                    nCountB++;
                }
                else if (oSegA.Type.Substring(0, 1) != "M" && oSegB.Type.Substring(0, 1) == "M")
                {
                    if (!oSegA.Data.IsEmpty)
                    {
                        oSegA.Display();
                        oSection           = new SectionOfLines();
                        oSection.Type      = oSegA.Type;
                        oSection.Position  = oSegA.PositionA;
                        oSection.PositionA = oSegA.PositionA;
                        oSection.PositionB = oSegB.PositionB;
                        oSection.Size      = oSegA.Size;
                        oSection.Data      = oSegA.Data;
                        Sections.Add(oSection);
                    }
                    nCountA++;
                }
                else if (oSegA.Type.Substring(0, 1) != "M" && oSegB.Type.Substring(0, 1) != "M")
                {
                    if (this.CompleteLines)
                    {
                        if (oSegA.PositionA < oSegB.PositionB)
                        {
                            if (!oSegA.Data.IsEmpty)
                            {
                                oSegA.Display();
                                oSection           = new SectionOfLines();
                                oSection.Type      = oSegA.Type;
                                oSection.Position  = oSegA.PositionA;
                                oSection.PositionA = oSegA.PositionA;
                                oSection.PositionB = oSegB.PositionB;
                                oSection.Size      = oSegA.Size;
                                oSection.Data      = oSegA.Data;
                                Sections.Add(oSection);
                            }
                            if (!oSegB.Data.IsEmpty)
                            {
                                oSegB.Display();
                                oSection           = new SectionOfLines();
                                oSection.Type      = oSegB.Type;
                                oSection.Position  = oSegB.PositionB;
                                oSection.PositionA = oSegA.PositionA;
                                oSection.PositionB = oSegB.PositionB;
                                oSection.Size      = oSegB.Size;
                                oSection.Data      = oSegB.Data;
                                Sections.Add(oSection);
                            }
                        }
                        else
                        {
                            if (!oSegB.Data.IsEmpty)
                            {
                                oSegB.Display();
                                oSection           = new SectionOfLines();
                                oSection.Type      = oSegB.Type;
                                oSection.Position  = oSegB.PositionB;
                                oSection.PositionA = oSegA.PositionA;
                                oSection.PositionB = oSegB.PositionB;
                                oSection.Size      = oSegB.Size;
                                oSection.Data      = oSegB.Data;
                                Sections.Add(oSection);
                            }
                            if (!oSegA.Data.IsEmpty)
                            {
                                oSegA.Display();
                                oSection           = new SectionOfLines();
                                oSection.Type      = oSegA.Type;
                                oSection.Position  = oSegA.PositionA;
                                oSection.PositionA = oSegA.PositionA;
                                oSection.PositionB = oSegB.PositionB;
                                oSection.Size      = oSegA.Size;
                                oSection.Data      = oSegA.Data;
                                Sections.Add(oSection);
                            }
                        }
                        nCountA++;
                        nCountB++;
                    }
                    else
                    {
                        if (!oSegA.Data.IsEmpty && !oSegB.Data.IsEmpty)
                        {
                            if (oSegA.Data.Length < this.SubLineMatchLimit && oSegB.Data.Length < this.SubLineMatchLimit)
                            {
                                //Look for sub-line matches.
                                oAlphaChars = oSegA.Data.GetCharacters();
                                oBetaChars  = oSegB.Data.GetCharacters();
                                CompareCharacters oCompareCharacters = new CompareCharacters();
                                oCompareCharacters.MinElements       = this.MinChars;
                                oCompareCharacters.MinChars          = this.MinChars;
                                oCompareCharacters.MinLines          = this.MinLines;
                                oCompareCharacters.LimitElements     = this.LimitCharacters;
                                oCompareCharacters.LimitCharacters   = this.LimitCharacters;
                                oCompareCharacters.LimitLines        = this.LimitLines;
                                oCompareCharacters.SubLineMatchLimit = this.SubLineMatchLimit;
                                oCompareCharacters.CompleteLines     = this.CompleteLines;
                                oCompareCharacters.Sections          = this.Sections;
                                oCompareCharacters.Interrupt         = this.Interrupt;
                                oCompareCharacters.Compare(oAlphaChars, oBetaChars);
                            }
                            else
                            {
                                //Don't look for sub-line matches if the mismatched blocks are too large,
                                //since this has a large performance impact for little likely benefit.
                                if (oSegA.PositionA < oSegB.PositionB)
                                {
                                    if (!oSegA.Data.IsEmpty)
                                    {
                                        oSegA.Display();
                                        oSection           = new SectionOfLines();
                                        oSection.Type      = oSegA.Type;
                                        oSection.Position  = oSegA.PositionA;
                                        oSection.PositionA = oSegA.PositionA;
                                        oSection.PositionB = oSegB.PositionB;
                                        oSection.Size      = oSegA.Size;
                                        oSection.Data      = oSegA.Data;
                                        Sections.Add(oSection);
                                    }
                                    if (!oSegB.Data.IsEmpty)
                                    {
                                        oSegB.Display();
                                        oSection           = new SectionOfLines();
                                        oSection.Type      = oSegB.Type;
                                        oSection.Position  = oSegB.PositionB;
                                        oSection.PositionA = oSegA.PositionA;
                                        oSection.PositionB = oSegB.PositionB;
                                        oSection.Size      = oSegB.Size;
                                        oSection.Data      = oSegB.Data;
                                        Sections.Add(oSection);
                                    }
                                }
                                else
                                {
                                    if (!oSegB.Data.IsEmpty)
                                    {
                                        oSegB.Display();
                                        oSection           = new SectionOfLines();
                                        oSection.Type      = oSegB.Type;
                                        oSection.Position  = oSegB.PositionB;
                                        oSection.PositionA = oSegA.PositionA;
                                        oSection.PositionB = oSegB.PositionB;
                                        oSection.Size      = oSegB.Size;
                                        oSection.Data      = oSegB.Data;
                                        Sections.Add(oSection);
                                    }
                                    if (!oSegA.Data.IsEmpty)
                                    {
                                        oSegA.Display();
                                        oSection           = new SectionOfLines();
                                        oSection.Type      = oSegA.Type;
                                        oSection.Position  = oSegA.PositionA;
                                        oSection.PositionA = oSegA.PositionA;
                                        oSection.PositionB = oSegB.PositionB;
                                        oSection.Size      = oSegA.Size;
                                        oSection.Data      = oSegA.Data;
                                        Sections.Add(oSection);
                                    }
                                }
                                nCountA++;
                                nCountB++;
                            }
                        }
                        nCountA++;
                        nCountB++;
                    }
                }
            }
            SignalEndOfReport();
        }