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



我在我的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
}

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

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

任何帮助都非常感谢。

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

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

我已经在比较文件方法中传递了这些行

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);

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

相关内容

  • 没有找到相关文章

最新更新