Esempio n. 1
0
 public static void Host(IRunConfiguration configuration, params string[] args)
 {
     _log.Info("Starting Host");
     _log.DebugFormat("Arguments: {0}", string.Join(",", args));
     var a = Parser.ParseArgs(args);
     if (a.InstanceName != null) configuration.WinServiceSettings.DisplayName = a.InstanceName;
     NamedAction actionKey = Parser.GetActionKey(a, configuration.DefaultAction);
     IAction action = _actions[actionKey];
     _log.DebugFormat("Running action: {0}", action);
     action.Do(configuration);
 }
Esempio n. 2
0
        }          /// <summary>         /// Go go gadget         /// </summary>

        public static void Host(IRunConfiguration configuration, params string[] args)

        {
            _log.Info("Starting Host");
            _log.DebugFormat("Arguments: {0}", string.Join(",", args));
            var a = Parser.ParseArgs(args);

            if (a.InstanceName != null)
            {
                configuration.WinServiceSettings.DisplayName = a.InstanceName;
            }
            NamedAction actionKey = Parser.GetActionKey(a, configuration.DefaultAction);
            IAction     action    = _actions[actionKey];

            _log.DebugFormat("Running action: {0}", action);
            action.Do(configuration);
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("server.log4net.xml"));
            _log.Info("Server Loading");

            IRunConfiguration cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("SampleService");
                c.SetServiceName("Sample Service");
                c.SetServiceName("Something");
                c.DependencyOnMsmq();

                c.RunAsLocalSystem();

                c.ConfigureService <PasswordUpdateService>(typeof(PasswordUpdateService).Name, s =>
                {
                    s.WhenStarted(o =>
                    {
                        IServiceBus bus = ServiceBusConfigurator.New(x =>
                        {
                            x.ReceiveFrom("msmq://localhost/mt_server");
                            x.ConfigureService <SubscriptionClientConfigurator>(b => { b.SetSubscriptionServiceEndpoint("msmq://localhost/mt_subscriptions"); });
                        });
                        o.Start(bus);
                    });
                    s.WhenStopped(o => o.Stop());
                    s.CreateServiceLocator(() =>
                    {
                        var container = new DefaultMassTransitContainer();
                        IEndpointFactory endpointFactory = EndpointFactoryConfigurator
                                                           .New(x =>
                        {
                            x.SetObjectBuilder(ServiceLocator.Current.GetInstance <IObjectBuilder>());
                            x.RegisterTransport <MsmqEndpoint>();
                        });
                        container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);
                        container.AddComponent <PasswordUpdateService>(typeof(PasswordUpdateService).Name);
                        return(ServiceLocator.Current);                                                //set in DefaultMTContainer
                    });
                });
            });

            Runner.Host(cfg, args);
        }
Esempio n. 4
0
        public void ConfigureService <T>(string[] args) where T : class, IServiceInterface
        {
            IRunConfiguration cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName(ServiceName);
                c.SetDisplayName(DisplayName);
                c.SetDescription(Description);

                c.RunAsLocalSystem();
                c.DependencyOnMsmq();

                c.ConfigureService <T>(typeof(T).Name, s =>
                {
                    MsmqEndpointConfigurator.Defaults(def => def.CreateMissingQueues = true);
                    s.CreateServiceLocator(() =>
                    {
                        Container container = new Container(x =>
                        {
                            x.AddRegistry(new IocRegistry(SourceQueue, SubscriptionQueue));

                            ContainerSetup(x);
                        });

                        IServiceLocator objectBuilder = new StructureMapObjectBuilder(container);
                        ServiceLocator.SetLocatorProvider(() => objectBuilder);
                        return(objectBuilder);
                    });

                    s.WhenStarted(start => start.Start());
                    s.WhenStopped(stop => stop.Stop());
                });
            });

            ObjectFactory.AssertConfigurationIsValid();

            Runner.Host(cfg, args);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var arguments = new HostArguments(args);

            if (arguments.Help)
            {
                arguments.PrintUsage();
                return;
            }

            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);
            }

            IRunConfiguration 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;
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }