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.
Prowlarr/NzbDrone.Host/ApplicationServer.cs

90 lines
3.0 KiB

using System;
using System.ServiceProcess;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
12 years ago
using NzbDrone.Host.AccessControl;
using NzbDrone.Host.Owin;
namespace NzbDrone.Host
{
12 years ago
public interface INzbDroneServiceFactory
{
12 years ago
ServiceBase Build();
void Start();
}
12 years ago
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IRuntimeInfo _runtimeInfo;
private readonly IHostController _hostController;
private readonly IProcessProvider _processProvider;
12 years ago
private readonly PriorityMonitor _priorityMonitor;
private readonly IStartupArguments _startupArguments;
private readonly IFirewallAdapter _firewallAdapter;
private readonly IUrlAclAdapter _urlAclAdapter;
12 years ago
private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo,
IProcessProvider processProvider, PriorityMonitor priorityMonitor, IStartupArguments startupArguments,
IFirewallAdapter firewallAdapter, IUrlAclAdapter urlAclAdapter, Logger logger)
{
_configFileProvider = configFileProvider;
_hostController = hostController;
_runtimeInfo = runtimeInfo;
_processProvider = processProvider;
12 years ago
_priorityMonitor = priorityMonitor;
_startupArguments = startupArguments;
_firewallAdapter = firewallAdapter;
_urlAclAdapter = urlAclAdapter;
12 years ago
_logger = logger;
}
protected override void OnStart(string[] args)
{
Start();
}
12 years ago
public void Start()
{
if (OsInfo.IsWindows && _runtimeInfo.IsAdmin)
{
_urlAclAdapter.RefreshRegistration();
_firewallAdapter.MakeAccessible();
}
_hostController.StartServer();
if (!_startupArguments.Flags.Contains(StartupArguments.NO_BROWSER) &&
_runtimeInfo.IsUserInteractive &&
_configFileProvider.LaunchBrowser)
{
try
{
12 years ago
_logger.Info("Starting default browser. {0}", _hostController.AppUrl);
_processProvider.OpenDefaultBrowser(_hostController.AppUrl);
}
catch (Exception e)
{
12 years ago
_logger.ErrorException("Failed to open URL in default browser.", e);
}
}
12 years ago
_priorityMonitor.Start();
}
protected override void OnStop()
{
12 years ago
_logger.Info("Attempting to stop application.");
_hostController.StopServer();
12 years ago
_logger.Info("Application has finished stop routine.");
}
public ServiceBase Build()
{
return this;
}
}
12 years ago
}