description | title | ms.custom | ms.date | ms.service | ms.topic |
---|---|---|---|---|---|
Learn more about: Stopping and Starting Orchestrations, Send Ports, and Receive Locations Programmatically |
Stopping and Starting Orchestrations, Send Ports, and Receive Locations Programmatically |
06/08/2017 |
biztalk-server |
article |
This topic provides sample code for programmatically stopping and starting orchestrations, send ports, and receive locations. You can perform these actions on all orchestrations, send ports, and receive locations as a group or individually. You can include this code in a program to perform these actions dynamically. You perform these actions in the graphical user interface at design time in Microsoft [!INCLUDEBTARN_CurrentVersion_FirstRef], or at run time in the BizTalk Administration console.
Note
For the code to start and stop orchestrations, you do not have to designate the orchestrations, send ports, or receive locations. The sample code performs the action on all orchestrations, send ports, and receive locations that [!INCLUDEBTARN_CurrentVersion_abbrev] installed at set up. For the code that acts on a single orchestration, send port, or receive location, add a parameter indicating on which orchestration, send port, or receive location you want the code to run.
The sample code in this topic includes separate code sections to do the following:
-
Start orchestrations—start all the send ports and receive locations, and enlist and start all orchestrations
-
Stop orchestrations—unenlist all orchestrations, unenlist all send ports, and disable all receive locations
-
Start a single send port
-
Enable a single receive location
-
Unenlist a single send port
-
Disable a single receive location
-
Start a single orchestration
-
Unenlist a single orchestration
The sample code in this topic includes separate code sections to do the functions listed in the "Demonstrates" section.
[!INCLUDE authentication-guidance]
using System;
using Microsoft.BizTalk.ExplorerOM;
namespace Control
{
class Control
{
BtsCatalogExplorer bceExplorer;
string[] sOrchestrations;
string[] sReceiveLocations;
string[] sSendPorts;
[STAThread]
static void Main(string[] args)
{
Control controlInstance = new Control();
if(args.Length>0 && args[0].ToUpper()=="STOP")
controlInstance.StopOrchestrations();
else
controlInstance.StartOrchestrations();
}
public Control()
{
bceExplorer = new BtsCatalogExplorer();
//Edit the following connection string to point to the correct database and server
bceExplorer.ConnectionString = "Integrated Security=SSPI;database=BizTalkMgmtDb;server=localhost";
//Orchestrations
sOrchestrations = new string[9];
sOrchestrations[0]="Microsoft.Solutions.BTARN.CommonTypes.OdxTypes,Microsoft.Solutions.BTARN.CommonTypes, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[1]="Microsoft.Solutions.BTARN.CommonTypes.SendExceptionToLOB,Microsoft.Solutions.BTARN.CommonTypes, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[2]="Microsoft.Solutions.BTARN.CommonTypes.SendExceptionToPrivateProcess,Microsoft.Solutions.BTARN.CommonTypes, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[3]="Microsoft.Solutions.BTARN.PrivateInitiator.PrivateInitiatorProcess,Microsoft.Solutions.BTARN.PrivateInitiator, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[4]="Microsoft.Solutions.BTARN.PrivateResponder.PrivateResponderProcess,Microsoft.Solutions.BTARN.PrivateResponder, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[5]="Microsoft.Solutions.BTARN.PublicInitiator.PublicInitiatorV11,Microsoft.Solutions.BTARN.PublicInitiator, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[6]="Microsoft.Solutions.BTARN.PublicInitiator.PublicInitiatorProcess,Microsoft.Solutions.BTARN.PublicInitiator, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[7]="Microsoft.Solutions.BTARN.PublicResponder.PublicResponderV11,Microsoft.Solutions.BTARN.PublicResponder, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
sOrchestrations[8]="Microsoft.Solutions.BTARN.PublicResponder.PublicResponderProcess,Microsoft.Solutions.BTARN.PublicResponder, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
//Send Ports
sSendPorts = new string[2];
sSendPorts[0]="PrivateInitiator_To_LOB";
sSendPorts[1]="PrivateResponder_To_LOB";
//Receive Locations
sReceiveLocations = new string[4];
sReceiveLocations[0]="LOB_To_PrivateInitiator";
sReceiveLocations[1]="LOB_To_PrivateResponder";
sReceiveLocations[2]="RNIF_Async_Receive";
sReceiveLocations[3]="RNIF_Sync_Receive";
}
public void StartOrchestrations()
{
bool bSuccess=true;
//Start all the send ports
for(int i=0;i<sSendPorts.Length;i++)
{
Console.WriteLine("Starting send port: " + sSendPorts[i]);
bSuccess=StartSendPort(sSendPorts[i]);
}
//Start all the receive locations
for(int i=0;i<sReceiveLocations.Length;i++)
{
Console.WriteLine("Enabling receive location: " + sReceiveLocations[i]);
bSuccess=EnableReceiveLocation(sReceiveLocations[i]);
}
//Enlist and start all orchestrations
for(int i=0;i<sOrchestrations.Length;i++)
{
Console.WriteLine("Starting orchestration: " + sOrchestrations[i].Split(',')[0]);
bSuccess=StartOrchestration(sOrchestrations[i]);
}
if(bSuccess)
Console.WriteLine("All artifacts successfully started");
else
Console.WriteLine("Not all artifacts were started");
}
public void StopOrchestrations()
{
bool bSuccess=true;
//Unenlist all orchestrations
for(int i=sOrchestrations.Length-1;i>=0;i--)
{
Console.WriteLine("Unelisting orchestration: " + sOrchestrations[i].Split(',')[0]);
bSuccess=UnenlistOrchestration(sOrchestrations[i]);
}
//Unenlist all the send ports
for(int i=sSendPorts.Length-1;i>=0;i--)
{
Console.WriteLine("Unenlisting send port: " + sSendPorts[i]);
bSuccess=UnenlistSendPort(sSendPorts[i]);
}
//Disable all the receive locations
for(int i=sReceiveLocations.Length-1;i>=0;i--)
{
Console.WriteLine("Disabling receive location: " + sReceiveLocations[i]);
bSuccess=DisableReceiveLocation(sReceiveLocations[i]);
}
if(bSuccess)
Console.WriteLine("All artifacts successfully stopped");
else
Console.WriteLine("Not all artifacts were stopped");
}
public bool StartSendPort(string sSendPortName)
{
try
{
SendPort sp = bceExplorer.SendPorts[sSendPortName];
sp.Status = PortStatus.Started;
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
public bool EnableReceiveLocation(string sReceivePortName)
{
try
{
ReceivePort rp = bceExplorer.ReceivePorts[sReceivePortName];
foreach(ReceiveLocation rl in rp.ReceiveLocations)
rl.Enable = true;
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
public bool UnenlistSendPort(string sSendPortName)
{
try
{
SendPort sp = bceExplorer.SendPorts[sSendPortName];
sp.Status = PortStatus.Bound;
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
public bool DisableReceiveLocation(string sReceivePortName)
{
try
{
ReceivePort rp = bceExplorer.ReceivePorts[sReceivePortName];
foreach(ReceiveLocation rl in rp.ReceiveLocations)
rl.Enable = false;
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
private bool StartOrchestration(string sOrchestrationName)
{
BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies;
foreach (Microsoft.BizTalk.ExplorerOM.BtsAssembly btsAssembly in btsAssemblyCollection)
{
if(sOrchestrationName.Split(',')[1]==btsAssembly.DisplayName.Split(',')[0])
{
foreach (Microsoft.BizTalk.ExplorerOM.BtsOrchestration btsOrchestration in btsAssembly.Orchestrations)
{
if(sOrchestrationName==btsOrchestration.AssemblyQualifiedName)
{
btsOrchestration.Status=OrchestrationStatus.Started;
try
{
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
}
}
}
return false;
}
private bool UnenlistOrchestration(string sOrchestrationName)
{
BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies;
foreach (Microsoft.BizTalk.ExplorerOM.BtsAssembly btsAssembly in btsAssemblyCollection)
{
if(sOrchestrationName.Split(',')[1]==btsAssembly.DisplayName.Split(',')[0])
{
foreach (Microsoft.BizTalk.ExplorerOM.BtsOrchestration btsOrchestration in btsAssembly.Orchestrations)
{
if(sOrchestrationName==btsOrchestration.AssemblyQualifiedName)
{
btsOrchestration.AutoTerminateInstances=true;
btsOrchestration.Status=OrchestrationStatus.Unenlisted;
try
{
bceExplorer.SaveChanges();
return true;
}
catch(Exception e)
{
Console.WriteLine(e.Message);
bceExplorer.DiscardChanges();
return false;
}
}
}
}
}
return false;
}
}
}