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); }
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 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 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 ConfigureService(ServiceConfigurator <IService> configurator) { configurator.ConstructUsing(BuildService); configurator.WhenStarted((service, control) => service.OnStart(control)); configurator.WhenStopped((service, control) => service.OnStop(control)); }
public static void WhenStartedAsLeader <T>( this ServiceConfigurator <T> configurator, Action <LeaderConfigurationBuilder <T> > builder) where T : class { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } LeaderConfiguration <T> leaderConfiguration = null; configurator.BeforeStoppingService(async() => { try { leaderConfiguration?.ServiceIsStopping.Cancel(); } catch (TaskCanceledException) { } if (leaderConfiguration != null) { await leaderConfiguration.LeaseManager.ReleaseLease(leaderConfiguration.NodeId); } }); configurator.WhenStarted(async service => { if (leaderConfiguration == null) { var configurationBuilder = new LeaderConfigurationBuilder <T>(); builder(configurationBuilder); if (!configurationBuilder.ServiceStoppingTokenIsSet) { var serviceStoppingTokenSource = new CancellationTokenSource(); configurationBuilder.WhenStopping(serviceStoppingTokenSource); } leaderConfiguration = configurationBuilder.Build(); } try { var worker = new Runner <T>(service, leaderConfiguration); await worker.Start(); } catch (TaskCanceledException) { // TaskCanceledException bubbles up if the service stopping cancellation token is set // so we swallow the exception so that the Topshelf OnException handler doesn't see it } }); }
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() }
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); }
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); }
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(); }
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); }
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()); }
public static ServiceConfigurator <T> WhenStarted <T>(this ServiceConfigurator <T> configurator, Action <T> callback) where T : class { if (configurator == null) { throw new ArgumentNullException("configurator"); } configurator.WhenStarted((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()); }
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); }
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); }); }
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 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(); }); }
private static void ConfigureService(ServiceConfigurator <ShutdownService> s) { s.ConstructUsing(t => new ShutdownService()); s.WhenStarted(t => t.Start()); s.WhenStopped(async t => await t.Stop()); }
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); }
public void WhenStarted(Action <TService> startAction) { _configurator.WhenStarted(startAction); }
private static void ConfigureService(ServiceConfigurator <BackupService> sc) { sc.ConstructUsing(() => new BackupService()); sc.WhenStarted(s => s.Start()); sc.WhenStopped(s => s.Stop()); }
private static void ConfigureService(ServiceConfigurator <WindowsService> serviceConfigurator) { serviceConfigurator.ConstructUsing(() => new WindowsService()); serviceConfigurator.WhenStarted(service => service.OnStart()); serviceConfigurator.WhenStopped(service => service.OnStop()); }