You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/src/NzbDrone.Host/ApplicationServer.cs

84 lines
2.5 KiB

using System.ServiceProcess;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Host.Owin;
namespace NzbDrone.Host
{
12 years ago
public interface INzbDroneServiceFactory
{
12 years ago
ServiceBase Build();
void Start();
}
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory, IHandle<ApplicationShutdownRequested>
12 years ago
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IRuntimeInfo _runtimeInfo;
private readonly IHostController _hostController;
12 years ago
private readonly PriorityMonitor _priorityMonitor;
private readonly IStartupContext _startupContext;
private readonly IBrowserService _browserService;
12 years ago
private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController,
IRuntimeInfo runtimeInfo, PriorityMonitor priorityMonitor, IStartupContext startupContext, IBrowserService browserService, Logger logger)
{
_configFileProvider = configFileProvider;
_hostController = hostController;
_runtimeInfo = runtimeInfo;
12 years ago
_priorityMonitor = priorityMonitor;
_startupContext = startupContext;
_browserService = browserService;
12 years ago
_logger = logger;
}
protected override void OnStart(string[] args)
{
Start();
}
12 years ago
public void Start()
{
_runtimeInfo.IsRunning = true;
_hostController.StartServer();
if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER)
&& _configFileProvider.LaunchBrowser)
{
_browserService.LaunchWebUI();
}
12 years ago
_priorityMonitor.Start();
}
protected override void OnStop()
{
Shutdown();
}
public ServiceBase Build()
{
return this;
}
private void Shutdown()
{
12 years ago
_logger.Info("Attempting to stop application.");
_hostController.StopServer();
12 years ago
_logger.Info("Application has finished stop routine.");
_runtimeInfo.IsRunning = false;
12 years ago
}
public void Handle(ApplicationShutdownRequested message)
12 years ago
{
if (!_runtimeInfo.IsWindowsService && !message.Restarting)
{
Shutdown();
}
}
}
}