如何在从 windows 表单应用程序进行比较时抑制启动超过比较 3

How to suppress launching beyond compare 3 while doing a comparison from windows forms application

我在我的 win 表单应用程序中使用 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";

}

比较结果是一个枚举,如下所示

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
}

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

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

非常感谢任何帮助。

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

Beyond Compare 应用程序有一个命令行开关,当我们想要抑制交互时需要通过它。它被称为“/无声”。

我在 CompareFiles 方法

中传递了这些行

public static ComparisonResult CompareFiles(字符串文件路径 1,字符串文件路径 2,字符串规则名称)

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

我的问题中上面发布的所有代码都工作正常,任何想要抑制交互的人都可以使用。