better routing.

pull/6/head
kay.one 12 years ago
parent 3b4eacdd31
commit ddff598ba4

@ -58,11 +58,8 @@ namespace NzbDrone.App.Test
Mocker.GetMock<INzbDroneServiceFactory>().Verify(c => c.Start(), Times.Once());
}
[TestCase(ApplicationModes.Interactive)]
[TestCase(ApplicationModes.InstallService)]
[TestCase(ApplicationModes.UninstallService)]
[TestCase(ApplicationModes.Help)]
public void Route_should_call_service_start_when_run_in_service_mode(ApplicationModes applicationModes)
[Test]
public void Route_should_call_service_start_when_run_in_service_mode()
{
var envMock = Mocker.GetMock<IRuntimeInfo>();
var serviceProvider = Mocker.GetMock<IServiceProvider>();
@ -71,8 +68,9 @@ namespace NzbDrone.App.Test
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
serviceProvider.Setup(c => c.ServiceExist(It.IsAny<string>())).Returns(true);
serviceProvider.Setup(c => c.GetStatus(It.IsAny<string>())).Returns(ServiceControllerStatus.StartPending);
Subject.Route(applicationModes);
Subject.Route();
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
}
@ -90,7 +88,6 @@ namespace NzbDrone.App.Test
Subject.Route(ApplicationModes.InstallService);
Mocker.VerifyAllMocks();
}
[Test]
@ -105,7 +102,6 @@ namespace NzbDrone.App.Test
Subject.Route(ApplicationModes.UninstallService);
Mocker.VerifyAllMocks();
}
}
}

@ -34,8 +34,8 @@ namespace NzbDrone.Common
Console.WriteLine();
Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName);
Console.WriteLine(" Commands:");
Console.WriteLine(" /{0} Install the application as a Windows Service ({1}).",StartupArguments.INSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /{0} Uninstall already installed Windows Service ({1}).",StartupArguments.UNINSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /{0} Install the application as a Windows Service ({1}).",StartupArguments.INSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /{0} Uninstall already installed Windows Service ({1}).",StartupArguments.UNINSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /{0} Don't open NzbDrone in a browser", StartupArguments.NO_BROWSER);
Console.WriteLine(" <No Arguments> Run application in console mode.");
}

@ -18,6 +18,7 @@ namespace NzbDrone.Common
ServiceController GetService(string serviceName);
void Stop(string serviceName);
void Start(string serviceName);
ServiceControllerStatus GetStatus(string serviceName);
}
public class ServiceProvider : IServiceProvider
@ -136,7 +137,13 @@ namespace NzbDrone.Common
}
}
public virtual void Start(string serviceName)
public ServiceControllerStatus GetStatus(string serviceName)
{
return GetService(serviceName).Status;
}
public void Start(string serviceName)
{
Logger.Info("Starting {0} Service...", serviceName);
var service = GetService(serviceName);

@ -93,6 +93,14 @@ namespace NzbDrone.Host
private ApplicationModes GetApplicationMode()
{
if (!_runtimeInfo.IsUserInteractive &&
OsInfo.IsWindows &&
_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
_serviceProvider.GetStatus(ServiceProvider.NZBDRONE_SERVICE_NAME) == ServiceControllerStatus.StartPending)
{
return ApplicationModes.Service;
}
if (_startupArguments.Flags.Contains(StartupArguments.HELP))
{
return ApplicationModes.Help;
@ -108,14 +116,6 @@ namespace NzbDrone.Host
return ApplicationModes.UninstallService;
}
if (!_runtimeInfo.IsUserInteractive &&
OsInfo.IsWindows &&
_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
_serviceProvider.GetService(ServiceProvider.NZBDRONE_SERVICE_NAME).Status == ServiceControllerStatus.StartPending)
{
return ApplicationModes.Service;
}
return ApplicationModes.Interactive;
}
}

Loading…
Cancel
Save