mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Replaced Nancy.Hosting.Self with Owin
SignalR to come!
This commit is contained in:
parent
54d95e2e20
commit
2ec79e6744
@ -1,48 +1,46 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Hosting.Self;
|
||||
using Nancy.Owin;
|
||||
using Owin;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public interface IHostController
|
||||
{
|
||||
bool ServerStarted { get; }
|
||||
string AppUrl { get; }
|
||||
void StartServer();
|
||||
void RestartServer();
|
||||
void StopServer();
|
||||
}
|
||||
|
||||
public class HostController : IHostController
|
||||
|
||||
public class OwinHostController : IHostController
|
||||
{
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly SecurityProvider _securityProvider;
|
||||
private readonly INancyBootstrapper _bootstrapper;
|
||||
private readonly Logger _logger;
|
||||
private NancyHost _host;
|
||||
private IDisposable _host;
|
||||
|
||||
|
||||
public bool ServerStarted { get; private set; }
|
||||
|
||||
public HostController(ConfigFileProvider configFileProvider, SecurityProvider securityProvider, INancyBootstrapper bootstrapper, Logger logger)
|
||||
public OwinHostController(ConfigFileProvider configFileProvider, INancyBootstrapper bootstrapper, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_securityProvider = securityProvider;
|
||||
_bootstrapper = bootstrapper;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void StartServer()
|
||||
{
|
||||
if (_securityProvider.IsNzbDroneUrlRegistered())
|
||||
_host = new NancyHost(new Uri(AppUrl), _bootstrapper);
|
||||
_host = WebApplication.Start(AppUrl, builder => RunNancy(builder, _bootstrapper));
|
||||
}
|
||||
|
||||
else
|
||||
_host = new NancyHost(new Uri(AppUrl), _bootstrapper, new HostConfiguration { RewriteLocalhost = false });
|
||||
|
||||
_host.Start();
|
||||
private static IAppBuilder RunNancy(IAppBuilder builder, INancyBootstrapper bootstrapper)
|
||||
{
|
||||
var nancyOwinHost = new NancyOwinHost(null, bootstrapper);
|
||||
return builder.Use((Func<Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task>>)(next => (Func<IDictionary<string, object>, Task>)nancyOwinHost.Invoke), new object[0]);
|
||||
}
|
||||
|
||||
public string AppUrl
|
||||
@ -52,14 +50,9 @@ public string AppUrl
|
||||
|
||||
public void RestartServer()
|
||||
{
|
||||
|
||||
_logger.Warn("Attempting to restart server.");
|
||||
|
||||
if (_host != null)
|
||||
{
|
||||
StopServer();
|
||||
}
|
||||
|
||||
StartServer();
|
||||
}
|
||||
|
||||
@ -68,9 +61,11 @@ public void StopServer()
|
||||
if (_host == null) return;
|
||||
|
||||
_logger.Info("Attempting to stop Nancy host");
|
||||
_host.Stop();
|
||||
_host.Dispose();
|
||||
_host = null;
|
||||
_logger.Info("Host has stopped");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -59,11 +59,17 @@
|
||||
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener">
|
||||
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.0.21.0-pre\lib\net40\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Hosting">
|
||||
<HintPath>..\packages\Microsoft.Owin.Hosting.0.21.0-pre\lib\net40\Microsoft.Owin.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy">
|
||||
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Hosting.Self">
|
||||
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
|
||||
<Reference Include="Nancy.Owin">
|
||||
<HintPath>..\packages\Nancy.Owin.0.16.1\lib\net40\Nancy.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@ -73,6 +79,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin">
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -172,6 +181,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Expansive\license.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNetZip" version="1.9.1.8" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Hosting" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Nancy" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Owin" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="5.0.3" targetFramework="net35" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="Owin" version="1.0" targetFramework="net40" />
|
||||
</packages>
|
@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Moq;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using NUnit.Framework;
|
||||
using Nancy.Hosting.Self;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Api.Commands;
|
||||
using NzbDrone.Api.Indexers;
|
||||
using NzbDrone.Api.RootFolders;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
@ -21,7 +20,7 @@ namespace NzbDrone.Integration.Test
|
||||
public abstract class IntegrationTest
|
||||
{
|
||||
private NancyBootstrapper _bootstrapper;
|
||||
private NancyHost _host;
|
||||
private IHostController _hostController;
|
||||
protected RestClient RestClient { get; private set; }
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetLogger("TEST");
|
||||
@ -82,24 +81,27 @@ public void SmokeTestSetup()
|
||||
|
||||
_bootstrapper = new NancyBootstrapper(Container);
|
||||
|
||||
const string url = "http://localhost:1313";
|
||||
|
||||
_host = new NancyHost(new Uri(url), _bootstrapper);
|
||||
var _hostConfig = new Mock<ConfigFileProvider>();
|
||||
_hostConfig.SetupGet(c => c.Port).Returns(1313);
|
||||
|
||||
RestClient = new RestClient(url + "/api/");
|
||||
_hostController = new OwinHostController(_hostConfig.Object, _bootstrapper, Logger);
|
||||
|
||||
|
||||
RestClient = new RestClient(_hostController.AppUrl + "/api/");
|
||||
Series = new SeriesClient(RestClient);
|
||||
Releases = new ReleaseClient(RestClient);
|
||||
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
||||
Commands = new ClientBase<CommandResource>(RestClient);
|
||||
Indexers = new IndexerClient(RestClient);
|
||||
|
||||
_host.Start();
|
||||
_hostController.StartServer();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void SmokeTestTearDown()
|
||||
{
|
||||
_host.Stop();
|
||||
_hostController.StopServer();
|
||||
|
||||
_bootstrapper.Shutdown();
|
||||
}
|
||||
|
@ -40,11 +40,23 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\FluentValidation.4.0.0.0\lib\Net40\FluentValidation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener">
|
||||
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.0.21.0-pre\lib\net40\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Hosting, Version=0.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.Owin.Hosting.0.21.0-pre\lib\net40\Microsoft.Owin.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy">
|
||||
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Hosting.Self">
|
||||
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
|
||||
<Reference Include="Nancy.Owin, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Nancy.Owin.0.16.1\lib\net40\Nancy.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.5.0.3\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
@ -55,6 +67,10 @@
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestSharp">
|
||||
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -62,5 +62,12 @@ public void wrong_slug_should_return_404()
|
||||
Series.Get("non-existing-slug", HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void invalid_id_should_return_404()
|
||||
{
|
||||
//TODO: fix
|
||||
Series.Get(99, HttpStatusCode.NotFound);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,10 +2,14 @@
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="2.0.1" targetFramework="net40" />
|
||||
<package id="FluentValidation" version="4.0.0.0" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Hosting" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" targetFramework="net40" />
|
||||
<package id="Nancy" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Owin" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="5.0.3" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.2" targetFramework="net40" />
|
||||
<package id="Owin" version="1.0" targetFramework="net40" />
|
||||
<package id="RestSharp" version="104.1" targetFramework="net40" />
|
||||
</packages>
|
@ -91,16 +91,28 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener">
|
||||
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.0.21.0-pre\lib\net40\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Hosting, Version=0.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.Owin.Hosting.0.21.0-pre\lib\net40\Microsoft.Owin.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy">
|
||||
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Hosting.Self">
|
||||
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
|
||||
<Reference Include="Nancy.Owin, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Nancy.Owin.0.16.1\lib\net40\Nancy.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
|
@ -1,9 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentMigrator" version="1.0.6.0" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Hosting" version="0.21.0-pre" targetFramework="net40" />
|
||||
<package id="Nancy" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Owin" version="0.16.1" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="NLog.Config" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="NLog.Schema" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="Owin" version="1.0" targetFramework="net40" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user