예제 #1
0
        private void Configure(HostConfigurator hostOptions)
        {
            hostOptions.SetDescription("PickleJar.ServiceHost.Description");
            hostOptions.SetDisplayName("PickleJar.ServiceHost.DisplayName");
            hostOptions.SetServiceName("PickleJar.ServiceHost.ServiceName");

            hostOptions.Service <AppRootService>(ConfigureService);

            hostOptions.EnablePauseAndContinue();
            hostOptions.EnableShutdown();

            hostOptions.DependsOnEventLog();
            hostOptions.RunAsNetworkService();
            hostOptions.StartAutomaticallyDelayed();

            hostOptions.UseSerilog();

            hostOptions.OnException(SetupLogging.LogException);
            hostOptions.AfterInstall(SetupLogging.AfterInstall);
            hostOptions.BeforeUninstall(SetupLogging.BeforeUninstall);
        }
예제 #2
0
        public static void ConfigureTownCrierService(this HostConfigurator config, Func <ITownCrier> townCrierFactory)
        {
            config.EnableServiceRecovery(rc =>
            {
                rc.RestartService(1);
                rc.SetResetPeriod(7);
            });

            config.EnablePauseAndContinue();
            config.EnableShutdown();

            config.Service <ITownCrier>(s =>
            {
                s.ConstructUsing(name => townCrierFactory());
                s.WhenStarted(tc =>
                {
                    Log.Information("Starting...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged += OnPowerChange;
                    tc.Start();
                });
                s.WhenStopped(tc =>
                {
                    Log.Information("Stopping...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });
                s.WhenPaused(tc =>
                {
                    Log.Information("Pausing...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });

                s.WhenContinued(tc =>
                {
                    Log.Information("Continuing...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged += OnPowerChange;
                    tc.Start();
                });

                s.WhenShutdown(tc =>
                {
                    Log.Information("Shutting down...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });

                s.WhenPowerEvent((service, args) =>
                {
                    Log.Information($"PowerEvent ({args.EventCode})");
                    return(false);
                });
            });

            config.RunAsLocalSystem();
            config.StartAutomatically();
        }
 public void WhenPaused(Func <T, HostControl, bool> pause)
 {
     _configurator.EnablePauseAndContinue();
     _pause = pause;
 }