main app cleanup.

pull/2/head
Keivan Beigi 12 years ago committed by kay.one
parent da2c0d1d65
commit 8900bbb3a1

@ -11,14 +11,14 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Kernel_can_get_kernel() public void Kernel_can_get_kernel()
{ {
CentralDispatch.Container.Should().NotBeNull(); NzbDroneBootstrapper.Container.Should().NotBeNull();
} }
[Test] [Test]
public void Kernel_should_return_same_kernel() public void Kernel_should_return_same_kernel()
{ {
var firstKernel = CentralDispatch.Container; var firstKernel = NzbDroneBootstrapper.Container;
var secondKernel = CentralDispatch.Container; var secondKernel = NzbDroneBootstrapper.Container;
firstKernel.Should().BeSameAs(secondKernel); firstKernel.Should().BeSameAs(secondKernel);
} }
@ -26,7 +26,7 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Kernel_should_be_able_to_resolve_ApplicationServer() public void Kernel_should_be_able_to_resolve_ApplicationServer()
{ {
var appServer = CentralDispatch.Container.Resolve<ApplicationServer>(); var appServer = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
appServer.Should().NotBeNull(); appServer.Should().NotBeNull();
} }
@ -34,8 +34,8 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void Kernel_should_resolve_same_ApplicationServer_instance() public void Kernel_should_resolve_same_ApplicationServer_instance()
{ {
var appServer1 = CentralDispatch.Container.Resolve<ApplicationServer>(); var appServer1 = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
var appServer2 = CentralDispatch.Container.Resolve<ApplicationServer>(); var appServer2 = NzbDroneBootstrapper.Container.Resolve<ApplicationServer>();
appServer1.Should().BeSameAs(appServer2); appServer1.Should().BeSameAs(appServer2);
} }

@ -7,7 +7,6 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Model; using NzbDrone.Common.Model;
using NzbDrone.Providers;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test
@ -24,14 +23,14 @@ namespace NzbDrone.App.Test
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null); Mocker.GetMock<ProcessProvider>().Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
Mocker.Resolve<MonitoringProvider>().EnsurePriority(null); Mocker.Resolve<PriorityMonitor>().EnsurePriority(null);
} }
[Test] [Test]
public void Ensure_should_log_warn_exception_rather_than_throw() public void Ensure_should_log_warn_exception_rather_than_throw()
{ {
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess()).Throws<InvalidOperationException>(); Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess()).Throws<InvalidOperationException>();
Mocker.Resolve<MonitoringProvider>().EnsurePriority(null); Mocker.Resolve<PriorityMonitor>().EnsurePriority(null);
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }

@ -1,12 +1,9 @@
using System.IO; using System.ServiceProcess;
using System.ServiceProcess;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Model;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test
{ {
@ -14,34 +11,34 @@ namespace NzbDrone.App.Test
public class RouterTest : TestBase public class RouterTest : TestBase
{ {
[TestCase(null, ApplicationMode.Console)] [TestCase(null, ApplicationModes.Console)]
[TestCase("", ApplicationMode.Console)] [TestCase("", ApplicationModes.Console)]
[TestCase("1", ApplicationMode.Help)] [TestCase("1", ApplicationModes.Help)]
[TestCase("ii", ApplicationMode.Help)] [TestCase("ii", ApplicationModes.Help)]
[TestCase("uu", ApplicationMode.Help)] [TestCase("uu", ApplicationModes.Help)]
[TestCase("i", ApplicationMode.InstallService)] [TestCase("i", ApplicationModes.InstallService)]
[TestCase("I", ApplicationMode.InstallService)] [TestCase("I", ApplicationModes.InstallService)]
[TestCase("/I", ApplicationMode.InstallService)] [TestCase("/I", ApplicationModes.InstallService)]
[TestCase("/i", ApplicationMode.InstallService)] [TestCase("/i", ApplicationModes.InstallService)]
[TestCase("-I", ApplicationMode.InstallService)] [TestCase("-I", ApplicationModes.InstallService)]
[TestCase("-i", ApplicationMode.InstallService)] [TestCase("-i", ApplicationModes.InstallService)]
[TestCase("u", ApplicationMode.UninstallService)] [TestCase("u", ApplicationModes.UninstallService)]
[TestCase("U", ApplicationMode.UninstallService)] [TestCase("U", ApplicationModes.UninstallService)]
[TestCase("/U", ApplicationMode.UninstallService)] [TestCase("/U", ApplicationModes.UninstallService)]
[TestCase("/u", ApplicationMode.UninstallService)] [TestCase("/u", ApplicationModes.UninstallService)]
[TestCase("-U", ApplicationMode.UninstallService)] [TestCase("-U", ApplicationModes.UninstallService)]
[TestCase("-u", ApplicationMode.UninstallService)] [TestCase("-u", ApplicationModes.UninstallService)]
public void GetApplicationMode_single_arg(string arg, ApplicationMode mode) public void GetApplicationMode_single_arg(string arg, ApplicationModes modes)
{ {
Router.GetApplicationMode(new[] { arg }).Should().Be(mode); Router.GetApplicationMode(new[] { arg }).Should().Be(modes);
} }
[TestCase("", "", ApplicationMode.Console)] [TestCase("", "", ApplicationModes.Console)]
[TestCase("", null, ApplicationMode.Console)] [TestCase("", null, ApplicationModes.Console)]
[TestCase("i", "n", ApplicationMode.Help)] [TestCase("i", "n", ApplicationModes.Help)]
public void GetApplicationMode_two_args(string a, string b, ApplicationMode mode) public void GetApplicationMode_two_args(string a, string b, ApplicationModes modes)
{ {
Router.GetApplicationMode(new[] { a, b }).Should().Be(mode); Router.GetApplicationMode(new[] { a, b }).Should().Be(modes);
} }
[Test] [Test]
@ -53,7 +50,7 @@ namespace NzbDrone.App.Test
serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME)); serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME));
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
Mocker.Resolve<Router>().Route(ApplicationMode.InstallService); Mocker.Resolve<Router>().Route(ApplicationModes.InstallService);
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
} }
@ -67,7 +64,7 @@ namespace NzbDrone.App.Test
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true); serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
Mocker.Resolve<Router>().Route(ApplicationMode.UninstallService); Mocker.Resolve<Router>().Route(ApplicationModes.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once()); serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
} }
@ -81,17 +78,17 @@ namespace NzbDrone.App.Test
appServerProvider.Setup(c => c.Start()); appServerProvider.Setup(c => c.Start());
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
Mocker.Resolve<Router>().Route(ApplicationMode.Console); Mocker.Resolve<Router>().Route(ApplicationModes.Console);
consoleProvider.Verify(c => c.WaitForClose(), Times.Once()); consoleProvider.Verify(c => c.WaitForClose(), Times.Once());
appServerProvider.Verify(c => c.Start(), Times.Once()); appServerProvider.Verify(c => c.Start(), Times.Once());
} }
[TestCase(ApplicationMode.Console)] [TestCase(ApplicationModes.Console)]
[TestCase(ApplicationMode.InstallService)] [TestCase(ApplicationModes.InstallService)]
[TestCase(ApplicationMode.UninstallService)] [TestCase(ApplicationModes.UninstallService)]
[TestCase(ApplicationMode.Help)] [TestCase(ApplicationModes.Help)]
public void Route_should_call_service_start_when_run_in_service_more(ApplicationMode applicationMode) public void Route_should_call_service_start_when_run_in_service_more(ApplicationModes applicationModes)
{ {
var envMock = Mocker.GetMock<EnvironmentProvider>(); var envMock = Mocker.GetMock<EnvironmentProvider>();
var serviceProvider = Mocker.GetMock<ServiceProvider>(); var serviceProvider = Mocker.GetMock<ServiceProvider>();
@ -100,7 +97,7 @@ namespace NzbDrone.App.Test
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>())); serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
Mocker.Resolve<Router>().Route(applicationMode); Mocker.Resolve<Router>().Route(applicationModes);
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once()); serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
} }
@ -116,7 +113,7 @@ namespace NzbDrone.App.Test
consoleMock.Setup(c => c.PrintServiceAlreadyExist()); consoleMock.Setup(c => c.PrintServiceAlreadyExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
Mocker.Resolve<Router>().Route(ApplicationMode.InstallService); Mocker.Resolve<Router>().Route(ApplicationModes.InstallService);
Mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }
@ -131,7 +128,7 @@ namespace NzbDrone.App.Test
consoleMock.Setup(c => c.PrintServiceDoestExist()); consoleMock.Setup(c => c.PrintServiceDoestExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
Mocker.Resolve<Router>().Route(ApplicationMode.UninstallService); Mocker.Resolve<Router>().Route(ApplicationModes.UninstallService);
Mocker.VerifyAllMocks(); Mocker.VerifyAllMocks();
} }

@ -35,11 +35,12 @@ namespace NzbDrone.Common
public void StartServer() public void StartServer()
{ {
_host = new NancyHost(new Uri(AppUrl), _bootstrapper); _host = new NancyHost(new Uri(AppUrl), _bootstrapper);
_host.Start();
} }
public string AppUrl public string AppUrl
{ {
get { return string.Format("http://localhost:{0}/", _configFileProvider.Port); } get { return string.Format("http://localhost:{0}", _configFileProvider.Port); }
} }

@ -0,0 +1,24 @@
using System;
namespace NzbDrone.Console
{
public static class AppMain
{
public static void Main(string[] args)
{
try
{
NzbDrone.AppMain.Main(args);
}
catch(Exception e)
{
System.Console.WriteLine(e.ToString());
}
System.Console.WriteLine("Press enter to exit...");
System.Console.ReadLine();
}
}
}

@ -8,7 +8,7 @@
<ProjectGuid>{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}</ProjectGuid> <ProjectGuid>{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone</RootNamespace> <RootNamespace>NzbDrone.Console</RootNamespace>
<AssemblyName>NzbDrone.Console</AssemblyName> <AssemblyName>NzbDrone.Console</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
@ -36,7 +36,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>..\NzbDrone\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@ -55,75 +55,35 @@
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Release\</IntermediateOutputPath> <IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Release\</IntermediateOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon> <ApplicationIcon>
</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject>NzbDrone.AppMain</StartupObject> <StartupObject>NzbDrone.Console.AppMain</StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Exceptron.Client, Version=1.0.20.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.Nlog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Bootstrappers.Autofac, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.Bootstrappers.Autofac.0.16.1\lib\net40\Nancy.Bootstrappers.Autofac.dll</HintPath>
</Reference>
<Reference Include="Nancy.Hosting.Self, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs"> <Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link> <Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ApplicationServer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CentralDispatch.cs" />
<Compile Include="Model\ApplicationMode.cs" />
<Compile Include="AppMain.cs" /> <Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />
<Compile Include="Router.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="..\NzbDrone\NLog.config">
<Content Include="NLog.config"> <Link>NLog.config</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> </None>
</Content> <None Include="..\NzbDrone\NLog.xsd">
<None Include="NLog.xsd"> <Link>NLog.xsd</Link>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<None Include="packages.config" /> <None Include="app.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NzbDrone.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0"> <BootstrapperPackage Include=".NETFramework,Version=v4.0">
@ -148,19 +108,16 @@
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\NzbDrone.Api\NzbDrone.Api.csproj"> <ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
<Project>{fd286df8-2d3a-4394-8ad5-443fade55fb2}</Project> <Project>{d12f7f2f-8a3c-415f-88fa-6dd061a84869}</Project>
<Name>NzbDrone.Api</Name> <Name>NzbDrone</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
<Name>NzbDrone.Core</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="..\NzbDrone\NzbDrone.ico">
<Link>NzbDrone.ico</Link>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent> <PreBuildEvent>

@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NzbDrone.exe")]
[assembly: Guid("67AADCD9-89AA-4D95-8281-3193740E70E5")]
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Sqo; using Sqo;
@ -16,6 +17,37 @@ namespace NzbDrone.Core.Datastore
void DeleteMany<T>(IEnumerable<T> objects) where T : ModelBase; void DeleteMany<T>(IEnumerable<T> objects) where T : ModelBase;
} }
public static class SiaqodbLogger
{
public static void ListenTo(Siaqodb db)
{
db.DeletedObject += OnDeletedObject;
db.LoadingObject +=OnLoadingObject;
db.LoadedObject +=OnLoadedObject;
}
private static void OnLoadedObject(object sender, LoadedObjectEventArgs e)
{
Write("Loaded", e.Object.GetType(), e.OID);
}
private static void OnLoadingObject(object sender, LoadingObjectEventArgs e)
{
Write("Loading", e.ObjectType, e.OID);
}
static void OnDeletedObject(object sender, DeletedEventsArgs e)
{
Write("Deleted", e.ObjectType, e.OID);
}
private static void Write(string operation, Type modelType, int id)
{
var message = string.Format("{0} {1}[{2}]", operation, modelType.Name, id);
Trace.WriteLine(message, "Siaqodb");
}
}
public class SiaqodbProxy : IObjectDatabase public class SiaqodbProxy : IObjectDatabase
{ {
private readonly Siaqodb _db; private readonly Siaqodb _db;
@ -23,8 +55,11 @@ namespace NzbDrone.Core.Datastore
public SiaqodbProxy(Siaqodb db) public SiaqodbProxy(Siaqodb db)
{ {
_db = db; _db = db;
//SiaqodbConfigurator.SetRaiseLoadEvents(true);
//SiaqodbLogger.ListenTo(_db);
} }
public void Dispose() public void Dispose()
{ {
@ -32,7 +67,7 @@ namespace NzbDrone.Core.Datastore
public IEnumerable<T> AsQueryable<T>() public IEnumerable<T> AsQueryable<T>()
{ {
return _db.Cast<T>(); return _db.LoadAllLazy<T>();
} }
public T Insert<T>(T obj) where T : ModelBase public T Insert<T>(T obj) where T : ModelBase

@ -23,15 +23,7 @@ namespace NzbDrone.Core.Instrumentation
private static object GetLogger(Type type) private static object GetLogger(Type type)
{ {
const string STRING_TO_REMOVE = "NzbDrone"; return LogManager.GetLogger(type.Name);
var loggerName = type.FullName;
if (loggerName.StartsWith(STRING_TO_REMOVE))
{
loggerName = loggerName.Substring(STRING_TO_REMOVE.Length + 1);
}
return LogManager.GetLogger(loggerName);
} }
} }
} }

@ -12,7 +12,6 @@ using System.Runtime.InteropServices;
[assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")] [assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")]
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")] [assembly: InternalsVisibleTo("NzbDrone.Core.Test")]
[assembly: InternalsVisibleTo("NzbDrone.Web")]
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:

@ -40,8 +40,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1E6B3C
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Api", "NzbDrone.Api\NzbDrone.Api.csproj", "{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Api", "NzbDrone.Api\NzbDrone.Api.csproj", "{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Console", "NzbDrone\NzbDrone.Console.csproj", "{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E0BC607C-90DC-4B3B-A2FB-7DC5B45338A4}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E0BC607C-90DC-4B3B-A2FB-7DC5B45338A4}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
JSLintOptions.xml = JSLintOptions.xml JSLintOptions.xml = JSLintOptions.xml
@ -53,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Backbone", "NzbDro
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Integration.Mvc", "Autofac.Integration.Mvc\Autofac.Integration.Mvc.csproj", "{DD874E64-C7EC-464D-925F-CF4A709EDEEF}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Integration.Mvc", "Autofac.Integration.Mvc\Autofac.Integration.Mvc.csproj", "{DD874E64-C7EC-464D-925F-CF4A709EDEEF}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Console", "NzbDrone.Console\NzbDrone.Console.csproj", "{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -320,24 +320,6 @@ Global
{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|Mixed Platforms.Build.0 = Release|Any CPU {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|Mixed Platforms.Build.0 = Release|Any CPU
{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|x64.ActiveCfg = Release|Any CPU {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|x64.ActiveCfg = Release|Any CPU
{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|x86.ActiveCfg = Release|Any CPU {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Services|x86.ActiveCfg = Release|Any CPU
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Any CPU.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.Build.0 = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x64.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.Build.0 = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Any CPU.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x64.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Any CPU.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Mixed Platforms.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Mixed Platforms.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x64.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x86.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x86.Build.0 = Release|x86
{64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Any CPU.Build.0 = Debug|Any CPU {64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {64E5482F-0C4F-46C6-9377-699D3EADBA9E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -389,6 +371,24 @@ Global
{DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|Mixed Platforms.Build.0 = Release|Any CPU {DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|Mixed Platforms.Build.0 = Release|Any CPU
{DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|x64.ActiveCfg = Release|Any CPU {DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|x64.ActiveCfg = Release|Any CPU
{DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|x86.ActiveCfg = Release|Any CPU {DD874E64-C7EC-464D-925F-CF4A709EDEEF}.Services|x86.ActiveCfg = Release|Any CPU
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Any CPU.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.Build.0 = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x64.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.ActiveCfg = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.Build.0 = Debug|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Any CPU.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x64.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Any CPU.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Mixed Platforms.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|Mixed Platforms.Build.0 = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x64.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x86.ActiveCfg = Release|x86
{3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Services|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -1,18 +1,23 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using NzbDrone.Providers;
using Autofac; using Autofac;
using NLog;
namespace NzbDrone namespace NzbDrone
{ {
public static class AppMain public static class AppMain
{ {
private static readonly Logger logger = LogManager.GetLogger("AppMain");
public static void Main(string[] args) public static void Main(string[] args)
{ {
try try
{ {
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version); logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception));
//Check if full version .NET is installed. //Check if full version .NET is installed.
try try
@ -21,29 +26,35 @@ namespace NzbDrone
} }
catch (Exception) catch (Exception)
{ {
Console.WriteLine("It looks like you don't have full version of .NET Framework installed. Press any key and you will be directed to the download page."); logger.Error("It looks like you don't have full version of .NET Framework installed. Press any key and you will be directed to the download page.");
Console.Read(); Console.Read();
try try
{ {
Process.Start("http://www.microsoft.com/download/en/details.aspx?id=17851"); Process.Start("http://www.microsoft.com/download/en/details.aspx?id=17851");
} }
catch (Exception) catch (Exception e)
{ {
Console.WriteLine("Opps. can't start default browser. Please visit http://www.microsoft.com/download/en/details.aspx?id=17851 to download .NET Framework 4."); logger.Warn("Oops. can't start default browser. Please visit http://www.microsoft.com/download/en/details.aspx?id=17851 to download .NET Framework 4.");
Console.ReadLine(); Console.ReadLine();
} }
return; return;
} }
CentralDispatch.Container.Resolve<Router>().Route(args); NzbDroneBootstrapper.Container.Resolve<Router>().Route(args);
} }
catch (Exception e) catch (Exception e)
{ {
MonitoringProvider.AppDomainException(e); AppDomainException(e);
} }
} }
public static void AppDomainException(Exception exception)
{
Console.WriteLine("EPIC FAIL: {0}", exception);
logger.FatalException("EPIC FAIL: " + exception.Message, exception);
}
} }
} }

@ -1,12 +1,11 @@
namespace NzbDrone.Model namespace NzbDrone
{ {
public enum ApplicationMode public enum ApplicationModes
{ {
Console, Console,
Help, Help,
InstallService, InstallService,
UninstallService, UninstallService,
Service, Service,
Nancy
} }
} }

@ -1,10 +1,7 @@
using System; using System;
using System.IO;
using System.Runtime.InteropServices;
using System.ServiceProcess; using System.ServiceProcess;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone namespace NzbDrone
@ -17,22 +14,20 @@ namespace NzbDrone
private readonly EnvironmentProvider _environmentProvider; private readonly EnvironmentProvider _environmentProvider;
private readonly IHostController _hostController; private readonly IHostController _hostController;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly MonitoringProvider _monitoringProvider; private readonly PriorityMonitor _priorityMonitor;
private readonly SecurityProvider _securityProvider; private readonly SecurityProvider _securityProvider;
private readonly DiskProvider _diskProvider;
public ApplicationServer(ConfigFileProvider configFileProvider, IHostController hostController, public ApplicationServer(ConfigFileProvider configFileProvider, IHostController hostController,
EnvironmentProvider environmentProvider, EnvironmentProvider environmentProvider,
ProcessProvider processProvider, MonitoringProvider monitoringProvider, ProcessProvider processProvider, PriorityMonitor priorityMonitor,
SecurityProvider securityProvider, DiskProvider diskProvider) SecurityProvider securityProvider)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_hostController = hostController; _hostController = hostController;
_environmentProvider = environmentProvider; _environmentProvider = environmentProvider;
_processProvider = processProvider; _processProvider = processProvider;
_monitoringProvider = monitoringProvider; _priorityMonitor = priorityMonitor;
_securityProvider = securityProvider; _securityProvider = securityProvider;
_diskProvider = diskProvider;
} }
public ApplicationServer() public ApplicationServer()
@ -47,19 +42,9 @@ namespace NzbDrone
public virtual void Start() public virtual void Start()
{ {
_hostController.StopServer();
_securityProvider.MakeAccessible(); _securityProvider.MakeAccessible();
if(_securityProvider.IsCurrentUserAdmin())
{
var tempFiles = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "Temporary ASP.NET Files");
logger.Debug("Creating Temporary ASP.Net folder: {0}", tempFiles);
_diskProvider.CreateDirectory(tempFiles);
}
_hostController.StartServer(); _hostController.StartServer();
//Todo: verify that IIS is actually started
if (_environmentProvider.IsUserInteractive && _configFileProvider.LaunchBrowser) if (_environmentProvider.IsUserInteractive && _configFileProvider.LaunchBrowser)
{ {
@ -74,7 +59,7 @@ namespace NzbDrone
} }
} }
_monitoringProvider.Start(); _priorityMonitor.Start();
} }
protected override void OnStop() protected override void OnStop()

@ -68,6 +68,12 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath> <HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
</Reference> </Reference>
<Reference Include="Exceptron.Client">
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.Nlog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="Nancy"> <Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath> <HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference> </Reference>
@ -92,15 +98,21 @@
<Compile Include="ApplicationServer.cs"> <Compile Include="ApplicationServer.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="CentralDispatch.cs" /> <Compile Include="NzbDroneBootstrapper.cs" />
<Compile Include="Model\ApplicationMode.cs" /> <Compile Include="ApplicationMode.cs" />
<Compile Include="AppMain.cs" /> <Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" /> <Compile Include="PriorityMonitor.cs" />
<Compile Include="Router.cs" /> <Compile Include="Router.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -1,21 +0,0 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration></UseBuildConfiguration>
<UseBuildPlatform />
<ProxyProcessPath></ProxyProcessPath>
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
<HiddenWarnings>PostBuildEventDisabled</HiddenWarnings>
</ProjectConfiguration>

@ -7,12 +7,12 @@ using NzbDrone.Core.Instrumentation;
namespace NzbDrone namespace NzbDrone
{ {
public static class CentralDispatch public static class NzbDroneBootstrapper
{ {
private static readonly IContainer container; private static readonly IContainer container;
private static readonly Logger logger = LogManager.GetLogger("Host.CentralDispatch"); private static readonly Logger logger = LogManager.GetLogger("NzbDroneBootstrapper");
static CentralDispatch() static NzbDroneBootstrapper()
{ {
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
BindKernel(builder); BindKernel(builder);

@ -1,29 +1,27 @@
using System; using System.Linq;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
namespace NzbDrone.Providers namespace NzbDrone
{ {
public class MonitoringProvider public class PriorityMonitor
{ {
private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider");
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly Logger _logger;
private Timer _processPriorityCheckTimer; private Timer _processPriorityCheckTimer;
public MonitoringProvider(ProcessProvider processProvider) public PriorityMonitor(ProcessProvider processProvider, Logger logger)
{ {
_processProvider = processProvider; _processProvider = processProvider;
_logger = logger;
} }
public void Start() public void Start()
{ {
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception));
_processPriorityCheckTimer = new Timer(EnsurePriority); _processPriorityCheckTimer = new Timer(EnsurePriority);
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30)); _processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
@ -48,14 +46,8 @@ namespace NzbDrone.Providers
} }
catch (Exception e) catch (Exception e)
{ {
logger.WarnException("Unable to verify priority", e); _logger.WarnException("Unable to verify priority", e);
} }
} }
public static void AppDomainException(Exception excepion)
{
Console.WriteLine("EPIC FAIL: {0}", excepion);
logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
}
} }
} }

@ -2,34 +2,29 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using Nancy.Hosting.Self;
using NzbDrone.Api;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.SysTray; using NzbDrone.Common.SysTray;
using NzbDrone.Model;
namespace NzbDrone namespace NzbDrone
{ {
public class Router public class Router
{ {
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly ApplicationServer _applicationServer; private readonly ApplicationServer _applicationServer;
private readonly ServiceProvider _serviceProvider; private readonly ServiceProvider _serviceProvider;
private readonly ConsoleProvider _consoleProvider; private readonly ConsoleProvider _consoleProvider;
private readonly EnvironmentProvider _environmentProvider; private readonly EnvironmentProvider _environmentProvider;
private readonly SysTrayProvider _sysTrayProvider; private readonly SysTrayProvider _sysTrayProvider;
private readonly ProcessProvider _processProvider; private readonly Logger _logger;
public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider, public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider,
ConsoleProvider consoleProvider, EnvironmentProvider environmentProvider, SysTrayProvider sysTrayProvider, ProcessProvider processProvider) ConsoleProvider consoleProvider, EnvironmentProvider environmentProvider, SysTrayProvider sysTrayProvider, Logger logger)
{ {
_applicationServer = applicationServer; _applicationServer = applicationServer;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_consoleProvider = consoleProvider; _consoleProvider = consoleProvider;
_environmentProvider = environmentProvider; _environmentProvider = environmentProvider;
_sysTrayProvider = sysTrayProvider; _sysTrayProvider = sysTrayProvider;
_processProvider = processProvider; _logger = logger;
} }
public void Route(IEnumerable<string> args) public void Route(IEnumerable<string> args)
@ -37,41 +32,27 @@ namespace NzbDrone
Route(GetApplicationMode(args)); Route(GetApplicationMode(args));
} }
public void Route(ApplicationMode applicationMode) public void Route(ApplicationModes applicationModes)
{ {
if (!_environmentProvider.IsUserInteractive) if (!_environmentProvider.IsUserInteractive)
{ {
applicationMode = ApplicationMode.Service; applicationModes = ApplicationModes.Service;
} }
logger.Info("Application mode: {0}", applicationMode); _logger.Info("Application mode: {0}", applicationModes);
switch (applicationMode) switch (applicationModes)
{ {
case ApplicationMode.Nancy: case ApplicationModes.Service:
{
var nancyHost = new NancyHost(new Uri("http://localhost:8282"), new NancyBootstrapper());
nancyHost.Start();
_processProvider.Start("http://localhost:8282");
_consoleProvider.WaitForClose();
break;
}
case ApplicationMode.Service:
{ {
logger.Trace("Service selected"); _logger.Trace("Service selected");
_serviceProvider.Run(_applicationServer); _serviceProvider.Run(_applicationServer);
break; break;
} }
case ApplicationMode.Console: case ApplicationModes.Console:
{ {
logger.Trace("Console selected"); _logger.Trace("Console selected");
_applicationServer.Start(); _applicationServer.Start();
if (ConsoleProvider.IsConsoleApplication) if (ConsoleProvider.IsConsoleApplication)
_consoleProvider.WaitForClose(); _consoleProvider.WaitForClose();
@ -83,9 +64,9 @@ namespace NzbDrone
break; break;
} }
case ApplicationMode.InstallService: case ApplicationModes.InstallService:
{ {
logger.Trace("Install Service selected"); _logger.Trace("Install Service selected");
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)) if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{ {
_consoleProvider.PrintServiceAlreadyExist(); _consoleProvider.PrintServiceAlreadyExist();
@ -97,9 +78,9 @@ namespace NzbDrone
} }
break; break;
} }
case ApplicationMode.UninstallService: case ApplicationModes.UninstallService:
{ {
logger.Trace("Uninstall Service selected"); _logger.Trace("Uninstall Service selected");
if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)) if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{ {
_consoleProvider.PrintServiceDoestExist(); _consoleProvider.PrintServiceDoestExist();
@ -119,21 +100,20 @@ namespace NzbDrone
} }
} }
public static ApplicationMode GetApplicationMode(IEnumerable<string> args) public static ApplicationModes GetApplicationMode(IEnumerable<string> args)
{ {
if (args == null) return ApplicationMode.Console; if (args == null) return ApplicationModes.Console;
var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList(); var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList();
if (cleanArgs.Count == 0) return ApplicationMode.Console; if (cleanArgs.Count == 0) return ApplicationModes.Console;
if (cleanArgs.Count != 1) return ApplicationMode.Help; if (cleanArgs.Count != 1) return ApplicationModes.Help;
var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower(); var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower();
if (arg == "i") return ApplicationMode.InstallService; if (arg == "i") return ApplicationModes.InstallService;
if (arg == "u") return ApplicationMode.UninstallService; if (arg == "u") return ApplicationModes.UninstallService;
if (arg == "n") return ApplicationMode.Nancy;
return ApplicationMode.Help; return ApplicationModes.Help;
} }
} }
} }

Loading…
Cancel
Save