Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus

pull/4/head
Mark McDowall 13 years ago
commit 9780a03c11

@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using FluentAssertions;
using FluentAssertions;
using NUnit.Framework;
using Ninject;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
@ -36,5 +30,14 @@ namespace NzbDrone.App.Test
appServer.Should().NotBeNull();
}
[Test]
public void Kernel_should_resolve_same_ApplicationServer_instance()
{
var appServer1 = CentralDispatch.Kernel.Get<ApplicationServer>();
var appServer2 = CentralDispatch.Kernel.Get<ApplicationServer>();
appServer1.Should().BeSameAs(appServer2);
}
}
}

@ -50,7 +50,9 @@
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="Ninject, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL" />
<Reference Include="Ninject">
<HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
@ -75,7 +77,7 @@
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
<Compile Include="CentralDispatchTests.cs" />
<Compile Include="ProgramTest.cs" />
<Compile Include="RouterTest.cs" />
<Compile Include="MonitoringProviderTest.cs" />
<Compile Include="ConfigProviderTest.cs" />
<Compile Include="IISProviderTest.cs" />

@ -1,43 +0,0 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
[TestFixture]
public class ProgramTest
{
[TestCase(null, ApplicationMode.Console)]
[TestCase("", ApplicationMode.Console)]
[TestCase("1", ApplicationMode.Help)]
[TestCase("ii", ApplicationMode.Help)]
[TestCase("uu", ApplicationMode.Help)]
[TestCase("i", ApplicationMode.InstallService)]
[TestCase("I", ApplicationMode.InstallService)]
[TestCase("/I", ApplicationMode.InstallService)]
[TestCase("/i", ApplicationMode.InstallService)]
[TestCase("-I", ApplicationMode.InstallService)]
[TestCase("-i", ApplicationMode.InstallService)]
[TestCase("u", ApplicationMode.UninstallService)]
[TestCase("U", ApplicationMode.UninstallService)]
[TestCase("/U", ApplicationMode.UninstallService)]
[TestCase("/u", ApplicationMode.UninstallService)]
[TestCase("-U", ApplicationMode.UninstallService)]
[TestCase("-u", ApplicationMode.UninstallService)]
public void GetApplicationMode_single_arg(string arg, ApplicationMode mode)
{
NzbDroneConsole.GetApplicationMode(new[] { arg }).Should().Be(mode);
}
[TestCase("", "", ApplicationMode.Console)]
[TestCase("", null, ApplicationMode.Console)]
[TestCase("i", "n", ApplicationMode.Help)]
public void GetApplicationMode_two_args(string a, string b, ApplicationMode mode)
{
NzbDroneConsole.GetApplicationMode(new[] { a, b }).Should().Be(mode);
}
}
}

@ -0,0 +1,142 @@
using System.ServiceProcess;
using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
[TestFixture]
public class RouterTest
{
[TestCase(null, ApplicationMode.Console)]
[TestCase("", ApplicationMode.Console)]
[TestCase("1", ApplicationMode.Help)]
[TestCase("ii", ApplicationMode.Help)]
[TestCase("uu", ApplicationMode.Help)]
[TestCase("i", ApplicationMode.InstallService)]
[TestCase("I", ApplicationMode.InstallService)]
[TestCase("/I", ApplicationMode.InstallService)]
[TestCase("/i", ApplicationMode.InstallService)]
[TestCase("-I", ApplicationMode.InstallService)]
[TestCase("-i", ApplicationMode.InstallService)]
[TestCase("u", ApplicationMode.UninstallService)]
[TestCase("U", ApplicationMode.UninstallService)]
[TestCase("/U", ApplicationMode.UninstallService)]
[TestCase("/u", ApplicationMode.UninstallService)]
[TestCase("-U", ApplicationMode.UninstallService)]
[TestCase("-u", ApplicationMode.UninstallService)]
public void GetApplicationMode_single_arg(string arg, ApplicationMode mode)
{
Router.GetApplicationMode(new[] { arg }).Should().Be(mode);
}
[TestCase("", "", ApplicationMode.Console)]
[TestCase("", null, ApplicationMode.Console)]
[TestCase("i", "n", ApplicationMode.Help)]
public void GetApplicationMode_two_args(string a, string b, ApplicationMode mode)
{
Router.GetApplicationMode(new[] { a, b }).Should().Be(mode);
}
[Test]
public void Route_should_call_install_service_when_application_mode_is_install()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.Install());
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(false);
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
serviceProviderMock.Verify(c => c.Install(), Times.Once());
}
[Test]
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.UnInstall());
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(), Times.Once());
}
[Test]
public void Route_should_call_console_service_when_application_mode_is_console()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleProvider = mocker.GetMock<ConsoleProvider>();
var appServerProvider = mocker.GetMock<ApplicationServer>();
consoleProvider.Setup(c => c.WaitForClose());
appServerProvider.Setup(c => c.Start());
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.Console);
consoleProvider.Verify(c => c.WaitForClose(), Times.Once());
appServerProvider.Verify(c => c.Start(), Times.Once());
}
[TestCase(ApplicationMode.Console)]
[TestCase(ApplicationMode.InstallService)]
[TestCase(ApplicationMode.UninstallService)]
[TestCase(ApplicationMode.Help)]
public void Route_should_call_service_start_when_run_in_service_more(ApplicationMode applicationMode)
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var envMock = mocker.GetMock<EnviromentProvider>();
var serviceProvider = mocker.GetMock<ServiceProvider>();
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
mocker.Resolve<Router>().Route(applicationMode);
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
}
[Test]
public void show_error_on_install_if_service_already_exist()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleMock = mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
mocker.VerifyAllMocks();
}
[Test]
public void show_error_on_uninstall_if_service_doesnt_exist()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var consoleMock = mocker.GetMock<ConsoleProvider>();
var serviceMock = mocker.GetMock<ServiceProvider>();
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoestExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(false);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
mocker.VerifyAllMocks();
}
}
}

@ -40,11 +40,22 @@ namespace NzbDrone.App.Test
var serviceController = new ServiceProvider();
//Act
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse("Service already installed");
serviceController.Install();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeTrue();
serviceController.UnInstall();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
}
[Test]
[Explicit]
public void UnInstallService()
{
var serviceController = new ServiceProvider();
//Act
serviceController.UnInstall();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
}
}
}

@ -4,6 +4,7 @@
<package id="FluentAssertions" version="1.5.0.0" />
<package id="Moq" version="4.0.10827" />
<package id="NBuilder" version="3.0.1" />
<package id="Ninject" version="2.2.1.4" />
<package id="NUnit" version="2.5.10.11092" />
<package id="Unity" version="2.1.505.0" />
</packages>

@ -1,6 +1,6 @@
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<targets>
<target name="consoleTarget" xsi:type="Console" layout="${date} ${logger} - ${message} ${exception}" />
<target name="consoleTarget" xsi:type="Console" layout="${message} ${exception}" />
<target name="udpTarget" xsi:type="Chainsaw" address="udp://127.0.0.1:20480"
includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNDC="true" includeMDC="true">
<parameter name="exception" layout="${exception:format=ToString}" xsi:type="NLogViewerParameterInfo" />

@ -0,0 +1,31 @@
using System;
using System.Reflection;
using NLog;
using Ninject;
namespace NzbDrone
{
public static class AppMain
{
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
public static void Main(string[] args)
{
try
{
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
CentralDispatch.Kernel.Get<Router>().Route(args);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Logger.Fatal(e.ToString());
}
}
}
}

@ -1,13 +1,13 @@
using System;
using System.Net;
using System.Threading;
using System.ServiceProcess;
using NLog;
using Ninject;
using NzbDrone.Providers;
namespace NzbDrone
{
public class ApplicationServer
public class ApplicationServer : ServiceBase
{
private static readonly Logger Logger = LogManager.GetLogger("Host.App");
@ -16,12 +16,13 @@ namespace NzbDrone
private readonly EnviromentProvider _enviromentProvider;
private readonly IISProvider _iisProvider;
private readonly ProcessProvider _processProvider;
private readonly MonitoringProvider _monitoringProvider;
private readonly WebClient _webClient;
[Inject]
public ApplicationServer(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider,
DebuggerProvider debuggerProvider, EnviromentProvider enviromentProvider,
ProcessProvider processProvider)
ProcessProvider processProvider, MonitoringProvider monitoringProvider)
{
_configProvider = configProvider;
_webClient = webClient;
@ -29,10 +30,17 @@ namespace NzbDrone
_debuggerProvider = debuggerProvider;
_enviromentProvider = enviromentProvider;
_processProvider = processProvider;
_monitoringProvider = monitoringProvider;
}
public ApplicationServer()
{
}
protected override void OnStart(string[] args)
{
Start();
}
public virtual void Start()
@ -65,9 +73,11 @@ namespace NzbDrone
Logger.ErrorException("Failed to load home page.", e);
}
}
_monitoringProvider.Start();
}
public virtual void Stop()
protected override void OnStop()
{
Logger.Info("Attempting to stop application.");
_iisProvider.StopServer();

@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NLog;
using NLog;
using Ninject;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone
@ -18,10 +12,10 @@ namespace NzbDrone
static CentralDispatch()
{
_kernel = new StandardKernel();
BindKernel();
InitilizeApp();
}
public static ApplicationMode ApplicationMode { get; set; }
public static StandardKernel Kernel
{
get
@ -33,6 +27,7 @@ namespace NzbDrone
private static void BindKernel()
{
_kernel = new StandardKernel();
_kernel.Bind<ApplicationServer>().ToSelf().InSingletonScope();
_kernel.Bind<ConfigProvider>().ToSelf().InSingletonScope();
_kernel.Bind<ConsoleProvider>().ToSelf().InSingletonScope();
_kernel.Bind<DebuggerProvider>().ToSelf().InSingletonScope();
@ -42,14 +37,14 @@ namespace NzbDrone
_kernel.Bind<ProcessProvider>().ToSelf().InSingletonScope();
_kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
_kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
}
private static void InitilizeApp()
{
_kernel.Get<ConfigProvider>().ConfigureNlog();
_kernel.Get<ConfigProvider>().CreateDefaultConfigFile();
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _kernel.Get<EnviromentProvider>().ApplicationPath);
Thread.CurrentThread.Name = "Host";
Logger.Info("Start-up Path:'{0}'", _kernel.Get<EnviromentProvider>().ApplicationPath);
}
}
}

@ -53,6 +53,9 @@
<PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>NzbDrone.AppMain</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility">
<EmbedInteropTypes>True</EmbedInteropTypes>
@ -85,7 +88,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationServer.cs" />
<Compile Include="ApplicationServer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CentralDispatch.cs" />
<Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Model\AuthenticationType.cs" />
@ -93,13 +98,10 @@
<Compile Include="Providers\ConsoleProvider.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
<Compile Include="NzbDroneService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ProcessAttacher.cs" />
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\IISProvider.cs" />
<Compile Include="NzbDroneConsole.cs" />
<Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />
<Compile Include="Providers\ProcessProvider.cs" />

@ -1,53 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using NLog;
using Ninject;
using NzbDrone.Model;
namespace NzbDrone
{
public static class NzbDroneConsole
{
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
private static void Main(string[] args)
{
try
{
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
CentralDispatch.ApplicationMode = GetApplicationMode(args);
CentralDispatch.Kernel.Get<Router>().Route();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Logger.Fatal(e.ToString());
}
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
public static ApplicationMode GetApplicationMode(IEnumerable<string> args)
{
if (args == null) return ApplicationMode.Console;
var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList();
if (cleanArgs.Count == 0) return ApplicationMode.Console;
if (cleanArgs.Count != 1) return ApplicationMode.Help;
var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower();
if (arg == "i") return ApplicationMode.InstallService;
if (arg == "u") return ApplicationMode.UninstallService;
return ApplicationMode.Help;
}
}
}

@ -1,18 +0,0 @@
using System.ServiceProcess;
using Ninject;
namespace NzbDrone
{
internal class NzbDroneService : ServiceBase
{
protected override void OnStart(string[] args)
{
CentralDispatch.Kernel.Get<ApplicationServer>().Start();
}
protected override void OnStop()
{
CentralDispatch.Kernel.Get<ApplicationServer>().Stop();
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
namespace NzbDrone.Providers
{
@ -8,13 +9,28 @@ namespace NzbDrone.Providers
{
while (true)
{
System.Console.ReadLine();
Console.ReadLine();
}
}
public virtual void PrintHelp()
{
System.Console.WriteLine("Help");
Console.WriteLine();
Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName);
Console.WriteLine(" Commands:");
Console.WriteLine(" /i Install the application as a Windows Service ({0}).", ServiceProvider.NzbDroneServiceName);
Console.WriteLine(" /u Uninstall already installed Windows Service ({0}).", ServiceProvider.NzbDroneServiceName);
Console.WriteLine(" <No Arguments> Run application in console mode.");
}
public virtual void PrintServiceAlreadyExist()
{
Console.WriteLine("A service with the same name ({0}) already exists. Aborting installation", ServiceProvider.NzbDroneServiceName);
}
public virtual void PrintServiceDoestExist()
{
Console.WriteLine("Can't find service ({0})", ServiceProvider.NzbDroneServiceName);
}
}
}

@ -20,9 +20,19 @@ namespace NzbDrone.Providers
{
get
{
var dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
var dir = new FileInfo(Environment.CurrentDirectory).Directory;
while (dir.GetDirectories("iisexpress").Length == 0)
while (!ContainsIIS(dir))
{
if (dir.Parent == null) break;
dir = dir.Parent;
}
if (ContainsIIS(dir)) return dir.FullName;
dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
while (!ContainsIIS(dir))
{
if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
dir = dir.Parent;
@ -31,5 +41,10 @@ namespace NzbDrone.Providers
return dir.FullName;
}
}
private static bool ContainsIIS(DirectoryInfo dir)
{
return dir.GetDirectories("iisexpress").Length != 0;
}
}
}

@ -120,7 +120,7 @@ namespace NzbDrone.Providers
if (e.Data.Contains(" NzbDrone."))
{
System.Console.WriteLine(e.Data);
Console.WriteLine(e.Data);
return;
}

@ -103,7 +103,7 @@ namespace NzbDrone.Providers
private static void AppDomainException(object excepion)
{
System.Console.WriteLine("EPIC FAIL: {0}", excepion);
Console.WriteLine("EPIC FAIL: {0}", excepion);
Logger.Fatal("EPIC FAIL: {0}", excepion);
#if RELEASE

@ -15,7 +15,9 @@ namespace NzbDrone.Providers
private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager");
public bool ServiceExist(string name)
public virtual bool ServiceExist(string name)
{
return
ServiceController.GetServices().Any(
@ -30,19 +32,21 @@ namespace NzbDrone.Providers
var installer = new ServiceProcessInstaller
{
Account = ServiceAccount.NetworkService
Account = ServiceAccount.LocalSystem
};
var serviceInstaller = new ServiceInstaller();
String[] cmdline = {@"/assemblypath=" + Assembly.GetExecutingAssembly().Location};
String[] cmdline = { @"/assemblypath=" + Assembly.GetExecutingAssembly().Location };
var context = new InstallContext("service_install.log", cmdline);
serviceInstaller.Context = context;
serviceInstaller.DisplayName = NzbDroneServiceName;
serviceInstaller.ServiceName = NzbDroneServiceName;
serviceInstaller.Description = "NzbDrone Application Server";
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.Parent = installer;
serviceInstaller.Install(new ListDictionary());
@ -54,10 +58,16 @@ namespace NzbDrone.Providers
{
var serviceInstaller = new ServiceInstaller();
var context = new InstallContext("install.log", null);
var context = new InstallContext("service_uninstall.log", null);
serviceInstaller.Context = context;
serviceInstaller.ServiceName = NzbDroneServiceName;
serviceInstaller.Uninstall(null);
}
public virtual void Run(ServiceBase service)
{
ServiceBase.Run(service);
}
}
}

@ -1,51 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone
{
class Router
public class Router
{
private static readonly Logger Logger = LogManager.GetLogger("Host.Router");
private readonly ApplicationServer _applicationServer;
private readonly ServiceProvider _serviceProvider;
private readonly ConsoleProvider _consoleProvider;
private readonly EnviromentProvider _enviromentProvider;
public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider, ConsoleProvider consoleProvider)
public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider, ConsoleProvider consoleProvider, EnviromentProvider enviromentProvider)
{
_applicationServer = applicationServer;
_serviceProvider = serviceProvider;
_consoleProvider = consoleProvider;
_enviromentProvider = enviromentProvider;
}
public void Route(IEnumerable<string> args)
{
Route(GetApplicationMode(args));
}
public void Route()
public void Route(ApplicationMode applicationMode)
{
switch (CentralDispatch.ApplicationMode)
Logger.Info("Application mode: {0}", applicationMode);
if (!_enviromentProvider.IsUserInteractive)
{
_serviceProvider.Run(_applicationServer);
}
else
{
case ApplicationMode.Console:
{
_applicationServer.Start();
_consoleProvider.WaitForClose();
break;
}
case ApplicationMode.InstallService:
{
_serviceProvider.Install();
break;
}
case ApplicationMode.UninstallService:
{
_serviceProvider.UnInstall();
break;
}
default:
{
_consoleProvider.PrintHelp();
break;
}
switch (applicationMode)
{
case ApplicationMode.Console:
{
_applicationServer.Start();
_consoleProvider.WaitForClose();
break;
}
case ApplicationMode.InstallService:
{
if (_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
{
_consoleProvider.PrintServiceAlreadyExist();
}
else
{
_serviceProvider.Install();
}
break;
}
case ApplicationMode.UninstallService:
{
if (!_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
{
_consoleProvider.PrintServiceDoestExist();
}
else
{
_serviceProvider.UnInstall();
}
break;
}
default:
{
_consoleProvider.PrintHelp();
break;
}
}
}
}
public static ApplicationMode GetApplicationMode(IEnumerable<string> args)
{
if (args == null) return ApplicationMode.Console;
var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList();
if (cleanArgs.Count == 0) return ApplicationMode.Console;
if (cleanArgs.Count != 1) return ApplicationMode.Help;
var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower();
if (arg == "i") return ApplicationMode.InstallService;
if (arg == "u") return ApplicationMode.UninstallService;
return ApplicationMode.Help;
}
}
}

Loading…
Cancel
Save