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;
            }
        }
Beispiel #2
0
        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());
            }
        }