Example #1
0
        /// <summary>
        /// Read the specified file and return its contents as a block of element lines.
        /// </summary>
        /// <param name="psFile">Text file specification.</param>
        /// <returns>Entire file contents as a block of element lines.</returns>
        public override Block Read(string psFile)
        {
            StreamReader     oSr;
            string           sLine  = string.Empty;
            StringCollection cLines = new StringCollection();

            ElementLine[] aElementLines = null;
            try
            {
                if (File.Exists(psFile))
                {
                    oSr = new StreamReader(psFile);
                    while (!oSr.EndOfStream)
                    {
                        sLine = oSr.ReadLine();
                        cLines.Add(sLine);
                    }
                    oSr.Close();
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            aElementLines = new ElementLine[cLines.Count];
            for (int nCount = 0; nCount < cLines.Count; nCount++)
            {
                aElementLines[nCount] = new ElementLine(cLines[nCount].ToString());
            }
            BlockOfLines oBlock = new BlockOfLines(aElementLines);

            return(oBlock);
        }
Example #2
0
        /// <summary>
        /// Read the specified string list and return its contents as a block of element lines.
        /// </summary>
        /// <param name="pcList">List of strings.</param>
        /// <returns>String list as a block of element lines.</returns>
        public Block ReadLines(List <string> pcLines)
        {
            ElementLine[] aElementLines = new ElementLine[pcLines.Count];
            for (int nCount = 0; nCount < pcLines.Count; nCount++)
            {
                aElementLines[nCount] = new ElementLine(pcLines[nCount].ToString());
            }
            BlockOfLines oBlock = new BlockOfLines(aElementLines);

            return(oBlock);
        }
Example #3
0
        /// <summary>
        /// Check if both blocks of elements are equal.
        /// </summary>
        /// <param name="poBlock1">Left hand side operand block to compare.</param>
        /// <param name="poBlock2">Right hand side operand block to compare.</param>
        /// <returns>True if equal, false otherwise.</returns>
        private static bool AreEqual(BlockOfLines poBlock1, BlockOfLines poBlock2)
        {
            bool bEqual = false;

            if (poBlock1.IsEmpty && !poBlock2.IsEmpty)
            {
                bEqual = false;
            }
            else if (!poBlock1.IsEmpty && poBlock2.IsEmpty)
            {
                bEqual = false;
            }
            else if (poBlock1.IsEmpty && poBlock2.IsEmpty)
            {
                bEqual = true;
            }
            else if (poBlock1.Length == 0 && poBlock2.Length == 0)
            {
                bEqual = true;
            }
            else if (poBlock1.Length != poBlock2.Length)
            {
                bEqual = false;
            }
            else if (poBlock1.Length == poBlock2.Length)
            {
                ElementLine[] aElements1 = (ElementLine[])poBlock1.Elements;
                ElementLine[] aElements2 = (ElementLine[])poBlock2.Elements;
                bEqual = true;
                for (long nCount = 0; nCount < aElements1.Length; nCount++)
                {
                    if (aElements1[nCount] != aElements2[nCount])
                    {
                        bEqual = false;
                        break;
                    }
                }
            }
            return(bEqual);
        }
Example #4
0
 /// <summary>
 /// Construct a new block to contain the line element array contained in the specified block.
 /// </summary>
 /// <param name="poBlock">Block of line elements.</param>
 public BlockOfLines(BlockOfLines poBlock)
 {
     maElements = (ElementLine[])poBlock.Elements;
 }
Example #5
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);
                 }
             }
         }
     }
 }
Example #6
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();
        }