Пример #1
0
                public TopshelfExitCode Run()
                {
                    var exitCode = _stopAndUninstallHost.Run();

                    if (exitCode == TopshelfExitCode.Ok)
                    {
                        exitCode = _installAndStartHost.Run();
                    }

                    return(exitCode);
                }
Пример #2
0
        public override void Run()
        {
            _log.Debug("[Topshelf] Starting up as an Azure Worker role");

            _host = HostFactory.New(x =>
            {
                Configure(x);

                x.UseHostBuilder((environment, settings) => new Builder(this, environment, settings));
            });

            _host.Run();
        }
Пример #3
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();
        }
Пример #4
0
                public TopshelfExitCode Run()
                {
                    var exitCode = _stopHost.Run();

                    if (exitCode == TopshelfExitCode.ServiceNotInstalled)
                    {
                        return(TopshelfExitCode.Ok);
                    }

                    if (exitCode == TopshelfExitCode.StopServiceFailed)
                    {
                        Process.GetProcessById(_processId).Kill();
                        exitCode = TopshelfExitCode.Ok;
                    }

                    if (exitCode == TopshelfExitCode.Ok)
                    {
                        exitCode = _uninstallHost.Run();
                    }

                    return(exitCode);
                }