I have need for this occasionally so I thought I would publish the code that I have written.
namespace StottIS.ChangeConfigration
{
public enum Active
{
Start,
Stop
}
public class Adapter
{
public static void RecieveLocationStateChange(string ReceivePort, string ReceiveLocation, Active ActiveFlag)
{
BtsCatalogExplorer root = new BtsCatalogExplorer();
try
{
root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";
//Enumerate the receive locations in each of the receive ports.
foreach (ReceivePort receivePort in root.ReceivePorts)
{
if (receivePort.Name == ReceivePort)
{
foreach (ReceiveLocation location in receivePort.ReceiveLocations)
if (location.Name == ReceiveLocation)
{
switch (ActiveFlag)
{
case Active.Start:
location.Enable = true;
break;
case Active.Stop:
location.Enable = false;
break;
default:
location.Enable = true;
break;
}
}
}
}
root.SaveChanges();
}
catch (Exception e)//If it fails, roll-back all changes.
{
root.DiscardChanges();
throw e;
}
}
}
}
In an orchestration Expression Shape, or in your code outside of BizTalk you simply call this code:
StottIS.ChangeConfigration.Adapter.RecieveLocationStateChange("Password Reset","Password Pickup",StottIS.ChangeConfigration.Active.Stop);