From 56a6e1372de53ffb8f4757df454cf718bf1416fd Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 16:57:03 -0800 Subject: [PATCH] Update client is now included in the build package --- NzbDrone.Common/ConfigFileProvider.cs | 8 ++++++++ NzbDrone.Common/LogConfiguration.cs | 1 - NzbDrone.Common/NzbDrone.Common.csproj | 4 ++++ .../PreformUpdateFixture.cs | 12 ++++++++--- NzbDrone.Core/Providers/UpdateProvider.cs | 20 +++++++++++++++++-- .../NzbDrone.Update.Test.csproj | 4 +++- NzbDrone.Update/NzbDrone.Update.csproj | 4 +++- NzbDrone.Update/app.config | 3 +++ package.bat | 9 +++++++-- 9 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 NzbDrone.Update/app.config diff --git a/NzbDrone.Common/ConfigFileProvider.cs b/NzbDrone.Common/ConfigFileProvider.cs index 495c57ce6..e82df3874 100644 --- a/NzbDrone.Common/ConfigFileProvider.cs +++ b/NzbDrone.Common/ConfigFileProvider.cs @@ -4,6 +4,7 @@ using System.Xml.Linq; using System.Xml.XPath; using NLog; +using Ninject; using NzbDrone.Common.Model; namespace NzbDrone.Common @@ -14,6 +15,8 @@ public class ConfigFileProvider private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private readonly string _configFile; + + [Inject] public ConfigFileProvider(EnviromentProvider enviromentProvider) { _enviromentProvider = enviromentProvider; @@ -22,6 +25,11 @@ public ConfigFileProvider(EnviromentProvider enviromentProvider) CreateDefaultConfigFile(); } + public ConfigFileProvider() + { + + } + public virtual Guid Guid { get diff --git a/NzbDrone.Common/LogConfiguration.cs b/NzbDrone.Common/LogConfiguration.cs index 7d7ede948..a5e32f16f 100644 --- a/NzbDrone.Common/LogConfiguration.cs +++ b/NzbDrone.Common/LogConfiguration.cs @@ -68,7 +68,6 @@ public static void RegisterUdpLogger() if (LogManager.ThrowExceptions) throw; } - } public static void RegisterExceptioneer() diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index b7461ac7b..a33eee862 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -30,11 +30,15 @@ TRACE prompt 4 + x86 ..\Libraries\Exceptioneer.WindowsFormsClient.dll + + ..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll + ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs index fdf863b3c..bdb668443 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs @@ -18,6 +18,8 @@ internal class PreformUpdateFixture : CoreTest { private const string SANDBOX_FOLDER = @"C:\Temp\nzbdrone_update\"; + private readonly Guid _clientGuid = Guid.NewGuid(); + private readonly UpdatePackage updatePackage = new UpdatePackage { FileName = "NzbDrone.kay.one.0.6.0.2031.zip", @@ -29,6 +31,7 @@ internal class PreformUpdateFixture : CoreTest public void Setup() { Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); + Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); } @@ -65,15 +68,18 @@ public void should_start_update_client() //Setup var updateClientPath = Mocker.GetMock().Object.GetUpdateClientExePath(); + Mocker.GetMock() + .SetupGet(c => c.NzbDroneProcessIdFromEnviroment).Returns(12); + //Act Mocker.Resolve().StartUpgrade(updatePackage); //Assert Mocker.GetMock().Verify( - c => c.Start(It.Is(p => + c => c.Start(It.Is(p => p.FileName == updateClientPath && - p.Arguments == "/12 /" - ))); + p.Arguments == "/12 /" + _clientGuid.ToString()) + )); } [Test] diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index e9863b636..0af33a383 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -16,8 +17,10 @@ class UpdateProvider { private readonly HttpProvider _httpProvider; private readonly ConfigProvider _configProvider; + private readonly ConfigFileProvider _configFileProvider; private readonly EnviromentProvider _enviromentProvider; private readonly ArchiveProvider _archiveProvider; + private readonly ProcessProvider _processProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Regex parseRegex = new Regex(@"(?:\>)(?NzbDrone.+?(?\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); @@ -25,13 +28,15 @@ class UpdateProvider [Inject] - public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, - EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider) + public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, ConfigFileProvider configFileProvider, + EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider) { _httpProvider = httpProvider; _configProvider = configProvider; + _configFileProvider = configFileProvider; _enviromentProvider = enviromentProvider; _archiveProvider = archiveProvider; + _processProvider = processProvider; } public UpdateProvider() @@ -82,6 +87,17 @@ public virtual void StartUpgrade(UpdatePackage updatePackage) logger.Info("Extracting Update package"); _archiveProvider.ExtractArchive(packageDestination, _enviromentProvider.GetUpdateSandboxFolder()); logger.Info("Update package extracted successfully"); + + logger.Info("Starting update client"); + + var startInfo = new ProcessStartInfo() + { + FileName = _enviromentProvider.GetUpdateClientExePath(), + Arguments = string.Format("/{0} /{1}", _enviromentProvider.NzbDroneProcessIdFromEnviroment, _configFileProvider.Guid) + }; + + _processProvider.Start(startInfo); + } } diff --git a/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj b/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj index 8b40d13af..8484b9288 100644 --- a/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj +++ b/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj @@ -48,7 +48,9 @@ ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll - + + ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll + ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll diff --git a/NzbDrone.Update/NzbDrone.Update.csproj b/NzbDrone.Update/NzbDrone.Update.csproj index 1310f2da8..1212ac035 100644 --- a/NzbDrone.Update/NzbDrone.Update.csproj +++ b/NzbDrone.Update/NzbDrone.Update.csproj @@ -11,7 +11,8 @@ NzbDrone.Update NzbDrone.Update v4.0 - Client + + 512 @@ -49,6 +50,7 @@ + diff --git a/NzbDrone.Update/app.config b/NzbDrone.Update/app.config new file mode 100644 index 000000000..e36560333 --- /dev/null +++ b/NzbDrone.Update/app.config @@ -0,0 +1,3 @@ + + + diff --git a/package.bat b/package.bat index bf4355f5f..5322f9fed 100644 --- a/package.bat +++ b/package.bat @@ -4,10 +4,12 @@ SET TARGET=%PACKAGEROOT%\NzbDrone rd %TARGET% /S /Q del nzbdrone*.zip /Q /F + + xcopy IISExpress %TARGET%\IISExpress /E /V /I /Y xcopy NzbDrone\bin\Release\*.* %TARGET%\ /E /V /I /Y - +xcopy NzbDrone.Update\bin\Release\*.* %TARGET%\NzbDrone.Update\ /E /V /I /Y xcopy NzbDrone.Web\bin\*.* %TARGET%\NzbDrone.Web\bin\ /E /V /I /Y xcopy NzbDrone.Web\App_GlobalResources\*.* %TARGET%\NzbDrone.Web\App_GlobalResources\ /E /V /I /Y @@ -15,7 +17,8 @@ xcopy NzbDrone.Web\Content\*.* %TARGET%\NzbDrone.Web\Content\ /E /V /I /Y xcopy NzbDrone.Web\Scripts\*.* %TARGET%\NzbDrone.Web\Scripts\ /E /V /I /Y xcopy NzbDrone.Web\Views\*.* %TARGET%\NzbDrone.Web\Views\ /E /V /I /Y -del %TARGET%\NzbDrone.Web\bin\*.xml /q +del %TARGET%\NzbDrone.Web\bin\*.xml /Q /F + xcopy NzbDrone.Web\log.config %TARGET%\NzbDrone.Web\ @@ -27,6 +30,8 @@ xcopy NzbDrone.Web\web.config %TARGET%\NzbDrone.Web\ CD %PACKAGEROOT% del nlog.xml /Q /F /S +del nlog.pdb /Q /F /S +del Twitterizer2.pdb /Q /F /S del *.vshost.exe.* /Q /F /S del ninject*.pdb /Q /F /S del ninject*.xml /Q /F /S