【翻译】如何获取正在运行的StreamInsight实例版本号?

原文链接:http://www.devbiker.net/post/StreamInsight-What-edition-am-I-running.aspx


有的时候知道自己正在使用的StreamInsight版本号会非常有帮助,尤其是在StreamInsight应用程序启动时记录下版本信息以备当前或者以后进行故障查找。可惜的是,StreamInsight API中并没有很好的方法用来获取该信息。当然,你可以使用诊断视图(Diagnostic Views)中的调度诊断视图来查看有多少个调度正在运行,从而获悉大致的版本信息。但即使如此,该信息依然不包含安装的处理器架构信息(x86/x64),也没有实例确切的版本号。哦,对了,这个诊断视图将不会出现在StreamInsight 1.2版本中。你所知道的将仅仅是运行版本为标准版Standard(1调度)还是是开发版Developer、数据中心版DataCenter或评估版(1调度/核)中的一种。而下面的这段代码将提供给你更多的信息:

 

/// <summary>
/// Gets information about the current StreamInsight service edition
/// </summary>
/// <param name="instanceName">Name of the StreamInsight instance.</param>
/// <returns>String with edition information</returns>
[System.Security.Permissions.RegistryPermission(
    SecurityAction.Demand, Read = "HKLM\\SOFTWARE\\Microsoft\\Microsoft StreamInsight")]
public string GetStreamInsightEditionInformation(string instanceName)
{
    try
    {
        var streamInsightRegistry = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
            @"SOFTWARE\Microsoft\Microsoft StreamInsight", false);
        var instanceKeyName = "MSSI." + instanceName;
        var instanceRegistryKey = streamInsightRegistry.OpenSubKey(instanceKeyName, false);
        StringBuilder sb = new StringBuilder();
        sb.Append("StreamInsight Version:");
        sb.AppendLine(instanceRegistryKey.GetValue("Version").ToString());
        sb.Append("Edition:");
        sb.AppendLine(instanceRegistryKey.GetValue("Edition").ToString());
        sb.Append("Platform:");
        sb.AppendLine(instanceRegistryKey.GetValue("PlatformId").ToString());
        return sb.ToString();
    }
    catch
    {
        return "Could not get StreamInsight information";
    }
}
注意:这个方法仅适用于StreamInsight在同一台机器运行的情况。因此如果你使用管理服务(Management Service)远程连接到StreamInsight时,并不能获取到版本信息。同样,上述代码段得到的是instance安装的StreamInsight的版本,而不一定是正在运行的实例!!例如,你可能有一个1.0的实例,一个1.1的实例和一个1.2的实例。如果你使用Server.Create(“1.0 Instance”),你事实上运行的是StreamInsight 1.2版本!值得庆幸的是,Server对象本身拥有一个Version属性可以告诉你正在运行的版本号。

 


评论:RegistryPermission特性的设置可见作者平时很重视安全编程,感兴趣的读者可以了解一下.NET 4.0中关于Security的变化。另外,我并没有在1.1版本中发现Server的Version属性。
posted @ 2011-07-03 23:53  StreamInsight  阅读(263)  评论(0编辑  收藏  举报