From ba11b3409903b1a9327343c66bd0c5e17673a14f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 11 Oct 2011 00:11:05 -0700 Subject: [PATCH 1/4] Service (work in progress) --- NzbDrone.App.Test/CentralDispatchTests.cs | 40 ++++++++++++ NzbDrone.App.Test/NzbDrone.App.Test.csproj | 2 + NzbDrone.App.Test/ProgramTest.cs | 4 +- .../{Application.cs => ApplicationServer.cs} | 11 +--- NzbDrone/CentralDispatch.cs | 53 ++++++++++++++++ NzbDrone/Console.cs | 63 ------------------- NzbDrone/NzbDrone.csproj | 5 +- NzbDrone/NzbDroneConsole.cs | 53 ++++++++++++++++ NzbDrone/NzbDroneService.cs | 7 ++- NzbDrone/Router.cs | 15 ++--- 10 files changed, 166 insertions(+), 87 deletions(-) create mode 100644 NzbDrone.App.Test/CentralDispatchTests.cs rename NzbDrone/{Application.cs => ApplicationServer.cs} (84%) create mode 100644 NzbDrone/CentralDispatch.cs delete mode 100644 NzbDrone/Console.cs create mode 100644 NzbDrone/NzbDroneConsole.cs diff --git a/NzbDrone.App.Test/CentralDispatchTests.cs b/NzbDrone.App.Test/CentralDispatchTests.cs new file mode 100644 index 000000000..67d1790c8 --- /dev/null +++ b/NzbDrone.App.Test/CentralDispatchTests.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using FluentAssertions; +using NUnit.Framework; +using Ninject; +using NzbDrone.Providers; + +namespace NzbDrone.App.Test +{ + [TestFixture] + public class CentralDispatchTests + { + [Test] + public void Kernel_can_get_kernel() + { + CentralDispatch.Kernel.Should().NotBeNull(); + } + + [Test] + public void Kernel_should_return_same_kernel() + { + var firstKernel = CentralDispatch.Kernel; + var secondKernel = CentralDispatch.Kernel; + + firstKernel.Should().BeSameAs(secondKernel); + } + + [Test] + public void Kernel_should_be_able_to_resolve_ApplicationServer() + { + var appServer = CentralDispatch.Kernel.Get(); + + appServer.Should().NotBeNull(); + } + + } +} diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index efcc045e1..12b6df60f 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -49,6 +49,7 @@ ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll + ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll @@ -72,6 +73,7 @@ + diff --git a/NzbDrone.App.Test/ProgramTest.cs b/NzbDrone.App.Test/ProgramTest.cs index 388a3ab0e..464fad9d4 100644 --- a/NzbDrone.App.Test/ProgramTest.cs +++ b/NzbDrone.App.Test/ProgramTest.cs @@ -29,7 +29,7 @@ namespace NzbDrone.App.Test [TestCase("-u", ApplicationMode.UninstallService)] public void GetApplicationMode_single_arg(string arg, ApplicationMode mode) { - Console.GetApplicationMode(new[] { arg }).Should().Be(mode); + NzbDroneConsole.GetApplicationMode(new[] { arg }).Should().Be(mode); } [TestCase("", "", ApplicationMode.Console)] @@ -37,7 +37,7 @@ namespace NzbDrone.App.Test [TestCase("i", "n", ApplicationMode.Help)] public void GetApplicationMode_two_args(string a, string b, ApplicationMode mode) { - Console.GetApplicationMode(new[] { a, b }).Should().Be(mode); + NzbDroneConsole.GetApplicationMode(new[] { a, b }).Should().Be(mode); } } } diff --git a/NzbDrone/Application.cs b/NzbDrone/ApplicationServer.cs similarity index 84% rename from NzbDrone/Application.cs rename to NzbDrone/ApplicationServer.cs index 13fe665cf..41665b52d 100644 --- a/NzbDrone/Application.cs +++ b/NzbDrone/ApplicationServer.cs @@ -7,7 +7,7 @@ using NzbDrone.Providers; namespace NzbDrone { - public class Application + public class ApplicationServer { private static readonly Logger Logger = LogManager.GetLogger("Host.App"); @@ -19,7 +19,7 @@ namespace NzbDrone private readonly WebClient _webClient; [Inject] - public Application(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider, + public ApplicationServer(ConfigProvider configProvider, WebClient webClient, IISProvider iisProvider, DebuggerProvider debuggerProvider, EnviromentProvider enviromentProvider, ProcessProvider processProvider) { @@ -29,14 +29,9 @@ namespace NzbDrone _debuggerProvider = debuggerProvider; _enviromentProvider = enviromentProvider; _processProvider = processProvider; - - _configProvider.ConfigureNlog(); - _configProvider.CreateDefaultConfigFile(); - Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _enviromentProvider.ApplicationPath); - Thread.CurrentThread.Name = "Host"; } - public Application() + public ApplicationServer() { } diff --git a/NzbDrone/CentralDispatch.cs b/NzbDrone/CentralDispatch.cs new file mode 100644 index 000000000..a0a55dfd4 --- /dev/null +++ b/NzbDrone/CentralDispatch.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using Ninject; +using NzbDrone.Model; +using NzbDrone.Providers; + +namespace NzbDrone +{ + public static class CentralDispatch + { + private static StandardKernel _kernel; + + static CentralDispatch() + { + _kernel = new StandardKernel(); + } + + public static ApplicationMode ApplicationMode { get; set; } + + public static StandardKernel Kernel + { + get + { + return _kernel; + } + } + + private static void BindKernel() + { + _kernel = new StandardKernel(); + _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(); + } + + private static void InitilizeApp() + { + _kernel.Get().ConfigureNlog(); + _kernel.Get().CreateDefaultConfigFile(); + Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _kernel.Get().ApplicationPath); + Thread.CurrentThread.Name = "Host"; + } + } +} diff --git a/NzbDrone/Console.cs b/NzbDrone/Console.cs deleted file mode 100644 index 8c32dea47..000000000 --- a/NzbDrone/Console.cs +++ /dev/null @@ -1,63 +0,0 @@ -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/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index d3a1b88be..191e1fd4c 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -85,7 +85,8 @@ - + + @@ -98,7 +99,7 @@ - + diff --git a/NzbDrone/NzbDroneConsole.cs b/NzbDrone/NzbDroneConsole.cs new file mode 100644 index 000000000..a0f6f1422 --- /dev/null +++ b/NzbDrone/NzbDroneConsole.cs @@ -0,0 +1,53 @@ +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().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 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/NzbDroneService.cs b/NzbDrone/NzbDroneService.cs index 3f1cdf35c..c2d41b092 100644 --- a/NzbDrone/NzbDroneService.cs +++ b/NzbDrone/NzbDroneService.cs @@ -1,4 +1,5 @@ using System.ServiceProcess; +using Ninject; namespace NzbDrone { @@ -6,12 +7,12 @@ namespace NzbDrone { protected override void OnStart(string[] args) { - base.OnStart(args); + CentralDispatch.Kernel.Get().Start(); } protected override void OnStop() { - base.OnStop(); - } + CentralDispatch.Kernel.Get().Stop(); + } } } \ No newline at end of file diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs index a03b0c9a3..bb1065bc5 100644 --- a/NzbDrone/Router.cs +++ b/NzbDrone/Router.cs @@ -9,27 +9,24 @@ namespace NzbDrone { class Router { - private readonly Application _application; + private readonly ApplicationServer _applicationServer; private readonly ServiceProvider _serviceProvider; private readonly ConsoleProvider _consoleProvider; - private readonly ApplicationMode _applicationMode; - - public Router(Application application, ServiceProvider serviceProvider, ConsoleProvider consoleProvider, ApplicationMode applicationMode) + public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider, ConsoleProvider consoleProvider) { - _application = application; + _applicationServer = applicationServer; _serviceProvider = serviceProvider; - _consoleProvider = consoleProvider; - _applicationMode = applicationMode; + _consoleProvider = consoleProvider; } public void Route() { - switch (_applicationMode) + switch (CentralDispatch.ApplicationMode) { case ApplicationMode.Console: { - _application.Start(); + _applicationServer.Start(); _consoleProvider.WaitForClose(); break; } From b6360eba261362831cff5bdff641cd79fc2c28f6 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 11 Oct 2011 00:14:46 -0700 Subject: [PATCH 2/4] orig file are added to .gitignore --- .gitignore | 3 +- NzbDrone/NzbDrone.csproj.orig | 154 ---------------------------------- 2 files changed, 2 insertions(+), 155 deletions(-) delete mode 100644 NzbDrone/NzbDrone.csproj.orig diff --git a/.gitignore b/.gitignore index acbce3bc6..dc442bdbe 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ _ReSharper*/ *Web.Publish.xml NzbDrone.Web/NzbDrone.Web.Publish.xml *.sdf -[Bb]anners \ No newline at end of file +[Bb]anners +*.orig \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj.orig b/NzbDrone/NzbDrone.csproj.orig deleted file mode 100644 index 2f3a2bcbb..000000000 --- a/NzbDrone/NzbDrone.csproj.orig +++ /dev/null @@ -1,154 +0,0 @@ - - - - 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 From 1ba959298b0d273742a9d582baff62137913c907 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 11 Oct 2011 19:24:43 -0700 Subject: [PATCH 3/4] Added BuildDateTime to central dispatch --- NzbDrone.Core.Test/CentralDispatchTest.cs | 6 ++++++ NzbDrone.Core/CentralDispatch.cs | 14 +++++++++++++- NzbDrone/CentralDispatch.cs | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/NzbDrone.Core.Test/CentralDispatchTest.cs b/NzbDrone.Core.Test/CentralDispatchTest.cs index 3df09023d..2b670fdfe 100644 --- a/NzbDrone.Core.Test/CentralDispatchTest.cs +++ b/NzbDrone.Core.Test/CentralDispatchTest.cs @@ -90,5 +90,11 @@ namespace NzbDrone.Core.Test { CentralDispatch.Version.Should().NotBeNull(); } + + [Test] + public void BuildDate_should_be_today() + { + CentralDispatch.BuildDateTime.Should().BeWithin(TimeSpan.FromHours(10)); + } } } diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 6eccb3a2c..c458bb02a 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -29,6 +29,17 @@ namespace NzbDrone.Core get { return Assembly.GetExecutingAssembly().GetName().Version; } } + + public static DateTime BuildDateTime + { + get + { + var fileLocation = Assembly.GetCallingAssembly().Location; + return new FileInfo(fileLocation).CreationTime; + } + + } + public static String AppPath { get @@ -53,12 +64,13 @@ namespace NzbDrone.Core } } + public static void InitializeApp() { BindKernel(); MigrationsHelper.Run(Connection.MainConnectionString, true); - + LogConfiguration.StartDbLogging(); _kernel.Get().SetupDefaultProfiles(); diff --git a/NzbDrone/CentralDispatch.cs b/NzbDrone/CentralDispatch.cs index a0a55dfd4..bc2df874f 100644 --- a/NzbDrone/CentralDispatch.cs +++ b/NzbDrone/CentralDispatch.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using NLog; using Ninject; using NzbDrone.Model; using NzbDrone.Providers; @@ -12,6 +13,7 @@ namespace NzbDrone public static class CentralDispatch { private static StandardKernel _kernel; + private static readonly Logger Logger = LogManager.GetLogger("Host.CentralDispatch"); static CentralDispatch() { From 87fe19ab4e4c413bd07ea85b03bfce940833d611 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 11 Oct 2011 19:39:46 -0700 Subject: [PATCH 4/4] Added compile date to footer --- NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 + NzbDrone.Core.Test/CentralDispatchTest.cs | 4 ++-- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 +- NzbDrone.Web/Views/Shared/Footer.cshtml | 2 +- NzbDrone/NzbDrone.csproj | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 12b6df60f..fe0aa62d4 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + x86 pdbonly diff --git a/NzbDrone.Core.Test/CentralDispatchTest.cs b/NzbDrone.Core.Test/CentralDispatchTest.cs index 2b670fdfe..2dc3b8b02 100644 --- a/NzbDrone.Core.Test/CentralDispatchTest.cs +++ b/NzbDrone.Core.Test/CentralDispatchTest.cs @@ -92,9 +92,9 @@ namespace NzbDrone.Core.Test } [Test] - public void BuildDate_should_be_today() + public void BuildDate_should_be_within_the_hour() { - CentralDispatch.BuildDateTime.Should().BeWithin(TimeSpan.FromHours(10)); + CentralDispatch.BuildDateTime.Should().BeWithin(TimeSpan.FromHours(1)); } } } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index dd19dde3b..dc45e4208 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -21,7 +21,7 @@ DEBUG;TRACE prompt 4 - AnyCPU + x86 pdbonly diff --git a/NzbDrone.Web/Views/Shared/Footer.cshtml b/NzbDrone.Web/Views/Shared/Footer.cshtml index 6a9e0c00a..a98c88721 100644 --- a/NzbDrone.Web/Views/Shared/Footer.cshtml +++ b/NzbDrone.Web/Views/Shared/Footer.cshtml @@ -1,5 +1,5 @@ @using NzbDrone.Core
- NZBDrone (@CentralDispatch.Version) + NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy"))
diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 191e1fd4c..329dde2c8 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -30,7 +30,7 @@ true
- AnyCPU + x86 true full false