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 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;
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        private void BuildServices()
        {
            _appManager = new ApplicationServiceManager(CompositionRoot.Container)
            {
                Settings = new ApplicationServiceManagerSettingsWithDefaultOn()
            };
            _appManager.ServiceFailed += OnServiceFailed;

            _backgroundJobManager                 = new BackgroundJobManager(CompositionRoot.Container);
            _backgroundJobManager.JobFailed      += OnJobFailed;
            _backgroundJobManager.StartInterval   = TimeSpan.FromSeconds(Debugger.IsAttached ? 0 : 10);
            _backgroundJobManager.ExecuteInterval = TimeSpan.FromMinutes(5);

            _backgroundJobManager.ScopeClosing += OnScopeClosing;
        }
        public void start_not_running_service_during_service_check()
        {
            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.CheckServices();

            service.Received().Start();
        }
        public void do_not_start_disabled_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(false);

            var sut = new ApplicationServiceManager(locator);

            sut.Settings = settingsRepos;
            sut.Start();

            service.DidNotReceive().Start();
        }
        public void do_not_stop_running_service_if_its_enabled()
        {
            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);
            ((IGuardedService)service).IsRunning.Returns(true);

            var sut = new ApplicationServiceManager(locator);

            sut.Settings = settingsRepos;
            sut.CheckServices();

            service.DidNotReceive().Stop();
        }
Ejemplo n.º 8
0
        private void BuildServices()
        {
            _appManager = new ApplicationServiceManager(CompositionRoot.Container);
            _appManager.ServiceFailed += OnServiceFailed;

            _backgroundJobManager            = new BackgroundJobManager(CompositionRoot.Container);
            _backgroundJobManager.JobFailed += OnJobFailed;
            if (Debugger.IsAttached)
            {
                _backgroundJobManager.StartInterval = TimeSpan.FromSeconds(0);
            }
            else
            {
                _backgroundJobManager.StartInterval = TimeSpan.FromSeconds(10);
            }
            _backgroundJobManager.ExecuteInterval = TimeSpan.FromMinutes(5);

            _backgroundJobManager.ScopeClosing += OnScopeClosing;
        }
        public void collect_errors_during_shutdown_and_allow_OK_services_to_shutdown_successfully()
        {
            var service = Substitute.For <IApplicationService, IGuardedService>();

            ((IGuardedService)service).IsRunning.Returns(true);
            service.When(x => x.Stop()).Do(x => { throw new NotSupportedException(); });
            var okService = Substitute.For <IApplicationService>();
            var locator   = Substitute.For <IContainer>();

            locator.ResolveAll <IApplicationService>().Returns(new[] { service, okService });
            var settingsRepos = Substitute.For <ISettingsRepository>();

            var sut = new ApplicationServiceManager(locator);

            sut.Settings = settingsRepos;
            Action actual = sut.Stop;

            actual.ShouldThrow <AggregateException>();
            okService.Received().Stop();
        }
        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();
        }
        public void all_exceptions_during_Start_should_be_collected_before_throwing_failure()
        {
            var service       = Substitute.For <IApplicationService>();
            var service2      = Substitute.For <IApplicationService>();
            var okService     = Substitute.For <IApplicationService>();
            var locator       = Substitute.For <IContainer>();
            var settingsRepos = Substitute.For <ISettingsRepository>();

            service.When(x => x.Start()).Do(x => { throw new NotSupportedException(); });
            service2.When(x => x.Start()).Do(x => { throw new NotImplementedException(); });
            locator.ResolveAll <IApplicationService>().Returns(new[] { service, okService, service2 });
            settingsRepos.IsEnabled(Arg.Any <Type>()).Returns(true);

            var sut = new ApplicationServiceManager(locator);

            sut.Settings = settingsRepos;
            Action actual = sut.Start;

            actual.ShouldThrow <AggregateException>().And.InnerExceptions.Count.Should().Be(2);
            okService.Received().Start();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
 private static void ConfigureApplicationServices(ApplicationServiceManager serviceManager)
 {
     serviceManager.AddService <IMessageDispatcher>();
     serviceManager.AddService <DebugPort>(isRequiredService: false);
 }
 private static void RemoteMessageDispatcherInitialization(ApplicationServiceManager serviceManager)
 {
     serviceManager.AddService <IRemoteMessageDispatcher>(isRequiredService: true);
 }
Ejemplo n.º 15
0
 private static void ConfigureApplicationServices(ApplicationServiceManager serviceManager)
 {
     serviceManager.AddService <IMessageDispatcher>();
     serviceManager.AddService <DebugConnection>();
 }
Ejemplo n.º 16
0
 private static void ConfigureApplicationServices(ApplicationServiceManager serviceManager)
 {
     serviceManager.AddService <IMessageDispatcher>();
     serviceManager.AddService <IInstallationSetManager>(InitializeInstallationSetManagerAsync);
 }