Wednesday, January 22, 2014

Programmatically Enable/Disable Receive pipeline


We can achieve this functionality using the  "Microsoft.BizTalk.ExplorerOM" component.

Add reference "Microsoft.BizTalk.ExplorerOM" component to your application.

BtsCatalogExplorer 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";

public bool SetReceiveLocationState(string receivePortName, bool stateValue)
{
            bool returnValue = false;
            try
            {
                ReceivePort receivePort = bceExplorer.ReceivePorts[receivePortName];
                receivePort.ReceiveLocations.Cast<ReceiveLocation>().ToList().ForEach(receiveLocation => receiveLocation.Enable = stateValue);

                bceExplorer.SaveChanges();
                returnValue = true;
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("SetReceiveLocationState", e.Message);
                bceExplorer.DiscardChanges();
                returnValue = false;
            }
            return returnValue;
        }

1 comment: