diff --git a/NzbDrone.App.Test/EnviromentProviderTest.cs b/NzbDrone.App.Test/EnviromentProviderTest.cs
index f2615bf76..919be960d 100644
--- a/NzbDrone.App.Test/EnviromentProviderTest.cs
+++ b/NzbDrone.App.Test/EnviromentProviderTest.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using FluentAssertions;
+using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Providers;
diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj
index 93f582cfa..efcc045e1 100644
--- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj
+++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj
@@ -72,6 +72,7 @@
+
diff --git a/NzbDrone.App.Test/ProgramTest.cs b/NzbDrone.App.Test/ProgramTest.cs
new file mode 100644
index 000000000..26827b648
--- /dev/null
+++ b/NzbDrone.App.Test/ProgramTest.cs
@@ -0,0 +1,42 @@
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+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)
+ {
+ Console.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)
+ {
+ Console.GetApplicationMode(new[] { a, b }).Should().Be(mode);
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/BacklogSearchJobTest.cs
index 8b9eaa187..f8289e204 100644
--- a/NzbDrone.Core.Test/BacklogSearchJobTest.cs
+++ b/NzbDrone.Core.Test/BacklogSearchJobTest.cs
@@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test
public class BacklogSearchJobTest
{
[Test]
- public void no_missing_epsiodes()
+ public void no_missing_epsiodes_should_not_trigger_any_search()
{
//Setup
var notification = new ProgressNotification("Backlog Search Job Test");
@@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test
}
[Test]
- public void individual_missing_episode_only()
+ public void individual_missing_episode()
{
//Setup
var notification = new ProgressNotification("Backlog Search Job Test");
diff --git a/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs b/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs
deleted file mode 100644
index 4d31e398e..000000000
--- a/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs
+++ /dev/null
@@ -1,187 +0,0 @@
-// ReSharper disable RedundantUsingDirective
-using System;
-using AutoMoq;
-using Moq;
-using NUnit.Framework;
-
-namespace NzbDrone.Core.Test
-{
- [TestFixture]
- // ReSharper disable InconsistentNaming
- public class AutoMoqerTest
- {
- [Test]
- public void GetMock_on_interface_returns_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- //Act
- var mock = mocker.GetMock();
-
- //Assert
- Assert.IsNotNull(mock);
- }
-
- [Test]
- public void GetMock_on_concrete_returns_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- //Act
- var mock = mocker.GetMock();
-
- //Assert
- Assert.IsNotNull(mock);
- }
-
-
- [Test]
- public void Resolve_doesnt_return_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- //Act
- var result = mocker.Resolve().Do();
-
- //Assert
- Assert.AreEqual("hello", result);
- }
-
- [Test]
- public void Resolve_with_dependency_doesnt_return_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- //Act
- var result = mocker.Resolve().VirtualMethod();
-
- //Assert
- Assert.AreEqual("hello", result);
- }
-
- [Test]
- public void Resolve_with_mocked_dependency_uses_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- mocker.GetMock()
- .Setup(m => m.VirtualMethod())
- .Returns("mocked");
-
- //Act
- var result = mocker.Resolve().CallVirtualChild();
-
- //Assert
- Assert.AreEqual("mocked", result);
- }
-
-
- [Test]
- public void Resolve_with_unbound_concerete_dependency_uses_mock()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- //Act
- var result = mocker.Resolve().CallVirtualChild();
-
- var mockedResult = new Mock().Object.VirtualMethod();
-
- //Assert
- Assert.AreEqual(mockedResult, result);
- }
-
-
- [Test]
- public void Resolve_with_constant_concerete_dependency_uses_constant()
- {
- //Arrange
- var mocker = new AutoMoqer();
-
- var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() };
-
- mocker.SetConstant(constant);
-
- //Act
- var result = mocker.Resolve().GetVirtualProperty();
-
- //Assert
- Assert.AreEqual(constant.PropValue, result);
- }
- }
-
- public class ConcreteClass
- {
- public string Do()
- {
- return "hello";
- }
- }
-
- public class Dependency : IDependency
- {
- }
-
- public interface IDependency
- {
- }
-
- public class ClassWithDependencies
- {
- public ClassWithDependencies(IDependency dependency)
- {
- Dependency = dependency;
- }
-
- public IDependency Dependency { get; set; }
- }
-
- public class ClassWithVirtualDependencies
- {
- private readonly VirtualDependency _virtualDependency;
-
- public ClassWithVirtualDependencies(IDependency dependency, VirtualDependency virtualDependency)
- {
- _virtualDependency = virtualDependency;
- Dependency = dependency;
- }
-
- public IDependency Dependency { get; set; }
-
- public string CallVirtualChild()
- {
- return _virtualDependency.VirtualMethod();
- }
-
- public string GetVirtualProperty()
- {
- return _virtualDependency.PropValue;
- }
- }
-
- public class VirtualDependency
- {
- private readonly IDependency _dependency;
-
- public VirtualDependency()
- {
- }
-
- public VirtualDependency(IDependency dependency)
- {
- _dependency = dependency;
- }
-
- public string PropValue { get; set; }
-
- public virtual string VirtualMethod()
- {
- return "hello";
- }
- }
-}
\ No newline at end of file
diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index 97048a860..dd19dde3b 100644
--- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -122,7 +122,6 @@
-
Code
diff --git a/NzbDrone/Application.cs b/NzbDrone/Application.cs
index 8c90cfa42..13fe665cf 100644
--- a/NzbDrone/Application.cs
+++ b/NzbDrone/Application.cs
@@ -2,6 +2,7 @@
using System.Net;
using System.Threading;
using NLog;
+using Ninject;
using NzbDrone.Providers;
namespace NzbDrone
@@ -11,22 +12,20 @@ namespace NzbDrone
private static readonly Logger Logger = LogManager.GetLogger("Host.App");
private readonly ConfigProvider _configProvider;
- private readonly ConsoleProvider _consoleProvider;
private readonly DebuggerProvider _debuggerProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly IISProvider _iisProvider;
private readonly ProcessProvider _processProvider;
private readonly WebClient _webClient;
+ [Inject]
public Application(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider,
- ConsoleProvider consoleProvider,
DebuggerProvider debuggerProvider, EnviromentProvider enviromentProvider,
ProcessProvider processProvider)
{
_configProvider = configProvider;
_webClient = webClient;
_iisProvider = iisProvider;
- _consoleProvider = consoleProvider;
_debuggerProvider = debuggerProvider;
_enviromentProvider = enviromentProvider;
_processProvider = processProvider;
@@ -37,7 +36,11 @@ namespace NzbDrone
Thread.CurrentThread.Name = "Host";
}
- public void Start()
+ public Application()
+ {
+ }
+
+ public virtual void Start()
{
_iisProvider.StopServer();
_iisProvider.StartServer();
@@ -55,23 +58,25 @@ namespace NzbDrone
{
Logger.ErrorException("Failed to open URL in default browser.", e);
}
-
- _consoleProvider.WaitForClose();
- return;
- }
-
- try
- {
- _webClient.DownloadString(_iisProvider.AppUrl);
}
- catch (Exception e)
+ else
{
- Logger.ErrorException("Failed to load home page.", e);
+ try
+ {
+ _webClient.DownloadString(_iisProvider.AppUrl);
+ }
+ catch (Exception e)
+ {
+ Logger.ErrorException("Failed to load home page.", e);
+ }
}
}
- public void Stop()
+ public virtual void Stop()
{
+ Logger.Info("Attempting to stop application.");
+ _iisProvider.StopServer();
+ Logger.Info("Application has finished stop routine.");
}
}
}
\ No newline at end of file
diff --git a/NzbDrone/ApplicationMode.cs b/NzbDrone/ApplicationMode.cs
new file mode 100644
index 000000000..7bd8835c6
--- /dev/null
+++ b/NzbDrone/ApplicationMode.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace NzbDrone
+{
+ public enum ApplicationMode
+ {
+ Console,
+ Help,
+ InstallService,
+ UninstallService
+ }
+}
diff --git a/NzbDrone/Console.cs b/NzbDrone/Console.cs
new file mode 100644
index 000000000..0da1cfc03
--- /dev/null
+++ b/NzbDrone/Console.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Linq;
+using System.Reflection;
+using NLog;
+using Ninject;
+using NzbDrone.Providers;
+
+namespace NzbDrone
+{
+ public static class Console
+ {
+ private static readonly StandardKernel Kernel = new StandardKernel();
+
+ private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
+
+ private static void Main(string[] args)
+ {
+ try
+ {
+ System.Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
+
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+ Kernel.Bind().ToSelf().InSingletonScope();
+
+ Kernel.Bind().ToConstant(GetApplicationMode(args));
+
+ Kernel.Get().Route();
+ }
+ catch (Exception e)
+ {
+ System.Console.WriteLine(e.ToString());
+ Logger.Fatal(e.ToString());
+ }
+
+ System.Console.WriteLine("Press enter to exit.");
+ System.Console.ReadLine();
+ }
+
+ public static ApplicationMode GetApplicationMode(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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj
index b7f3cdc3f..63449e4ea 100644
--- a/NzbDrone/NzbDrone.csproj
+++ b/NzbDrone/NzbDrone.csproj
@@ -86,6 +86,7 @@
+
@@ -96,12 +97,13 @@
-
+
+
diff --git a/NzbDrone/NzbDroneService.cs b/NzbDrone/NzbDroneService.cs
index 1fa341161..3f1cdf35c 100644
--- a/NzbDrone/NzbDroneService.cs
+++ b/NzbDrone/NzbDroneService.cs
@@ -12,6 +12,6 @@ namespace NzbDrone
protected override void OnStop()
{
base.OnStop();
- }
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone/ProcessInfo.cs b/NzbDrone/ProcessInfo.cs
index 5a287b970..858989d70 100644
--- a/NzbDrone/ProcessInfo.cs
+++ b/NzbDrone/ProcessInfo.cs
@@ -7,7 +7,5 @@ namespace NzbDrone
public int Id { get; set; }
public ProcessPriorityClass Priority { get; set; }
public string StartPath { get; set; }
-
- public bool HasExited { get; set; }
}
}
\ No newline at end of file
diff --git a/NzbDrone/Program.cs b/NzbDrone/Program.cs
deleted file mode 100644
index acd830e37..000000000
--- a/NzbDrone/Program.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using System;
-using System.Reflection;
-using NLog;
-using Ninject;
-using NzbDrone.Providers;
-
-namespace NzbDrone
-{
- public static class Program
- {
- public static readonly StandardKernel Kernel = new StandardKernel();
-
- private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
-
- private static void Main()
- {
- try
- {
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
- Kernel.Bind().ToSelf().InSingletonScope();
-
- Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
- Kernel.Get().Start();
- Kernel.Get().Start();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- Logger.Fatal(e.ToString());
- }
-
- Console.WriteLine("Press enter to exit.");
- Console.ReadLine();
- }
- }
-}
\ No newline at end of file
diff --git a/NzbDrone/Providers/ConsoleProvider.cs b/NzbDrone/Providers/ConsoleProvider.cs
index d49586ab1..e5b98643d 100644
--- a/NzbDrone/Providers/ConsoleProvider.cs
+++ b/NzbDrone/Providers/ConsoleProvider.cs
@@ -8,8 +8,13 @@ namespace NzbDrone.Providers
{
while (true)
{
- Console.ReadLine();
+ System.Console.ReadLine();
}
}
+
+ public virtual void PrintHelp()
+ {
+ System.Console.WriteLine("Help");
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs
index ce2478f7d..0e78fd8b3 100644
--- a/NzbDrone/Providers/IISProvider.cs
+++ b/NzbDrone/Providers/IISProvider.cs
@@ -120,7 +120,7 @@ namespace NzbDrone.Providers
if (e.Data.Contains(" NzbDrone."))
{
- Console.WriteLine(e.Data);
+ System.Console.WriteLine(e.Data);
return;
}
diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs
index 55c80d0af..fecd3de10 100644
--- a/NzbDrone/Providers/MonitoringProvider.cs
+++ b/NzbDrone/Providers/MonitoringProvider.cs
@@ -103,7 +103,7 @@ namespace NzbDrone.Providers
private static void AppDomainException(object excepion)
{
- Console.WriteLine("EPIC FAIL: {0}", excepion);
+ System.Console.WriteLine("EPIC FAIL: {0}", excepion);
Logger.Fatal("EPIC FAIL: {0}", excepion);
#if RELEASE
diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs
new file mode 100644
index 000000000..56d0a88b6
--- /dev/null
+++ b/NzbDrone/Router.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NzbDrone.Providers;
+
+namespace NzbDrone
+{
+ class Router
+ {
+ private readonly Application _application;
+ private readonly ServiceProvider _serviceProvider;
+ private readonly ConsoleProvider _consoleProvider;
+ private readonly ApplicationMode _applicationMode;
+
+
+ public Router(Application application, ServiceProvider serviceProvider, ConsoleProvider consoleProvider, ApplicationMode applicationMode)
+ {
+ _application = application;
+ _serviceProvider = serviceProvider;
+ _consoleProvider = consoleProvider;
+ _applicationMode = applicationMode;
+ }
+
+ public void Route()
+ {
+ switch (_applicationMode)
+ {
+ case ApplicationMode.Console:
+ {
+ _application.Start();
+ _consoleProvider.WaitForClose();
+ break;
+ }
+ case ApplicationMode.InstallService:
+ {
+ _serviceProvider.Install();
+ break;
+ }
+ case ApplicationMode.UninstallService:
+ {
+ _serviceProvider.UnInstall();
+ break;
+ }
+ default:
+ {
+ _consoleProvider.PrintHelp();
+ break;
+ }
+ }
+ }
+ }
+}