从windows窗体应用程序进行比较时,如何抑制超出比较3的启动

时间:2015-04-26 03:37:47

标签: winforms beyondcompare3

我在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";

}

和comparisonresult是一个枚举如下

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
}

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

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

任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:1)

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

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

我已经在 CompareFiles 方法

中传递了这些行

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

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

我在问题中所有上述发布的代码都运行正常,任何想要抑制互动的人都可以使用。