public void invoke_event_if_we_failed_to_start_service_during_check() { var service = Substitute.For <IApplicationService, IGuardedService>(); ((IGuardedService)service).IsRunning.Returns(false); var okService = Substitute.For <IApplicationService>(); var locator = Substitute.For <IContainer>(); locator.ResolveAll <IApplicationService>().Returns(new[] { service, okService }); var settingsRepos = Substitute.For <ISettingsRepository>(); settingsRepos.IsEnabled(Arg.Any <Type>()).Returns(true); ApplicationServiceFailedEventArgs actual = null; var sut = new ApplicationServiceManager(locator); sut.Settings = settingsRepos; sut.CheckInterval = TimeSpan.FromMilliseconds(100); sut.StartInterval = TimeSpan.FromMilliseconds(100); sut.ServiceStartFailed += (o, e) => actual = e; sut.Start(); service.When(x => x.Start()).Do(x => { throw new InvalidOperationException(); }); Thread.Sleep(200); actual.Should().NotBeNull(); actual.ApplicationService.Should().Be(service); actual.Exception.Should().BeOfType <InvalidOperationException>(); }
public void Start(IAppBuilder app) { WarmupPlugins(); _log.Debug("Starting ..."); try { _compositionRoot.Build(registrar => { LetPluginsRegisterServices(registrar); registrar.RegisterService(x => _cqsBuilder.CreateCommandBus(Container), Lifetime.Singleton); registrar.RegisterService(x => _cqsBuilder.CreateQueryBus(Container), Lifetime.Singleton); registrar.RegisterService(x => _cqsBuilder.CreateEventBus(Container), Lifetime.Singleton); // let us guard it since it runs events in the background. var service = registrar.Registrations.First(x => x.Implements(typeof(IEventBus))); service.AddService(typeof(IApplicationService)); registrar.RegisterService(x => _cqsBuilder.CreateRequestReplyBus(Container), Lifetime.Singleton); }, Startup.ConfigurationStore); BuildServices(); _appManager.Start(); _backgroundJobManager.Start(); _log.Debug("...started"); } catch (Exception exception) { _log.Error("Failed to start.", exception); throw; } }
public void Start() { _log.Debug("Starting ..."); try { _compositionRoot.Build(registrar => { registrar.RegisterService(x => _cqsBuilder.CreateCommandBus(Container), Lifetime.Singleton); registrar.RegisterService(x => _cqsBuilder.CreateQueryBus(Container), Lifetime.Singleton); registrar.RegisterService(x => _cqsBuilder.CreateEventBus(Container), Lifetime.Singleton); registrar.RegisterService(x => _cqsBuilder.CreateRequestReplyBus(Container), Lifetime.Singleton); }); BuildServices(); ConfigureDataMapper(); _appManager.Start(); _backgroundJobManager.Start(); _log.Debug("...started"); } catch (Exception exception) { _log.Error("Failed to start.", exception); throw; } }
public void stop_stänger_av_den_regelbundna_kontrollen() { var service = Substitute.For <IApplicationService, IGuardedService>(); ((IGuardedService)service).IsRunning.Returns(true); var locator = Substitute.For <IContainer>(); locator.ResolveAll <IApplicationService>().Returns(new[] { service }); var settingsRepos = Substitute.For <ISettingsRepository>(); settingsRepos.IsEnabled(Arg.Any <Type>()).Returns(true); var sut = new ApplicationServiceManager(locator); sut.Settings = settingsRepos; sut.CheckInterval = TimeSpan.FromMilliseconds(100); sut.StartInterval = TimeSpan.FromMilliseconds(100); sut.Start(); Thread.Sleep(200); sut.Stop(); service.ClearReceivedCalls(); Thread.Sleep(200); var result = ((IGuardedService)service).DidNotReceive().IsRunning; }
public void Start(StartContext context) { var adapter = new DependencyInjectionAdapter(context.ServiceProvider); _appManager = _appManager = new ApplicationServiceManager(adapter) { Settings = new ApplicationServiceManagerSettingsWithDefaultOn(_configuration) }; _appManager.ServiceFailed += OnServiceFailed; _appManager.Start(); }
public void Start(IAppBuilder app) { WarmupPlugins(); _log.Debug("Starting ..."); try { _compositionRoot.Build(registrar => { LetPluginsRegisterServices(registrar); registrar.RegisterService <IMessageBus>(x => { var queue = x.Resolve <IMessageQueueProvider>().Open("Messaging"); var bus = new SingleInstanceMessageBus(queue); return(bus); }, Lifetime.Singleton); registrar.RegisterConcrete <ScopedQueryBus>(); registrar.RegisterService(CreateMessageInvoker, Lifetime.Scoped); registrar.RegisterService(x => CreateQueueListener(x, "Messaging", "Messaging"), Lifetime.Singleton); registrar.RegisterService(x => CreateQueueListener(x, "Reports", "Messaging"), Lifetime.Singleton); registrar.RegisterService(x => CreateQueueListener(x, "Feedback", "Messaging"), Lifetime.Singleton); registrar.RegisterInstance <IMessageQueueProvider>(_queueProvider); // let us guard it since it runs events in the background. //var service = registrar.Registrations.First(x => x.Implements(typeof(IMessageBus))); //service.AddService(typeof(IApplicationService)); }, Startup.ConfigurationStore); var listeners = Container.ResolveAll <QueueListener>().ToArray(); listeners .ForEach(x => x .RunAsync(_shutdownToken.Token) .ContinueWith(OnStopped) ); BuildServices(); _appManager.Start(); _backgroundJobManager.Start(); _log.Debug("...started"); } catch (Exception exception) { _log.Error("Failed to start.", exception); throw; } }
public void start_enabled_service() { var service = Substitute.For <IApplicationService>(); var locator = Substitute.For <IContainer>(); locator.ResolveAll <IApplicationService>().Returns(new[] { service }); var settingsRepos = Substitute.For <ISettingsRepository>(); settingsRepos.IsEnabled(Arg.Any <Type>()).Returns(true); var sut = new ApplicationServiceManager(locator); sut.Settings = settingsRepos; sut.Start(); service.Received().Start(); }
public void Start_should_activate_the_check_timer() { var service = Substitute.For <IApplicationService, IGuardedService>(); var locator = Substitute.For <IContainer>(); locator.ResolveAll <IApplicationService>().Returns(new[] { service }); var settingsRepos = Substitute.For <ISettingsRepository>(); settingsRepos.IsEnabled(Arg.Any <Type>()).Returns(true); var sut = new ApplicationServiceManager(locator); sut.Settings = settingsRepos; sut.StartInterval = TimeSpan.FromMilliseconds(100); sut.Start(); service.ClearReceivedCalls(); Thread.Sleep(200); service.Received().Start(); }
private void RunDemo() { var adapter = CreateContainer(); _serviceManager = new ApplicationServiceManager(adapter); _serviceManager.ServiceFailed += OnApplicationFailure; _serviceManager.Start(); _jobManager = new BackgroundJobManager(adapter); _jobManager.JobFailed += OnJobFailed; _jobManager.Start(); //Press enter to shut down Console.ReadLine(); _jobManager.Stop(); _serviceManager.Stop(); Console.WriteLine("Done, press enter to exit"); Console.ReadLine(); }