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/MonitoringProviderTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs index 0713810c5..f2439d9d4 100644 --- a/NzbDrone.App.Test/MonitoringProviderTest.cs +++ b/NzbDrone.App.Test/MonitoringProviderTest.cs @@ -8,6 +8,7 @@ using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Model; using NzbDrone.Providers; namespace NzbDrone.App.Test 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..388a3ab0e --- /dev/null +++ b/NzbDrone.App.Test/ProgramTest.cs @@ -0,0 +1,43 @@ +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) + { + 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/Console.cs b/NzbDrone/Console.cs new file mode 100644 index 000000000..8c32dea47 --- /dev/null +++ b/NzbDrone/Console.cs @@ -0,0 +1,63 @@ +using System; +using System.Linq; +using System.Reflection; +using NLog; +using Ninject; +using NzbDrone.Model; +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/Model/ApplicationMode.cs b/NzbDrone/Model/ApplicationMode.cs new file mode 100644 index 000000000..58eccb381 --- /dev/null +++ b/NzbDrone/Model/ApplicationMode.cs @@ -0,0 +1,10 @@ +namespace NzbDrone.Model +{ + public enum ApplicationMode + { + Console, + Help, + InstallService, + UninstallService + } +} diff --git a/NzbDrone/ProcessInfo.cs b/NzbDrone/Model/ProcessInfo.cs similarity index 76% rename from NzbDrone/ProcessInfo.cs rename to NzbDrone/Model/ProcessInfo.cs index 5a287b970..f1086c2ab 100644 --- a/NzbDrone/ProcessInfo.cs +++ b/NzbDrone/Model/ProcessInfo.cs @@ -1,13 +1,11 @@ using System.Diagnostics; -namespace NzbDrone +namespace NzbDrone.Model { public class ProcessInfo { 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/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 0a0f3c79a..d3a1b88be 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -86,8 +86,9 @@ + - + @@ -97,12 +98,13 @@ - + + diff --git a/NzbDrone/NzbDrone.csproj.orig b/NzbDrone/NzbDrone.csproj.orig new file mode 100644 index 000000000..2f3a2bcbb --- /dev/null +++ b/NzbDrone/NzbDrone.csproj.orig @@ -0,0 +1,154 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869} + Exe + Properties + NzbDrone + NzbDrone + v4.0 + 512 + + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + BasicCorrectnessRules.ruleset + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + NzbDrone.ico + + + + True + + + True + + + True + + + False + ..\Libraries\Exceptioneer.WindowsFormsClient.dll + + + ..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll + + + False + ..\Libraries\NLog.dll + + + + + + + + + + + + + +<<<<<<< HEAD + +======= + +>>>>>>> markus + + + + + + Component + + + + + + + + + + + + + + + + + + + + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + + + + + + \ No newline at end of file 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/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/ConfigProvider.cs b/NzbDrone/Providers/ConfigProvider.cs index b53590ef5..3e4cf5dd6 100644 --- a/NzbDrone/Providers/ConfigProvider.cs +++ b/NzbDrone/Providers/ConfigProvider.cs @@ -69,7 +69,6 @@ namespace NzbDrone.Providers public virtual AuthenticationType AuthenticationType { get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); } - set { SetValue("AuthenticationType", (int)value); } } public virtual void ConfigureNlog() diff --git a/NzbDrone/Providers/ConfigProvider.cs.orig b/NzbDrone/Providers/ConfigProvider.cs.orig new file mode 100644 index 000000000..f1e6db1be --- /dev/null +++ b/NzbDrone/Providers/ConfigProvider.cs.orig @@ -0,0 +1,228 @@ +using System; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using System.Xml.XPath; +using NLog; +using NLog.Config; +<<<<<<< HEAD +using Ninject; +======= +using NzbDrone.Model; +>>>>>>> markus + +namespace NzbDrone.Providers +{ + public class ConfigProvider + { + private readonly EnviromentProvider _enviromentProvider; + private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider"); + + [Inject] + public ConfigProvider(EnviromentProvider enviromentProvider) + { + _enviromentProvider = enviromentProvider; + } + + public ConfigProvider() + { + + } + + public virtual int PortNumber + { + get { return GetValueInt("Port", 8989); } + } + + public virtual bool LaunchBrowser + { + get { return GetValueBoolean("LaunchBrowser", true); } + } + + public virtual string IISDirectory + { + get { return Path.Combine(_enviromentProvider.ApplicationPath, "IISExpress"); } + } + + public virtual string IISExePath + { + get { return Path.Combine(IISDirectory, "iisexpress.exe"); } + } + + public virtual string IISConfigPath + { + get { return Path.Combine(IISDirectory, "AppServer", "applicationhost.config"); } + } + + public virtual string AppDataDirectory + { + get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web", "App_Data"); } + } + + public virtual string ConfigFile + { + get { return Path.Combine(AppDataDirectory, "Config.xml"); } + } + + public virtual string NlogConfigPath + { + get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); } + } + +<<<<<<< HEAD +======= + public virtual AuthenticationType AuthenticationType + { + get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); } + set { SetValue("AuthenticationType", (int)value); } + } +>>>>>>> markus + + public virtual void ConfigureNlog() + { + LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false); + } + + public virtual void UpdateIISConfig(string configPath) + { + Logger.Info(@"Server configuration file: {0}", configPath); + Logger.Info(@"Configuring server to: [http://localhost:{0}]", PortNumber); + + var configXml = XDocument.Load(configPath); + + var bindings = + configXml.XPathSelectElement("configuration/system.applicationHost/sites").Elements("site").Where( + d => d.Attribute("name").Value.ToLowerInvariant() == "nzbdrone").First().Element("bindings"); + bindings.Descendants().Remove(); + bindings.Add( + new XElement("binding", + new XAttribute("protocol", "http"), + new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber)) + )); + + bindings.Add( + new XElement("binding", + new XAttribute("protocol", "http"), + new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber)) + )); + + //Update the authenticationTypes + + var location = configXml.XPathSelectElement("configuration").Elements("location").Where( + d => d.Attribute("path").Value.ToLowerInvariant() == "nzbdrone").First(); + + + var authenticationTypes = location.XPathSelectElements("system.webServer/security/authentication").First().Descendants(); + + //Set all authentication types enabled to false + foreach (var child in authenticationTypes) + { + child.Attribute("enabled").Value = "false"; + } + + var configuredAuthType = String.Format("{0}Authentication", AuthenticationType.ToString()).ToLowerInvariant(); + + //Set the users authenticationType to true + authenticationTypes.Where(t => t.Name.ToString().ToLowerInvariant() == configuredAuthType).Single().Attribute("enabled").Value = "true"; + + configXml.Save(configPath); + } + + public virtual void CreateDefaultConfigFile() + { + //Create the config file here + Directory.CreateDirectory(AppDataDirectory); + + if (!File.Exists(ConfigFile)) + { + WriteDefaultConfig(); + } + } + +<<<<<<< HEAD + private void WriteDefaultConfig() +======= + public virtual string GetValue(string key, object defaultValue, string parent = null) +>>>>>>> markus + { + var xDoc = XDocument.Load(ConfigFile); + var config = xDoc.Descendants("Config").Single(); + + var parentContainer = config; + + if (!String.IsNullOrEmpty(parent)) + { + //Add the parent + if (config.Descendants(parent).Count() != 1) + { + SetValue(key, defaultValue, parent); + + //Reload the configFile + xDoc = XDocument.Load(ConfigFile); + config = xDoc.Descendants("Config").Single(); + } + + parentContainer = config.Descendants(parent).Single(); + } + + var valueHolder = parentContainer.Descendants(key).ToList(); + + if (valueHolder.Count() == 1) + return valueHolder.First().Value; + + //Save the value + SetValue(key, defaultValue, parent); + + //return the default value + return defaultValue.ToString(); + } + + public virtual int GetValueInt(string key, int defaultValue, string parent = null) + { + return Convert.ToInt32(GetValue(key, defaultValue, parent)); + } + + public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null) + { + return Convert.ToBoolean(GetValue(key, defaultValue, parent)); + } + + public virtual void SetValue(string key, object value, string parent = null) + { + var xDoc = XDocument.Load(ConfigFile); + var config = xDoc.Descendants("Config").Single(); + + var parentContainer = config; + + if (!String.IsNullOrEmpty(parent)) + { + //Add the parent container if it doesn't already exist + if (config.Descendants(parent).Count() != 1) + { + config.Add(new XElement(parent)); + } + + parentContainer = config.Descendants(parent).Single(); + } + + var keyHolder = parentContainer.Descendants(key); + + if (keyHolder.Count() != 1) + parentContainer.Add(new XElement(key, value)); + + else + parentContainer.Descendants(key).Single().Value = value.ToString(); + + xDoc.Save(ConfigFile); + } + + public virtual void WriteDefaultConfig() + { + var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); + + xDoc.Add(new XElement("Config")); + + xDoc.Save(ConfigFile); + } + } +} \ 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/Providers/ProcessProvider.cs b/NzbDrone/Providers/ProcessProvider.cs index fd12e3e68..da8822155 100644 --- a/NzbDrone/Providers/ProcessProvider.cs +++ b/NzbDrone/Providers/ProcessProvider.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using NLog; +using NzbDrone.Model; namespace NzbDrone.Providers { diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs new file mode 100644 index 000000000..a03b0c9a3 --- /dev/null +++ b/NzbDrone/Router.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NzbDrone.Model; +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; + } + } + } + } +}