Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus

pull/4/head
Mark McDowall 13 years ago
commit 4915b32cc6

3
.gitignore vendored

@ -36,4 +36,5 @@ _ReSharper*/
*Web.Publish.xml
NzbDrone.Web/NzbDrone.Web.Publish.xml
*.sdf
[Bb]anners
[Bb]anners
*.orig

@ -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<ApplicationServer>();
appServer.Should().NotBeNull();
}
}
}

@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -49,6 +50,7 @@
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="Ninject, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
@ -72,6 +74,7 @@
<Compile Include="AutoMoq\AutoMoqerTest.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
<Compile Include="CentralDispatchTests.cs" />
<Compile Include="ProgramTest.cs" />
<Compile Include="MonitoringProviderTest.cs" />
<Compile Include="ConfigProviderTest.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);
}
}
}

@ -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));
}
}
}

@ -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<QualityProvider>().SetupDefaultProfiles();

@ -1,5 +1,5 @@
@using NzbDrone.Core
<div>
NZBDrone (@CentralDispatch.Version)
NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy"))
</div>

@ -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()
{
}

@ -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<ConfigProvider>().ToSelf().InSingletonScope();
_kernel.Bind<ConsoleProvider>().ToSelf().InSingletonScope();
_kernel.Bind<DebuggerProvider>().ToSelf().InSingletonScope();
_kernel.Bind<EnviromentProvider>().ToSelf().InSingletonScope();
_kernel.Bind<IISProvider>().ToSelf().InSingletonScope();
_kernel.Bind<MonitoringProvider>().ToSelf().InSingletonScope();
_kernel.Bind<ProcessProvider>().ToSelf().InSingletonScope();
_kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
_kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
}
private static void InitilizeApp()
{
_kernel.Get<ConfigProvider>().ConfigureNlog();
_kernel.Get<ConfigProvider>().CreateDefaultConfigFile();
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _kernel.Get<EnviromentProvider>().ApplicationPath);
Thread.CurrentThread.Name = "Host";
}
}
}

@ -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<ConfigProvider>().ToSelf().InSingletonScope();
Kernel.Bind<ConsoleProvider>().ToSelf().InSingletonScope();
Kernel.Bind<DebuggerProvider>().ToSelf().InSingletonScope();
Kernel.Bind<EnviromentProvider>().ToSelf().InSingletonScope();
Kernel.Bind<IISProvider>().ToSelf().InSingletonScope();
Kernel.Bind<MonitoringProvider>().ToSelf().InSingletonScope();
Kernel.Bind<ProcessProvider>().ToSelf().InSingletonScope();
Kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
Kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
Kernel.Bind<ApplicationMode>().ToConstant(GetApplicationMode(args));
Kernel.Get<Router>().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;
}
}
}

@ -30,7 +30,7 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@ -85,7 +85,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="ApplicationServer.cs" />
<Compile Include="CentralDispatch.cs" />
<Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="Model\ProcessInfo.cs" />
@ -98,7 +99,7 @@
<Compile Include="ProcessAttacher.cs" />
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\IISProvider.cs" />
<Compile Include="Console.cs" />
<Compile Include="NzbDroneConsole.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />
<Compile Include="Providers\ProcessProvider.cs" />

@ -1,154 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone</RootNamespace>
<AssemblyName>NzbDrone</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<CodeAnalysisRuleSet>BasicCorrectnessRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Exceptioneer.WindowsFormsClient, Version=1.0.0.812, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
</Reference>
<Reference Include="Ninject">
<HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<<<<<<< HEAD
<Compile Include="ApplicationMode.cs" />
=======
<Compile Include="Model\AuthenticationType.cs" />
>>>>>>> markus
<Compile Include="ProcessInfo.cs" />
<Compile Include="Providers\ConsoleProvider.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
<Compile Include="NzbDroneService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ProcessAttacher.cs" />
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\IISProvider.cs" />
<Compile Include="Console.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />
<Compile Include="Providers\ProcessProvider.cs" />
<Compile Include="Providers\ServiceProvider.cs" />
<Compile Include="Providers\WebClientProvider.cs" />
<Compile Include="Router.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="NzbDrone.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -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<Router>().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<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;
}
}
}

@ -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<ApplicationServer>().Start();
}
protected override void OnStop()
{
base.OnStop();
}
CentralDispatch.Kernel.Get<ApplicationServer>().Stop();
}
}
}

@ -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;
}

Loading…
Cancel
Save