private void ControlArtifacts(BtsCatalogExplorer catalog, Application application, Dictionary <string, Dictionary <string, object> > artifacts) { bool needSave = false; foreach (KeyValuePair <string, Dictionary <string, object> > kvp in artifacts) { try { if (ControlIndividualArtifact(kvp.Key, kvp.Value, catalog, application)) { needSave = true; } } catch (Exception) { catalog.DiscardChanges(); throw; } } if (needSave) { try { base.Log.LogMessage("Committing " + _artifactName + " actions..."); catalog.SaveChanges(); base.Log.LogMessage("Committed " + _artifactName + " actions."); } catch (Exception) { catalog.DiscardChanges(); throw; } } }
static void Main(string[] args) { // Handle the command-line arguments and switches if (args.Length != 1) { PrintUsage(); return; } if (("/?" == args[0]) || ("-?" == args[0])) { PrintUsage(); return; } // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = string.Format("SERVER={0};DATABASE={1};Integrated Security=SSPI", SystemInformation.ComputerName, "BizTalkMgmtDB"); try { // Get the requested party from the collection Party party = catalog.Parties[args[0]]; if (null == party) { Console.WriteLine("Party named " + args[0] + " was not found."); return; } Console.WriteLine("Deleting party: " + party.Name); // Remove the party catalog.RemoveParty(party); // commit the changes catalog.SaveChanges(); Console.WriteLine("Party deleted."); } catch (ConstraintException ce) { // Any changes need to be reverted // when there is an error catalog.DiscardChanges(); // Since this is a common configruation excpetion // we don't need a stack trace Console.WriteLine(ce.Message); } catch (Exception e) { // Any changes need to be reverted // when there is an error catalog.DiscardChanges(); Console.WriteLine(e.ToString()); } }
static void CreateSendPort() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { // create a new static one-way SendPort SendPort myStaticOnewaySendPort = catalog.AddNewSendPort(false, false); myStaticOnewaySendPort.Name = "myStaticOnewaySendPort1"; myStaticOnewaySendPort.PrimaryTransport.TransportType = catalog.ProtocolTypes[0]; myStaticOnewaySendPort.PrimaryTransport.Address = "http://sample1"; myStaticOnewaySendPort.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; // create a new dynamic two-way sendPort SendPort myDynamicTwowaySendPort = catalog.AddNewSendPort(true, true); myDynamicTwowaySendPort.Name = "myDynamicTwowaySendPort1"; myDynamicTwowaySendPort.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; myDynamicTwowaySendPort.ReceivePipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLReceive"]; // persist changes to BizTalk configuration database catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void DeleteReceivePort() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Remove a receive port. foreach (ReceivePort receivePort in root.ReceivePorts) { if (receivePort.Name == "My Receive Port") { root.RemoveReceivePort(receivePort); break; } } //Try to commit the changes made so far. root.SaveChanges(); } catch (Exception e) //If it fails, roll-back everything we have done so far { root.DiscardChanges(); throw e; } }
public void UnbindOrchestration() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { BtsOrchestrationCollection orchestrations = catalog.Assemblies["HelloWorld"].Orchestrations; // Reset the bindings orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["SendInvoicePort"].SendPort = null; // Not using SendPortGroup for HelloWorld Sample *** // //orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["SendInvoicePort"].SendPortGroup = null; orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["ReceivePOPort"].ReceivePort = null; orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Host = null; // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
public void BindOrchestration() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { BtsOrchestrationCollection orchestrations = catalog.Assemblies["HelloWorld"].Orchestrations; // Specify either a sendport or a sendportgroup for the orchestration outbound port orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["SendInvoicePort"].SendPort = catalog.SendPorts["HelloWorldSendPort"]; // Not using SendPortGroup for HelloWorld Sample *** // //orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["SendInvoicePort"].SendPortGroup = catalog.SendPortGroups["SendPortGroup_1"]; // Specify a receiveport for orchestration inbound port orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Ports["ReceivePOPort"].ReceivePort = catalog.ReceivePorts["HelloWorldReceivePort"]; // Specify a host by index or name. orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Host = catalog.Hosts["BizTalkServerApplication"]; // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void DeleteReceiveLocation() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Remove receive location with the name "My Receive Location" from //the receive port. //Enumerate the receive locations in the recieve port. foreach (ReceivePort receivePort in root.ReceivePorts) { //Enumerate the receive locations. foreach (ReceiveLocation location in receivePort.ReceiveLocations) { if (location.Name == "My Receive Location") { receivePort.RemoveReceiveLocation(location); break; } } } //Try to commit the changes made so far. root.SaveChanges(); } catch (Exception e) //If it fails, roll-back all changes. { root.DiscardChanges(); throw e; } }
static void ChangeSendPortStatus() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { SendPort sendport = catalog.SendPorts["myStaticOnewaySendPort1"]; // start the sendport to begin processing messages sendport.Status = PortStatus.Started; Console.WriteLine(sendport.Name + ": " + sendport.Status.ToString()); catalog.SaveChanges(); // stop the sendport to stop processing and suspend messages sendport.Status = PortStatus.Stopped; Console.WriteLine(sendport.Name + ": " + sendport.Status.ToString()); catalog.SaveChanges(); // unenlist the sendport to stop processing and discard messages sendport.Status = PortStatus.Bound; Console.WriteLine(sendport.Name + ": " + sendport.Status.ToString()); catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void CreateReceivePort() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Create a new one way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(false); //Note that if you do not set the name property of the ReceivePort, //it will use the default name generated. myreceivePort.Name = "My Receive Port"; myreceivePort.Tracking = TrackingTypes.AfterReceivePipeline; //Try to commit the changes made so far. If it fails, roll-back //all the changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
static void DeleteSendPortGroup() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Integrated Security=SSPI;database=BizTalkMgmtDb;server= YOURSERVER"; // remove a send port group foreach (SendPortGroup sendPortGroup in root.SendPortGroups) { if (sendPortGroup.Name == "My Send Port Group") { root.RemoveSendPortGroup(sendPortGroup); break; } } //try to commit the changes we made so far. root.SaveChanges(); } catch (Exception e) //If it fails, roll-back everything we have done so far { root.DiscardChanges(); throw e; } }
static void ConfigureSendPort() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { SendPort sendport = catalog.SendPorts["myStaticOnewaySendPort1"]; // specify tracking settings for health and activity tracking sendport.Tracking = TrackingTypes.BeforeSendPipeline | TrackingTypes.AfterSendPipeline; // specify an encryption certificate for outgoing messages foreach (CertificateInfo certificate in catalog.Certificates) { if (certificate.UsageType == CertUsageType.Encryption) { sendport.EncryptionCert = certificate; } } // NOTE: do we need to doc the filter format // specify filters for content-based routing sendport.Filter = "<Filter><Group>" + "<Statement Property='SMTP.Subject' Operator='0' Value='Purchase Order'/>" + "<Statement Property='SMTP.From' Operator='0' Value='Customer'/>" + "</Group></Filter>"; // specify transform maps for document normalization foreach (Transform transform in catalog.Transforms) { if (transform.SourceSchema.FullName == "myPO" && transform.TargetSchema.FullName == "partnerPO") { sendport.OutboundTransforms.Add(transform); } } // persist changes to BizTalk configuration database catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void CreateParty() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { // Create a party Party myParty = catalog.AddNewParty(); myParty.Name = "FedEx"; // create a standard alias PartyAlias standardAlias = myParty.AddNewAlias(); standardAlias.Name = "D-U-N-S (Dun & Bradstreet)"; standardAlias.Value = "Value1"; // Create a custom alias PartyAlias customAlias = myParty.AddNewAlias(); customAlias.Name = "Telephone"; customAlias.Qualifier = "100"; customAlias.Value = "4257076302"; // Add party send ports myParty.SendPorts.Add(catalog.SendPorts["NormalDelivery"]); myParty.SendPorts.Add(catalog.SendPorts["ExpressDelivery"]); // Specify a signature certificate, make sure the certificate is available // in the AddressBook store of the Local Machine foreach (CertificateInfo certificate in catalog.Certificates) { if (certificate.ShortName == "BR, Certisign Certificadora Digital Ltda., Certisign - Autoridade Certificadora - AC2") { myParty.SignatureCert = certificate; break; } } // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void ConfigureReceivePort() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Create a new two-way receive port. //Passing the false value creates a one-way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(true); myreceivePort.Name = "My Receive Port"; //optional property myreceivePort.Tracking = TrackingTypes.AfterReceivePipeline; //optional //Set the primary receive location. foreach (ReceiveLocation location in myreceivePort.ReceiveLocations) { if (location.Address == "http://abc.com") { myreceivePort.PrimaryReceiveLocation = location; //optional break; } } //Assign the first send pipeline found to process the response message. foreach (Pipeline pipeline in root.Pipelines) { if (pipeline.Type == PipelineType.Send) { myreceivePort.SendPipeline = pipeline; //optional property break; } } myreceivePort.Authentication = AuthenticationType.RequiredDropMessage; //optional //Try to commit the changes made so far. //If the commit fails, roll-back all changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
static void CreateSendPortGroup() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Integrated Security=SSPI;database=BizTalkMgmtDb;server=YOURSERVER"; //create a new send port group SendPortGroup mySendPortGroup = root.AddNewSendPortGroup(); mySendPortGroup.Name = "My Send Port Group"; //try to commit the changes we made so far. If it fails, roll-back //everything we have done so far root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
static void EnumerateSendPorts() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { // display all sendports and status foreach (SendPort sendport in catalog.SendPorts) { Console.WriteLine(sendport.Name + ": " + sendport.Status.ToString()); } } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
public void UnenlistOrchestration() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { BtsOrchestrationCollection orchestrations = catalog.Assemblies["HelloWorld"].Orchestrations; // Set the orchestration status to Unenlisted orchestrations["Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule"].Status = OrchestrationStatus.Unenlisted; // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void DeleteParty() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { Party party = catalog.Parties["FedEx"]; // Remove the party catalog.RemoveParty(party); // commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void DeleteSendPorts() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { // delete specific sendports by name catalog.RemoveSendPort(catalog.SendPorts["myStaticOnewaySendPort1"]); catalog.RemoveSendPort(catalog.SendPorts["myDynamicTwowaySendPort1"]); // persist changes to BizTalk configuration database catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void UnenlistParty() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { // Search for the shipper role Role svcRole = null; foreach (Role role in catalog.Assemblies[0].Roles) { if (role.Name == "ShipperRole") { svcRole = role; break; } } // Remove the enlisted party foreach (EnlistedParty enlistedparty in svcRole.EnlistedParties) { if (enlistedparty.Party.Name == "FedEx") { svcRole.RemoveEnlistedParty(enlistedparty); break; } } // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
static void EnlistParty() { // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"; try { Party myParty = catalog.Parties["FedEx"]; // Search for the shipper role Role svcRole = null; foreach (Role role in catalog.Assemblies[0].Roles) { if (role.Name == "ShipperRole") { svcRole = role; break; } } // Enlist the party under the shipper role EnlistedParty enlistedParty = svcRole.AddNewEnlistedParty(myParty); enlistedParty.Mappings[0].SendPort = (SendPort)myParty.SendPorts[0]; // NormalDelivery enlistedParty.Mappings[1].SendPort = (SendPort)myParty.SendPorts[1]; // ExpressDelivery // Commit the changes catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
public void StartUnenlistOrchestration(string sOrchestrationName, bool isStart) { bceExplorer = new BtsCatalogExplorer(); //Edit the following connection string to point to the correct database and server bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString; BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies; foreach (BtsAssembly btsAssembly in btsAssemblyCollection) { foreach (BtsOrchestration btsOrchestration in btsAssembly.Orchestrations) { if (sOrchestrationName.Equals(btsOrchestration.FullName)) { try { if (isStart) { btsOrchestration.Status = OrchestrationStatus.Started; } else { btsOrchestration.AutoTerminateInstances = true; btsOrchestration.Status = OrchestrationStatus.Unenlisted; } bceExplorer.SaveChanges(); } catch (Exception e) { bceExplorer.DiscardChanges(); throw e; } } } } }
static void Main(string[] args) { // connect to the local BizTalk Configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; Application cbrApplication = catalog.Applications["CBRApplication"]; if (cbrApplication != null) { try { //*************************************************** // create Sendport for processing US orders //*************************************************** SendPort sendportUSOrders = cbrApplication.AddNewSendPort(false, false); sendportUSOrders.Name = "SendportUSOrders"; sendportUSOrders.PrimaryTransport.TransportType = catalog.ProtocolTypes[0]; sendportUSOrders.PrimaryTransport.Address = "http://process_orders_US.asp"; sendportUSOrders.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; //*************************************************** // specify filter for content-based routing of US orders // In the sample project the CountryCode for US is 100 //*************************************************** sendportUSOrders.Filter = "<Filter><Group>" + "<Statement Property='BTS.ReceivePortName' Operator='0' Value='ReceivePortPO'/>" + "<Statement Property='CBRSample.CountryCode' Operator='0' Value='100'/>" + "</Group></Filter>"; // enumerate all transforms and add a transform map that can normalize documents for US orders foreach (Transform transform in catalog.Transforms) { if (transform.SourceSchema.FullName == "CBRSample.CBRInputSchema" && transform.TargetSchema.FullName == "CBRSample.CBROutputSchemaUS") { sendportUSOrders.OutboundTransforms.Add(transform); break; } } // enlist and start the send port sendportUSOrders.Status = PortStatus.Started; //*************************************************** // create Sendport for processing CAN orders //*************************************************** SendPort sendportCANOrders = cbrApplication.AddNewSendPort(false, false); sendportCANOrders.Name = "SendportCANOrders"; sendportCANOrders.PrimaryTransport.TransportType = catalog.ProtocolTypes[0]; sendportCANOrders.PrimaryTransport.Address = "http://process_orders_CAN.asp"; sendportCANOrders.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; //*************************************************** // specify filter for content-based routing of CAN orders // In the sample project the CountryCode for CAN is 200 //*************************************************** sendportCANOrders.Filter = "<Filter><Group>" + "<Statement Property='BTS.ReceivePortName' Operator='0' Value='ReceivePortPO'/>" + "<Statement Property='CBRSample.CountryCode' Operator='0' Value='200'/>" + "</Group></Filter>"; // add a specific transform map to normalize documents for CAN orders Transform map = catalog.Transforms["CBRSample.CBRInput2CANMap"]; if (map != null) { sendportCANOrders.OutboundTransforms.Add(map); } // enlist and start the send port sendportCANOrders.Status = PortStatus.Started; // persist changes to BizTalk Configuration database catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } } else // No CbrApplication { catalog.DiscardChanges(); throw new Exception(@"You must deploy the SDK\Samples\Messaging\CBRSample in order to " + "create the referenced application, schema, and maps."); } }
public bool UnenlistSendPort(string sSendPortName) { try { bceExplorer = new BtsCatalogExplorer(); //Edit the following connection string to point to the correct database and server bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString; 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 void StopSendPort(string sSendPortName) { try { bceExplorer = new BtsCatalogExplorer(); //Edit the following connection string to point to the correct database and server bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString; SendPort sp = bceExplorer.SendPorts[sSendPortName]; if (sp.Status == PortStatus.Started) { sp.Status = PortStatus.Stopped; bceExplorer.SaveChanges(); UnenlistSendPort(sSendPortName); } } catch (Exception e) { bceExplorer.DiscardChanges(); throw e; } }
static void Main(string[] args) { // Handle the command-line arguments and switches if (args.Length != 1) { PrintUsage(); return; } if (("/?" == args[0]) || ("-?" == args[0])) { PrintUsage(); return; } // Create the root object and set the connection string BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = string.Format("SERVER={0};DATABASE={1};Integrated Security=SSPI", SystemInformation.ComputerName, "BizTalkMgmtDB"); try { // Get the requested assembly from the collaction BtsAssembly assembly = catalog.Assemblies[args[0]]; if (null == assembly) { Console.WriteLine("Assembly named " + args[0] + " was not found."); return; } Console.WriteLine("Removing enlisted parties from assembly " + assembly.Name + "."); // Go through each Role in the assembly foreach (Role role in assembly.Roles) { // Find the number of Parties enlisted int numberOfEnlistedParties = role.EnlistedParties.Count; // For each enlisted party, remove it for (int count = 0; count < numberOfEnlistedParties; count++) { EnlistedParty enlistedParty = role.EnlistedParties[0]; Console.WriteLine("Unenlisting the " + enlistedParty.Party.Name + " Party from the " + enlistedParty.Role.Name + " Role."); role.RemoveEnlistedParty(enlistedParty); } } // commit the changes catalog.SaveChanges(); Console.WriteLine("All enlisted parties for assemlby " + assembly.Name + " have been removed."); } catch (ConstraintException ce) { // Any changes need to be reverted // when there is an error catalog.DiscardChanges(); // Since this is a common configruation excpetion // we don't need a stack trace Console.WriteLine(ce.Message); } catch (Exception e) { // Any changes need to be reverted // when there is an error catalog.DiscardChanges(); Console.WriteLine(e.ToString()); } }
public void EnableReceiveLocation(string sReceivePortName, string sReceiveLocationName) { try { bceExplorer = new BtsCatalogExplorer(); //Edit the following connection string to point to the correct database and server bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString; ReceivePort rp = bceExplorer.ReceivePorts[sReceivePortName]; foreach (ReceiveLocation rl in rp.ReceiveLocations) { if (rl.Name.Equals(sReceiveLocationName)) { if (rl.Enable == false) { rl.Enable = true; } } } bceExplorer.SaveChanges(); } catch (Exception e) { bceExplorer.DiscardChanges(); throw e; } }
public override bool Execute() { int retryCount = 5; if ((string.IsNullOrEmpty(_startOption) && string.IsNullOrEmpty(_stopOption)) || (!string.IsNullOrEmpty(_startOption) && !string.IsNullOrEmpty(_stopOption))) { this.Log.LogError("Please specify either StartOption or StopOption."); return(false); } using (BtsCatalogExplorer catalog = BizTalkCatalogExplorerFactory.GetCatalogExplorer()) { Application application = catalog.Applications[_applicationName]; if (application == null) { this.Log.LogError("Unable to find application '{0}' in catalog.", _applicationName); return(false); } ApplicationStartOption startOption = 0; ApplicationStopOption stopOption = 0; if (!string.IsNullOrEmpty(_startOption)) { startOption = ParseStartEnum(_startOption); } else { stopOption = ParseStopEnum(_stopOption); } for (int i = 0; i < retryCount; i++) { this.Log.LogMessage("(Retry count {0})", i); try { if (startOption != 0) { this.Log.LogMessage("Starting {0} application...", _applicationName); application.Start(startOption); } else { this.Log.LogMessage("Stopping {0} application...", _applicationName); application.Stop(stopOption); } catalog.SaveChanges(); break; } catch (Exception ex) { catalog.DiscardChanges(); if (!ex.Message.Contains("deadlocked")) { this.Log.LogErrorFromException(ex, false); return(false); } } } } return(true); }
/// <summary> /// Creates solicit-response HTTP send port /// </summary> /// <param name="uri">Send port URI</param> /// <param name="portName">Send port name</param> /// <param name="receivePort">Name of the receive port to bind this send port to</param> /// <returns>True if successful, otherwise false</returns> public static bool CreateHttpSolicitResponsePort(string uri, string portName, string receivePort, string affiliateApplication, ref string retMsg) { IBtsCatalogExplorer explorer = null; try { string mgmtDBName = "BizTalkMgmtDb"; string mgmtDBServer = "localhost"; ManagementClass groupSettings = new ManagementClass("root\\MicrosoftBizTalkServer:MSBTS_GroupSetting"); foreach (ManagementObject obj in groupSettings.GetInstances()) { mgmtDBName = (string)obj.Properties["MgmtDbName"].Value; mgmtDBServer = (string)obj.Properties["MgmtDbServerName"].Value; } // Get BizTalk Explorer object explorer = new BtsCatalogExplorer(); explorer.ConnectionString = "SERVER=" + mgmtDBServer + ";DATABASE=" + mgmtDBName + ";Integrated Security=SSPI"; // Delete this port if it already exists foreach (ISendPort port in explorer.GetCollection(CollectionType.SendPort)) { if (port.Name.ToLower() == portName.ToLower()) { port.Status = PortStatus.Bound; explorer.RemoveSendPort(port); break; } } explorer.SaveChanges(); // Add send port ISendPort transmitPort = explorer.AddNewSendPort(false, true); transmitPort.Name = portName; ITransportInfo TransInfo = transmitPort.PrimaryTransport; TransInfo.Address = uri; // Set protocol type foreach (IProtocolType protocol in explorer.GetCollection(CollectionType.ProtocolType)) { if (protocol.Name == "HTTP") { TransInfo.TransportType = protocol; } } // Set the transport data string transportTypeData = "<CustomProps>" + "<Address vt=\"8\">" + TransInfo.Address + "</Address>" + "<IsSolicitResponse vt=\"11\">1</IsSolicitResponse>" + "<RequestTimeout vt=\"3\">120</RequestTimeout>" + "<MaxRedirects vt=\"3\">0</MaxRedirects>" + "<ContentType vt=\"8\">text/xml</ContentType>" + "<URI vt=\"8\">" + TransInfo.Address + "</URI>" + "<UseSSO vt=\"11\">1</UseSSO>" + "<AffiliateApplicationName vt=\"8\">" + affiliateApplication + "</AffiliateApplicationName>" + "<AuthenticationScheme vt=\"8\">Basic</AuthenticationScheme>" + "</CustomProps>"; // Set transport config TransInfo.TransportTypeData = transportTypeData; ITransportInfo transInfo = transmitPort.PrimaryTransport; // Set reference to transmit pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Send) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruTransmit")) { transmitPort.SendPipeline = pipe; break; } } // For synchronous communications we should set up a receive pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Receive) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruReceive")) { transmitPort.ReceivePipeline = pipe; break; } } // Set filter transmitPort.Filter = "<Filter>" + "<Group>" + "<Statement Property=\"BTS.ReceivePortName\" Operator=\"0\" Value=\"" + receivePort + "\" />" + "</Group>" + "</Filter>"; // Enlist and start send port transmitPort.Status = PortStatus.Started; // Remember this created send port explorer.SaveChanges(); } catch (Exception e) { retMsg = e.Message.ToString(); if (explorer != null) { explorer.DiscardChanges(); } return(false); } return(true); }
/// <summary> /// Creates receive port with one request-response HTTP receive location /// </summary> /// <param name="virtualDirectory">Virtual directory name</param> /// <param name="portName">Receive port name</param> /// <param name="locationName">Receive location name</param> /// <returns>True if successful, otherwise false</returns> public static bool CreateHttpRequestResponsePort(string virtualDirectory, string portName, string locationName, ref string retMsg) { IBtsCatalogExplorer explorer = null; try { string mgmtDBName = "BizTalkMgmtDb"; string mgmtDBServer = "localhost"; ManagementClass groupSettings = new ManagementClass("root\\MicrosoftBizTalkServer:MSBTS_GroupSetting"); foreach (ManagementObject obj in groupSettings.GetInstances()) { mgmtDBName = (string)obj.Properties["MgmtDbName"].Value; mgmtDBServer = (string)obj.Properties["MgmtDbServerName"].Value; } // Get BizTalk Explorer object explorer = new BtsCatalogExplorer(); explorer.ConnectionString = "SERVER=" + mgmtDBServer + ";DATABASE=" + mgmtDBName + ";Integrated Security=SSPI"; // Delete this port if it already exists foreach (IReceivePort port in explorer.GetCollection(CollectionType.ReceivePort)) { if (port.Name.ToLower() == portName.ToLower()) { explorer.RemoveReceivePort(port); break; } } explorer.SaveChanges(); // Add new port IReceivePort receivePort = explorer.AddNewReceivePort(true); receivePort.Name = portName; // Add new location IReceiveLocation rxLocation = receivePort.AddNewReceiveLocation(); rxLocation.Name = locationName; // Set the receive location rxLocation.Address = "/" + virtualDirectory + "/BTSHttpReceive.dll"; // Set the transport type foreach (IProtocolType protocol in explorer.GetCollection(CollectionType.ProtocolType)) { if (protocol.Name == "HTTP") { rxLocation.TransportType = protocol; } } // Set the transport data rxLocation.TransportTypeData = "<CustomProps>" + "<Address vt=\"8\">" + rxLocation.Address + "</Address>" + "<LoopBack vt=\"11\">0</LoopBack>" + "<IsSynchronous vt=\"11\">1</IsSynchronous>" + "<ReturnCorrelationHandle vt=\"11\">0</ReturnCorrelationHandle>" + "<ResponseContentType vt=\"8\">text/html</ResponseContentType>" + "<URI vt=\"8\">" + rxLocation.Address + "</URI>" + "<UseSSO vt=\"11\">1</UseSSO>" + "</CustomProps>"; // Set the receive pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Receive) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruReceive")) { rxLocation.ReceivePipeline = pipe; break; } } // Set the receive handler foreach (IReceiveHandler handler in explorer.GetCollection(CollectionType.ReceiveHandler)) { if (handler.TransportType == rxLocation.TransportType) { rxLocation.ReceiveHandler = handler; break; } } foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Send) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruTransmit")) { receivePort.SendPipeline = pipe; break; } } // Enable this receive location rxLocation.Enable = true; // Save changes explorer.SaveChanges(); } catch (Exception e) { retMsg = e.Message.ToString(); if (explorer != null) { explorer.DiscardChanges(); } return(false); } return(true); }
static void CreateAndConfigureReceiveLocation() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //First, create a new one way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(false); //Note that if you dont set the name property for the receieve port, //it will create a new receive location and add it to the receive //port. myreceivePort.Name = "My Receive Port"; //Create a new receive location and add it to the receive port ReceiveLocation myreceiveLocation = myreceivePort.AddNewReceiveLocation(); foreach (ReceiveHandler handler in root.ReceiveHandlers) { if (handler.TransportType.Name == "HTTP") { myreceiveLocation.ReceiveHandler = handler; break; } } //Associate a transport protocol and URI with the receive location. foreach (ProtocolType protocol in root.ProtocolTypes) { if (protocol.Name == "HTTP") { myreceiveLocation.TransportType = protocol; break; } } myreceiveLocation.Address = "/home"; //Assign the first receive pipeline found to process the message. foreach (Pipeline pipeline in root.Pipelines) { if (pipeline.Type == PipelineType.Receive) { myreceiveLocation.ReceivePipeline = pipeline; break; } } //Enable the receive location. myreceiveLocation.Enable = true; myreceiveLocation.FragmentMessages = Fragmentation.Yes; //optional property myreceiveLocation.ServiceWindowEnabled = false; //optional property //Try to commit the changes made so far. If the commit fails, //roll-back all changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
public bool DisableAllReceiveLocations(string sReceivePortName) { try { bceExplorer = new BtsCatalogExplorer(); //Edit the following connection string to point to the correct database and server bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString; 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; } }