Example #1
0
        public static void ServiceConfiguration()
        {
            Topshelf.Host host = HostFactory.New(svcHost =>
            {
                log.Debug("Enter the host factory");
                svcHost.EnablePauseAndContinue();
                svcHost.EnableShutdown();
                svcHost.StartAutomatically();
                svcHost.SetDescription("A test harness designed to provide N messages to a queue and consume them.");
                svcHost.SetDisplayName("Data Services Rabbit Test Harness");
                svcHost.SetServiceName("DataServicesRabbitTestHarness");
                svcHost.RunAs(ConfigurationManager.AppSettings["rmq.SvcUser"], ConfigurationManager.AppSettings["rmq.SvcPassword"]);

                svcHost.Service <Emitter>(svc =>
                {
                    log.Debug("Enter the Windows service constructor");
                    svc.ConstructUsing(() => new Emitter());

                    svc.WhenStarted(tsvc =>
                    {
                        log.Debug("Start Rabbit test service");
                        tsvc.Start();
                        tsvc.EmitMsg();
                    });

                    svc.WhenStopped(tsvc =>
                    {
                        log.Debug("Stopping Rabbit test service");
                        tsvc.Stop();
                        log.Debug("Stopped Rabbit test service");
                    });

                    svc.WhenPaused(tsvc => tsvc.Pause());

                    svc.WhenContinued(tsvc =>
                    {
                        tsvc.Continue();
                    });

                    svc.WhenShutdown(tsvc =>
                    {
                        Consumer.ReceiveMsg();
                        Thread.Sleep(100);
                        tsvc.Stop();
                    });
                });
            });
            host.Run();
        }
        public WindowsServiceWorkerHost(IDependencyResolver dependencyResolver,
                                        Action<HostConfigurator> serviceConfigurator)
            : base(dependencyResolver)
        {
            if (serviceConfigurator == null)
                throw new ArgumentNullException("serviceConfigurator");

            host = HostFactory.New(x =>
            {
                x.Service<IWorker>(y =>
                {
                    y.ConstructUsing(z => Worker);
                    y.WhenStarted(z => z.Start());
                    y.WhenStopped(z => z.Stop());
                });

                serviceConfigurator(x);
            });
        }
Example #3
0
 public UpdateHost(Topshelf.Host stopAndUninstallHost, Topshelf.Host installAndStartHost)
 {
     _stopAndUninstallHost = stopAndUninstallHost;
     _installAndStartHost  = installAndStartHost;
 }
Example #4
0
 public StopAndUninstallHost(Topshelf.Host stopHost, Topshelf.Host uninstallHost, int processId)
 {
     _stopHost      = stopHost;
     _uninstallHost = uninstallHost;
     _processId     = processId;
 }