/// <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(); }