public override void Execute(HostArguments args) { if (args.Options.Count == 0) { return; } var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); foreach (var option in args.Options) { if (option.Key == "NServiceBus/Transport") { configuration.ConnectionStrings.ConnectionStrings.Remove("NServiceBus/Transport"); configuration.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("NServiceBus/Transport", option.Value)); } else { configuration.AppSettings.Settings.Remove(option.Key); configuration.AppSettings.Settings.Add(new KeyValueConfigurationElement(option.Key, option.Value)); } } configuration.Save(); Console.Out.WriteLine("Options written to config file."); }
public void TestFixtureSetup() { hostArguments = new HostArguments(new string[0]) { EndpointName = "EndpointNameFromHostArgs" }; }
public void Execute(HostArguments args) { foreach (var commandType in commands) { var command = (AbstractCommand)Activator.CreateInstance(commandType); command.Execute(args); } }
internal EndpointType(HostArguments arguments, Type type) : this(type) { if (arguments == null) { throw new ArgumentNullException("arguments"); } this.arguments = arguments; }
public void when_endpoint_type_is_not_provided_via_hostargs_it_should_fall_through_to_other_modes_of_determining_endpoint_type() { Sut = new EndpointTypeDeterminer(AssemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); hostArguments = new HostArguments(new string[0]); // will match with config-based type RetrievedEndpointType = Sut.GetEndpointConfigurationTypeForHostedEndpoint(hostArguments).Type; Assert.AreEqual(EndpointTypeDefinedInConfigurationFile, RetrievedEndpointType); }
public void when_invalid_endpoint_type_is_provided_via_hostargs_it_should_blow_up() { Sut = new EndpointTypeDeterminer(AssemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); hostArguments = new HostArguments(new string[0]) { EndpointConfigurationType = "I am an invalid type name" }; RetrievedEndpointType = Sut.GetEndpointConfigurationTypeForHostedEndpoint(hostArguments).Type; }
public override void Execute(HostArguments args) { if (String.IsNullOrEmpty(args.ServiceControlUrl)) { return; } ExtractConfig(args.OutputPath); UpdateConfig(args.OutputPath, args.ServiceControlUrl); }
internal EndpointType GetEndpointConfigurationTypeForHostedEndpoint(HostArguments arguments) { Type type; if (TryGetEndpointConfigurationTypeFromArguments(arguments, out type)) { return new EndpointType(arguments,type); } return GetEndpointConfigurationType(arguments); }
static void Main(string[] args) { var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } new CommandRunner(arguments.Commands).Execute(arguments); }
/// <summary> /// Returns an instance of GenericHost" /// </summary> protected override object DoGetInstance(Type serviceType, string key) { var endpoint = Type.GetType(key, true); var arguments = new HostArguments(Args); var endpointName = string.Empty; if (arguments.EndpointName != null) endpointName = arguments.EndpointName; return new WindowsHost(endpoint, Args, endpointName, arguments.ScannedAssemblies.ToArray()); }
public void when_endpoint_type_is_provided_via_hostargs_it_should_have_first_priority() { Sut = new EndpointTypeDeterminer(AssemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); hostArguments = new HostArguments(new string[0]) { EndpointConfigurationType = typeof (TestEndpointType).AssemblyQualifiedName }; RetrievedEndpointType = Sut.GetEndpointConfigurationTypeForHostedEndpoint(hostArguments).Type; Assert.AreEqual(typeof (TestEndpointType), RetrievedEndpointType); }
public override void Execute(HostArguments args) { if (!IsServiceInstalled(args.ServiceName)) { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine("The '{0}' service is not installed.", args.ServiceName); Console.ResetColor(); return; } ExecuteInternal(args); }
static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += (s, e) => ResolveAssembly(e.Name); var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } new CommandRunner(arguments.Commands).Execute(arguments); }
static void DomainInitializer(string[] args) { Console.WriteLine("Initializing the installer in the Install AppDomain"); var arguments = new HostArguments(args); string endpointName = null; if (arguments.EndpointName != null) { endpointName = arguments.EndpointName; } username = arguments.Username; host = new WindowsHost(Type.GetType(arguments.EndpointConfigurationType, true), args, endpointName, arguments.Install, arguments.ScannedAssemblies); }
public void ExecuteInternal(HostArguments args) { var serviceInstaller = new ServiceInstaller { ServiceName = args.ServiceName, Description = args.Description, DisplayName = args.DisplayName, }; SetStartMode(serviceInstaller, args.StartMode); var serviceProcessInstaller = new ServiceProcessInstaller { Username = args.Username, Password = args.Password, Account = args.ServiceAccount, }; var installers = new Installer[] { serviceInstaller, serviceProcessInstaller }; var arguments = String.Empty; if (!String.IsNullOrEmpty(args.Url)) { arguments += string.Format(" --url=\"{0}\"", args.Url); } using (var hostInstaller = new HostInstaller(args, arguments, installers)) using (var transactedInstaller = new TransactedInstaller()) { transactedInstaller.Installers.Add(hostInstaller); var assembly = Assembly.GetEntryAssembly(); var path = String.Format("/assemblypath={0}", assembly.Location); string[] commandLine = {path}; var context = new InstallContext(null, commandLine); transactedInstaller.Context = context; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); action(transactedInstaller); } }
public override void Execute(HostArguments args) { using (var service = new Host(args)) { service.Run(); if (!Environment.UserInteractive) { return; } Process.Start(args.Url); Console.WriteLine("Running on {0}", args.Url); Console.WriteLine("Press enter to exit"); Console.ReadLine(); } }
public Bootstrapper(ServiceBase host = null, HostArguments hostArguments = null, Configure configure = null) { // .NET default limit is 10. RavenDB in conjunction with transports that use HTTP exceeds that limit. ServicePointManager.DefaultConnectionLimit = Settings.HttpDefaultConnectionLimit; Settings.ServiceName = DetermineServiceName(host, hostArguments); ConfigureLogging(); var containerBuilder = new ContainerBuilder(); Container = containerBuilder.Build(); // Disable Auditing for the service control endpoint Configure.Features.Disable<Audit>(); Configure.Features.Enable<Sagas>(); Feature.Disable<AutoSubscribe>(); Feature.Disable<SecondLevelRetries>(); Configure.Serialization.Json(); Configure.Transactions.Advanced(t => t.DisableDistributedTransactions().DoNotWrapHandlersExecutionInATransactionScope()); Feature.EnableByDefault<StorageDrivenPublisher>(); Configure.ScaleOut(s => s.UseSingleBrokerQueue()); var transportType = DetermineTransportType(); if (configure == null) { configure = Configure .With(AllAssemblies.Except("ServiceControl.Plugin")); } bus = configure .DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t) || IsExternalContract(t)) .DefineEndpointName(Settings.ServiceName) .AutofacBuilder(Container) .UseTransport(transportType) .MessageForwardingInCaseOfFault() .DefineCriticalErrorAction((s, exception) => { if (host != null) { host.Stop(); } }) .UnicastBus() .CreateBus(); }
public EndpointType GetEndpointConfigurationType(HostArguments arguments) { Type type; if (TryGetEndpointConfigurationTypeFromConfiguration(out type)) { return new EndpointType(arguments,type); } if (TryGetEndpointConfigurationTypeFromScannedAssemblies(out type)) { return new EndpointType(arguments,type); } 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); }
bool TryGetEndpointConfigurationTypeFromArguments(HostArguments arguments, out Type type) { if (arguments.EndpointConfigurationType == null) { type = null; return false; } var endpointType = Type.GetType(arguments.EndpointConfigurationType, false); if (endpointType == null) { throw new ConfigurationErrorsException( string.Format( "Command line argument 'endpointConfigurationType' has specified to use the type '{0}' but that type could not be loaded.", arguments.EndpointConfigurationType)); } type = endpointType; return true; }
public override void Execute(HostArguments args) { if (!Environment.UserInteractive) { using (var service = new Host()) { service.Run(); } return; } using (var service = new Host()) { using (var waitHandle = new ManualResetEvent(false)) { service.OnStopping = () => { service.OnStopping = () => { }; waitHandle.Set(); }; service.Run(); Console.CancelKeyPress += (sender, e) => { service.OnStopping = () => { }; e.Cancel = true; waitHandle.Set(); }; Console.WriteLine("Press Ctrl+C to exit"); waitHandle.WaitOne(); } } }
public override void Execute(HostArguments args) { }
public abstract Task Execute(HostArguments args);
public void when_servicename_is_not_provided_via_hostargs_and_endpoint_has_no_namespace_it_should_use_the_assembly_name() { hostArguments = new HostArguments(new string[0]); Sut = new EndpointType(hostArguments, typeof (TestEndpointTypeWithoutANamespace)); Assert.AreEqual("NServiceBus.Hosting.Tests", Sut.ServiceName); }
internal MultipleHostsFoundException(HostArguments args, IHost[] hosts) : base(string.Format("Multiple hosts was found to handle arguments: \r\n{0}\r\n\r\nThe hosts are:\r\n\r\n{1}\r\n\r\nTo fix this problem you need to inspect the \"CanHandle\"-method of the hosts to find out why the criteria is met.", args, string.Join(", ", ((IEnumerable <IHost>)hosts).Select <IHost, string>((IHost x) => x.Name())))) { }
public override void Execute(HostArguments args) { ExtractApp(args); UpdateVersion(args.OutputPath); UpdateConfig(args.OutputPath, args.ServiceControlUrl); }
public override void Execute(HostArguments args) { #if !DEBUG DeleteAppJsFile(args); #endif }
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); }
public override void Execute(HostArguments args) { ExtractApp(args.OutputPath); UpdateVersion(args.OutputPath); }
public override void Execute(HostArguments args) { new DatabaseMigrationsBootstrapper().Run(new Settings(args.ServiceName)); }
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); }
public override void Execute(HostArguments args) { WindowsInstallerRunner.RunInstallers = true; WindowsInstallerRunner.RunAs = args.Username; new Bootstrapper(null, args); }
string DetermineServiceName(ServiceBase host, HostArguments hostArguments) { //if Arguments not null then bootstrapper was run from installer so use servicename passed to the installer if (hostArguments != null) { return hostArguments.ServiceName; } // Try to get HostName from Windows Service Name, default to "Particular.ServiceControl" if ((host == null) || (string.IsNullOrWhiteSpace(host.ServiceName))) { return "Particular.ServiceControl"; } return host.ServiceName; }
public override void Execute(HostArguments args) { var bootstrapper = new MaintenanceBootstrapper(); bootstrapper.Run(args); }
static void Main(string[] args) { var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } var assemblyScanner = new AssemblyScanner { ThrowExceptions = false }; var endpointTypeDeterminer = new EndpointTypeDeterminer(assemblyScanner, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); var endpointConfigurationType = endpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(arguments); assemblyScannerResults = endpointTypeDeterminer.AssemblyScannerResults; var endpointConfigurationFile = endpointConfigurationType.EndpointConfigurationFile; var endpointName = endpointConfigurationType.EndpointName; var serviceName = endpointConfigurationType.ServiceName; var endpointVersion = endpointConfigurationType.EndpointVersion; var displayName = serviceName + "-" + endpointVersion; if (arguments.SideBySide) { serviceName += "-" + endpointVersion; } //Add the endpoint name so that the new appDomain can get it if (arguments.EndpointName == null && !String.IsNullOrEmpty(endpointName)) { args = args.Concat(new[] { String.Format(@"/endpointName={0}", endpointName) }).ToArray(); } //Add the ScannedAssemblies name so that the new appDomain can get it if (arguments.ScannedAssemblies.Count == 0) { args = assemblyScannerResults.Assemblies.Select(s => s.ToString()).Aggregate(args, (current, result) => current.Concat(new[] { String.Format(@"/scannedAssemblies={0}", result) }).ToArray()); } //Add the endpointConfigurationType name so that the new appDomain can get it if (arguments.EndpointConfigurationType == null) { args = args.Concat(new[] { String.Format(@"/endpointConfigurationType={0}", endpointConfigurationType.AssemblyQualifiedName) }).ToArray(); } if (arguments.Install) { WindowsInstaller.Install(args, endpointConfigurationFile); } var cfg = RunnerConfigurator.New(x => { x.ConfigureServiceInIsolation <WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c => { c.ConfigurationFile(endpointConfigurationFile); c.WhenStarted(service => service.Start()); c.WhenStopped(service => service.Stop()); c.CommandLineArguments(args, () => SetHostServiceLocatorArgs); c.CreateServiceLocator(() => new HostServiceLocator()); }); if (arguments.Username != null && arguments.Password != null) { x.RunAs(arguments.Username, arguments.Password); } else { x.RunAsLocalSystem(); } if (arguments.StartManually) { x.DoNotStartAutomatically(); } x.SetDisplayName(arguments.DisplayName ?? displayName); x.SetServiceName(serviceName); x.SetDescription(arguments.Description ?? string.Format("NServiceBus Endpoint Host Service for {0}", displayName)); var serviceCommandLine = new List <string>(); if (!String.IsNullOrEmpty(arguments.EndpointConfigurationType)) { serviceCommandLine.Add(String.Format(@"/endpointConfigurationType:""{0}""", arguments.EndpointConfigurationType)); } if (!String.IsNullOrEmpty(endpointName)) { serviceCommandLine.Add(String.Format(@"/endpointName:""{0}""", endpointName)); } if (!String.IsNullOrEmpty(serviceName)) { serviceCommandLine.Add(String.Format(@"/serviceName:""{0}""", serviceName)); } if (!assemblyScannerResults.ErrorsThrownDuringScanning && arguments.ScannedAssemblies.Count > 0) { serviceCommandLine.AddRange(arguments.ScannedAssemblies.Select(assembly => String.Format(@"/scannedAssemblies:""{0}""", assembly))); } if (arguments.OtherArgs.Any()) { serviceCommandLine.AddRange(arguments.OtherArgs); } var commandLine = String.Join(" ", serviceCommandLine); x.SetServiceCommandLine(commandLine); if (arguments.DependsOn == null) { x.DependencyOnMsmq(); } else { foreach (var dependency in arguments.DependsOn) { x.DependsOn(dependency); } } }); try { Runner.Host(cfg, args); } catch (StateMachineException exception) { var innerException = exception.InnerException; innerException.PreserveStackTrace(); throw innerException; } }
public override void Execute(HostArguments args) { bootstrapper = new Bootstrapper(null, args); bootstrapper.Start(); }
public bool Handle(HostArguments args, HandleAsWindowsService service) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } if (!args.CommandArgs.TryGetValue(Command, out string action)) { return(false); } bool ActionIs(KeyValuePair <string, string> command) => string.Equals(command.Value, action, StringComparison.OrdinalIgnoreCase); if (ActionIs(InstallCommand)) { var configuration = new WindowsServiceConfiguration(GetServiceName(service), ExePath, ExeArgs(args)) .DisplayName(Prefix(service.DisplayName)) .Description(service.Description); args.CommandArgs.TryGetValue(ServiceStartMode, out string startMode); if (Enum.TryParse(startMode, true, out ServiceStartMode serviceStartMode)) { configuration.StartMode(serviceStartMode); } if (args.CommandArgs.TryGetValue(ServiceAccountCommand, out string account)) { if (Enum.TryParse(account, true, out ServiceAccount serviceAccount)) { configuration.RunAs(serviceAccount); } } else { args.CommandArgs.TryGetValue(ServiceAccountUsernameCommand, out string username); args.CommandArgs.TryGetValue(ServiceAccountPasswordCommand, out string password); if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { configuration.RunAsUser(username, password); } } _windowsServices.Install(configuration); } else if (ActionIs(UninstallCommand)) { _windowsServices.Uninstall(GetServiceName(service)); } else { using (var serviceBase = new CustomService(GetServiceName(service), service.OnStartFactory)) { ServiceBase.Run(serviceBase); } } return(true); }
static void Main(string[] args) { var arguments = new HostArguments(args); if (arguments.Help) { arguments.PrintUsage(); return; } var assemblyScanner = new AssemblyScanner(); //TODO: re-enable when we make message scanning lazy //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IHandleMessages<>).Assembly); //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(IConfigureThisEndpoint).Assembly); //assemblyScanner.MustReferenceAtLeastOneAssembly.Add(typeof(Program).Assembly); assemblyScannerResults = assemblyScanner.GetScannableAssemblies(); var endpointTypeDeterminer = new EndpointTypeDeterminer(assemblyScannerResults, () => ConfigurationManager.AppSettings["EndpointConfigurationType"]); var endpointConfigurationType = endpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(arguments); var endpointConfigurationFile = endpointConfigurationType.EndpointConfigurationFile; var endpointName = endpointConfigurationType.EndpointName; var serviceName = endpointConfigurationType.ServiceName; var endpointVersion = endpointConfigurationType.EndpointVersion; var displayName = serviceName + "-" + endpointVersion; if (arguments.SideBySide) { serviceName += "-" + endpointVersion; } //Add the endpoint name so that the new appDomain can get it if (arguments.EndpointName == null && !String.IsNullOrEmpty(endpointName)) { args = args.Concat(new[] { String.Format(@"/endpointName={0}", endpointName) }).ToArray(); } //Add the ScannedAssemblies name so that the new appDomain can get it if (arguments.ScannedAssemblies.Count == 0) { args = assemblyScannerResults.Assemblies.Select(s => s.ToString()).Aggregate(args, (current, result) => current.Concat(new[] { String.Format(@"/scannedAssemblies={0}", result) }).ToArray()); } //Add the endpointConfigurationType name so that the new appDomain can get it if (arguments.EndpointConfigurationType == null) { args = args.Concat(new[] { String.Format(@"/endpointConfigurationType={0}", endpointConfigurationType.AssemblyQualifiedName) }).ToArray(); } if (arguments.Install) { WindowsInstaller.Install(args, endpointConfigurationFile); } var cfg = RunnerConfigurator.New(x => { x.ConfigureServiceInIsolation<WindowsHost>(endpointConfigurationType.AssemblyQualifiedName, c => { c.ConfigurationFile(endpointConfigurationFile); c.WhenStarted(service => service.Start()); c.WhenStopped(service => service.Stop()); c.CommandLineArguments(args, () => SetHostServiceLocatorArgs); c.CreateServiceLocator(() => new HostServiceLocator()); }); if (arguments.Username != null && arguments.Password != null) { x.RunAs(arguments.Username, arguments.Password); } else { x.RunAsLocalSystem(); } if (arguments.StartManually) { x.DoNotStartAutomatically(); } x.SetDisplayName(arguments.DisplayName ?? displayName); x.SetServiceName(serviceName); x.SetDescription(arguments.Description ?? string.Format("NServiceBus Endpoint Host Service for {0}", displayName)); var serviceCommandLine = new List<string>(); if (!String.IsNullOrEmpty(arguments.EndpointConfigurationType)) { serviceCommandLine.Add(String.Format(@"/endpointConfigurationType:""{0}""", arguments.EndpointConfigurationType)); } if (!String.IsNullOrEmpty(endpointName)) { serviceCommandLine.Add(String.Format(@"/endpointName:""{0}""", endpointName)); } if (!String.IsNullOrEmpty(serviceName)) { serviceCommandLine.Add(String.Format(@"/serviceName:""{0}""", serviceName)); } if (arguments.ScannedAssemblies.Count > 0) { serviceCommandLine.AddRange(arguments.ScannedAssemblies.Select(assembly => String.Format(@"/scannedAssemblies:""{0}""", assembly))); } if (arguments.OtherArgs.Any()) { serviceCommandLine.AddRange(arguments.OtherArgs); } var commandLine = String.Join(" ", serviceCommandLine); x.SetServiceCommandLine(commandLine); if (arguments.DependsOn == null) x.DependencyOnMsmq(); else foreach (var dependency in arguments.DependsOn) x.DependsOn(dependency); }); try { Runner.Host(cfg, args); } catch (StateMachineException exception) { var innerException = exception.InnerException; innerException.PreserveStackTrace(); throw innerException; } }
public abstract void Execute(HostArguments args);
public void when_serviceName_is_not_provided_via_hostArgs_and_endpoint_has_a_namespace_it_should_use_the_namespace() { hostArguments = new HostArguments(new string[0]); EndpointType = new EndpointType(hostArguments, typeof (TestEndpointType)); Assert.AreEqual("NServiceBus.Hosting.Tests.EndpointTypeTests", EndpointType.ServiceName); }
public override void Execute(HostArguments args) { RunAndWait(args); }
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); }
public bool CanHandle(HostArguments args) { return(true); }
private static bool CommandIs(HostArguments args, string command) { return (string.Equals(args.Command, command, StringComparison.OrdinalIgnoreCase) || args.CommandArgs.Contains(command)); }
public override void Execute(HostArguments args) { new SetupBootstrapper(new Settings(args.ServiceName)).Run(args.Username); }
public void when_servicename_is_provided_via_hostargs_it_should_have_first_priority() { hostArguments = new HostArguments(new string[0]) { ServiceName = "ServiceNameFromHostArgs" }; Sut = new EndpointType(hostArguments, typeof (TestEndpointType)); Assert.AreEqual("ServiceNameFromHostArgs", Sut.ServiceName); }
protected void RunExecute(HostArguments args) { this.Resolve <IApplicationContext>().Execute(args); }
public override void Execute(HostArguments args) { WindowsInstallerRunner.RunInstallers = true; WindowsInstallerRunner.RunAs = args.Username; new Bootstrapper(); }