프로그래밍 방식으로 오케스트레이션, 송신 포트 및 수신 위치 중지 및 시작
이 항목에서는 프로그래밍 방식으로 오케스트레이션을 중지 및 시작하고, 포트를 보내고, 위치를 수신하기 위한 샘플 코드를 제공합니다. 모든 오케스트레이션에서 이러한 작업을 수행하고, 포트를 보내고, 위치를 그룹으로 또는 개별적으로 받을 수 있습니다. 이 코드를 프로그램에 포함하여 이러한 작업을 동적으로 수행할 수 있습니다. 디자인 타임에 Microsoft BizTalk Accelerator for RosettaNet(BTARN)의 그래픽 사용자 인터페이스 또는 BizTalk 관리 콘솔의 런타임에 이러한 작업을 수행합니다.
참고
코드가 오케스트레이션을 시작하고 중지하려면 오케스트레이션을 지정하거나, 포트를 보내거나, 위치를 받을 필요가 없습니다. 샘플 코드는 설정 시 BTARN이 설치한 모든 오케스트레이션, 송신 포트 및 수신 위치에 대한 작업을 수행합니다. 단일 오케스트레이션, 송신 포트 또는 수신 위치에서 작동하는 코드의 경우 코드를 실행할 오케스트레이션, 송신 포트 또는 수신 위치를 나타내는 매개 변수를 추가합니다.
데모
이 항목의 샘플 코드에는 다음을 수행하는 별도의 코드 섹션이 포함되어 있습니다.
오케스트레이션 시작 - 모든 송신 포트 및 수신 위치를 시작하고 모든 오케스트레이션을 등록하고 시작합니다.
오케스트레이션 중지 - 모든 오케스트레이션을 등록 취소하고, 모든 송신 포트를 등록 취소하고, 모든 수신 위치를 사용하지 않도록 설정합니다.
단일 송신 포트 시작
단일 수신 위치 사용
단일 송신 포트의 목록 해제
단일 수신 위치 사용 안 함
단일 오케스트레이션 시작
단일 오케스트레이션의 목록 해제
예제
이 항목의 샘플 코드에는 "시연" 섹션에 나열된 함수를 수행하는 별도의 코드 섹션이 포함되어 있습니다.
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;
}
}
}