Merge branch kay.one into markus.
This commit is contained in:
commit
b695a4433e
|
@ -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;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using FizzWare.NBuilder;
|
|||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Model;
|
||||
using NzbDrone.Providers;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<Compile Include="AutoMoq\AutoMoqerTest.cs" />
|
||||
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
||||
<Compile Include="ProgramTest.cs" />
|
||||
<Compile Include="MonitoringProviderTest.cs" />
|
||||
<Compile Include="ConfigProviderTest.cs" />
|
||||
<Compile Include="IISProviderTest.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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<IDependency>();
|
||||
|
||||
//Assert
|
||||
Assert.IsNotNull(mock);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMock_on_concrete_returns_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var mock = mocker.GetMock<ConcreteClass>();
|
||||
|
||||
//Assert
|
||||
Assert.IsNotNull(mock);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Resolve_doesnt_return_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConcreteClass>().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<VirtualDependency>().VirtualMethod();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("hello", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Resolve_with_mocked_dependency_uses_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<VirtualDependency>()
|
||||
.Setup(m => m.VirtualMethod())
|
||||
.Returns("mocked");
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ClassWithVirtualDependencies>().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<ClassWithVirtualDependencies>().CallVirtualChild();
|
||||
|
||||
var mockedResult = new Mock<VirtualDependency>().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<ClassWithVirtualDependencies>().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";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -122,7 +122,6 @@
|
|||
<Compile Include="IndexerTests.cs" />
|
||||
<Compile Include="InventoryProvider_QualityNeededTest.cs" />
|
||||
<Compile Include="Framework\AutoMoq\AutoMoqer.cs" />
|
||||
<Compile Include="Framework\AutoMoq\AutoMoqerTest.cs" />
|
||||
<Compile Include="Framework\AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -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
|
||||
else
|
||||
{
|
||||
_webClient.DownloadString(_iisProvider.AppUrl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace NzbDrone.Model
|
||||
{
|
||||
public enum ApplicationMode
|
||||
{
|
||||
Console,
|
||||
Help,
|
||||
InstallService,
|
||||
UninstallService
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -86,8 +86,9 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Application.cs" />
|
||||
<Compile Include="Model\ApplicationMode.cs" />
|
||||
<Compile Include="Model\AuthenticationType.cs" />
|
||||
<Compile Include="ProcessInfo.cs" />
|
||||
<Compile Include="Model\ProcessInfo.cs" />
|
||||
<Compile Include="Providers\ConsoleProvider.cs" />
|
||||
<Compile Include="Providers\DebuggerProvider.cs" />
|
||||
<Compile Include="Providers\EnviromentProvider.cs" />
|
||||
|
@ -97,12 +98,13 @@
|
|||
<Compile Include="ProcessAttacher.cs" />
|
||||
<Compile Include="Providers\ConfigProvider.cs" />
|
||||
<Compile Include="Providers\IISProvider.cs" />
|
||||
<Compile Include="Program.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" />
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
<?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>
|
|
@ -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<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();
|
||||
|
||||
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
|
||||
Kernel.Get<MonitoringProvider>().Start();
|
||||
Kernel.Get<Application>().Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
Logger.Fatal(e.ToString());
|
||||
}
|
||||
|
||||
Console.WriteLine("Press enter to exit.");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,8 +8,13 @@ namespace NzbDrone.Providers
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
Console.ReadLine();
|
||||
System.Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void PrintHelp()
|
||||
{
|
||||
System.Console.WriteLine("Help");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,7 +120,7 @@ namespace NzbDrone.Providers
|
|||
|
||||
if (e.Data.Contains(" NzbDrone."))
|
||||
{
|
||||
Console.WriteLine(e.Data);
|
||||
System.Console.WriteLine(e.Data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Model;
|
||||
|
||||
namespace NzbDrone.Providers
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue