Windows service is half working,
This commit is contained in:
parent
7549c26ffe
commit
6b7923bd52
|
@ -1,12 +1,6 @@
|
||||||
using System;
|
using FluentAssertions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Providers;
|
|
||||||
|
|
||||||
namespace NzbDrone.App.Test
|
namespace NzbDrone.App.Test
|
||||||
{
|
{
|
||||||
|
@ -36,5 +30,14 @@ namespace NzbDrone.App.Test
|
||||||
appServer.Should().NotBeNull();
|
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">
|
<Reference Include="Moq">
|
||||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<Reference Include="nunit.framework">
|
||||||
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
@ -46,5 +46,16 @@ namespace NzbDrone.App.Test
|
||||||
serviceController.UnInstall();
|
serviceController.UnInstall();
|
||||||
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
|
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="FluentAssertions" version="1.5.0.0" />
|
||||||
<package id="Moq" version="4.0.10827" />
|
<package id="Moq" version="4.0.10827" />
|
||||||
<package id="NBuilder" version="3.0.1" />
|
<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="NUnit" version="2.5.10.11092" />
|
||||||
<package id="Unity" version="2.1.505.0" />
|
<package id="Unity" version="2.1.505.0" />
|
||||||
</packages>
|
</packages>
|
|
@ -18,6 +18,8 @@ namespace NzbDrone
|
||||||
static CentralDispatch()
|
static CentralDispatch()
|
||||||
{
|
{
|
||||||
_kernel = new StandardKernel();
|
_kernel = new StandardKernel();
|
||||||
|
BindKernel();
|
||||||
|
InitilizeApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationMode ApplicationMode { get; set; }
|
public static ApplicationMode ApplicationMode { get; set; }
|
||||||
|
@ -33,6 +35,7 @@ namespace NzbDrone
|
||||||
private static void BindKernel()
|
private static void BindKernel()
|
||||||
{
|
{
|
||||||
_kernel = new StandardKernel();
|
_kernel = new StandardKernel();
|
||||||
|
_kernel.Bind<ApplicationServer>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<ConfigProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<ConfigProvider>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<ConsoleProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<ConsoleProvider>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<DebuggerProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<DebuggerProvider>().ToSelf().InSingletonScope();
|
||||||
|
@ -42,6 +45,7 @@ namespace NzbDrone
|
||||||
_kernel.Bind<ProcessProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<ProcessProvider>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
|
||||||
_kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitilizeApp()
|
private static void InitilizeApp()
|
||||||
|
|
|
@ -53,6 +53,9 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
|
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>NzbDrone.NzbDroneConsole</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Accessibility">
|
<Reference Include="Accessibility">
|
||||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Model;
|
using NzbDrone.Model;
|
||||||
|
@ -14,10 +16,12 @@ namespace NzbDrone
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
|
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
|
||||||
|
|
||||||
private static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//while (!Debugger.IsAttached) Thread.Sleep(100);
|
||||||
|
|
||||||
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
|
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
|
||||||
|
|
||||||
CentralDispatch.ApplicationMode = GetApplicationMode(args);
|
CentralDispatch.ApplicationMode = GetApplicationMode(args);
|
||||||
|
@ -29,9 +33,6 @@ namespace NzbDrone
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
Logger.Fatal(e.ToString());
|
Logger.Fatal(e.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Press enter to exit.");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationMode GetApplicationMode(IEnumerable<string> args)
|
public static ApplicationMode GetApplicationMode(IEnumerable<string> args)
|
||||||
|
|
|
@ -1,18 +1,43 @@
|
||||||
using System.ServiceProcess;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.ServiceProcess;
|
||||||
|
using System.Threading;
|
||||||
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
|
|
||||||
namespace NzbDrone
|
namespace NzbDrone
|
||||||
{
|
{
|
||||||
internal class NzbDroneService : ServiceBase
|
public class NzbDroneService : ServiceBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static readonly Logger Logger = LogManager.GetLogger("Host.CentralDispatch");
|
||||||
|
|
||||||
protected override void OnStart(string[] args)
|
protected override void OnStart(string[] args)
|
||||||
{
|
{
|
||||||
CentralDispatch.Kernel.Get<ApplicationServer>().Start();
|
try
|
||||||
|
{
|
||||||
|
while (!Debugger.IsAttached) Thread.Sleep(100);
|
||||||
|
Debugger.Break();
|
||||||
|
CentralDispatch.Kernel.Get<ApplicationServer>().Start();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
|
Logger.Fatal("Failed to start Windows Service", e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStop()
|
protected override void OnStop()
|
||||||
{
|
{
|
||||||
CentralDispatch.Kernel.Get<ApplicationServer>().Stop();
|
try
|
||||||
|
{
|
||||||
|
CentralDispatch.Kernel.Get<ApplicationServer>().Stop();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Fatal("Failed to stop Windows Service", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,20 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace NzbDrone.Providers
|
namespace NzbDrone.Providers
|
||||||
{
|
{
|
||||||
public class ConsoleProvider
|
public class ConsoleProvider
|
||||||
{
|
{
|
||||||
|
private static readonly Logger Logger = LogManager.GetLogger("Host.ConsoleProvider");
|
||||||
|
|
||||||
public virtual void WaitForClose()
|
public virtual void WaitForClose()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
System.Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void PrintHelp()
|
public virtual void PrintHelp()
|
||||||
{
|
{
|
||||||
System.Console.WriteLine("Help");
|
Logger.Info("Printing Help");
|
||||||
|
Console.WriteLine("Help");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,14 +20,22 @@ namespace NzbDrone.Providers
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
|
var dir = new FileInfo(Environment.CurrentDirectory).Directory;
|
||||||
|
|
||||||
|
while (dir.GetDirectories("iisexpress").Length == 0)
|
||||||
|
{
|
||||||
|
if (dir.Parent == null) break;
|
||||||
|
dir = dir.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
|
||||||
|
|
||||||
while (dir.GetDirectories("iisexpress").Length == 0)
|
while (dir.GetDirectories("iisexpress").Length == 0)
|
||||||
{
|
{
|
||||||
if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
|
if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
|
||||||
dir = dir.Parent;
|
dir = dir.Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir.FullName;
|
return dir.FullName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ namespace NzbDrone.Providers
|
||||||
serviceInstaller.DisplayName = NzbDroneServiceName;
|
serviceInstaller.DisplayName = NzbDroneServiceName;
|
||||||
serviceInstaller.ServiceName = NzbDroneServiceName;
|
serviceInstaller.ServiceName = NzbDroneServiceName;
|
||||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||||
|
|
||||||
|
|
||||||
serviceInstaller.Parent = installer;
|
serviceInstaller.Parent = installer;
|
||||||
|
|
||||||
serviceInstaller.Install(new ListDictionary());
|
serviceInstaller.Install(new ListDictionary());
|
||||||
|
@ -54,7 +56,7 @@ namespace NzbDrone.Providers
|
||||||
{
|
{
|
||||||
var serviceInstaller = new ServiceInstaller();
|
var serviceInstaller = new ServiceInstaller();
|
||||||
|
|
||||||
var context = new InstallContext("install.log", null);
|
var context = new InstallContext("service_uninstall.log", null);
|
||||||
serviceInstaller.Context = context;
|
serviceInstaller.Context = context;
|
||||||
serviceInstaller.ServiceName = NzbDroneServiceName;
|
serviceInstaller.ServiceName = NzbDroneServiceName;
|
||||||
serviceInstaller.Uninstall(null);
|
serviceInstaller.Uninstall(null);
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
using NzbDrone.Model;
|
using NzbDrone.Model;
|
||||||
using NzbDrone.Providers;
|
using NzbDrone.Providers;
|
||||||
|
|
||||||
namespace NzbDrone
|
namespace NzbDrone
|
||||||
{
|
{
|
||||||
class Router
|
public class Router
|
||||||
{
|
{
|
||||||
|
private static readonly Logger Logger = LogManager.GetLogger("Host.Router");
|
||||||
|
|
||||||
private readonly ApplicationServer _applicationServer;
|
private readonly ApplicationServer _applicationServer;
|
||||||
private readonly ServiceProvider _serviceProvider;
|
private readonly ServiceProvider _serviceProvider;
|
||||||
private readonly ConsoleProvider _consoleProvider;
|
private readonly ConsoleProvider _consoleProvider;
|
||||||
|
@ -17,13 +20,15 @@ namespace NzbDrone
|
||||||
{
|
{
|
||||||
_applicationServer = applicationServer;
|
_applicationServer = applicationServer;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_consoleProvider = consoleProvider;
|
_consoleProvider = consoleProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Route()
|
public void Route()
|
||||||
{
|
{
|
||||||
|
Logger.Info("Application mode: {0}", CentralDispatch.ApplicationMode);
|
||||||
switch (CentralDispatch.ApplicationMode)
|
switch (CentralDispatch.ApplicationMode)
|
||||||
{
|
{
|
||||||
|
|
||||||
case ApplicationMode.Console:
|
case ApplicationMode.Console:
|
||||||
{
|
{
|
||||||
_applicationServer.Start();
|
_applicationServer.Start();
|
||||||
|
|
Loading…
Reference in New Issue