2013-11-26 09:53:36 +03:00
|
|
|
using NLog;
|
2011-10-23 08:26:43 +03:00
|
|
|
using NzbDrone.Common;
|
2011-10-09 05:16:11 +03:00
|
|
|
|
2013-08-07 08:32:22 +03:00
|
|
|
namespace NzbDrone.Host
|
2011-10-09 05:16:11 +03:00
|
|
|
{
|
2011-10-13 05:24:30 +03:00
|
|
|
public class Router
|
2011-10-09 05:16:11 +03:00
|
|
|
{
|
2013-04-16 07:52:41 +03:00
|
|
|
private readonly INzbDroneServiceFactory _nzbDroneServiceFactory;
|
2013-05-11 02:53:50 +03:00
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2013-04-16 07:52:41 +03:00
|
|
|
private readonly IConsoleService _consoleService;
|
2013-03-01 03:50:50 +03:00
|
|
|
private readonly Logger _logger;
|
2011-10-09 05:16:11 +03:00
|
|
|
|
2013-11-26 09:53:36 +03:00
|
|
|
public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider,
|
|
|
|
IConsoleService consoleService, Logger logger)
|
2011-10-09 05:16:11 +03:00
|
|
|
{
|
2013-04-16 07:52:41 +03:00
|
|
|
_nzbDroneServiceFactory = nzbDroneServiceFactory;
|
2011-10-09 05:16:11 +03:00
|
|
|
_serviceProvider = serviceProvider;
|
2013-04-16 07:52:41 +03:00
|
|
|
_consoleService = consoleService;
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger = logger;
|
2011-10-09 05:16:11 +03:00
|
|
|
}
|
|
|
|
|
2013-03-01 03:50:50 +03:00
|
|
|
public void Route(ApplicationModes applicationModes)
|
2011-10-14 04:22:51 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger.Info("Application mode: {0}", applicationModes);
|
2013-01-16 02:17:12 +03:00
|
|
|
|
2013-03-01 03:50:50 +03:00
|
|
|
switch (applicationModes)
|
2013-01-06 11:11:14 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
case ApplicationModes.Service:
|
2013-01-06 11:11:14 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger.Trace("Service selected");
|
2013-04-16 07:52:41 +03:00
|
|
|
_serviceProvider.Run(_nzbDroneServiceFactory.Build());
|
2013-01-06 11:11:14 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-10-14 04:22:51 +03:00
|
|
|
|
2013-08-07 08:32:22 +03:00
|
|
|
case ApplicationModes.Interactive:
|
2013-01-06 11:11:14 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger.Trace("Console selected");
|
2013-04-16 07:52:41 +03:00
|
|
|
_nzbDroneServiceFactory.Start();
|
2013-01-06 11:11:14 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-03-01 03:50:50 +03:00
|
|
|
case ApplicationModes.InstallService:
|
2013-01-06 11:11:14 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger.Trace("Install Service selected");
|
2013-01-06 11:11:14 +03:00
|
|
|
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
2011-10-14 04:22:51 +03:00
|
|
|
{
|
2013-04-16 07:52:41 +03:00
|
|
|
_consoleService.PrintServiceAlreadyExist();
|
2011-10-14 04:22:51 +03:00
|
|
|
}
|
2013-01-06 11:11:14 +03:00
|
|
|
else
|
2011-10-14 04:22:51 +03:00
|
|
|
{
|
2013-01-06 11:11:14 +03:00
|
|
|
_serviceProvider.Install(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
2011-10-14 04:22:51 +03:00
|
|
|
}
|
2013-01-06 11:11:14 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-03-01 03:50:50 +03:00
|
|
|
case ApplicationModes.UninstallService:
|
2013-01-06 11:11:14 +03:00
|
|
|
{
|
2013-03-01 03:50:50 +03:00
|
|
|
_logger.Trace("Uninstall Service selected");
|
2013-01-06 11:11:14 +03:00
|
|
|
if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
2011-10-14 04:22:51 +03:00
|
|
|
{
|
2013-07-09 03:47:09 +03:00
|
|
|
_consoleService.PrintServiceDoesNotExist();
|
2011-10-14 04:22:51 +03:00
|
|
|
}
|
2013-01-06 11:11:14 +03:00
|
|
|
else
|
2011-10-14 04:22:51 +03:00
|
|
|
{
|
2013-01-06 11:11:14 +03:00
|
|
|
_serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
2011-10-14 04:22:51 +03:00
|
|
|
}
|
2013-01-06 11:11:14 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-04-16 07:52:41 +03:00
|
|
|
_consoleService.PrintHelp();
|
2013-01-06 11:11:14 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-10-14 04:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-09 05:16:11 +03:00
|
|
|
}
|
|
|
|
}
|