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); } } }
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(); }
public static ServiceConfigurator <T> WhenPaused <T>(this ServiceConfigurator <T> configurator, Action <T> callback) where T : class { if (configurator == null) { throw new ArgumentNullException("configurator"); } configurator.WhenPaused((service, control) => { callback(service); return(true); }); return(configurator); }
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 WhenPaused(Action <TService> pauseAction) { _configurator.WhenPaused(pauseAction); }