none
Command line to start BizTalk EDI Application

    Question

  • Okay, so, I've been able to command line silent install BizTalk. I can command line import an application (msi), and I can command line import the bindings for the application....do I really have to go into the BizTalk Server Administration Console to start the EDI Applications? :)

    I've been using the command line BTSTask for ImportApp and ImportBindings to get the apps set up, and all looks good! I've got them running from a .bat file to automate my process for me...now, I would like to start them from the same .bat file.

    Did I miss the command for that somewhere?

    Thanks in advance!

    mpleaf


    • Edited by mpleaf Tuesday, February 07, 2012 11:43 PM
    Tuesday, February 07, 2012 11:43 PM

Answers

  • Not that I know of :-(

    Let me know if you have any questions... because I cut this from a much larger BizTalk utility, I may have missed something.


    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.

    • Marked as answer by mpleaf Thursday, February 09, 2012 9:20 PM
    Wednesday, February 08, 2012 6:14 PM

All replies

  • I wrote a command line utility and placed it in my bins folder (part of system path).  This was a cut/paste job that I placed in a separate class, but it should give you something to go on.   Make sure you compile it in 32-bit only, as the ExplorerOM only supports 32-bit.

    #region Namespaces
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Text;
    // Microsoft
    using Microsoft.Win32;
    // BizTalk
    using Microsoft.BizTalk.ExplorerOM;
    #endregion

    public class BTSUtility
    {
        #region Constants
        private const string BizTalkConnectionFormatString = "Server={0};Initial Catalog={1};Integrated Security=SSPI;";
        #endregion

        #region Globals
        private static string bizTalkConnectionString = string.Empty;
        private static string servername = ".";
        private static string biztalkManagementDbName = "BizTalkMgmtDb";
        private static string applicationName = null;
        private static bool allApplications = false;
        private static bool startApplication = false;
        private static Hashtable displayed = new Hashtable();
        #endregion

        #region Internal Helper Methods
        #region Get BizTalk Connection String Method
        private static string GetBizTalkConnectionString()
        {
            using (RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BizTalk Server\3.0\Administration"))
            {
                string keyValue = string.Empty;

                // Read the BizTalk Server Name
                keyValue = key.GetValue("MgmtDBServer") as string;
                if (!string.IsNullOrEmpty(keyValue))
                {
                    servername = keyValue;
                }

                // Read the BizTalk Management DB name
                keyValue = key.GetValue("MgmtDBName") as string;
                if (!string.IsNullOrEmpty(keyValue))
                {
                    biztalkManagementDbName = keyValue;
                }

                // Close the registry key
                key.Close();
            }

            // Format the BizTalk connection string
            bizTalkConnectionString = string.Format(BizTalkConnectionFormatString, servername, biztalkManagementDbName);

            // Return the connection string
            return bizTalkConnectionString;
        }
        #endregion

        #region Get BizTalk Catalog Explorer
        private static BtsCatalogExplorer GetBtsCatalogExplorer()
        {
            BtsCatalogExplorer catalog = new BtsCatalogExplorer();
            catalog.ConnectionString = GetBizTalkConnectionString();
            return catalog;
        }
        #endregion
        #endregion

        #region Control Application Method
        private static void ControlApplication(string applicationName)
        {
            if (startApplication)
            {
                #region Start Application
                Application application = GetBtsCatalogExplorer().Applications[applicationName];

                if (application != null)
                {
                    foreach (Application app in application.References)
                    {
                        if ((app.Status != Status.Started) && (app.Status != Status.NotApplicable))
                        {
                            ControlApplication(app.Name);
                        }
                    }

                    using (BtsCatalogExplorer catalog = GetBtsCatalogExplorer())
                    {
                        if (catalog.Applications[applicationName].Status != Status.Started)
                        {
                            if (displayed[applicationName] == null)
                            {
                                Console.WriteLine("Starting application: {0}", applicationName);
                                displayed.Add(applicationName, applicationName);
                            }

                            // Now start this application
                            catalog.Applications[applicationName].Start(ApplicationStartOption.StartAll);

                            // Commit the change
                            catalog.SaveChanges();
                        }
                    }
                }
                else
                {
                    throw new ApplicationException(string.Format("Invalid application specified.  Name: {0}", applicationName));
                }
                #endregion
            }
            else
            {
                #region Stop Application
                if (GetBtsCatalogExplorer().Applications[applicationName] != null)
                {
                    ApplicationCollection applications = GetBtsCatalogExplorer().Applications;
                    foreach (Application app in applications)
                    {
                        if ((app.References[applicationName] != null) &&
                            (app.References[applicationName].Status != Status.Stopped) &&
                            (app.References[applicationName].Status != Status.NotApplicable))
                        {
                            ControlApplication(app.Name);
                        }
                    }

                    using (BtsCatalogExplorer catalog = GetBtsCatalogExplorer())
                    {
                        for (int i = 0; i < catalog.Applications[applicationName].Orchestrations.Count; i++)
                        {
                            catalog.Applications[applicationName].Orchestrations[i].Status = OrchestrationStatus.Unenlisted;
                        }
                        for (int i = 0; i < catalog.Applications[applicationName].SendPorts.Count; i++)
                        {
                            catalog.Applications[applicationName].SendPorts[i].Status = PortStatus.Stopped;
                        }
                        catalog.SaveChanges();

                        if (catalog.Applications[applicationName].Status != Status.Stopped)
                        {
                            if (displayed[applicationName] == null)
                            {
                                Console.WriteLine("Stopping application: {0}", applicationName);
                                displayed.Add(applicationName, applicationName);
                            }

                            // Stop the application
                            catalog.Applications[applicationName].Stop(ApplicationStopOption.StopAll);

                            try
                            {
                                // Commit the change
                                catalog.SaveChanges();
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                else
                {
                    throw new ApplicationException(string.Format("Invalid application specified.  Name: {0}", applicationName));
                }
                #endregion
            }
        }
        #endregion
    }


    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.

    Wednesday, February 08, 2012 3:25 AM
  • Ummm...yeah...wow! :)

    Sorry, code is not my thing. Was hoping there was a part of BTSTask command line or something to do so. I appreciate the help David, I will pass this on to one of my dev folks to see if it makes sense to him. I take it this means, there really isn't a command line to start them?

    mpleaf

    Wednesday, February 08, 2012 4:52 PM
  • Not that I know of :-(

    Let me know if you have any questions... because I cut this from a much larger BizTalk utility, I may have missed something.


    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.

    • Marked as answer by mpleaf Thursday, February 09, 2012 9:20 PM
    Wednesday, February 08, 2012 6:14 PM