Johan Åhlén

Johan Åhlén's blog about life, universe and everything.

Autodetecting Instance Names in StreamInsight

Since the RTM version you have to specify the instance name when connecting to or creating an in-process StreamInsight server. There is no such thing as a "Default Instance" like there is in the SQL Server database engine. Since users are very creative when picking the name of their StreamInsight installation you need to either have your application ask for the instance name or autodetect it.

The instance name can be autodetected from the registry. The only problem is that you need sufficient permissions to read the appropriate registry key, which you won't have in Windows 7 or Vista if you just start the application as usual from Visual Studio. Instead you have to start Visual Studio with Run as administrator.

Here's an example class to enumerate the installed instances (yes there can be more than one instance). It also provides you the info you need to deploy and run your applications on the StreamInsightHost.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace JAhlenExample
{
    public class StreamInsightSetupInfo
    {
        public const string RegKeyPrefix = "MSSI.";

        public static string[] EnumerateInstances()
        {
            RegistryKey masterKey;

            try
            {
                masterKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Microsoft StreamInsight");
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new Exception("Access denied to StreamInsight registry key. Make sure you run with high enough permissions. If executing from Visual Studio you may have to run Visual Studio as administrator.");
            }

            var lst = new List<string>();

            foreach (var key in masterKey.GetSubKeyNames())
            {
                if (key.StartsWith(RegKeyPrefix))
                {
                    lst.Add(key.Substring(RegKeyPrefix.Length));
                }
            }

            return lst.ToArray();
        }

        public static string GetHostPath(string instanceName)
        {
            var masterKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Microsoft StreamInsight\" + RegKeyPrefix + instanceName);
            var dumperPath = masterKey.GetValue("StreamInsightDumperPath").ToString();

            var streamInsightRootPath = dumperPath.Substring(0, dumperPath.LastIndexOf('\\'));
            streamInsightRootPath = dumperPath.Substring(0, streamInsightRootPath.LastIndexOf('\\') + 1);

            return streamInsightRootPath + @"Host\";
        }

        public static string GetServiceName(string instanceName)
        {
            return "MSSI$" + instanceName;
        }

        public static string GetEndpointName(string instanceName)
        {
            return "http://localhost/StreamInsight/" + instanceName;
        }
    }
}

Posted: Jul 19 2010, 08:23 AM by jahlen
Filed under:

Comments

No Comments