Пример #1
0
        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;
            }
        }
 private void receiveTreeView_DoubleClick(object sender, EventArgs e)
 {
     if (receiveTreeView.SelectedNode != null)
     {
         if (receiveTreeView.SelectedNode.Parent != null)
         {
             using (var expl = new BtsCatalogExplorer()
             {
                 ConnectionString = ConfigurationManager.AppSettings["connString"].ToString()
             })
             {
                 ReceivePortCollection enm = expl.ReceivePorts;
                 foreach (ReceivePort port in enm)
                 {
                     if (port.Name == receiveTreeView.SelectedNode.Text)
                     {
                         rcvNameLbl.Text     = receiveTreeView.SelectedNode.Text;
                         rcvPortNameTxt.Text = port.Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
                         rcvPortTypeLbl.Text = port.IsTwoWay.ToString();
                     }
                 }
             }
         }
     }
 }
Пример #3
0
        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;
            }
        }
Пример #4
0
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            if (string.IsNullOrEmpty(this.DatabaseServer))
            {
                this.DatabaseServer = this.MachineName;
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Connecting to BtsCatalogExplorer: Server: {0}. Database: {1}", this.DatabaseServer, this.Database));
            using (this.explorer = new BtsCatalogExplorer())
            {
                this.explorer.ConnectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Database={1};Integrated Security=SSPI;", this.DatabaseServer, this.Database);
                this.GetManagementScope(WmiBizTalkNamespace);
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "{0} Adaptor: {1} on: {2}", this.TaskAction, this.AdaptorName, this.MachineName));

                switch (this.TaskAction)
                {
                case CreateTaskAction:
                    this.CreateOrUpdate();
                    break;

                case CheckExistsTaskAction:
                    this.CheckExists();
                    break;

                case DeleteTaskAction:
                    this.Delete();
                    break;

                default:
                    this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                    return;
                }
            }
        }
 private void sendTreeView_DoubleClick(object sender, EventArgs e)
 {
     if (sendTreeView.SelectedNode != null)
     {
         if (sendTreeView.SelectedNode.Parent != null)
         {
             using (var expl = new BtsCatalogExplorer()
             {
                 ConnectionString = ConfigurationManager.AppSettings["connString"].ToString()
             })
             {
                 SendPortCollection enm = expl.SendPorts;
                 foreach (SendPort port in enm)
                 {
                     if (port.Name == sendTreeView.SelectedNode.Text)
                     {
                         sendPortLbl.Text     = sendTreeView.SelectedNode.Text;
                         sendPortNametxt.Text = port.Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
                         sendPortUriTxt.Text  = port.PrimaryTransport != null ? port.PrimaryTransport.Address : "";
                         sendPortTypelbl.Text = port.PrimaryTransport != null ? port.PrimaryTransport.TransportType.Name : "";
                     }
                 }
             }
         }
     }
 }
Пример #6
0
        public static BtsCatalogExplorer GetBtsCatalogExplorer()
        {
            BtsCatalogExplorer explorer = new BtsCatalogExplorer();

            explorer.ConnectionString = ConnectionString(GetMgmtServerInfo());
            return(explorer);
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="explorer"></param>
        public void Load(BtsCatalogExplorer explorer, Application application)
        {
            TraceManager.SmartTrace.TraceIn();


            this.name = application.Name;

            TraceManager.SmartTrace.TraceInfo("Processing Application  : " + this.Name);

            // Referenced Applications
            LoadReferences(application);

            LoadBackReferences(application);

            LoadPipelines(explorer, application);

            LoadSchemas(explorer, application);

            LoadMaps(application);

            LoadOrchestrations(explorer, application);

            LoadReceivePorts(explorer, application);

            LoadSendPorts(explorer, application);

            LoadSendPortGroups(explorer, application);

            LoadAssemblies(explorer, application);

            LoadRoleLinks(explorer, application);

            TraceManager.SmartTrace.TraceOut();
        }
Пример #8
0
        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;
            }
        }
Пример #9
0
        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;
            }
        }
        private static DataTable GetHostNameDataTable()
        {
            try
            {
                BtsCatalogExplorer explorer = CreateBtsCatalogExplorer();

                HostCollection hosts = explorer.Hosts;

                DataTable  dt = new DataTable();
                DataColumn dc = new DataColumn();
                dc.ColumnName = "HostName";
                dt.Columns.Add(dc);

                foreach (Host item in hosts)
                {
                    DataRow dr = dt.NewRow();
                    dr["HostName"] = item.Name;
                    dt.Rows.Add(dr);
                }

                return(dt);
            }
            catch (Exception)
            {
                throw;
            }
        }
 /// <summary>
 /// the "remote" version?
 /// </summary>
 /// <param name="mgmtDBServer">Database server containing BTS MgmtDBServer</param>
 /// <param name="mgmtDBName">BTS Mgmt DB Name</param>
 /// <returns>BtsCatalogExplorer object (ExplorerOM)</returns>
 public static BtsCatalogExplorer CatalogExplorer(string mgmtDBServer, string mgmtDBName)
 {
     BtsCatalogExplorer catalog = new BtsCatalogExplorer();
     catalog.ConnectionString = String.Format("Server={0};Database={1};Integrated Security=SSPI", mgmtDBServer,
                                               mgmtDBName);
     return catalog;
 }
Пример #12
0
        private BtsCatalogExplorer CreateCatalogExplorer()
        {
            BtsCatalogExplorer catalogExploerer = new BtsCatalogExplorer();

            catalogExploerer.ConnectionString = String.Format(Constants._DB_CONN_STRING, this.DbServerName, this.MgmtDBName);
            return(catalogExploerer);
        }
Пример #13
0
        public ProtocolTypeCollection GetAdapters()
        {
            List <string>      adapters        = new List <string>();
            BtsCatalogExplorer catalogExplorer = CreateCatalogExplorer();

            return(catalogExplorer.ProtocolTypes);
        }
Пример #14
0
        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;
            }
        }
Пример #15
0
        public override bool Execute()
        {
            using (BtsCatalogExplorer catalog = BizTalkCatalogExplorerFactory.GetCatalogExplorer())
            {
                Application application = catalog.Applications[_applicationName];
                if (application == null)
                {
                    this.Log.LogError("Unable to find BizTalk application '{0}'.", _applicationName);
                    return(false);
                }

                foreach (ITaskItem ti in _appsToReference)
                {
                    Application appToRef = catalog.Applications[ti.ItemSpec];
                    if (appToRef == null)
                    {
                        this.Log.LogError("Unable to find BizTalk application '{0}' to reference from application '{1}'.", ti.ItemSpec, _applicationName);
                        return(false);
                    }

                    this.Log.LogMessage("Adding reference to BizTalk application '{0}' from BizTalk application '{1}'.", _applicationName, ti.ItemSpec);
                    application.AddReference(appToRef);
                }

                if (_appsToReference.Length > 0)
                {
                    catalog.SaveChanges();
                }

                this.Log.LogMessage("Finished adding application references to BizTalk application '{0}'.", _applicationName);
            }

            return(true);
        }
Пример #16
0
        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;
                }
            }
        }
Пример #17
0
        static void EnumerateReceiveLocations()
        {
            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)
                {
                    Console.WriteLine(receivePort.Name);
                    //Enumerate the receive locations.
                    foreach (ReceiveLocation location in
                             receivePort.ReceiveLocations)
                    {
                        Console.WriteLine(location.Name);
                    }
                }
            }
            catch (Exception e)            //If it fails, roll-back all changes.
            {
                throw e;
            }
        }
Пример #18
0
        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;
            }
        }
        /// <summary>
        /// retrieve all system message type to avoid process on it
        /// </summary>
        public static List <String> InitializeAvoidSchemaTypeList()
        {
            List <string> AvoidSchemasType = new List <string>();

            //initialize catalog to browse assembly to get system assembly
            using (BtsCatalogExplorer catalog = new BtsCatalogExplorer())
            {
                catalog.ConnectionString = BtsConnectionString;
                foreach (BtsAssembly assembly in catalog.Assemblies)
                {
                    //once got system assembly let's add all system schemas
                    if (assembly.IsSystem)
                    {
                        if (assembly.Schemas != null)
                        {
                            //add all schema declared in those assemblies
                            foreach (Schema schema in assembly.Schemas)
                            {
                                if (schema.Type == SchemaType.Document)
                                {
                                    AvoidSchemasType.Add(String.Concat(schema.TargetNameSpace, "#", schema.RootName));
                                }
                            }
                        }
                    }
                }
            }

            return(AvoidSchemasType);
        }
Пример #20
0
        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;
            }
        }
Пример #21
0
        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;
            }
        }
        /// <summary>
        /// Tries to start the app one piece at a time as there was a problem doing it in bulk
        /// </summary>
        /// <param name="catalog"></param>
        /// <param name="applicationName"></param>
        private static void AlternativeStart(BtsCatalogExplorer catalog, string applicationName)
        {
            Trace.WriteLine("Attempting alternative method to start application");
            var app = catalog.Applications[applicationName];

            foreach (SendPort sendPort in app.SendPorts)
            {
                Trace.WriteLine(string.Format("Starting send port: {0}", sendPort.Name));
                StartSendPort(sendPort.Name);
            }

            foreach (ReceivePort recievePort in app.ReceivePorts)
            {
                foreach (ReceiveLocation recieveLocation in recievePort.ReceiveLocations)
                {
                    Trace.WriteLine(string.Format("Starting recieve location: {0}", recieveLocation.Name));
                    EnableRecieveLocation(recieveLocation.Name, recievePort.Name);
                }
            }

            foreach (BtsOrchestration orchestration in app.Orchestrations)
            {
                Trace.WriteLine(string.Format("Starting orchestration: {0}", orchestration.FullName));
                EnlistOrchestration(orchestration.FullName, orchestration.BtsAssembly.DisplayName, orchestration.Host.Name);
                StartOrchestration(orchestration.FullName, orchestration.BtsAssembly.DisplayName);
            }
        }
Пример #23
0
        public void RemoveApplication(string applicationName)
        {
            BtsCatalogExplorer catalogExplorer = CreateCatalogExplorer();
            Application        appToRemove     = catalogExplorer.Applications[applicationName];

            catalogExplorer.RemoveApplication(appToRemove);
        }
Пример #24
0
        public override bool Execute()
        {
            try
            {
                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);
                    }

                    // First, get all of the artifacts associated with the BizTalk application
                    Dictionary <string, Dictionary <string, object> > artifacts = GetArtifactsWithDefaultAction(application);

                    if (artifacts == null)
                    {
                        return(false);
                    }

                    // Next, reconcile the user-specified artifacts with the actual artifacts
                    if (_artifacts != null)
                    {
                        foreach (ITaskItem ti in _artifacts)
                        {
                            if (!artifacts.ContainsKey(ti.ItemSpec))
                            {
                                base.Log.LogWarning(_artifactName + " '" + ti.ItemSpec + "' does not exist in the BizTalk application.");
                                continue;
                            }

                            Dictionary <string, object> metadata = artifacts[ti.ItemSpec] as Dictionary <string, object>;

                            CopyMetadata(ti, metadata);

                            string actionMetadataName  = (_mode == ModeType.Deploy) ? "DeployAction" : "UndeployAction";
                            object actionMetadataValue = null;

                            if (metadata.TryGetValue(actionMetadataName, out actionMetadataValue))
                            {
                                metadata[ActionMetadataKey] = GetAction((string)actionMetadataValue);
                            }
                        }
                    }

                    // Finally, carry out the actions against the artifacts
                    ControlArtifacts(catalog, application, artifacts);
                }

                return(true);
            }
            catch (Exception ex)
            {
                this.Log.LogErrorFromException(ex, false);
                return(false);
            }
        }
Пример #25
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 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());
            }
        }
        /// <summary>
        /// thios will check for the existance of a  biztalk application
        /// </summary>
        /// <param name="explorer"></param>
        /// <param name="applicationName"></param>
        /// <returns></returns>
        public static bool ApplicationExists(BtsCatalogExplorer explorer, string applicationName)
        {
            if (explorer == null)
            {
                throw new NullReferenceException("The explorer has not been provided");
            }

            return(explorer.Applications.Cast <Application>().Any(btsApp => btsApp.Name == applicationName));
        }
        public static BtsCatalogExplorer CreateBizTalkCatalogExplorer(string managementDatabaseConnectionString)
        {
            var explorer = new BtsCatalogExplorer
            {
                ConnectionString = managementDatabaseConnectionString
            };

            return(explorer);
        }
        public static Application FindBizTalkApplication(string applicationName, BtsCatalogExplorer explorer)
        {
            if (explorer == null)
            {
                throw new ArgumentNullException(nameof(explorer));
            }

            return(explorer.Applications[applicationName]);
        }
Пример #29
0
        private static void Get(ref LinkedList <string> list, string btsapp, string connectionString)
        {
            try
            {
                // Get the application dependencies based on the assembly dependencies
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand sqlCom = new SqlCommand();
                    sqlCom.Connection  = conn;
                    sqlCom.CommandText = "dbo.USP_GetApplicationDependencies";
                    sqlCom.CommandType = CommandType.StoredProcedure;

                    SqlParameter p = new SqlParameter();
                    p.Direction     = ParameterDirection.Input;
                    p.DbType        = DbType.String;
                    p.ParameterName = "@p_BTSApplication";
                    p.Value         = btsapp;
                    sqlCom.Parameters.Add(p);

                    // also add the application to the linked list
                    if (!list.Contains(btsapp))
                    {
                        list.AddLast(new LinkedListNode <string>(btsapp));
                    }

                    SqlDataReader reader = sqlCom.ExecuteReader(CommandBehavior.CloseConnection);
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            SqlString s0 = reader.GetSqlString(0);
                            SqlString s1 = reader.GetSqlString(1);

                            if ((!s1.IsNull) && (s1.Value.ToLower() != btsapp.ToLower()))
                            {
                                AddNode(ref list, s0.Value, s1.Value);
                            }
                        }
                    }
                }
                // Get the application dependencies based on application references
                BtsCatalogExplorer explorer = new BtsCatalogExplorer();
                explorer.ConnectionString = connectionString;
                GetReferredBy(ref list, btsapp, explorer);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Failed to retrieve the Application Dependencies for the application {0} - {1} : {2}", btsapp, connectionString, ex.Message), ex);
            }
        }
 private static BtsCatalogExplorer CreateBtsCatalogExplorer()
 {
     try
     {
         BtsCatalogExplorer explorer = new BtsCatalogExplorer();
         explorer.ConnectionString = BtsConfigDbHelper.BtsConfigurationDatabase.GetConnectionString();
         return(explorer);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public void Test() {

            var explorer = new BtsCatalogExplorer();
            explorer.ConnectionString = ConnectionStringHelper.GetMgmtConnectionString();

            foreach (SendPort sp in explorer.SendPorts)
            {
                if (sp.Name == "zzzzzz")
                    Console.WriteLine(sp.Name);
            }

            createTransmitBindings("microservicebus.com", "mySendPort", "localhost", 3400, "application/xml");

        }
        private void btnApplications_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbServer.Text))
            {
                MessageBox.Show(@"Server name should not be empty");
            }
            else
            {
                string connectionString = string.Format("SERVER={0};DATABASE=BizTalkMgmtDb;Integrated Security=SSPI",
                    tbServer.Text);
                var catalog = new BtsCatalogExplorer
                {
                    ConnectionString = connectionString
                };
                List<Application> apps = catalog.Applications.Cast<Application>().ToList();
                var appSelections = new ListSelectionWrapper<Application>(apps, "Name");

                ddlApplications.DataSource = appSelections;
                ddlApplications.DisplayMemberSingleItem = "Name";
                ddlApplications.DisplayMember = "NameConcatenated";
                ddlApplications.ValueMember = "Selected";
            }
        }
Пример #33
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataTable RetrieveAllSchemas(StringCollection applicationList)
        {
            DataTable dt = new DataTable();
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            // define the table's schema
            dt.Columns.Add(new DataColumn("SchemaName", typeof(string)));
            dt.Columns.Add(new DataColumn("MessageType", typeof(string)));
            dt.Columns.Add(new DataColumn("SchemaType", typeof(string)));
            dt.Columns.Add(new DataColumn("Assembly", typeof(string)));
            dt.Columns.Add(new DataColumn("Application", typeof(string)));

            try
            {
                DataRow dr = null;

                foreach (Schema schema in bceExplorer.Schemas)
                {
                    if (applicationList.Contains(schema.Application.Name))
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr[0] = schema.FullName;
                        dr[1] = schema.TargetNameSpace + "#" + schema.RootName;
                        dr[2] = schema.Type.ToString();
                        dr[3] = schema.BtsAssembly.Name;
                        dr[4] = schema.Application.Name;

                        dt.Rows.Add(dr);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return dt;
        }
Пример #34
0
        public DataTable RetrieveArtifactHandlers(string artifactType)
        {
            ArrayList filter = new ArrayList();
            DataTable dt = new DataTable();
            DataRow dr = null;
            bceExplorer = new BtsCatalogExplorer();
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            int rowCount = 0;
            // define the table's schema
            dt.Columns.Add(new DataColumn("Id", typeof(string)));
            dt.Columns.Add(new DataColumn("HandlerName", typeof(string)));

            if (artifactType == BCCUIHelper.Constants.ARTIFACT_SND)
            {
                foreach(SendHandler sendHandler in bceExplorer.SendHandlers)
                {
                    if (filter.Contains(sendHandler.Name))
                    {
                        continue;
                    }
                    else
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["Id"] = rowCount;
                        dr["HandlerName"] = sendHandler.Name;
                        dt.Rows.Add(dr);
                        rowCount = rowCount + 1;
                        filter.Add(sendHandler.Name);
                    }
                }
            }
            else if (artifactType == BCCUIHelper.Constants.ARTIFACT_RCV)
            {
                foreach (ReceiveHandler rcvHandler in bceExplorer.ReceiveHandlers)
                {
                    if (filter.Contains(rcvHandler.Name))
                    {
                        continue;
                    }
                    else
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["Id"] = rowCount;
                        dr["HandlerName"] = rcvHandler.Name;
                        dt.Rows.Add(dr);
                        rowCount = rowCount + 1;
                        filter.Add(rcvHandler.Name);
                    }
                }
            }
            else if (artifactType == BCCUIHelper.Constants.ARTIFACT_ODX)
            {
                foreach (Host host in bceExplorer.Hosts)
                {
                    if (filter.Contains(host.Name))
                    {
                        continue;
                    }
                    else
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["Id"] = rowCount;
                        dr["HandlerName"] = host.Name;
                        dt.Rows.Add(dr);
                        rowCount = rowCount + 1;
                        filter.Add(host.Name);
                    }
                }
            }

            return dt;
        }
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            if (string.IsNullOrEmpty(this.DatabaseServer))
            {
                this.DatabaseServer = this.MachineName;
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Connecting to BtsCatalogExplorer: Server: {0}. Database: {1}", this.DatabaseServer, this.Database));
            using (this.explorer = new BtsCatalogExplorer())
            {
                if (string.IsNullOrEmpty(this.HostName) && this.TaskAction != GetTaskAction)
                {
                    this.Log.LogError("HostName is required.");
                    return;
                }

                this.explorer.ConnectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Database={1};Integrated Security=SSPI;", this.DatabaseServer, this.Database);
                this.GetManagementScope(WmiBizTalkNamespace);
                this.LogTaskMessage(this.TaskAction != GetTaskAction ? string.Format(CultureInfo.CurrentCulture, "{0} {1} ReceiveHandler for: {2} on {3}", this.TaskAction, this.AdapterName, this.HostName, this.MachineName) : string.Format(CultureInfo.CurrentCulture, "Get ReceiveHandlers for Adaptor: {0} matching HostName: {1} on {2}", this.AdapterName, this.HostName, this.MachineName));

                switch (this.TaskAction)
                {
                    case CreateTaskAction:
                        this.Create();
                        break;
                    case CheckExistsTaskAction:
                        this.CheckExists();
                        break;
                    case DeleteTaskAction:
                        this.Delete();
                        break;
                    case GetTaskAction:
                        this.Get();
                        break;
                    default:
                        this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                        return;
                }
            }
        }
Пример #36
0
 /// <summary>
 /// Bound/Started/Stopped
 /// </summary>
 /// <param name="sSendPortName"></param>
 /// <returns></returns>
 public string RetrieveSendPortStatus(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];
         return sp.Status.ToString();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #37
0
        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;
            }
        }
Пример #38
0
        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;
            }
        }
Пример #39
0
        public DataTable RetrieveAllOrchestrations()
        {
            DataTable dt = new DataTable();
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies;

            // define the table's schema
            dt.Columns.Add(new DataColumn("HDName", typeof(string)));
            dt.Columns.Add(new DataColumn("Application", typeof(string)));
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Status", typeof(string)));
            dt.Columns.Add(new DataColumn("AssemblyName", typeof(string)));
            dt.Columns.Add(new DataColumn("Version", typeof(string)));
            dt.Columns.Add(new DataColumn("Token", typeof(string)));

            try
            {
                foreach (BtsAssembly btsAssembly in btsAssemblyCollection)
                {
                    Host host = null;

                    foreach (BtsOrchestration btsOrchestration in btsAssembly.Orchestrations)
                    {
                        // Create the rows
                        DataRow dr = dt.NewRow();
                        dr["HDName"] = btsOrchestration.FullName;
                        dr["Application"] = btsOrchestration.Application.Name;
                        dr["Name"] = btsOrchestration.FullName;

                        host = btsOrchestration.Host;

                        if (host != null)
                        {
                            dr["Status"] = btsOrchestration.Status.ToString();
                        }
                        else
                        {
                            dr["Status"] = btsOrchestration.Status.ToString() + " (unbound)";
                        }

                        dr["AssemblyName"] = btsOrchestration.BtsAssembly.Name;
                        dr["Version"] = btsOrchestration.BtsAssembly.Version;
                        dr["Token"] = btsOrchestration.BtsAssembly.PublicKeyToken;

                        dt.Rows.Add(dr);

                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return dt;
        }
        public bool isAdapterInstalled()
        {
            var explorer = new BtsCatalogExplorer();

            try
            {
                bool installed = false;
                explorer.ConnectionString = ConnectionStringHelper.GetMgmtConnectionString();
                foreach (ProtocolType p in explorer.ProtocolTypes)
                {
                    installed = p.Name == "microServiceBus";
                    if (installed)
                        break;
                }

                return installed;
            }
            catch { return false; }

        }
        private static void createReceiveBindings(string applicationName, 
            string receivePortName, 
            string receiveLocationName)
        {
            var explorer = new BtsCatalogExplorer();

            try
            {
                explorer.ConnectionString = ConnectionStringHelper.GetMgmtConnectionString();

                var application = explorer.Applications[applicationName];
                if (application == null)
                {
                    application = explorer.AddNewApplication();
                    application.Name = applicationName;
                    explorer.SaveChanges();
                }
                System.Diagnostics.Trace.WriteLine("application done", "microservicebus");

                var receivePort = application.ReceivePorts[receivePortName];
                if (receivePort == null)
                {
                    receivePort = application.AddNewReceivePort(false);
                    receivePort.Name = receivePortName;
                    explorer.SaveChanges();
                }
                System.Diagnostics.Trace.WriteLine("receive port done", "microservicebus");
                var receiveLocation = receivePort.ReceiveLocations[receiveLocationName];
                if (receiveLocation == null)
                {
                    var submitURI = string.Format("microservicebus://{0}", receiveLocationName);
                    var pipeline = explorer.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruReceive"];
                    var transport = explorer.ProtocolTypes["microServiceBus"];
                    receiveLocation = receivePort.AddNewReceiveLocation();
                    receiveLocation.Address = submitURI;
                    receiveLocation.Description = "Automaticly created by the microServiceBus.com host.";
                    receiveLocation.Name = receiveLocationName;
                    receiveLocation.ReceivePipeline = pipeline;
                    receiveLocation.TransportType = transport;
                    receiveLocation.TransportTypeData = @"<CustomProps><AdapterConfig vt=""8"">&lt;CustomProps xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""&gt;&lt;uri&gt;"+submitURI+@"&lt;/uri&gt;&lt;/CustomProps&gt;</AdapterConfig></CustomProps>";
                    foreach (ReceiveHandler receiveHandler in explorer.ReceiveHandlers)
                    {
                        if (receiveHandler.Name == "BizTalkServerIsolatedHost" &&
                            receiveHandler.TransportType.Name == "microServiceBus")
                        {
                            receiveLocation.ReceiveHandler = receiveHandler;
                            break;
                        }

                    }
                    receiveLocation.Enable = true;
                    explorer.SaveChanges();
                    System.Diagnostics.Trace.WriteLine("all done", "microservicebus");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private static void createTransmitBindings(string applicationName,
            string sendPortName,
            string address,
            int port,
            string contentType)
        {
            var explorer = new BtsCatalogExplorer();

            try
            {
                explorer.ConnectionString = ConnectionStringHelper.GetMgmtConnectionString();

                var application = explorer.Applications[applicationName];
                if (application == null)
                {
                    application = explorer.AddNewApplication();
                    application.Name = applicationName;
                    explorer.SaveChanges();
                }


                var sendPort = application.SendPorts[sendPortName];
                if (sendPort == null)
                {
                    var uri = string.Format("microservicebus://{0}:{1}", address, port);
                    var pipeline = explorer.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruTransmit"];
                    sendPort = application.AddNewSendPort(false, false);
                    sendPort.Name = sendPortName;
                    sendPort.SendPipeline = pipeline;
                    
                    var transport = explorer.ProtocolTypes["microServiceBus"];
                    sendPort.Description = "Automaticly created by the microServiceBus.com host.";
                    sendPort.PrimaryTransport.Address = uri;
                    sendPort.PrimaryTransport.TransportType = transport;
                    sendPort.PrimaryTransport.TransportTypeData = @"<CustomProps><AdapterConfig vt=""8"">&lt;CustomProps xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""&gt;&lt;uri&gt;" + uri + @"&lt;/uri&gt;&lt;address&gt;" + address + @"&lt;/address&gt;&lt;port&gt;" + port.ToString() + @"&lt;/port&gt;&lt;contentType&gt;"+ contentType + @"&lt;/contentType&gt;&lt;/CustomProps&gt;</AdapterConfig></CustomProps>";
                    foreach (SendHandler sendHandler in explorer.SendHandlers)
                    {
                        if (sendHandler.TransportType.Name == "microServiceBus")
                        {
                            sendPort.PrimaryTransport.SendHandler = sendHandler;
                            break;
                        }

                    }
                    sendPort.Status = PortStatus.Started;
                    explorer.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private static void removeBindings(string applicationName)
        {
            var explorer = new BtsCatalogExplorer();

            try
            {
                explorer.ConnectionString = ConnectionStringHelper.GetMgmtConnectionString();

                var application = explorer.Applications[applicationName];
                if (application != null)
                {
                    application.Stop(ApplicationStopOption.StopAll);
                    explorer.SaveChanges();
                    foreach (ReceivePort receivePort in application.ReceivePorts)
                    {
                        foreach (ReceiveLocation location in receivePort.ReceiveLocations)
                        {
                            location.Enable = false;
                        }
                        explorer.RemoveReceivePort(receivePort);
                    }


                    explorer.RemoveApplication(application);
                    explorer.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to apply bindings.");
            }
        }
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            if (string.IsNullOrEmpty(this.DatabaseServer))
            {
                this.DatabaseServer = this.MachineName;
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Connecting to BtsCatalogExplorer: Server: {0}. Database: {1}", this.DatabaseServer, this.Database));
            using (this.explorer = new BtsCatalogExplorer())
            {
                this.explorer.ConnectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Database={1};Integrated Security=SSPI;", this.DatabaseServer, this.Database);
                switch (this.TaskAction)
                {
                    case CreateTaskAction:
                        this.Create();
                        break;
                    case GetTaskAction:
                        this.GetApplications();
                        break;
                    case CheckExistsTaskAction:
                        this.CheckApplicationExists();
                        break;
                    case StartAllTaskAction:
                    case EnableAllReceiveLocationsTaskAction:
                    case StartAllOrchestrationsTaskAction:
                    case StartAllSendPortGroupsTaskAction:
                    case StartAllSendPortsTaskAction:
                    case StartReferencedApplicationsTaskAction:
                        this.StartApplication();
                        break;
                    case StopAllTaskAction:
                    case DisableAllReceiveLocationsTaskAction:
                    case UndeployAllPoliciesTaskAction:
                    case UnenlistAllOrchestrationsTaskAction:
                    case UnenlistAllSendPortGroupsTaskAction:
                    case UnenlistAllSendPortsTaskAction:
                    case StopReferencedApplicationsTaskAction:
                        this.StopApplication();
                        break;
                    case EnableReceiveLocationsTaskAction:
                    case DisableReceiveLocationsTaskAction:
                        this.ControlReceiveLocations();
                        break;
                    case DeleteTaskAction:
                        this.Delete();
                        break;
                    case ExportToMsiTaskAction:
                        this.ExportToMsi();
                        break;
                    case ImportFromMsiTaskAction:
                        this.ImportFromMsi();
                        break;
                    case RemoveReferenceTaskAction:
                    case AddReferenceTaskAction:
                        this.ConfigureReference();
                        break;
                    case ImportBindingsTaskAction:
                        this.ImportBindings();
                        break;
                    case ExportBindingsTaskAction:
                        this.ExportBindings();
                        break;
                    default:
                        this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                        return;
                }
            }
        }
Пример #45
0
        public DataTable EnumerateAllArtifacts()
        {
            DataTable dt = new DataTable();
            DataRow dr = null;
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies;
            BizTalkOperations btOperations = new BizTalkOperations();

            // define the table's schema
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Status", typeof(string)));
            dt.Columns.Add(new DataColumn("Data", typeof(string)));

            try
            {
                // Enumerate all orchestrations
                foreach (BtsAssembly btsAssembly in btsAssemblyCollection)
                {
                        dr = dt.NewRow();
                        dr["Name"] = btsAssembly.Name;
                        dr["Status"] = "";
                        dr["Data"] = "Assembly:" + btsAssembly.DisplayName + ":" + btsAssembly.Version + ":" + btsAssembly.PublicKeyToken;
                        dt.Rows.Add(dr);

                    foreach (BtsOrchestration btsOrchestration in btsAssembly.Orchestrations)
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["Name"] = btsOrchestration.FullName;
                        dr["Status"] = btsOrchestration.Status.ToString();
                        dr["Data"] = "Orchestration:" + btsOrchestration.BtsAssembly.Name + ":v" + btsOrchestration.BtsAssembly.Version + ":" + btsOrchestration.BtsAssembly.PublicKeyToken;
                        dt.Rows.Add(dr);

                        // Enumerate ports and operations
                        foreach (OrchestrationPort port in btsOrchestration.Ports)
                        {
                            dr = dt.NewRow();
                            dr["Name"] = port.Name;
                            dr["Status"] = "";
                            dr["Data"] = "Port Type:" + port.PortType.FullName + ":" + port.PortType.AssemblyQualifiedName;
                            dt.Rows.Add(dr);

                            foreach (PortTypeOperation operation in port.PortType.Operations)
                            {
                                dr = dt.NewRow();
                                dr["Name"] = operation.Name;
                                dr["Status"] = "";
                                dr["Data"] = "PortTypeOperation:" + operation.Type;
                                dt.Rows.Add(dr);
                            }
                        }

                        // Enumerate used roles
                        foreach (Role role in btsOrchestration.UsedRoles)
                        {
                            dr = dt.NewRow();
                            dr["Name"] = role.Name;
                            dr["Status"] = "";
                            dr["Data"] = "ServiceLinkType:" + role.ServiceLinkType;
                            dt.Rows.Add(dr);

                            foreach (EnlistedParty enlistedparty in role.EnlistedParties)
                            {
                                dr = dt.NewRow();
                                dr["Name"] = enlistedparty.Party.Name;
                                dr["Status"] = "";
                                dr["Data"] = "Data:" + enlistedparty.Party.CustomData;
                                dt.Rows.Add(dr);
                            }
                        }
                    }
                }

                foreach (SendPort sp in bceExplorer.SendPorts)
                {
                    dr = dt.NewRow();
                    dr["Name"] = sp.Name;
                    dr["Status"] = sp.Status.ToString();

                    if (sp.PrimaryTransport != null)
                    {
                       dr["Data"] = "Send Port:" + sp.PrimaryTransport.Address + ":" + sp.PrimaryTransport.TransportType.Name;
                    }
                    dt.Rows.Add(dr);
                }

                foreach (ReceivePort rp in bceExplorer.ReceivePorts)
                {
                    foreach (ReceiveLocation rl in rp.ReceiveLocations)
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["Name"] = rp.Name;
                        dr["Status"] = (rl.Enable ? "Enabled" : "Disabled");
                        dr["Data"] = "Receive Location:" + rl.Name;
                        dt.Rows.Add(dr);
                    }
                }

                // Host instances
                ManagementClass objHostSettingClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostInstance", null);
                foreach (ManagementObject objShare in objHostSettingClass.GetInstances())
                {
                    dr = dt.NewRow();
                    dr["Name"] = objShare.Properties["RunningServer"].Value.ToString();
                    string status = objShare.Properties["ServiceState"].Value.ToString();
                    dr["Status"] = ("4".Equals(status) ? "Running" : "Stopped");
                    dr["Data"] = "Host:" + objShare.Properties["HostName"].Value.ToString();
                    dt.Rows.Add(dr);
                }

                if (btOperations != null)
                {
                    // Loop and get the service instances
                    foreach (MessageBoxServiceInstance serviceInstance in btOperations.GetServiceInstances())
                    {
                        if (serviceInstance.Application != null )
                        {
                            foreach (BizTalkMessage msg in serviceInstance.Messages)
                            {
                                dr = dt.NewRow();
                                dr["Name"] = serviceInstance.Application.ToUpper();
                                dr["Status"] = msg.InstanceStatus;
                                dr["Data"] = "Message:" + msg.MessageID + ":" + msg.InstanceID.ToString() + ":" + msg.CreationTime.ToString();
                                dt.Rows.Add(dr);
                            }
                        }
                    }
                }

                foreach (Transform transform in bceExplorer.Transforms)
                {
                    dr = dt.NewRow();
                    dr["Name"] = transform.FullName;
                    dr["Status"] = "";
                    dr["Data"] = "Map:" + transform.SourceSchema.FullName + ":" + transform.TargetSchema.FullName;
                    dt.Rows.Add(dr);
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return dt;
        }
Пример #46
0
        public DataTable RetrieveAllMaps(StringCollection applicationList)
        {
            DataTable dt = new DataTable();
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            // define the table's schema
            dt.Columns.Add(new DataColumn("SourceSchema", typeof(string)));
            dt.Columns.Add(new DataColumn("SourceSchemaRoot", typeof(string)));
            dt.Columns.Add(new DataColumn("MapName", typeof(string)));
            dt.Columns.Add(new DataColumn("TargetSchema", typeof(string)));
            dt.Columns.Add(new DataColumn("TargetSchemaRoot", typeof(string)));
            dt.Columns.Add(new DataColumn("Assembly", typeof(string)));
            dt.Columns.Add(new DataColumn("Application", typeof(string)));

            try
            {
                DataRow dr = null;

                foreach (Transform map in bceExplorer.Transforms)
                {
                    if (applicationList.Contains(map.Application.Name))
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["SourceSchema"] = map.SourceSchema.FullName;
                        dr["SourceSchemaRoot"] = map.SourceSchema.RootName;
                        dr["TargetSchema"] = map.TargetSchema.FullName;
                        dr["TargetSchemaRoot"] = map.TargetSchema.RootName;
                        dr["MapName"] = map.FullName;
                        dr["Assembly"] = map.BtsAssembly.Name;
                        dr["Application"] = map.Application.Name;

                        dt.Rows.Add(dr);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return dt;
        }
Пример #47
0
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            if (!BizTalkHelper.IsValidName(this.HostName, @"[`~!@#\$%\^&\*\(\)\+=\[\]\{}\|\/;:\""'<>,\.\?-]|\s"))
            {
                Log.LogError(@"The HostName contains an invalid character. The following characters are not permitted: `~!@#$%^&*()+=[]{}|\/;:\""'<>,.?-<space>");
                return;
            }

            if (string.IsNullOrEmpty(this.DatabaseServer))
            {
                this.DatabaseServer = this.MachineName;
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Connecting to BtsCatalogExplorer: Server: {0}. Database: {1}", this.DatabaseServer, this.Database));
            using (this.explorer = new BtsCatalogExplorer())
            {
                this.explorer.ConnectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Database={1};Integrated Security=SSPI;", this.DatabaseServer, this.Database);
                this.GetManagementScope(WmiBizTalkNamespace);
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "{0} Host: {1} on: {2}", this.TaskAction, this.HostName, this.MachineName));

                switch (this.TaskAction)
                {
                    case CreateTaskAction:
                    case UpdateTaskAction:
                        this.CreateOrUpdate();
                        break;
                    case CheckExistsTaskAction:
                        this.CheckExists();
                        break;
                    case DeleteTaskAction:
                        this.Delete();
                        break;
                    default:
                        this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                        return;
                }
            }
        }
Пример #48
0
        public StringCollection RetrieveAllApplications()
        {
            StringCollection appCollection = null;
            bceExplorer = new BtsCatalogExplorer();
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            ApplicationCollection btsAppCollection = bceExplorer.Applications;

            try
            {
                appCollection = new StringCollection();

                foreach (Application application in btsAppCollection)
                {
                    appCollection.Add(application.Name);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e.Message + e.StackTrace, "Retrieve-All-Applications");
            }

            return appCollection;
        }
Пример #49
0
        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;
            }
        }
Пример #50
0
        public StringCollection RetrieveAllApplications(StringCollection applicationList)
        {
            StringCollection appCollection = null;
            bceExplorer = new BtsCatalogExplorer();
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            ApplicationCollection btsAppCollection = bceExplorer.Applications;

            try
            {
                appCollection = new StringCollection();

                foreach (Application application in btsAppCollection)
                {
                    if (applicationList.Contains(application.Name))
                    {
                        appCollection.Add(application.Name);
                    }
                }
            }
            catch (Exception e)
            {
                Debug(e.Message);
            }

            return appCollection;
        }
Пример #51
0
        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;
                        }

                    }
                }
            }
        }
        private IBtsCatalogExplorer2 ConnectExplorer()
        {
            SqlConnectionStringBuilder builder = null;

            if (!String.IsNullOrWhiteSpace(this.DatabaseServer))
            {
                builder = new SqlConnectionStringBuilder();

                builder.IntegratedSecurity = true;

                builder.DataSource = this.DatabaseServer;
            }

            if (!String.IsNullOrWhiteSpace(this.Database))
            {
                if (builder == null)
                {
                    builder = new SqlConnectionStringBuilder();

                    builder.IntegratedSecurity = true;

                    builder.DataSource = Environment.MachineName;

                    this.DatabaseServer = builder.DataSource;
                }

                builder.InitialCatalog = this.Database;
            }

            if (builder == null)
            {
                builder = new SqlConnectionStringBuilder();

                builder.IntegratedSecurity = true;

                builder.DataSource = Environment.MachineName;
                builder.InitialCatalog = "BizTalkMgmtDb";

                this.DatabaseServer = builder.DataSource;
                this.Database = builder.InitialCatalog;
            }

            IBtsCatalogExplorer2 explorer = new BtsCatalogExplorer();

            explorer.ConnectionString = builder.ConnectionString;

            return explorer;
        }
Пример #53
0
        public bool RetrieveReceiveLocationStatus(string sReceivePortName, string sReceiveLocationName)
        {
            bool status = false;

            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))
                    {
                        status = rl.Enable;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                status = false;
            }

            return status;
        }
Пример #54
0
        public DataTable RetrieveAllAdapters()
        {
            DataTable dt = new DataTable();
            DataRow dr = null;
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;

            // define the table's schema
            dt.Columns.Add(new DataColumn("ProtocolName", typeof(string)));
            dt.Columns.Add(new DataColumn("DefaultSendHandler", typeof(string)));
            dt.Columns.Add(new DataColumn("Capabilities", typeof(string)));

            ProtocolTypeCollection protocolTypeCollection = bceExplorer.ProtocolTypes;
            SendHandler defaultHandler = null;

            foreach (ProtocolType protocolType in protocolTypeCollection)
            {
                dr = dt.NewRow();
                dr[0] = protocolType.Name;
                defaultHandler = protocolType.DefaultSendHandler;

                if (defaultHandler != null)
                {
                    dr[1] = protocolType.DefaultSendHandler.Name;
                }
                else
                {
                    dr[1] = "none";
                }

                Capabilities ability = protocolType.Capabilities;
                dr[2] = ability.ToString();

                dt.Rows.Add(dr);
            }

            return dt;
        }
Пример #55
0
        public string RetrieveDefaultBizTalkApplication()
        {
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;

            string defaultAppName = string.Empty;

            ApplicationCollection appCollection = bceExplorer.Applications;

            foreach (Application app in appCollection)
            {
                if (app.IsDefaultApplication)
                {
                    defaultAppName = app.Name;
                    break;
                }
            }

            return defaultAppName;
        }
Пример #56
0
        public BtsOrchestration GetOrchestrationByName(string orchestrationName, string applicationName)
        {
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            BtsAssemblyCollection btsAssemblyCollection = bceExplorer.Assemblies;

            BizTalkOperations btOperations = new BizTalkOperations();
            try
            {
                foreach (BtsAssembly btsAssembly in btsAssemblyCollection)
                {
                    foreach (BtsOrchestration btsOrchestration in btsAssembly.Orchestrations)
                    {
                        // Show only HUB related orchestrations.
                        if ((applicationName.ToUpper()).Equals(btsOrchestration.BtsAssembly.Application.Name.ToUpper())
                            && orchestrationName.Equals(btsOrchestration.FullName))
                        {
                            return btsOrchestration;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return null;
        }
Пример #57
0
        public DataTable RetrieveAllSendPorts(StringCollection applicationList)
        {
            DataTable dt = new DataTable();
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            // define the table's schema
            dt.Columns.Add(new DataColumn("SendPortName", typeof(string)));
            dt.Columns.Add(new DataColumn("Status", typeof(string)));
            dt.Columns.Add(new DataColumn("URI", typeof(string)));
            dt.Columns.Add(new DataColumn("TransportType", typeof(string)));
            dt.Columns.Add(new DataColumn("Application", typeof(string)));
            dt.Columns.Add(new DataColumn("PortType", typeof(string)));

            try
            {
                DataRow dr = null;

                foreach (SendPort sp in bceExplorer.SendPorts)
                {
                    if (applicationList.Contains(sp.Application.Name))
                    {
                        // create the rows
                        dr = dt.NewRow();
                        dr["SendPortName"] = sp.Name;
                        dr["Status"] = sp.Status.ToString();
                        dr["Application"] = sp.Application.Name;

                        if (sp.IsDynamic && sp.IsTwoWay)
                        {
                            dr["PortType"] = "Dynamic Solicit-Response";
                        }
                        else if (!sp.IsDynamic && sp.IsTwoWay)
                        {
                            dr["PortType"] = "Static Solicit-Response";
                        }
                        else if (sp.IsDynamic && !sp.IsTwoWay)
                        {
                            dr["PortType"] = "Dynamic One-way";
                        }
                        else
                        {
                            dr["PortType"] = "Static One-way";
                        }

                        if (sp.PrimaryTransport != null)
                        {
                            dr["URI"] = sp.PrimaryTransport.Address;
                            dr["TransportType"] = sp.PrimaryTransport.TransportType.Name;
                        }
                        dt.Rows.Add(dr);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return dt;
        }
Пример #58
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="applicationName"></param>
        /// <param name="oCount">Orchestration count</param>
        /// <param name="rCount">Receive location count</param>
        /// <param name="sCount">Send Port count</param>
        /// <param name="oaHosts">Orchestration unique hosts</param>
        /// <param name="raHosts">Receive port hosts</param>
        /// <param name="saHosts">Send port hosts</param>
        /// <returns></returns>
        public DataTable EnumerateAllArtifacts(string applicationName, 
            out int oCount, out int rCount, out int sCount,
            out int oaHosts, out int raHosts, out int saHosts)
        {
            DataTable dt = new DataTable();
            DataRow dr = null;
            bceExplorer = new BtsCatalogExplorer();
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            oaHosts = 0; raHosts = 0; saHosts = 0;
            oCount = 0; rCount = 0; sCount = 0;
            int rowCounter = 0;
            // define the table's schema
            dt.Columns.Add(new DataColumn("ArtifactType", typeof(string)));
            dt.Columns.Add(new DataColumn("ArtifactName", typeof(string)));
            dt.Columns.Add(new DataColumn("ArtifactHost", typeof(string)));
            dt.Columns.Add(new DataColumn("ID", typeof(string)));

            try
            {
                ArrayList namedArray = null;
                string hostName = string.Empty;

                foreach (Application application in bceExplorer.Applications)
                {
                    if (application.Name.Equals(applicationName))
                    {
                        namedArray = new ArrayList();

                        foreach (BtsOrchestration btsOrchestration in application.Orchestrations)
                        {
                            // create the rows
                            dr = dt.NewRow();
                            dr["ArtifactType"] = BCCUIHelper.Constants.ARTIFACT_ODX;
                            dr["ArtifactName"] = btsOrchestration.FullName;

                            if (btsOrchestration.Host != null)
                            {
                                hostName = btsOrchestration.Host.Name;
                            }
                            else
                            {
                                hostName = "(unbound)";
                            }

                            dr["ArtifactHost"] = hostName;
                            dr["ID"] = rowCounter.ToString();

                            if (!namedArray.Contains(hostName))
                            {
                                namedArray.Add(hostName);
                            }

                            dt.Rows.Add(dr);
                            oCount = oCount + 1;
                            rowCounter = rowCounter + 1;
                        }

                        oaHosts = namedArray.Count;
                        namedArray = new ArrayList();

                        foreach (SendPort sp in application.SendPorts)
                        {
                            dr = dt.NewRow();
                            dr["ArtifactType"] = BCCUIHelper.Constants.ARTIFACT_SND;
                            dr["ArtifactName"] = sp.Name;

                            if (sp.PrimaryTransport != null && sp.PrimaryTransport.SendHandler != null)
                            {
                                hostName = sp.PrimaryTransport.SendHandler.Name;
                                dr["ArtifactHost"] = hostName;

                                if (!namedArray.Contains(hostName))
                                {
                                    namedArray.Add(hostName);
                                }

                                sCount = sCount + 1;
                            }
                            else
                            {
                                dr["ArtifactHost"] = "&lt;empty&gt;";
                            }

                            dr["ID"] = rowCounter.ToString();
                            dt.Rows.Add(dr);
                            rowCounter = rowCounter + 1;
                        }

                        saHosts = namedArray.Count;
                        namedArray = new ArrayList();

                        foreach (ReceivePort rp in application.ReceivePorts)
                        {
                           foreach (ReceiveLocation rl in rp.ReceiveLocations)
                            {
                                // create the rows
                                dr = dt.NewRow();
                                dr["ArtifactType"] = BCCUIHelper.Constants.ARTIFACT_RCV;
                                dr["ArtifactName"] = rl.Name;

                                if (rl.ReceiveHandler.Host != null)
                                {
                                    hostName = rl.ReceiveHandler.Host.Name;
                                }
                                else
                                {
                                    hostName = "&lt;empty&gt;";
                                }

                                dr["ArtifactHost"] = hostName;

                                if (!namedArray.Contains(hostName))
                                {
                                    namedArray.Add(hostName);
                                }

                                dr["ID"] = rowCounter.ToString();
                                dt.Rows.Add(dr);
                                rCount = rCount + 1;
                                rowCounter = rowCounter + 1;
                            }
                        }

                        raHosts = namedArray.Count;
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return dt;
        }
Пример #59
0
        public ArrayList RetrieveAllReceiveLocations(string sReceivePortName)
        {
            ArrayList array = new ArrayList();
            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)
                {
                    array.Add(rl.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return array;
        }
Пример #60
0
        public DataTable RetrieveAllReceivePorts()
        {
            DataTable dt = new DataTable();
            bceExplorer = new BtsCatalogExplorer();
            //Edit the following connection string to point to the correct database and server
            bceExplorer.ConnectionString = bizTalkMgmtDbConnectionString;
            dt.Columns.Add(new DataColumn("ReceivePortName", typeof(string)));
            dt.Columns.Add(new DataColumn("Status", typeof(string)));
            dt.Columns.Add(new DataColumn("ReceivePortLocation", typeof(string)));
            dt.Columns.Add(new DataColumn("Application", typeof(string)));
            dt.Columns.Add(new DataColumn("ReceiveLocationURI", typeof(string)));

            try
            {
                foreach (ReceivePort rp in bceExplorer.ReceivePorts)
                {
                    foreach (ReceiveLocation rl in rp.ReceiveLocations)
                    {
                        // create the rows
                        DataRow dr = dt.NewRow();
                        dr["ReceivePortName"] = rp.Name;
                        dr["Status"] = (rl.Enable ? "Enabled" : "Disabled");
                        dr["ReceivePortLocation"] = rl.Name;
                        dr["Application"] = rp.Application.Name;
                        dr["ReceiveLocationURI"] = rl.Address;
                        dt.Rows.Add(dr);
                    }
                }

                dt.DefaultView.Sort = "ReceivePortName ASC";

            }
            catch (Exception e)
            {
                throw e;
            }

            return dt;
        }