public static ServiceConfigurator <T> OwinEndpoint <T>(this ServiceConfigurator <T> configurator, Action <WebAppConfigurator> appConfigurator = null) where T : class
        {
            var config = new WebAppConfigurator();

            appConfigurator?.Invoke(config);

            configurator.BeforeStartingService(t => config.Start());
            configurator.WhenShutdown((t, c) => config.Stop());

            return(configurator);
        }
Example #2
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 static ServiceConfigurator <T> WhenShutdown <T>(this ServiceConfigurator <T> configurator,
                                                               Action <T> callback)
            where T : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException("configurator");
            }

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

            return(configurator);
        }
Example #4
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());
                });
            }));
        }