diff --git a/NzbDrone.App.Test/ContainerFixture.cs b/NzbDrone.App.Test/ContainerFixture.cs index 2c828875e..9198d5367 100644 --- a/NzbDrone.App.Test/ContainerFixture.cs +++ b/NzbDrone.App.Test/ContainerFixture.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Indexers; using NzbDrone.Core.Jobs; using NzbDrone.Core.Lifecycle; +using NzbDrone.Host; using NzbDrone.Test.Common; using FluentAssertions; using System.Linq; diff --git a/NzbDrone.App.Test/MonitoringProviderTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs index 388f1b11d..2d504b072 100644 --- a/NzbDrone.App.Test/MonitoringProviderTest.cs +++ b/NzbDrone.App.Test/MonitoringProviderTest.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Common.Model; +using NzbDrone.Host; using NzbDrone.Test.Common; namespace NzbDrone.App.Test diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.ncrunchproject b/NzbDrone.App.Test/NzbDrone.App.Test.ncrunchproject deleted file mode 100644 index 514d01a85..000000000 --- a/NzbDrone.App.Test/NzbDrone.App.Test.ncrunchproject +++ /dev/null @@ -1,22 +0,0 @@ - - false - true - false - true - false - false - false - false - true - true - false - true - true - 60000 - - - - AutoDetect - STA - x86 - \ No newline at end of file diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.Host.Test.csproj similarity index 96% rename from NzbDrone.App.Test/NzbDrone.App.Test.csproj rename to NzbDrone.App.Test/NzbDrone.Host.Test.csproj index ce39d3b22..a2dbe6680 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.Host.Test.csproj @@ -79,14 +79,14 @@ {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} NzbDrone.Core + + {95C11A9E-56ED-456A-8447-2C89C1139266} + NzbDrone.Host + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} NzbDrone.Test.Common - - {D12F7F2F-8A3C-415F-88FA-6DD061A84869} - NzbDrone - diff --git a/NzbDrone.App.Test/RouterTest.cs b/NzbDrone.App.Test/RouterTest.cs index c1db19af9..b09080571 100644 --- a/NzbDrone.App.Test/RouterTest.cs +++ b/NzbDrone.App.Test/RouterTest.cs @@ -3,6 +3,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Host; using NzbDrone.Test.Common; namespace NzbDrone.App.Test @@ -51,13 +52,13 @@ namespace NzbDrone.App.Test Mocker.GetMock().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock().SetupGet(c => c.IsConsoleApplication).Returns(true); - Subject.Route(ApplicationModes.Console); + Subject.Route(ApplicationModes.Interactive); Mocker.GetMock().Verify(c => c.WaitForClose(), Times.Once()); Mocker.GetMock().Verify(c => c.Start(), Times.Once()); } - [TestCase(ApplicationModes.Console)] + [TestCase(ApplicationModes.Interactive)] [TestCase(ApplicationModes.InstallService)] [TestCase(ApplicationModes.UninstallService)] [TestCase(ApplicationModes.Help)] diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 5e20e20f9..dc7dd87d3 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -92,6 +92,10 @@ {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} NzbDrone.Core + + {95C11A9E-56ED-456A-8447-2C89C1139266} + NzbDrone.Host + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} NzbDrone.Test.Common diff --git a/NzbDrone.Common.Test/ServiceFactoryFixture.cs b/NzbDrone.Common.Test/ServiceFactoryFixture.cs index af376617a..ca5a6a773 100644 --- a/NzbDrone.Common.Test/ServiceFactoryFixture.cs +++ b/NzbDrone.Common.Test/ServiceFactoryFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Host; using NzbDrone.Test.Common; namespace NzbDrone.Common.Test diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 49dc43e6e..4b5abaf50 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -1,5 +1,8 @@ -using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; using NLog; using NzbDrone.Common.Model; @@ -17,6 +20,7 @@ namespace NzbDrone.Common void KillAll(string processName); bool Exists(string processName); ProcessPriorityClass GetCurrentProcessPriority(); + Process ShellExecute(string path, string args = null, Action onOutputDataReceived = null, Action onErrorDataReceived = null); } public class ProcessProvider : IProcessProvider @@ -77,6 +81,54 @@ namespace NzbDrone.Common return Start(new ProcessStartInfo(path)); } + public Process ShellExecute(string path, string args = null, Action onOutputDataReceived = null, Action onErrorDataReceived = null) + { + var logger = LogManager.GetLogger(new FileInfo(path).Name); + + var startInfo = new ProcessStartInfo(path, args) + { + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true, + }; + + + logger.Info("Starting {0} {1}", path, args); + + var process = Process.Start(startInfo); + + process.OutputDataReceived += (sender, eventArgs) => + { + if (string.IsNullOrWhiteSpace(eventArgs.Data)) return; + + logger.Debug(eventArgs.Data); + + if (onOutputDataReceived != null) + { + onOutputDataReceived(eventArgs.Data); + } + }; + + process.ErrorDataReceived += (sender, eventArgs) => + { + if (string.IsNullOrWhiteSpace(eventArgs.Data)) return; + + logger.Error(eventArgs.Data); + + if (onErrorDataReceived != null) + { + onErrorDataReceived(eventArgs.Data); + } + }; + + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + process.Start(); + + return process; + } + public Process Start(ProcessStartInfo startInfo) { Logger.Info("Starting process. [{0}]", startInfo.FileName); diff --git a/NzbDrone.Console/AppMain.cs b/NzbDrone.Console/ConsoleApp.cs similarity index 76% rename from NzbDrone.Console/AppMain.cs rename to NzbDrone.Console/ConsoleApp.cs index 573b9fdad..f82384b1d 100644 --- a/NzbDrone.Console/AppMain.cs +++ b/NzbDrone.Console/ConsoleApp.cs @@ -2,17 +2,15 @@ namespace NzbDrone.Console { - public static class AppMain + public static class ConsoleApp { public static void Main(string[] args) { try { - - NzbDrone.AppMain.Main(args); - + Host.Bootstrap.Start(args); } - catch(Exception e) + catch (Exception e) { System.Console.WriteLine(e.ToString()); } diff --git a/NzbDrone.Console/NzbDrone.Console.csproj b/NzbDrone.Console/NzbDrone.Console.csproj index 137768ec3..42aab5be4 100644 --- a/NzbDrone.Console/NzbDrone.Console.csproj +++ b/NzbDrone.Console/NzbDrone.Console.csproj @@ -54,23 +54,15 @@ 4 - ..\NzbDrone\NzbDrone.ico + ..\NzbDrone.Host\NzbDrone.ico - NzbDrone.Console.AppMain + NzbDrone.Console.ConsoleApp OnBuildSuccess - - False - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - - - False - ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll - @@ -78,22 +70,9 @@ Properties\SharedAssemblyInfo.cs - + - - - app.config - - - NLog.config - - - NLog.xsd - Designer - - - False @@ -117,15 +96,14 @@ - - {d12f7f2f-8a3c-415f-88fa-6dd061a84869} - NzbDrone + + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} + NzbDrone.Common + + + {95c11a9e-56ed-456a-8447-2c89c1139266} + NzbDrone.Host - - - - NzbDrone.ico - diff --git a/NzbDrone.Console/Properties/AssemblyInfo.cs b/NzbDrone.Console/Properties/AssemblyInfo.cs index 35b5ef144..32f30358f 100644 --- a/NzbDrone.Console/Properties/AssemblyInfo.cs +++ b/NzbDrone.Console/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("NzbDrone.exe")] +[assembly: AssemblyTitle("NzbDrone.Host")] [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("10.0.0.*")] -[assembly: AssemblyFileVersion("10.0.0.*")] +[assembly: AssemblyFileVersion("10.0.0.*")] \ No newline at end of file diff --git a/NzbDrone.Console/packages.config b/NzbDrone.Console/packages.config deleted file mode 100644 index 6d679e899..000000000 --- a/NzbDrone.Console/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/NzbDrone.Core/Update/InstallUpdateService.cs b/NzbDrone.Core/Update/InstallUpdateService.cs index 82c544a3d..5a48968f6 100644 --- a/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/NzbDrone.Core/Update/InstallUpdateService.cs @@ -72,13 +72,8 @@ namespace NzbDrone.Core.Update updateSandboxFolder); _logger.Info("Starting update client"); - var startInfo = new ProcessStartInfo - { - FileName = _appFolderInfo.GetUpdateClientExePath(), - Arguments = _processProvider.GetCurrentProcess().Id.ToString() - }; - var process = _processProvider.Start(startInfo); + var process = _processProvider.ShellExecute(_appFolderInfo.GetUpdateClientExePath(), _processProvider.GetCurrentProcess().Id.ToString()); _processProvider.WaitForExit(process); diff --git a/NzbDrone/ApplicationModes.cs b/NzbDrone.Host/ApplicationModes.cs similarity index 73% rename from NzbDrone/ApplicationModes.cs rename to NzbDrone.Host/ApplicationModes.cs index a92579385..aa425948c 100644 --- a/NzbDrone/ApplicationModes.cs +++ b/NzbDrone.Host/ApplicationModes.cs @@ -1,8 +1,8 @@ -namespace NzbDrone +namespace NzbDrone.Host { public enum ApplicationModes { - Console, + Interactive, Help, InstallService, UninstallService, diff --git a/NzbDrone/ApplicationServer.cs b/NzbDrone.Host/ApplicationServer.cs similarity index 95% rename from NzbDrone/ApplicationServer.cs rename to NzbDrone.Host/ApplicationServer.cs index 523e3143b..f91720d68 100644 --- a/NzbDrone/ApplicationServer.cs +++ b/NzbDrone.Host/ApplicationServer.cs @@ -4,10 +4,10 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; -using NzbDrone.Host; -using NzbDrone.Owin; +using NzbDrone.Host.Host; +using NzbDrone.Host.Owin; -namespace NzbDrone +namespace NzbDrone.Host { public interface INzbDroneServiceFactory { @@ -49,11 +49,10 @@ namespace NzbDrone public void Start() { - if (_runtimeInfo.IsAdmin) + if (OsInfo.IsWindows && _runtimeInfo.IsAdmin) { _urlAclAdapter.RefreshRegistration(); _firewallAdapter.MakeAccessible(); - } _hostController.StartServer(); diff --git a/NzbDrone/AppMain.cs b/NzbDrone.Host/Bootstrap.cs similarity index 88% rename from NzbDrone/AppMain.cs rename to NzbDrone.Host/Bootstrap.cs index 43c227d83..469e8ad2b 100644 --- a/NzbDrone/AppMain.cs +++ b/NzbDrone.Host/Bootstrap.cs @@ -2,18 +2,19 @@ using System.Diagnostics; using System.Reflection; using NLog; +using NzbDrone.Common.Composition; using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Security; using NzbDrone.Core.Datastore; -namespace NzbDrone +namespace NzbDrone.Host { - public static class AppMain + public static class Bootstrap { private static readonly Logger Logger = LogManager.GetLogger("AppMain"); - public static void Main(string[] args) + public static IContainer Start(string[] args) { try { @@ -42,19 +43,21 @@ namespace NzbDrone Console.ReadLine(); } - return; + return null; } var container = MainAppContainerBuilder.BuildContainer(args); DbFactory.RegisterDatabase(container); container.Resolve().Route(); + + return container; } catch (Exception e) { Logger.FatalException("Epic Fail " + e.Message, e); + throw; } } - } } \ No newline at end of file diff --git a/NzbDrone/Host/FirewallAdapter.cs b/NzbDrone.Host/Host/FirewallAdapter.cs similarity index 99% rename from NzbDrone/Host/FirewallAdapter.cs rename to NzbDrone.Host/Host/FirewallAdapter.cs index 8d04068cb..044ed12d3 100644 --- a/NzbDrone/Host/FirewallAdapter.cs +++ b/NzbDrone.Host/Host/FirewallAdapter.cs @@ -1,9 +1,9 @@ using System; -using NLog; using NetFwTypeLib; +using NLog; using NzbDrone.Core.Configuration; -namespace NzbDrone.Host +namespace NzbDrone.Host.Host { public interface IFirewallAdapter { diff --git a/NzbDrone/Host/UrlAclAdapter.cs b/NzbDrone.Host/Host/UrlAclAdapter.cs similarity index 71% rename from NzbDrone/Host/UrlAclAdapter.cs rename to NzbDrone.Host/Host/UrlAclAdapter.cs index eab0da32f..ac9469690 100644 --- a/NzbDrone/Host/UrlAclAdapter.cs +++ b/NzbDrone.Host/Host/UrlAclAdapter.cs @@ -1,11 +1,10 @@ using System; -using System.Diagnostics; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; -namespace NzbDrone.Host +namespace NzbDrone.Host.Host { public interface IUrlAclAdapter { @@ -40,28 +39,19 @@ namespace NzbDrone.Host RunNetsh(arguments); } - private string RunNetsh(string arguments) + private void RunNetsh(string arguments) { try { - var startInfo = new ProcessStartInfo() - { - RedirectStandardOutput = true, - UseShellExecute = false, - FileName = "netsh.exe", - Arguments = arguments - }; - var process = _processProvider.Start(startInfo); + + var process = _processProvider.ShellExecute("netsh.exe", arguments); process.WaitForExit(5000); - return process.StandardOutput.ReadToEnd(); } catch (Exception ex) { _logger.WarnException("Error executing netsh with arguments: " + arguments, ex); } - - return null; } } } \ No newline at end of file diff --git a/NzbDrone/MainAppContainerBuilder.cs b/NzbDrone.Host/MainAppContainerBuilder.cs similarity index 89% rename from NzbDrone/MainAppContainerBuilder.cs rename to NzbDrone.Host/MainAppContainerBuilder.cs index 99ea55b01..eb00dfa05 100644 --- a/NzbDrone/MainAppContainerBuilder.cs +++ b/NzbDrone.Host/MainAppContainerBuilder.cs @@ -7,7 +7,7 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Organizer; using NzbDrone.Core.RootFolders; -namespace NzbDrone +namespace NzbDrone.Host { public class MainAppContainerBuilder : ContainerBuilderBase { @@ -17,7 +17,7 @@ namespace NzbDrone } private MainAppContainerBuilder(string[] args) - : base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api") + : base("NzbDrone.Host", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api") { AutoRegisterImplementations(); diff --git a/NzbDrone/NLog.config b/NzbDrone.Host/NLog.config similarity index 100% rename from NzbDrone/NLog.config rename to NzbDrone.Host/NLog.config diff --git a/NzbDrone/NLog.xsd b/NzbDrone.Host/NLog.xsd similarity index 100% rename from NzbDrone/NLog.xsd rename to NzbDrone.Host/NLog.xsd diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj new file mode 100644 index 000000000..df614234b --- /dev/null +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -0,0 +1,190 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {95C11A9E-56ED-456A-8447-2C89C1139266} + Library + Properties + NzbDrone.Host + NzbDrone.Host + v4.0 + 512 + + + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + ..\ + true + + + x86 + true + full + false + ..\_output\ + DEBUG;TRACE + prompt + 4 + true + BasicCorrectnessRules.ruleset + + + x86 + pdbonly + true + ..\_output\ + TRACE + prompt + 4 + + + + + + + + + + + OnOutputUpdated + + + + ..\Libraries\Interop.NetFwTypeLib.dll + True + + + False + ..\packages\Microsoft.AspNet.SignalR.Core.1.1.2\lib\net40\Microsoft.AspNet.SignalR.Core.dll + + + False + ..\packages\Microsoft.AspNet.SignalR.Owin.1.1.2\lib\net40\Microsoft.AspNet.SignalR.Owin.dll + + + False + ..\packages\Microsoft.Owin.Hosting.1.1.0-beta2\lib\net40\Microsoft.Owin.Hosting.dll + + + ..\packages\Nancy.0.16.1\lib\net40\Nancy.dll + + + False + ..\packages\Nancy.Owin.0.16.1\lib\net40\Nancy.Owin.dll + + + False + ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll + + + False + ..\packages\Owin.1.0\lib\net40\Owin.dll + + + + + + + + Properties\SharedAssemblyInfo.cs + + + Component + + + + + + + + + + + + + + + + + + + Always + Designer + + + Designer + + + + + + + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2} + NzbDrone.Api + + + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} + NzbDrone.Common + + + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} + NzbDrone.Core + + + + + + + + + xcopy /s /y "$(SolutionDir)\Libraries\Sqlite\*.*" "$(TargetDir)" + + + + \ No newline at end of file diff --git a/NzbDrone/NzbDrone.ico b/NzbDrone.Host/NzbDrone.ico similarity index 100% rename from NzbDrone/NzbDrone.ico rename to NzbDrone.Host/NzbDrone.ico diff --git a/NzbDrone/Owin/IHostController.cs b/NzbDrone.Host/Owin/IHostController.cs similarity index 83% rename from NzbDrone/Owin/IHostController.cs rename to NzbDrone.Host/Owin/IHostController.cs index 7d5150437..9df77feb4 100644 --- a/NzbDrone/Owin/IHostController.cs +++ b/NzbDrone.Host/Owin/IHostController.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Owin +namespace NzbDrone.Host.Owin { public interface IHostController { diff --git a/NzbDrone/Owin/MiddleWare/IOwinMiddleWare.cs b/NzbDrone.Host/Owin/MiddleWare/IOwinMiddleWare.cs similarity index 77% rename from NzbDrone/Owin/MiddleWare/IOwinMiddleWare.cs rename to NzbDrone.Host/Owin/MiddleWare/IOwinMiddleWare.cs index bcba8d456..1b5e8ce5b 100644 --- a/NzbDrone/Owin/MiddleWare/IOwinMiddleWare.cs +++ b/NzbDrone.Host/Owin/MiddleWare/IOwinMiddleWare.cs @@ -1,6 +1,6 @@ using Owin; -namespace NzbDrone.Owin.MiddleWare +namespace NzbDrone.Host.Owin.MiddleWare { public interface IOwinMiddleWare { diff --git a/NzbDrone/Owin/MiddleWare/NancyMiddleWare.cs b/NzbDrone.Host/Owin/MiddleWare/NancyMiddleWare.cs similarity index 95% rename from NzbDrone/Owin/MiddleWare/NancyMiddleWare.cs rename to NzbDrone.Host/Owin/MiddleWare/NancyMiddleWare.cs index 84be7e9b7..0cae23f98 100644 --- a/NzbDrone/Owin/MiddleWare/NancyMiddleWare.cs +++ b/NzbDrone.Host/Owin/MiddleWare/NancyMiddleWare.cs @@ -5,7 +5,7 @@ using Nancy.Bootstrapper; using Nancy.Owin; using Owin; -namespace NzbDrone.Owin.MiddleWare +namespace NzbDrone.Host.Owin.MiddleWare { public class NancyMiddleWare : IOwinMiddleWare { diff --git a/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs b/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs similarity index 96% rename from NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs rename to NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs index f06278588..ba9a436fa 100644 --- a/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs +++ b/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs @@ -4,7 +4,7 @@ using NzbDrone.Api.SignalR; using NzbDrone.Common.Composition; using Owin; -namespace NzbDrone.Owin.MiddleWare +namespace NzbDrone.Host.Owin.MiddleWare { public class SignalRMiddleWare : IOwinMiddleWare { diff --git a/NzbDrone/Owin/OwinHostController.cs b/NzbDrone.Host/Owin/OwinHostController.cs similarity index 96% rename from NzbDrone/Owin/OwinHostController.cs rename to NzbDrone.Host/Owin/OwinHostController.cs index c462cf446..0055883b6 100644 --- a/NzbDrone/Owin/OwinHostController.cs +++ b/NzbDrone.Host/Owin/OwinHostController.cs @@ -1,14 +1,14 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.Owin.Hosting; using NLog; using NzbDrone.Common.Security; using NzbDrone.Core.Configuration; -using NzbDrone.Owin.MiddleWare; +using NzbDrone.Host.Owin.MiddleWare; using Owin; -using System.Linq; -namespace NzbDrone.Owin +namespace NzbDrone.Host.Owin { public class OwinHostController : IHostController { diff --git a/NzbDrone/PriorityMonitor.cs b/NzbDrone.Host/PriorityMonitor.cs similarity index 97% rename from NzbDrone/PriorityMonitor.cs rename to NzbDrone.Host/PriorityMonitor.cs index 28d037d7d..28caf28ac 100644 --- a/NzbDrone/PriorityMonitor.cs +++ b/NzbDrone.Host/PriorityMonitor.cs @@ -4,7 +4,7 @@ using System.Threading; using NLog; using NzbDrone.Common; -namespace NzbDrone +namespace NzbDrone.Host { public class PriorityMonitor { diff --git a/NzbDrone.Host/Properties/AssemblyInfo.cs b/NzbDrone.Host/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..72143ef17 --- /dev/null +++ b/NzbDrone.Host/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +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("C2172AF4-F9A6-4D91-BAEE-C2E4EE680613")] + + +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("10.0.0.*")] +[assembly: AssemblyFileVersion("10.0.0.*")] diff --git a/NzbDrone/Router.cs b/NzbDrone.Host/Router.cs similarity index 88% rename from NzbDrone/Router.cs rename to NzbDrone.Host/Router.cs index 48ccf2aaf..964dde846 100644 --- a/NzbDrone/Router.cs +++ b/NzbDrone.Host/Router.cs @@ -1,10 +1,8 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.SysTray; -using IServiceProvider = NzbDrone.Common.IServiceProvider; -namespace NzbDrone +namespace NzbDrone.Host { public class Router { @@ -13,18 +11,16 @@ namespace NzbDrone private readonly StartupArguments _startupArguments; private readonly IConsoleService _consoleService; private readonly IRuntimeInfo _runtimeInfo; - private readonly ISystemTrayApp _systemTrayProvider; private readonly Logger _logger; public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider, StartupArguments startupArguments, - IConsoleService consoleService, IRuntimeInfo runtimeInfo, ISystemTrayApp systemTrayProvider, Logger logger) + IConsoleService consoleService, IRuntimeInfo runtimeInfo, Logger logger) { _nzbDroneServiceFactory = nzbDroneServiceFactory; _serviceProvider = serviceProvider; _startupArguments = startupArguments; _consoleService = consoleService; _runtimeInfo = runtimeInfo; - _systemTrayProvider = systemTrayProvider; _logger = logger; } @@ -52,7 +48,7 @@ namespace NzbDrone break; } - case ApplicationModes.Console: + case ApplicationModes.Interactive: { _logger.Trace("Console selected"); _nzbDroneServiceFactory.Start(); @@ -60,10 +56,6 @@ namespace NzbDrone { _consoleService.WaitForClose(); } - else - { - _systemTrayProvider.Start(); - } break; } @@ -120,7 +112,7 @@ namespace NzbDrone return ApplicationModes.UninstallService; } - return ApplicationModes.Console; + return ApplicationModes.Interactive; } } } diff --git a/NzbDrone/app.config b/NzbDrone.Host/app.config similarity index 100% rename from NzbDrone/app.config rename to NzbDrone.Host/app.config diff --git a/NzbDrone/packages.config b/NzbDrone.Host/packages.config similarity index 79% rename from NzbDrone/packages.config rename to NzbDrone.Host/packages.config index b916d2a06..c6acac73f 100644 --- a/NzbDrone/packages.config +++ b/NzbDrone.Host/packages.config @@ -1,6 +1,5 @@  - @@ -8,10 +7,8 @@ - - \ No newline at end of file diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index a86146166..9c3ebdb10 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -12,9 +12,10 @@ using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Jobs; +using NzbDrone.Host; +using NzbDrone.Host.Owin; +using NzbDrone.Host.Owin.MiddleWare; using NzbDrone.Integration.Test.Client; -using NzbDrone.Owin; -using NzbDrone.Owin.MiddleWare; using NzbDrone.Test.Common.Categories; using RestSharp; diff --git a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj index 435637e90..b3ee0c330 100644 --- a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj +++ b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj @@ -121,14 +121,14 @@ {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} NzbDrone.Core + + {95C11A9E-56ED-456A-8447-2C89C1139266} + NzbDrone.Host + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} NzbDrone.Test.Common - - {d12f7f2f-8a3c-415f-88fa-6dd061a84869} - NzbDrone - diff --git a/NzbDrone.sln b/NzbDrone.sln index 72bc32a89..4fa697bac 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core", "NzbDrone.C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core.Test", "NzbDrone.Core.Test\NzbDrone.Core.Test.csproj", "{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.App.Test", "NzbDrone.App.Test\NzbDrone.App.Test.csproj", "{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Host.Test", "NzbDrone.App.Test\NzbDrone.Host.Test.csproj", "{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Test.Dummy", "NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj", "{FAFB5948-A222-4CF6-AD14-026BE7564802}" EndProject @@ -52,6 +52,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Integration.Test", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exceptron.Client", "Exceptron.Client\Exceptron.Client.csproj", "{B1784698-592E-4132-BDFA-9817409E3A96}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Host", "NzbDrone.Host\NzbDrone.Host.csproj", "{95C11A9E-56ED-456A-8447-2C89C1139266}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Host", "Host", "{486ADF86-DD89-4E19-B805-9D94F19800D9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -134,6 +138,10 @@ Global {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|x86.Build.0 = Debug|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Release|x86.ActiveCfg = Release|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Release|x86.Build.0 = Release|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|x86.ActiveCfg = Debug|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|x86.Build.0 = Debug|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|x86.ActiveCfg = Release|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -151,6 +159,9 @@ Global {CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} + {D12F7F2F-8A3C-415F-88FA-6DD061A84869} = {486ADF86-DD89-4E19-B805-9D94F19800D9} + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976} = {486ADF86-DD89-4E19-B805-9D94F19800D9} + {95C11A9E-56ED-456A-8447-2C89C1139266} = {486ADF86-DD89-4E19-B805-9D94F19800D9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35;packages\Unity.2.1.505.2\lib\NET35 diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index d06fd6099..dd99af137 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -54,114 +54,35 @@ 4 - NzbDrone.ico + ..\NzbDrone.Host\NzbDrone.ico - NzbDrone.AppMain + NzbDrone.WindowsApp OnOutputUpdated - - False - ..\packages\FluentMigrator.1.1.1.0\lib\40\FluentMigrator.dll - - - False - ..\packages\FluentMigrator.1.1.1.0\tools\FluentMigrator.Runner.dll - - - False - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - - - ..\Libraries\Interop.NetFwTypeLib.dll - True - - - False - ..\packages\Microsoft.AspNet.SignalR.Core.1.1.2\lib\net40\Microsoft.AspNet.SignalR.Core.dll - - - False - ..\packages\Microsoft.AspNet.SignalR.Owin.1.1.2\lib\net40\Microsoft.AspNet.SignalR.Owin.dll - - - - ..\packages\Microsoft.Owin.1.1.0-beta2\lib\net40\Microsoft.Owin.dll - - - False - ..\packages\Microsoft.Owin.Host.HttpListener.1.1.0-beta2\lib\net40\Microsoft.Owin.Host.HttpListener.dll - - - False - ..\packages\Microsoft.Owin.Hosting.1.1.0-beta2\lib\net40\Microsoft.Owin.Hosting.dll - - - ..\packages\Nancy.0.16.1\lib\net40\Nancy.dll - - - False - ..\packages\Nancy.Owin.0.16.1\lib\net40\Nancy.Owin.dll - - - False - ..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll - - - False - ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll - - - False - ..\packages\Owin.1.0\lib\net40\Owin.dll - - Properties\SharedAssemblyInfo.cs - - Component + + True + True + Resources.resx - - - - - - - - - - + - - Form - - - - Always - Designer - - - Designer - - - - - - False @@ -185,19 +106,24 @@ - - {FD286DF8-2D3A-4394-8AD5-443FADE55FB2} - NzbDrone.Api - {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} NzbDrone.Common - - {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} - NzbDrone.Core + + {95C11A9E-56ED-456A-8447-2C89C1139266} + NzbDrone.Host + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + diff --git a/NzbDrone/Properties/Resources.Designer.cs b/NzbDrone/Properties/Resources.Designer.cs new file mode 100644 index 000000000..d47a0a7ea --- /dev/null +++ b/NzbDrone/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.32559 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NzbDrone.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NzbDrone.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon NzbDroneIcon { + get { + object obj = ResourceManager.GetObject("NzbDroneIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + } +} diff --git a/NzbDrone/Properties/Resources.resx b/NzbDrone/Properties/Resources.resx new file mode 100644 index 000000000..ad9178376 --- /dev/null +++ b/NzbDrone/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\..\nzbdrone.host\nzbdrone.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/NzbDrone/Resources/NzbDroneIcon.bmp b/NzbDrone/Resources/NzbDroneIcon.bmp new file mode 100644 index 000000000..55516c7aa Binary files /dev/null and b/NzbDrone/Resources/NzbDroneIcon.bmp differ diff --git a/NzbDrone/SysTray/SysTrayApp.cs b/NzbDrone/SysTray/SysTrayApp.cs index a748a635a..77dab4f53 100644 --- a/NzbDrone/SysTray/SysTrayApp.cs +++ b/NzbDrone/SysTray/SysTrayApp.cs @@ -1,12 +1,9 @@ using System; using System.ComponentModel; -using System.Drawing; -using System.Reflection; -using System.Threading; using System.Windows.Forms; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Owin; +using NzbDrone.Host.Owin; namespace NzbDrone.SysTray { @@ -32,15 +29,15 @@ namespace NzbDrone.SysTray public void Start() { - Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException); - Application.ApplicationExit += new EventHandler(OnApplicationExit); + Application.ThreadException += OnThreadException; + Application.ApplicationExit += OnApplicationExit; _trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser); _trayMenu.MenuItems.Add("-"); _trayMenu.MenuItems.Add("Exit", OnExit); _trayIcon.Text = String.Format("NzbDrone - {0}", BuildInfo.Version); - _trayIcon.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("NzbDrone.NzbDrone.ico")); + _trayIcon.Icon = Properties.Resources.NzbDroneIcon; _trayIcon.ContextMenu = _trayMenu; _trayIcon.Visible = true; @@ -85,7 +82,14 @@ namespace NzbDrone.SysTray private void LaunchBrowser(object sender, EventArgs e) { - _processProvider.Start(_hostController.AppUrl); + try + { + _processProvider.Start(_hostController.AppUrl); + } + catch (Exception) + { + + } } private void OnApplicationExit(object sender, EventArgs e) @@ -100,10 +104,17 @@ namespace NzbDrone.SysTray private void DisposeTrayIcon() { - _trayIcon.Visible = false; - _trayIcon.Icon = null; - _trayIcon.Visible = false; - _trayIcon.Dispose(); + try + { + _trayIcon.Visible = false; + _trayIcon.Icon = null; + _trayIcon.Visible = false; + _trayIcon.Dispose(); + } + catch (Exception e) + { + + } } } } \ No newline at end of file diff --git a/NzbDrone/WindowsApp.cs b/NzbDrone/WindowsApp.cs new file mode 100644 index 000000000..c4759f29e --- /dev/null +++ b/NzbDrone/WindowsApp.cs @@ -0,0 +1,24 @@ +using System; +using System.Windows.Forms; +using NzbDrone.SysTray; + +namespace NzbDrone +{ + public static class WindowsApp + { + public static void Main(string[] args) + { + try + { + var container = Host.Bootstrap.Start(args); + container.Register(); + container.Resolve().Start(); + } + catch (Exception e) + { + var message = string.Format("{0}: {1}", e.GetType().Name, e.Message); + MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!"); + } + } + } +} \ No newline at end of file