private void CompareArticles(string ver1, string ver2, ref string leftRes, ref string rightRes)
	{
		System.Text.StringBuilder res1 = new System.Text.StringBuilder();
		System.Text.StringBuilder res2 = new System.Text.StringBuilder();
		DiffList_StringData s1 = new DiffList_StringData(ver1);
		DiffList_StringData s2 = new DiffList_StringData(ver2);
		DiffEngine de = new DiffEngine();
		ArrayList rep;
		int i = 0, count1 = 1, count2 = 1;
		int linesupdated = 0, linesadded = 0, linesdeleted = 0;
		int symbolschanged = 0, symbolsadded = 0, symbolsdeleted = 0;

		de.ProcessDiff(s1, s2, DiffEngineLevel.SlowPerfect);
		rep = de.DiffReport();

		foreach (DiffResultSpan drs in rep)
		{
			switch (drs.Status)
			{
				case DiffResultSpanStatus.DeleteSource:
					res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #FF7863\">");
						res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
						res1.Append("</span>");
						res2.Append("<br />");
						count1++;
						linesdeleted++;
					}
					break;
				case DiffResultSpanStatus.NoChange: 
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
						res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
						res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
						count1++; count2++;
					}
					break;
				case DiffResultSpanStatus.AddDestination:
					res1.Append("<a name=\"right_" + count2.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append("<br />");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #54C954\">");
						res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
						res2.Append("</span>");
						count2++;
						linesadded++;
					}
					break;
				case DiffResultSpanStatus.Replace:
					res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
					for (i = 0; i < drs.Length; i++)
					{
						res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
						res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
						res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
						res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
						CompareLines(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line, ((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line, res1, res2, ref symbolschanged, ref symbolsadded, ref symbolsdeleted);
						res1.Append("</span>");
						res2.Append("</span>");
						res1.Append("<br />");
						res2.Append("<br />");
						count1++; count2++;
						linesupdated++;
					}
					break;
			}
		}
		CollectLinesStats(linesupdated, linesadded, linesdeleted);
		CollectSymbolsStats(symbolschanged, symbolsadded, symbolsdeleted);
		leftRes = res1.ToString();
		rightRes = res2.ToString();
	}
Exemple #2
0
    private void CompareArticles(string ver1, string ver2, ref string leftRes, ref string rightRes)
    {
        System.Text.StringBuilder res1 = new System.Text.StringBuilder();
        System.Text.StringBuilder res2 = new System.Text.StringBuilder();
        DiffList_StringData       s1   = new DiffList_StringData(ver1);
        DiffList_StringData       s2   = new DiffList_StringData(ver2);
        DiffEngine de = new DiffEngine();
        ArrayList  rep;
        int        i = 0, count1 = 1, count2 = 1;
        int        linesupdated = 0, linesadded = 0, linesdeleted = 0;
        int        symbolschanged = 0, symbolsadded = 0, symbolsdeleted = 0;

        de.ProcessDiff(s1, s2, DiffEngineLevel.SlowPerfect);
        rep = de.DiffReport();

        foreach (DiffResultSpan drs in rep)
        {
            switch (drs.Status)
            {
            case DiffResultSpanStatus.DeleteSource:
                res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
                    res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #FF7863\">");
                    res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
                    res1.Append("</span>");
                    res2.Append("<br />");
                    count1++;
                    linesdeleted++;
                }
                break;

            case DiffResultSpanStatus.NoChange:
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
                    res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
                    res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    res1.Append(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line + "<br />");
                    res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
                    count1++; count2++;
                }
                break;

            case DiffResultSpanStatus.AddDestination:
                res1.Append("<a name=\"right_" + count2.ToString("0000") + "\">" + "</a>\r\n");
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append("<br />");
                    res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
                    res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #54C954\">");
                    res2.Append(((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line + "<br />");
                    res2.Append("</span>");
                    count2++;
                    linesadded++;
                }
                break;

            case DiffResultSpanStatus.Replace:
                res1.Append("<a name=\"left_" + count1.ToString("0000") + "\">" + "</a>\r\n");
                for (i = 0; i < drs.Length; i++)
                {
                    res1.Append(count1.ToString("0000") + "&nbsp;&nbsp;");
                    res2.Append(count2.ToString("0000") + "&nbsp;&nbsp;");
                    res1.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
                    res2.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color: #C1E5FF\">");
                    CompareLines(((TextLine)s1.GetByIndex(drs.SourceIndex + i)).Line, ((TextLine)s2.GetByIndex(drs.DestIndex + i)).Line, res1, res2, ref symbolschanged, ref symbolsadded, ref symbolsdeleted);
                    res1.Append("</span>");
                    res2.Append("</span>");
                    res1.Append("<br />");
                    res2.Append("<br />");
                    count1++; count2++;
                    linesupdated++;
                }
                break;
            }
        }
        CollectLinesStats(linesupdated, linesadded, linesdeleted);
        CollectSymbolsStats(symbolschanged, symbolsadded, symbolsdeleted);
        leftRes  = res1.ToString();
        rightRes = res2.ToString();
    }