2

我在我的 win forms 应用程序中使用 Beyond Compare 3 在两个输出文件夹(ProdOutput 和 SITOutput)中进行比较。我正在使用以下代码行进行比较

public static void LaunchViewer(string filepath1, string filepath2)
    {
        string arguments = String.Format("\"{0}\" \"{1}\"", filepath1, filepath2);
        ProcessStartInfo psi = new ProcessStartInfo(ApplicationPath, arguments);
        using (Process p = Process.Start(psi))
        {
            ComparsionResult = CompareFiles(filepath1, filepath2, BeyondCompareRules.EverythingElse);
        }
    }



public static ComparisonResult CompareFiles(string filepath1, string filepath2, string ruleName)
        {

            ComparisonResult result = ComparisonResult.None;

            string arguments = String.Format("/quickcompare /rules=\"{0}\" \"{1}\" \"{2}\"", ruleName, filepath1, filepath2);

            ProcessStartInfo psi = new ProcessStartInfo(ApplicationPath, arguments);
            psi.UseShellExecute = false;
            psi.RedirectStandardInput = true;
            psi.RedirectStandardOutput = true;

            using (Process p = Process.Start(psi))
            {
                p.StandardInput.WriteLine("EXIT [ErrorLevel]");
                p.WaitForExit();

                int exitCode = p.ExitCode;
                switch (exitCode)
                {
                    case 0:
                        result = ComparisonResult.Match;
                        break;
                    case 1:
                        result = ComparisonResult.Similar;
                        break;
                    case 2:
                        result = ComparisonResult.DoNotMatch;
                        break;
                    case 3:
                        result = ComparisonResult.ComparisonError;
                        break;
                    default :
                        result = ComparisonResult.DoNotMatch;
                        break;
                }
            }
            return result;
        }

超越比较规则如下

public sealed class BeyondCompareRules
{

    private BeyondCompareRules()
    {
    }

    /// <summary>
    /// A comparison rule set for C/C++/C# source files
    /// </summary>
    public const string CLanguageSource = "C/C++/C# Source";
    public const string Cobol = "COBOL";
    public const string CommaSeparatedValues = "Comma Separated Values";
    public const string DelphiSource = "Delphi Source";
    public const string DelphiForms = "Delphi Forms";
    public const string GeneralText = "General Text";
    public const string Html = "HTML";
    public const string Java = "JAVA";
    public const string Python = "Python";
    public const string RegistryDump = "Registry Dump";
    public const string Utf8Text = "UTF8 Text";
    public const string VisualBasic = "Visual Basic";
    public const string Xml = "XML";

    /// <summary>
    /// The default set of comparison rules
    /// </summary>
    public const string EverythingElse = "Everything Else";

}

和 compareresult 是一个枚举如下

public enum ComparisonResult
{

    /// <summary>
    /// Indicates a null or uninitialized value
    /// </summary>
    None = 0,
    /// <summary>
    /// The Quick Compare returned a Positive Match
    /// </summary>
    Match = 1,
    /// <summary>
    /// The Quick Compare detected small differences
    /// </summary>
    Similar = 2,
    /// <summary>
    /// The Quick Compare detected significant differences
    /// </summary>
    DoNotMatch = 3,
    /// <summary>
    /// The Quick Compare utility returned an error/unknown result
    /// </summary>
    ComparisonError = 4
}

我需要的是在进行比较时禁止启动超越比较屏幕,但应该进行比较并且应该返回结果。现在使用上面的代码,我可以进行比较,也可以查看我不想做的差异。

我想我可以通过传递参数来做一些事情,但不确定它是什么以及我应该如何以及在哪里放置它。

任何帮助高度赞赏。

4

1 回答 1

1

经过多次尝试不同的方法来实现该功能,最后一小段代码确实解决了这个问题。

当我们想要抑制交互时,需要传递一个命令行开关,用于超出比较应用程序。它被称为“/静音”。

我已经在CompareFiles方法中传递了这些行

公共静态比较结果比较文件(字符串文件路径1,字符串文件路径2,字符串规则名称)

ComparisonResult result = ComparisonResult.None;
string arguments = String.Format("/quickcompare /rules=\"{0}\" \"{1}\" \"{2}\" /silent", ruleName, filepath1, filepath2);

我的问题中所有上面发布的代码都运行良好,任何想要抑制交互的人都可以使用。

于 2015-04-27T17:31:39.673 回答