static void DomainInitializer(string[] args)
        {
            Console.WriteLine("Initializing the installer in the Install AppDomain");
            Parser.Args commandLineArguments = Parser.ParseArgs(args);
            var         arguments            = new HostArguments(commandLineArguments);

            string endpointName = string.Empty;

            if (arguments.EndpointName != null)
            {
                endpointName = arguments.EndpointName.Value;
            }

            string[] scannedAssemblies = null;
            if (arguments.ScannedAssemblies != null)
            {
                scannedAssemblies = arguments.ScannedAssemblies.Value.Split(';').ToArray();
            }

            if (arguments.Username != null)
            {
                MsmqUtilities.AccountToBeAssignedQueuePermissions(arguments.Username.Value);
            }

            host = new WindowsHost(Type.GetType(arguments.EndpointConfigurationType.Value, true), args, endpointName, commandLineArguments.Install, (arguments.InstallInfrastructure != null), scannedAssemblies);
        }
Beispiel #2
0
        private static IArgument GetArgument(Parser.Args arguments, string key)
        {
            IArgument argument = arguments.CustomArguments.Where(x => x.Key != null).SingleOrDefault(x => x.Key.ToUpper() == key.ToUpper());

            if (argument != null)
            {
                arguments.CustomArguments = arguments.CustomArguments.Except(new[] { argument });
            }

            return(argument);
        }
Beispiel #3
0
 public HostArguments(Parser.Args arguments)
 {
     Help        = GetArgument(arguments, "help") ?? GetArgument(arguments, "?");
     ServiceName = GetArgument(arguments, "serviceName");
     DisplayName = GetArgument(arguments, "displayName");
     Description = GetArgument(arguments, "description");
     EndpointConfigurationType = GetArgument(arguments, "endpointConfigurationType");
     DependsOn     = GetArgument(arguments, "dependsOn");
     StartManually = GetArgument(arguments, "startManually");
     Username      = GetArgument(arguments, "username");
     Password      = GetArgument(arguments, "password");
 }
Beispiel #4
0
 public HostArguments(Parser.Args arguments)
 {
     Help        = GetArgument(arguments, "help") ?? GetArgument(arguments, "?");
     ServiceName = GetArgument(arguments, "serviceName");
     DisplayName = GetArgument(arguments, "displayName");
     Description = GetArgument(arguments, "description");
     EndpointConfigurationType = GetArgument(arguments, "endpointConfigurationType");
     DependsOn             = GetArgument(arguments, "dependsOn");
     StartManually         = GetArgument(arguments, "startManually");
     Username              = GetArgument(arguments, "username");
     Password              = GetArgument(arguments, "password");
     SideBySide            = GetArgument(arguments, "sideBySide");
     EndpointName          = GetArgument(arguments, "endpointName");
     InstallInfrastructure = GetArgument(arguments, "installInfrastructure");
     ScannedAssemblies     = GetArgument(arguments, "scannedAssemblies");
 }
        /// <summary>
        /// Returns an instance of <see cref="GenericHost"/>
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        protected override object DoGetInstance(Type serviceType, string key)
        {
            var endpoint = Type.GetType(key, true);

            Parser.Args commandLineArguments = Parser.ParseArgs(Args);
            var         arguments            = new HostArguments(commandLineArguments);

            string endpointName = string.Empty;

            if (arguments.EndpointName != null)
            {
                endpointName = arguments.EndpointName.Value;
            }

            string[] scannedAssemblies = null;
            if (arguments.ScannedAssemblies != null)
            {
                scannedAssemblies = arguments.ScannedAssemblies.Value.Split(';').ToArray();
            }

            return(new WindowsHost(endpoint, Args, endpointName, false, false, scannedAssemblies));
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Parser.Args commandLineArguments = Parser.ParseArgs(args);
            var         arguments            = new HostArguments(commandLineArguments);

            if (arguments.Help != null)
            {
                DisplayHelpContent();

                return;
            }

            var endpointConfigurationType = GetEndpointConfigurationType(arguments);

            if (endpointConfigurationType == null)
            {
                if (arguments.InstallInfrastructure == null)
                {
                    throw new InvalidOperationException("No endpoint configuration found in scanned assemblies. " +
                                                        "This usually happens when NServiceBus fails to load your assembly containing IConfigureThisEndpoint." +
                                                        " Try specifying the type explicitly in the NServiceBus.Host.exe.config using the appsetting key: EndpointConfigurationType, " +
                                                        "Scanned path: " + AppDomain.CurrentDomain.BaseDirectory);
                }

                Console.WriteLine("Running infrastructure installers and exiting (ignoring other command line parameters if exist).");
                InstallInfrastructure();
                return;
            }

            AssertThatEndpointConfigurationTypeHasDefaultConstructor(endpointConfigurationType);
            string endpointConfigurationFile = GetEndpointConfigurationFile(endpointConfigurationType);

            var endpointName    = GetEndpointName(endpointConfigurationType, arguments);
            var endpointVersion = GetEndpointVersion(endpointConfigurationType);

            var serviceName = endpointName;

            if (arguments.ServiceName != null)
            {
                serviceName = arguments.ServiceName.Value;
            }

            var displayName = serviceName + "-" + endpointVersion;

            if (arguments.SideBySide != null)
            {
                serviceName += "-" + endpointVersion;

                displayName += " (SideBySide)";
            }

            //add the endpoint name so that the new appdomain can get it
            args = args.Concat(new[] { endpointName }).ToArray();

            AppDomain.CurrentDomain.SetupInformation.AppDomainInitializerArguments = args;
            if ((commandLineArguments.Install) || (arguments.InstallInfrastructure != null))
            {
                WindowsInstaller.Install(args, endpointConfigurationType, endpointName, endpointConfigurationFile,
                                         commandLineArguments.Install, arguments.InstallInfrastructure != null);
            }


            IRunConfiguration cfg = RunnerConfigurator.New(x =>
            {
                x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c =>
                {
                    c.ConfigurationFile(endpointConfigurationFile);
                    c.CommandLineArguments(args, () => SetHostServiceLocatorArgs);
                    c.WhenStarted(service => service.Start());
                    c.WhenStopped(service => service.Stop());
                    c.CreateServiceLocator(() => new HostServiceLocator());
                });

                if (arguments.Username != null && arguments.Password != null)
                {
                    x.RunAs(arguments.Username.Value, arguments.Password.Value);
                }
                else
                {
                    x.RunAsLocalSystem();
                }

                if (arguments.StartManually != null)
                {
                    x.DoNotStartAutomatically();
                }

                x.SetDisplayName(arguments.DisplayName != null ? arguments.DisplayName.Value : displayName);
                x.SetServiceName(serviceName);
                x.SetDescription(arguments.Description != null ? arguments.Description.Value : "NServiceBus Message Endpoint Host Service for " + displayName);

                var serviceCommandLine = commandLineArguments.CustomArguments.AsCommandLine();
                serviceCommandLine    += " /serviceName:\"" + serviceName + "\"";
                serviceCommandLine    += " /endpointName:\"" + endpointName + "\"";

                x.SetServiceCommandLine(serviceCommandLine);

                if (arguments.DependsOn == null)
                {
                    x.DependencyOnMsmq();
                }
                else
                {
                    foreach (var dependency in arguments.DependsOn.Value.Split(','))
                    {
                        x.DependsOn(dependency);
                    }
                }
            });

            Runner.Host(cfg, args);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Parser.Args commandLineArguments = Parser.ParseArgs(args);
            var         arguments            = new HostArguments(commandLineArguments);

            if (arguments.Help != null)
            {
                DisplayHelpContent();

                return;
            }

            var endpointConfigurationType = GetEndpointConfigurationType(arguments);

            AssertThatEndpointConfigurationTypeHasDefaultConstructor(endpointConfigurationType);

            string endpointConfigurationFile = GetEndpointConfigurationFile(endpointConfigurationType);


            var endpointName    = GetEndpointName(endpointConfigurationType);
            var endpointVersion = GetEndpointVersion(endpointConfigurationType);

            if (arguments.ServiceName != null)
            {
                endpointName = arguments.ServiceName.Value;
            }

            var serviceName = endpointName;

            var displayName = serviceName + "-" + endpointVersion;

            //add the endpoint name so that the new appdomain can get it
            args = args.Concat(new[] { endpointName }).ToArray();

            AppDomain.CurrentDomain.SetupInformation.AppDomainInitializerArguments = args;

            if (commandLineArguments.Install)
            {
                WindowsInstaller.Install(args, endpointConfigurationType, endpointName, endpointConfigurationFile);
            }

            IRunConfiguration cfg = RunnerConfigurator.New(x =>
            {
                x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c =>
                {
                    c.ConfigurationFile(endpointConfigurationFile);
                    c.CommandLineArguments(args, () => SetHostServiceLocatorArgs);
                    c.WhenStarted(service => service.Start());
                    c.WhenStopped(service => service.Stop());
                    c.CreateServiceLocator(() => new HostServiceLocator());
                });

                if (arguments.Username != null && arguments.Password != null)
                {
                    x.RunAs(arguments.Username.Value, arguments.Password.Value);
                }
                else
                {
                    x.RunAsLocalSystem();
                }

                if (arguments.StartManually != null)
                {
                    x.DoNotStartAutomatically();
                }

                x.SetDisplayName(arguments.DisplayName != null ? arguments.DisplayName.Value : displayName);
                x.SetServiceName(serviceName);
                x.SetDescription(arguments.Description != null ? arguments.Description.Value : "NServiceBus Message Endpoint Host Service for " + displayName);

                var serviceCommandLine = commandLineArguments.CustomArguments.AsCommandLine();
                serviceCommandLine    += " /serviceName:\"" + serviceName + "\"";

                x.SetServiceCommandLine(serviceCommandLine);

                if (arguments.DependsOn == null)
                {
                    x.DependencyOnMsmq();
                }
                else
                {
                    foreach (var dependency in arguments.DependsOn.Value.Split(','))
                    {
                        x.DependsOn(dependency);
                    }
                }
            });

            Runner.Host(cfg, args);
        }
Beispiel #8
0
        private static void Main(string[] args)
        {
            Parser.Args commandLineArguments = Parser.ParseArgs(args);
            var         arguments            = new HostArguments(commandLineArguments);

            if (arguments.Help != null)
            {
                DisplayHelpContent();

                return;
            }

            Type endpointConfigurationType = GetEndpointConfigurationType(arguments);

            AssertThatEndpointConfigurationTypeHasDefaultConstructor(endpointConfigurationType);

            string endpointConfigurationFile = GetEndpointConfigurationFile(endpointConfigurationType);

            var endpointConfiguration = Activator.CreateInstance(endpointConfigurationType);

            EndpointId = GetEndpointId(endpointConfiguration);

            AppDomain.CurrentDomain.SetupInformation.AppDomainInitializerArguments = args;

            IRunConfiguration cfg = RunnerConfigurator.New(x =>
            {
                x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c =>
                {
                    c.ConfigurationFile(endpointConfigurationFile);
                    c.CommandLineArguments(args, () => SetHostServiceLocatorArgs);
                    c.WhenStarted(service => service.Start());
                    c.WhenStopped(service => service.Stop());
                    c.CreateServiceLocator(() => new HostServiceLocator());
                });

                if (arguments.Username != null && arguments.Password != null)
                {
                    x.RunAs(arguments.Username.Value, arguments.Password.Value);
                }
                else
                {
                    x.RunAsLocalSystem();
                }

                if (arguments.StartManually != null)
                {
                    x.DoNotStartAutomatically();
                }

                x.SetDisplayName(arguments.DisplayName != null ? arguments.DisplayName.Value : EndpointId);
                x.SetServiceName(arguments.ServiceName != null ? arguments.ServiceName.Value : EndpointId);
                x.SetDescription(arguments.Description != null ? arguments.Description.Value : "NServiceBus Message Endpoint Host Service");
                x.DependencyOnMsmq();

                var serviceCommandLine = commandLineArguments.CustomArguments.AsCommandLine();

                if (arguments.ServiceName != null)
                {
                    serviceCommandLine += " /serviceName:\"" + arguments.ServiceName.Value + "\"";
                }

                x.SetServiceCommandLine(serviceCommandLine);

                if (arguments.DependsOn != null)
                {
                    var dependencies = arguments.DependsOn.Value.Split(',');

                    foreach (var dependency in dependencies)
                    {
                        if (dependency.ToUpper() == KnownServiceNames.Msmq)
                        {
                            continue;
                        }

                        x.DependsOn(dependency);
                    }
                }
            });

            Runner.Host(cfg, args);
        }