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.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..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 @@ -49,6 +50,7 @@ ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll + ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll @@ -72,6 +74,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.Core.Test/CentralDispatchTest.cs b/NzbDrone.Core.Test/CentralDispatchTest.cs index 3df09023d..2dc3b8b02 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_within_the_hour() + { + CentralDispatch.BuildDateTime.Should().BeWithin(TimeSpan.FromHours(1)); + } } } 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.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/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..bc2df874f --- /dev/null +++ b/NzbDrone/CentralDispatch.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using NLog; +using Ninject; +using NzbDrone.Model; +using NzbDrone.Providers; + +namespace NzbDrone +{ + public static class CentralDispatch + { + private static StandardKernel _kernel; + private static readonly Logger Logger = LogManager.GetLogger("Host.CentralDispatch"); + + 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..329dde2c8 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -30,7 +30,7 @@ true
- AnyCPU + x86 true full false @@ -85,7 +85,8 @@ - + + @@ -98,7 +99,7 @@ - + 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 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; }