Arresto e avvio di orchestrazioni, porte di trasmissione e indirizzi di ricezione a livello di codice
Questo argomento fornisce codice di esempio per l'arresto e l'avvio di orchestrazioni a livello di codice, le porte di invio e le posizioni di ricezione. È possibile eseguire queste azioni su tutte le orchestrazioni, le porte di invio e le posizioni di ricezione come gruppo o singolarmente. È possibile includere questo codice in un programma per eseguire queste azioni in modo dinamico. Queste azioni vengono eseguite nell'interfaccia utente grafica in fase di progettazione in Microsoft BizTalk Accelerator for RosettaNet (BTARN) o in fase di esecuzione nella console di amministrazione BizTalk.
Nota
Per avviare e arrestare le orchestrazioni, non è necessario designare le orchestrazioni, le porte di invio o le posizioni di ricezione. Il codice di esempio esegue l'azione su tutte le orchestrazioni, le porte di invio e le posizioni di ricezione installate da BTARN nella configurazione. Per il codice che agisce su una singola orchestrazione, porta di invio o posizione di ricezione, aggiungere un parametro che indica in quale orchestrazione, porta di invio o posizione di ricezione si vuole eseguire il codice.
Dimostra
Il codice di esempio in questo argomento include sezioni di codice separate per eseguire le operazioni seguenti:
Avviare le orchestrazioni: avviare tutte le porte di invio e le posizioni di ricezione e inserire e avviare tutte le orchestrazioni
Arrestare le orchestrazioni: annullare l'elenco di tutte le orchestrazioni, annullare l'elenco di tutte le porte di invio e disabilitare tutte le posizioni di ricezione
Avviare una singola porta di invio
Abilitare una singola posizione di ricezione
Annullare l'elenco di una singola porta di invio
Disabilitare una singola posizione di ricezione
Avviare una singola orchestrazione
Annullare l'elenco di un'orchestrazione singola
Esempio
Il codice di esempio in questo argomento include sezioni di codice separate per eseguire le funzioni elencate nella sezione "Dimostrazioni".
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;
}
}
}