Exemple #1
0
 private static void Callback(ServiceConfigurator <MyActorService> actorService)
 {
     actorService.ConstructUsing(n => new MyActorService());
     actorService.WhenStarted(service => service.Start());
     actorService.WhenStopped(service => service.Stop());
     //continue and restart directives are also available
 }
        public void EstablishContext()
        {
            using (var startEvent = new ManualResetEvent(false))
            {
                _srv = new TestService();

                _channelAdaptor = new ChannelAdapter();
                _hostChannel = WellknownAddresses.GetServiceCoordinatorHost(_channelAdaptor);

                using (_channelAdaptor.Connect(config => config.AddConsumerOf<ServiceStarted>().UsingConsumer(msg => startEvent.Set())))
                {

                    ServiceConfigurator<TestService> c = new ServiceConfigurator<TestService>();
                    c.WhenStarted(s => s.Start());
                    c.WhenStopped(s => s.Stop());
                    c.WhenPaused(s => { _wasPaused = true; });
                    c.WhenContinued(s => { _wasContinued = true; });
                    c.HowToBuildService(name => _srv);

                    _serviceController = c.Create(WellknownAddresses.GetServiceCoordinatorProxy());
                    _serviceController.Start();

                    startEvent.WaitOne(5.Seconds());

                    _serviceController.State.ShouldEqual(ServiceState.Started);
                }
            }
        }
Exemple #3
0
        static int Main(string[] args)
        {
            try {
                var exitCode = HostFactory.Run(c =>
                {
                    c.Service <DummyRigService>(service =>
                    {
                        ServiceConfigurator <DummyRigService> s = service;
                        s.ConstructUsing(() => new DummyRigService());
                        s.WhenStarted(a => a.Start());
                        s.WhenStopped(a => a.Stop());
                    });
                    c.SetServiceName("DummyRigHamBus");
                    c.SetDisplayName("DummyRig HamBus server");
                    c.SetDescription("Web server for DummyRig and hambus");
                });
                return((int)exitCode);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);

                    Console.WriteLine("\n\nCould not open COM object! Exiting");


                    return(-1);
                }
            }
            return(0);
        }
Exemple #4
0
        public static int Main(string[] args)
        {
            {
                var exitCode = HostFactory.Run(c =>
                {
                    c.Service <Service>(service =>
                    {
                        c.SetServiceName(ServiceName);
                        c.SetDisplayName(DisplayName);
                        c.SetDescription(ServiceDescription);

                        c.EnablePauseAndContinue();
                        c.EnableShutdown();

                        c.StartAutomatically();
                        c.RunAsLocalSystem();

                        ServiceConfigurator <Service> s = service;
                        s.ConstructUsing(() => new Service());
                        s.WhenStarted(a => a.Start());
                        s.WhenStopped(a => a.Stop());
                    });
                });
                return((int)exitCode);
            }
        }
        public void ConfigureService(ServiceConfigurator <IService> configurator)
        {
            configurator.ConstructUsing(BuildService);

            configurator.WhenStarted((service, control) => service.OnStart(control));

            configurator.WhenStopped((service, control) => service.OnStop(control));
        }
Exemple #6
0
        private static void ConfigureServiceClass(ServiceConfigurator <WindowsService> svc)
        {
            svc.ConstructUsing(name => new WindowsService());
            svc.WhenStarted(es => es.Start());
            svc.WhenStopped(es => es.Stop());

            // use this later if/when needed
            // svc.WhenCustomCommandReceived()
        }
        private static void ConfigureServiceClass(ServiceConfigurator<WindowsService> svc)
        {
            svc.ConstructUsing(name => new WindowsService());
            svc.WhenStarted(es => es.Start());
            svc.WhenStopped(es => es.Stop());

            // use this later if/when needed
            // svc.WhenCustomCommandReceived()
        }
        private static void UseStartup <TStartup>(ServiceConfigurator <IBusHost> configurator)
            where TStartup : Startup, new()
        {
            var startup = new TStartup();

            configurator.ConstructUsing(settings => startup.BuildHost(settings));

            configurator.WhenStarted(startup.OnStart);

            configurator.WhenStopped(startup.OnStop);
        }
Exemple #9
0
        public static ServiceConfigurator <T> ConstructUsingStructureMap <T>(this ServiceConfigurator <T> configurator) where T : class
        {
            if (typeof(T).GetInterfaces()?.Length > 0 && typeof(ServiceControl).IsAssignableFrom(typeof(T)))
            {
                configurator.WhenStarted((service, control) => ((ServiceControl)service).Start(control));
                configurator.WhenStopped((service, control) => ((ServiceControl)service).Stop(control));
            }

            configurator.ConstructUsing(GetFactory <T>());
            return(configurator);
        }
Exemple #10
0
        private void ConfigureService(ServiceConfigurator <AppRootService> serviceOptions)
        {
            serviceOptions.ConstructUsing(name => new AppRootService());

            serviceOptions.WhenStarted(tc => tc.Start());
            serviceOptions.WhenStopped(tc => tc.Stop());

            serviceOptions.WhenPaused(tc => tc.Pause());
            serviceOptions.WhenContinued(tc => tc.Continue());

            serviceOptions.WhenShutdown(tc => tc.Shutdown());
        }
        public void EstablishContext()
        {
            _srv = new TestService();

            ServiceConfigurator<TestService> c = new ServiceConfigurator<TestService>();
            c.WhenStarted(s => s.Start());
            c.WhenStopped(s => s.Stop());
            c.WhenPaused(s => { _wasPaused = true; });
            c.WhenContinued(s => { _wasContinued = true; });
            c.HowToBuildService((name)=> _srv);
            _serviceController = c.Create();
            _serviceController.Start();
        }
Exemple #12
0
        static int Main(string[] args)
        {
            var exitCode = HostFactory.Run(c =>
            {
                c.Service <Service>(service =>
                {
                    ServiceConfigurator <Service> s = service;
                    s.ConstructUsing(() => new Service());
                    s.WhenStarted(a => a.Start());
                    s.WhenStopped(a => a.Stop());
                });
            });

            return((int)exitCode);
        }
        public static ServiceConfigurator <T> WhenStopped <T>(this ServiceConfigurator <T> configurator, Action <T> callback)
            where T : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException("configurator");
            }

            configurator.WhenStopped((service, control) =>
            {
                callback(service);

                return(true);
            });

            return(configurator);
        }
        private static void Setup(ServiceConfigurator<SubscriptionConfigurationService> serviceConfig)
        {
            var container = new ContainerBuilder()
            .RegisterServiceBus()
            .RegisterObservers(typeof(Program).Assembly)
            .Build();

            var resolver = new Resolver(container.ResolveNamed, container.Resolve);

            serviceConfig.ConstructUsing(
                s =>
                new SubscriptionConfigurationService(resolver,
                 map => map.ListenTo<SimpleMessage>().Using<SimpleHandler>().WithConfiguration(new SubscriptionConfiguration("Test_1"))
                    ));
            serviceConfig.WhenStarted(service => service.Start());
            serviceConfig.WhenStopped(service => service.Stop());
        }
Exemple #15
0
        private static void Setup(ServiceConfigurator <SubscriptionConfigurationService> serviceConfig)
        {
            var container = new ContainerBuilder()
                            .RegisterServiceBus()
                            .RegisterObservers(typeof(Program).Assembly)
                            .Build();

            var resolver = new Resolver(container.ResolveNamed, container.Resolve);

            serviceConfig.ConstructUsing(
                s =>
                new SubscriptionConfigurationService(resolver,
                                                     map => map.ListenTo <SimpleMessage>().Using <SimpleHandler>().WithConfiguration(new SubscriptionConfiguration("Test_1"))
                                                     ));
            serviceConfig.WhenStarted(service => service.Start());
            serviceConfig.WhenStopped(service => service.Stop());
        }
Exemple #16
0
        public static ServiceConfigurator <T> ConstructUsingStructureMap <T>(this ServiceConfigurator <T> configurator) where T : class
        {
            var hasInterfaces = typeof(T).GetInterfaces()?.Length > 0;

            if (hasInterfaces && IsAssignable <ServiceControl, T>())
            {
                configurator.WhenStarted((service, control) => ((ServiceControl)service).Start(control));
                configurator.WhenStopped((service, control) => ((ServiceControl)service).Stop(control));
            }

            if (hasInterfaces && IsAssignable <ServiceSessionChange, T>())
            {
                configurator.WhenSessionChanged((service, control, args) => ((ServiceSessionChange)service).SessionChange(control, args));
            }

            configurator.ConstructUsing(GetFactory <T>());
            return(configurator);
        }
Exemple #17
0
        static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                string instanceName = System.Configuration.ConfigurationManager.AppSettings["WindowsServiceName"];

                x.Service <HangFireService>(s =>
                {
                    ServiceConfigurator <HangFireService> s1 = s as ServiceConfigurator <HangFireService>;
                    s1.ConstructUsing(name => new HangFireService());
                    s1.WhenStarted(tc => tc.Start());
                    s1.WhenStopped(tc => tc.Stop());
                });

                //x.RunAsLocalService();
                x.RunAsLocalSystem();
                x.SetServiceName(instanceName);
                x.SetDisplayName(instanceName);
                x.SetDescription(instanceName);
            });
        }
Exemple #18
0
        public virtual int Run()
        {
            return((int)HostFactory.Run(config =>
            {
                config.UseLog4Net();

                if (_configuration.ServiceName == null)
                {
                    _configuration.ServiceName = _defaultConfiguration.ServiceName;
                }
                if (_configuration.ServiceDisplayName == null)
                {
                    _configuration.ServiceDisplayName = _defaultConfiguration.ServiceDisplayName;
                }
                if (_configuration.ServiceInstanceName == null)
                {
                    _configuration.ServiceInstanceName = _defaultConfiguration.ServiceInstanceName;
                }
                if (_configuration.ServiceDescription == null)
                {
                    _configuration.ServiceDescription = _defaultConfiguration.ServiceDescription;
                }

                config.SetServiceName(_configuration.ServiceName);
                config.SetDisplayName(_configuration.ServiceDisplayName);
                config.SetInstanceName(_configuration.ServiceInstanceName);
                config.SetDescription(_configuration.ServiceDescription);

                config.Service <HostedService>(service =>
                {
                    ServiceConfigurator <HostedService> hostedService = service;
                    hostedService.ConstructUsing(() => HostedService.Create(_configuration));
                    hostedService.WhenStarted((s, hostControl) => s.Start(hostControl).Result);
                    hostedService.WhenStopped(s => s.Stopped());
                    hostedService.WhenPaused(s => s.Paused());
                    hostedService.WhenContinued(s => s.Continued());
                    hostedService.WhenShutdown(s => s.Shutdown());
                });
            }));
        }
        public void Should_work()
        {
            var c = new ServiceConfigurator<TestService>();
            c.WhenStarted(s => s.Start());
            c.WhenStopped(s => s.Stop());

            using (IServiceController service = c.Create(WellknownAddresses.GetServiceCoordinatorProxy()))
            {
                service.Start();

                service.State
                    .ShouldEqual(ServiceState.Started);
            }
        }
 private static void ConfigureService(ServiceConfigurator<BackupService> sc)
 {
     sc.ConstructUsing(() => new BackupService());
     sc.WhenStarted(s => s.Start());
     sc.WhenStopped(s => s.Stop());
 }
        public void Should_work()
        {
            var c = new ServiceConfigurator<TestService>();
            c.WhenStarted(s => s.Start());
            c.WhenStopped(s => s.Stop());

            IServiceController service = c.Create();
            service.Start();

            service.State
                .ShouldEqual(ServiceState.Started);
        }
 private static void ConfigureService(ServiceConfigurator <BackupService> sc)
 {
     sc.ConstructUsing(() => new BackupService());
     sc.WhenStarted(s => s.Start());
     sc.WhenStopped(s => s.Stop());
 }
Exemple #23
0
 private static void ConfigureService(ServiceConfigurator <WindowsService> serviceConfigurator)
 {
     serviceConfigurator.ConstructUsing(() => new WindowsService());
     serviceConfigurator.WhenStarted(service => service.OnStart());
     serviceConfigurator.WhenStopped(service => service.OnStop());
 }
Exemple #24
0
 private static void ConfigureService(ServiceConfigurator <ShutdownService> s)
 {
     s.ConstructUsing(t => new ShutdownService());
     s.WhenStarted(t => t.Start());
     s.WhenStopped(async t => await t.Stop());
 }
Exemple #25
0
 public void WhenStopped(Action <TService> stopAction)
 {
     _configurator.WhenStopped(stopAction);
 }
Exemple #26
0
        public static void Configuration(ServiceConfigurator <ValidationService> config)
        {
            IKernel kernel = null;

            IDisposable webapiApp = null;

            config.ConstructUsing(() =>
            {
                return(new ValidationService());
            });

            config.BeforeStartingService(h =>
            {
                h.RequestAdditionalTime(ServerSettings.AdditionalStartupTime);

                kernel = ConfigModule.GetKernel();

                log.Info("{0} Service Started", ServiceName);
            });

            config.WhenStarted(s =>
            {
                //configuration for hangfire server.
                //tells it to use in memory storage instead of having to have a SQL backend
                Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();

                // tells hangfire which IoC to use when newing up jobs.
                Hangfire.GlobalConfiguration.Configuration.UseNinjectActivator(kernel);

                RunValidationServer(kernel);

                webapiApp = WebApp.Start(ServerSettings.WebAPIUrl, builder =>
                {
                    kernel.Get <ValidationService>().Configuration(builder);
                });
            });

            config.AfterStartingService(() =>
            {
#if DEBUG
#endif
            });

            config.WhenStopped(s =>
            {
                if (kernel != null)
                {
                    var busCleanup = kernel.Get <IBusCleanup>();
                    busCleanup.StopAllBuses();

                    log.Info("{0} Service Stopped - bus cleanup and kernel disposed", ServiceName);
                }

                //In theory, IBusCleanup should allow notifications to be sent before an app closes down.
                //However, in this case more time was required.
                //TODO - verify not needed System.Threading.Thread.Sleep(500);

                log.Info("{0} Service Stopped", ServiceName);

                webapiApp.Dispose();

                kernel.Dispose();
            });
        }