.comment-link {margin-left:.6em;}

Ben Cops

Tuesday, April 05, 2005

Programming BizTalk with WMI and the VStudio addin

The WMI addin for visual studio is pretty cool. After some flailing about sans documentation (well there is some, but its along the lines of "HostSettings: Represents the host settings"), and a swift decompile of the management classes to check out exactly what it was doing with what parameter (thanks again, reflector), the paradigm sunk in.

I added managed classes for MSBTS_HostSetting, and MSBTS_Orchestration. From this I can determine the default host:


this.Log(Level.Info, "Getting default host");
HostSetting.HostSettingCollection hosts = HostSetting.GetInstances();
if (hosts.Count < 1)
throw new BuildException("No hosts found");
string hostName = "";
foreach (HostSetting host in hosts)
{
if (host.IsDefault)
{
hostName = host.Name;
break;
}
}


And start an orchestration:


//get all orchestrations on the local server using WMI
Orchestration.OrchestrationCollection orchs = Orchestration.GetInstances();
//loop over all the orchestrations exposed by WMI and find the one we want to start now
foreach (Orchestration orchestration in orchs)
{
if (orchestration.Name == targetOrch)
{
this.Log(Level.Info, "Starting " + orchestration.Name);
orchestration.Enlist(hostName);
orchestration.Start(2, 2, 2);
this.Log(Level.Info, "Started " + orchestration.Name);
}
}

0 Comments:

Post a Comment

<< Home