moved hosting, system tray out of common
This commit is contained in:
parent
2ec79e6744
commit
45b4972091
|
@ -59,18 +59,6 @@
|
|||
<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.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>
|
||||
<HintPath>..\packages\Newtonsoft.Json.5.0.3\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
|
@ -79,15 +67,10 @@
|
|||
<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" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
|
@ -131,7 +114,6 @@
|
|||
<Compile Include="Expansive\Tree.cs" />
|
||||
<Compile Include="Expansive\TreeNode.cs" />
|
||||
<Compile Include="Expansive\TreeNodeList.cs" />
|
||||
<Compile Include="HostController.cs" />
|
||||
<Compile Include="IJsonSerializer.cs" />
|
||||
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
|
||||
<Compile Include="Reflection\ReflectionExtensions.cs" />
|
||||
|
@ -153,10 +135,6 @@
|
|||
<Compile Include="RestProvider.cs" />
|
||||
<Compile Include="SecurityProvider.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
<Compile Include="SysTray\SysTrayApp.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysTray\SysTrayProvider.cs" />
|
||||
<Compile Include="TinyIoC.cs" />
|
||||
<Compile Include="TryParseExtension.cs" />
|
||||
<Compile Include="UdpProvider.cs" />
|
||||
|
|
|
@ -110,5 +110,10 @@ namespace NzbDrone.Common
|
|||
Name = process.ProcessName
|
||||
};
|
||||
}
|
||||
|
||||
public void KillAll(string nzbdrone)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,6 @@
|
|||
<?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.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,39 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
|
||||
namespace NzbDrone.Core.Lifecycle
|
||||
{
|
||||
public class AppRestartJob : IJob
|
||||
{
|
||||
private readonly IHostController _hostController;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public AppRestartJob(IHostController hostController)
|
||||
{
|
||||
_hostController = hostController;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Restart NzbDrone"; }
|
||||
}
|
||||
|
||||
public TimeSpan DefaultInterval
|
||||
{
|
||||
get { return TimeSpan.FromTicks(0); }
|
||||
}
|
||||
|
||||
public virtual void Start(ProgressNotification notification, dynamic options)
|
||||
{
|
||||
notification.CurrentMessage = "Restarting NzbDrone";
|
||||
logger.Info("Restarting NzbDrone");
|
||||
|
||||
_hostController.StopServer();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -300,7 +300,6 @@
|
|||
<Compile Include="Jobs\JobRepository.cs" />
|
||||
<Compile Include="Jobs\JobTimer.cs" />
|
||||
<Compile Include="Lifecycle\AppShutdownJob.cs" />
|
||||
<Compile Include="Lifecycle\AppRestartJob.cs" />
|
||||
<Compile Include="Lifecycle\ApplicationStartedEvent.cs" />
|
||||
<Compile Include="MediaCover\MediaCover.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeFileMovingService.cs" />
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
|
@ -11,6 +12,8 @@ using NzbDrone.Api.RootFolders;
|
|||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using NzbDrone.Owin;
|
||||
using NzbDrone.Owin.MiddleWare;
|
||||
using RestSharp;
|
||||
using TinyIoC;
|
||||
|
||||
|
@ -85,7 +88,7 @@ namespace NzbDrone.Integration.Test
|
|||
var _hostConfig = new Mock<ConfigFileProvider>();
|
||||
_hostConfig.SetupGet(c => c.Port).Returns(1313);
|
||||
|
||||
_hostController = new OwinHostController(_hostConfig.Object, _bootstrapper, Logger);
|
||||
_hostController = new OwinHostController(_hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
||||
|
||||
|
||||
RestClient = new RestClient(_hostController.AppUrl + "/api/");
|
||||
|
|
|
@ -12,17 +12,15 @@ namespace NzbDrone.Update.Providers
|
|||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
private readonly IHostController _hostController;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider,
|
||||
ProcessProvider processProvider, EnvironmentProvider environmentProvider, IHostController hostController)
|
||||
ProcessProvider processProvider, EnvironmentProvider environmentProvider)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
_processProvider = processProvider;
|
||||
_environmentProvider = environmentProvider;
|
||||
_hostController = hostController;
|
||||
}
|
||||
|
||||
public UpdateProvider()
|
||||
|
@ -79,7 +77,7 @@ namespace NzbDrone.Update.Providers
|
|||
}
|
||||
|
||||
logger.Info("Killing all orphan IISExpress processes");
|
||||
_hostController.StopServer();
|
||||
_processProvider.KillAll("NzbDrone");
|
||||
|
||||
logger.Info("Creating backup of existing installation");
|
||||
_diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder());
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.ServiceProcess;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Owin;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.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>
|
||||
|
@ -115,7 +116,9 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||
|
@ -127,9 +130,18 @@
|
|||
<Compile Include="MainAppContainerBuilder.cs" />
|
||||
<Compile Include="ApplicationMode.cs" />
|
||||
<Compile Include="AppMain.cs" />
|
||||
<Compile Include="Owin\MiddleWare\NancyMiddleWare.cs" />
|
||||
<Compile Include="Owin\IHostController.cs" />
|
||||
<Compile Include="Owin\MiddleWare\IOwinMiddleWare.cs" />
|
||||
<Compile Include="Owin\MiddleWare\SignalRMiddleWare.cs" />
|
||||
<Compile Include="Owin\OwinHostController.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PriorityMonitor.cs" />
|
||||
<Compile Include="Router.cs" />
|
||||
<Compile Include="SysTray\SysTrayApp.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysTray\SysTrayProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
namespace NzbDrone.Owin
|
||||
{
|
||||
public interface IHostController
|
||||
{
|
||||
string AppUrl { get; }
|
||||
void StartServer();
|
||||
void RestartServer();
|
||||
void StopServer();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using Owin;
|
||||
|
||||
namespace NzbDrone.Owin.MiddleWare
|
||||
{
|
||||
public interface IOwinMiddleWare
|
||||
{
|
||||
void Attach(IAppBuilder appBuilder);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Owin;
|
||||
using Owin;
|
||||
|
||||
namespace NzbDrone.Owin.MiddleWare
|
||||
{
|
||||
public class NancyMiddleWare : IOwinMiddleWare
|
||||
{
|
||||
private readonly INancyBootstrapper _nancyBootstrapper;
|
||||
|
||||
public NancyMiddleWare(INancyBootstrapper nancyBootstrapper)
|
||||
{
|
||||
_nancyBootstrapper = nancyBootstrapper;
|
||||
}
|
||||
|
||||
public void Attach(IAppBuilder appBuilder)
|
||||
{
|
||||
var nancyOwinHost = new NancyOwinHost(null, _nancyBootstrapper);
|
||||
appBuilder.Use((Func<Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task>>)(next => (Func<IDictionary<string, object>, Task>)nancyOwinHost.Invoke), new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Owin;
|
||||
using Owin;
|
||||
|
||||
namespace NzbDrone.Owin.MiddleWare
|
||||
{
|
||||
public class SignalRMiddleWare : IOwinMiddleWare
|
||||
{
|
||||
private readonly INancyBootstrapper _nancyBootstrapper;
|
||||
|
||||
public SignalRMiddleWare(INancyBootstrapper nancyBootstrapper)
|
||||
{
|
||||
_nancyBootstrapper = nancyBootstrapper;
|
||||
}
|
||||
|
||||
public void Attach(IAppBuilder appBuilder)
|
||||
{
|
||||
return;
|
||||
var nancyOwinHost = new NancyOwinHost(null, _nancyBootstrapper);
|
||||
appBuilder.Use((Func<Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task>>)(next => (Func<IDictionary<string, object>, Task>)nancyOwinHost.Invoke), new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,36 +5,37 @@ using Microsoft.Owin.Hosting;
|
|||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Owin;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Owin.MiddleWare;
|
||||
using Owin;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
namespace NzbDrone.Owin
|
||||
{
|
||||
public interface IHostController
|
||||
{
|
||||
string AppUrl { get; }
|
||||
void StartServer();
|
||||
void RestartServer();
|
||||
void StopServer();
|
||||
}
|
||||
|
||||
|
||||
public class OwinHostController : IHostController
|
||||
{
|
||||
private readonly ConfigFileProvider _configFileProvider;
|
||||
private readonly INancyBootstrapper _bootstrapper;
|
||||
private readonly IEnumerable<IOwinMiddleWare> _owinMiddleWares;
|
||||
private readonly Logger _logger;
|
||||
private IDisposable _host;
|
||||
|
||||
public OwinHostController(ConfigFileProvider configFileProvider, INancyBootstrapper bootstrapper, Logger logger)
|
||||
public OwinHostController(ConfigFileProvider configFileProvider, IEnumerable<IOwinMiddleWare> owinMiddleWares, Logger logger)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_bootstrapper = bootstrapper;
|
||||
_owinMiddleWares = owinMiddleWares;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void StartServer()
|
||||
{
|
||||
_host = WebApplication.Start(AppUrl, builder => RunNancy(builder, _bootstrapper));
|
||||
_host = WebApplication.Start(AppUrl, BuildApp);
|
||||
}
|
||||
|
||||
private void BuildApp(IAppBuilder appBuilder)
|
||||
{
|
||||
foreach (var middleWare in _owinMiddleWares)
|
||||
{
|
||||
middleWare.Attach(appBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private static IAppBuilder RunNancy(IAppBuilder builder, INancyBootstrapper bootstrapper)
|
||||
|
@ -67,5 +68,4 @@ namespace NzbDrone.Common
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.SysTray;
|
||||
using NzbDrone.SysTray;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Owin;
|
||||
|
||||
namespace NzbDrone.Common.SysTray
|
||||
namespace NzbDrone.SysTray
|
||||
{
|
||||
public class SysTrayApp : Form
|
||||
{
|
|
@ -1,7 +1,6 @@
|
|||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace NzbDrone.Common.SysTray
|
||||
namespace NzbDrone.SysTray
|
||||
{
|
||||
public class SysTrayProvider
|
||||
{
|
Loading…
Reference in New Issue