using System.Text;
using System.ServiceProcess;
using System.ServiceModel;
using HCM.BajaWare.Services;

namespace HCM.BajaWare.TestHost
{
    public class bajaWareWindowsService : ServiceBase
    {
        public ServiceHost serviceHost1 = null;
        public ServiceHost serviceHost2 = null;
        public ServiceHost serviceHost3 = null;
        public ServiceHost serviceHost4 = null;
        public ServiceHost serviceHost5 = null;
        public ServiceHost serviceHost6 = null;
        public ServiceHost serviceHost7 = null;
        public ServiceHost serviceHost8 = null;
        public ServiceHost serviceHost9 = null;
        public ServiceHost serviceHost10 = null;


        public bajaWareWindowsService()
        {
            ServiceName = "WCFWindowsServiceBajaWare";

        }

        public static void Main()
        {
            ServiceBase.Run(new bajaWareWindowsService());
        }


        // Start the Windows service.
        protected override void OnStart(string[] args)
        {
            if (serviceHost1 != null || serviceHost2 != null || serviceHost3 != null || serviceHost4 != null || serviceHost5 != null || serviceHost6 != null || serviceHost7 != null || serviceHost8 != null || serviceHost9 != null || serviceHost10 != null)
            {
                serviceHost1.Close();
                serviceHost2.Close();
                serviceHost3.Close();
                serviceHost4.Close();
                serviceHost5.Close();
                serviceHost6.Close();
                serviceHost7.Close();
                serviceHost8.Close();
                serviceHost9.Close();
                serviceHost10.Close();
            }

            // Create a ServiceHost for the CalculatorService type and 
            // provide the base address.
            serviceHost1 = new ServiceHost(typeof(InterfacesService));
            serviceHost2 = new ServiceHost(typeof(InterfacesServicePersonas));
            serviceHost3 = new ServiceHost(typeof(InterfacesServicesCatalogos));
            serviceHost4 = new ServiceHost(typeof(CreditoEmpresarialService));
            serviceHost5 = new ServiceHost(typeof(InterfacesServiceGarantias));
            serviceHost6 = new ServiceHost(typeof(InterfaceServicesAccionistas));
            serviceHost7 = new ServiceHost(typeof(InterfaceServicesAavales));
            serviceHost8 = new ServiceHost(typeof(InterfacesServiceCreditHipot));
            serviceHost9 = new ServiceHost(typeof(MonitoreoDatosService));
            serviceHost10 = new ServiceHost(typeof(InterfacesServicePermisos));

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost1.Open();
            serviceHost2.Open();
            serviceHost3.Open();
            serviceHost4.Open();
            serviceHost5.Open();
            serviceHost6.Open();
            serviceHost7.Open();
            serviceHost8.Open();
            serviceHost9.Open();
            serviceHost10.Open();
        }

        protected override void OnStop()
        {
            if (serviceHost1 != null || serviceHost2 != null || serviceHost3 != null || serviceHost4 != null || serviceHost5 != null || serviceHost6 != null || serviceHost7 != null || serviceHost8 != null || serviceHost9 != null || serviceHost10 != null)
            {
                serviceHost1.Close();
                serviceHost1 = null;
                serviceHost2.Close();
                serviceHost2 = null;
                serviceHost3.Close();
                serviceHost3 = null;
                serviceHost4.Close();
                serviceHost4 = null;
                serviceHost5.Close();
                serviceHost5 = null;
                serviceHost6.Close();
                serviceHost6 = null;
                serviceHost7.Close();
                serviceHost7 = null;
                serviceHost8.Close();
                serviceHost8 = null;
                serviceHost9.Close();
                serviceHost9 = null;
                serviceHost10.Close();
                serviceHost10 = null;

            }
        }
    }
}

