From 56a6e1372de53ffb8f4757df454cf718bf1416fd Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 16:57:03 -0800 Subject: [PATCH 1/7] 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.Linq; using System.Xml.Linq; using System.Xml.XPath; using NLog; +using Ninject; using NzbDrone.Common.Model; namespace NzbDrone.Common @@ -14,6 +15,8 @@ namespace NzbDrone.Common private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private readonly string _configFile; + + [Inject] public ConfigFileProvider(EnviromentProvider enviromentProvider) { _enviromentProvider = enviromentProvider; @@ -22,6 +25,11 @@ namespace NzbDrone.Common 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 @@ namespace NzbDrone.Common 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 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests { 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 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests public void Setup() { Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); + Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); } @@ -65,15 +68,18 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests //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 @@ namespace NzbDrone.Core.Providers { 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 @@ namespace NzbDrone.Core.Providers [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 @@ namespace NzbDrone.Core.Providers 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 From 88f4d15fa947a5ac2509eb079ad0b2945bc748b4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 17:27:11 -0800 Subject: [PATCH 2/7] Added some update tests --- NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 + .../NzbDrone.Common.Test.csproj | 1 + NzbDrone.Common.Test/PathExtentionFixture.cs | 27 +++++++++++++++++++ NzbDrone.Common/PathExtentions.cs | 8 +++++- .../PreformUpdateFixture.cs | 15 ++++++++++- NzbDrone.Core/Providers/UpdateProvider.cs | 9 +++++-- .../NzbDrone.Test.Common.csproj | 1 + 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 7fe0e878b..4bb247286 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86 diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index d979c397e..2b5a0dfda 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86 diff --git a/NzbDrone.Common.Test/PathExtentionFixture.cs b/NzbDrone.Common.Test/PathExtentionFixture.cs index c1d5abb4d..7924da49a 100644 --- a/NzbDrone.Common.Test/PathExtentionFixture.cs +++ b/NzbDrone.Common.Test/PathExtentionFixture.cs @@ -13,8 +13,11 @@ namespace NzbDrone.Common.Test private EnviromentProvider GetEnviromentProvider() { var envMoq = new Mock(); + envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\"); + envMoq.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); + return envMoq.Object; } @@ -49,5 +52,29 @@ namespace NzbDrone.Common.Test { GetEnviromentProvider().GetNlogConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config"); } + + [Test] + public void Sanbox() + { + GetEnviromentProvider().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\"); + } + + [Test] + public void GetUpdatePackageFolder() + { + GetEnviromentProvider().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\"); + } + + [Test] + public void GetUpdateClientFolder() + { + GetEnviromentProvider().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\"); + } + + [Test] + public void GetUpdateClientExePath() + { + GetEnviromentProvider().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\NzbDrone.Update.exe"); + } } } diff --git a/NzbDrone.Common/PathExtentions.cs b/NzbDrone.Common/PathExtentions.cs index 6a1071097..49f2d46a6 100644 --- a/NzbDrone.Common/PathExtentions.cs +++ b/NzbDrone.Common/PathExtentions.cs @@ -20,6 +20,7 @@ namespace NzbDrone.Common private const string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone\\"; private const string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup\\"; private const string UPDATE_CLIENT_EXE = "nzbdrone.update.exe"; + private const string UPDATE_CLIENT_FOLDER_NAME = "NzbDrone.Update\\"; public static string GetIISFolder(this EnviromentProvider enviromentProvider) { @@ -91,9 +92,14 @@ namespace NzbDrone.Common return Path.Combine(enviromentProvider.GetUpdateSandboxFolder(), UPDATE_PACKAGE_FOLDER_NAME); } + public static string GetUpdateClientFolder(this EnviromentProvider enviromentProvider) + { + return Path.Combine(enviromentProvider.GetUpdatePackageFolder(), UPDATE_CLIENT_FOLDER_NAME); + } + public static string GetUpdateClientExePath(this EnviromentProvider enviromentProvider) { - return Path.Combine(enviromentProvider.GetUpdateSandboxFolder(), UPDATE_CLIENT_EXE); + return Path.Combine(enviromentProvider.GetUpdateClientFolder(), UPDATE_CLIENT_EXE); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs index bdb668443..9e23e3c29 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests } [Test] - public void Should_call_download_and_extract_using_correct_arguments() + public void Should_extract_update_package() { var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName); @@ -62,6 +62,19 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests c => c.ExtractArchive(updateArchive, SANDBOX_FOLDER)); } + [Test] + public void Should_copy_update_client_to_root_of_sandbox() + { + var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); + + //Act + Mocker.Resolve().StartUpgrade(updatePackage); + + //Assert + Mocker.GetMock().Verify( + c => c.CopyDirectory(updateClientFolder, SANDBOX_FOLDER)); + } + [Test] public void should_start_update_client() { diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index 0af33a383..f2d6b66a0 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -21,6 +21,7 @@ namespace NzbDrone.Core.Providers private readonly EnviromentProvider _enviromentProvider; private readonly ArchiveProvider _archiveProvider; private readonly ProcessProvider _processProvider; + private readonly DiskProvider _diskProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Regex parseRegex = new Regex(@"(?:\>)(?NzbDrone.+?(?\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); @@ -29,7 +30,7 @@ namespace NzbDrone.Core.Providers [Inject] public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, ConfigFileProvider configFileProvider, - EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider) + EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider, DiskProvider diskProvider) { _httpProvider = httpProvider; _configProvider = configProvider; @@ -37,6 +38,7 @@ namespace NzbDrone.Core.Providers _enviromentProvider = enviromentProvider; _archiveProvider = archiveProvider; _processProvider = processProvider; + _diskProvider = diskProvider; } public UpdateProvider() @@ -88,8 +90,11 @@ namespace NzbDrone.Core.Providers _archiveProvider.ExtractArchive(packageDestination, _enviromentProvider.GetUpdateSandboxFolder()); logger.Info("Update package extracted successfully"); - logger.Info("Starting update client"); + logger.Info("Preparing client"); + _diskProvider.CopyDirectory(_enviromentProvider.GetUpdateClientFolder(), _enviromentProvider.GetUpdateSandboxFolder()); + + logger.Info("Starting update client"); var startInfo = new ProcessStartInfo() { FileName = _enviromentProvider.GetUpdateClientExePath(), diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index 71cdb191b..60777f58a 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x86 From 6369d4f81794eba9003916b67ab8ef451395026e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 18:54:09 -0800 Subject: [PATCH 3/7] Update updates ;) --- .gitignore | 3 +- NzbDrone.Common/LogConfiguration.cs | 8 ++++- NzbDrone.Common/Properties/AssemblyInfo.cs | 4 +-- .../PreformUpdateFixture.cs | 23 +++++++++++++ NzbDrone.Core/CentralDispatch.cs | 1 + NzbDrone.Core/NzbDrone.Core.csproj | 1 + NzbDrone.Core/Properties/AssemblyInfo.cs | 4 +-- NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs | 33 +++++++++++++++++++ NzbDrone.Core/Providers/UpdateProvider.cs | 8 ++++- NzbDrone.Update/Properties/AssemblyInfo.cs | 4 +-- NzbDrone.Web/Global.asax.cs | 5 +-- NzbDrone.Web/Properties/AssemblyInfo.cs | 4 +-- NzbDrone/Properties/AssemblyInfo.cs | 4 +-- 13 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs diff --git a/.gitignore b/.gitignore index 11bfc37d5..31ea5068e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ NzbDrone.Web/NzbDrone.Web.Publish.xml *.orig _rawPackage/ NzbDrone.zip -NzbDrone.sln.DotSettings.user* \ No newline at end of file +NzbDrone.sln.DotSettings.user* +config.xml \ No newline at end of file diff --git a/NzbDrone.Common/LogConfiguration.cs b/NzbDrone.Common/LogConfiguration.cs index a5e32f16f..c4740a4cf 100644 --- a/NzbDrone.Common/LogConfiguration.cs +++ b/NzbDrone.Common/LogConfiguration.cs @@ -50,12 +50,18 @@ namespace NzbDrone.Common { try { - var udpTarget = new ChainsawTarget(); + var udpTarget = new NLogViewerTarget(); udpTarget.Address = "udp://127.0.0.1:20480"; udpTarget.IncludeCallSite = true; udpTarget.IncludeSourceInfo = true; udpTarget.IncludeNLogData = true; udpTarget.IncludeNdc = true; + udpTarget.Parameters.Add(new NLogViewerParameterInfo + { + Name = "Exception", + Layout = "${exception:format=ToString}" + }); + LogManager.Configuration.AddTarget(udpTarget.GetType().Name, udpTarget); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, udpTarget)); diff --git a/NzbDrone.Common/Properties/AssemblyInfo.cs b/NzbDrone.Common/Properties/AssemblyInfo.cs index 09cbe12f1..56062366d 100644 --- a/NzbDrone.Common/Properties/AssemblyInfo.cs +++ b/NzbDrone.Common/Properties/AssemblyInfo.cs @@ -12,5 +12,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.0.*")] -[assembly: AssemblyFileVersion("0.6.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.*")] \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs index 9e23e3c29..d2a9d7932 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs @@ -35,6 +35,29 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests } + [Test] + public void should_delete_sandbox_before_update_if_folder_exists() + { + Mocker.GetMock().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(true); + + //Act + Mocker.Resolve().StartUpgrade(updatePackage); + + //Assert + Mocker.GetMock().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true)); + } + + [Test] + public void should_not_delete_sandbox_before_update_if_folder_doesnt_exists() + { + Mocker.GetMock().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(false); + + //Act + Mocker.Resolve().StartUpgrade(updatePackage); + + //Assert + Mocker.GetMock().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true), Times.Never()); + } [Test] public void Should_download_update_package() diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 6195b784d..3e12ff1c9 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -91,6 +91,7 @@ namespace NzbDrone.Core Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); + Kernel.Bind().To().InSingletonScope(); Kernel.Get().Initialize(); Kernel.Get().StartTimer(30); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 0704a0304..82ee618e9 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -217,6 +217,7 @@ + diff --git a/NzbDrone.Core/Properties/AssemblyInfo.cs b/NzbDrone.Core/Properties/AssemblyInfo.cs index 22129d044..0647faa1b 100644 --- a/NzbDrone.Core/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core/Properties/AssemblyInfo.cs @@ -16,5 +16,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.0.*")] -[assembly: AssemblyFileVersion("0.6.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.*")] \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs b/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs new file mode 100644 index 000000000..58ff10345 --- /dev/null +++ b/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs @@ -0,0 +1,33 @@ +using NzbDrone.Core.Model.Notification; + +namespace NzbDrone.Core.Providers.Jobs +{ + public class AppUpdateJob : IJob + { + private readonly UpdateProvider _updateProvider; + + public AppUpdateJob(UpdateProvider updateProvider) + { + _updateProvider = updateProvider; + } + + public string Name + { + get { return "Update Application Job"; } + } + + public int DefaultInterval + { + get { return 0; } + } + + public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + { + notification.CurrentMessage = "Updating NzbDrone"; + + var updatePackage = _updateProvider.GetAvilableUpdate(); + + _updateProvider.StartUpgrade(updatePackage); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index f2d6b66a0..454600020 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -13,7 +13,7 @@ using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { - class UpdateProvider + public class UpdateProvider { private readonly HttpProvider _httpProvider; private readonly ConfigProvider _configProvider; @@ -82,6 +82,12 @@ namespace NzbDrone.Core.Providers { var packageDestination = Path.Combine(_enviromentProvider.GetUpdateSandboxFolder(), updatePackage.FileName); + if (_diskProvider.FolderExists(_enviromentProvider.GetUpdateSandboxFolder())) + { + logger.Info("Deleting old update files"); + _diskProvider.DeleteFolder(_enviromentProvider.GetUpdateSandboxFolder(), true); + } + logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination); _httpProvider.DownloadFile(updatePackage.Url, packageDestination); logger.Info("Download completed for update package from [{0}]", updatePackage.FileName); diff --git a/NzbDrone.Update/Properties/AssemblyInfo.cs b/NzbDrone.Update/Properties/AssemblyInfo.cs index 5ab9d9465..0c2c44382 100644 --- a/NzbDrone.Update/Properties/AssemblyInfo.cs +++ b/NzbDrone.Update/Properties/AssemblyInfo.cs @@ -12,5 +12,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.0.*")] -[assembly: AssemblyFileVersion("0.6.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.*")] \ No newline at end of file diff --git a/NzbDrone.Web/Global.asax.cs b/NzbDrone.Web/Global.asax.cs index 407d03145..35509a499 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -56,12 +56,13 @@ namespace NzbDrone.Web protected override IKernel CreateKernel() { + LogManager.Configuration = new XmlLoggingConfiguration(new EnviromentProvider().GetNlogConfigPath(), false); + Common.LogConfiguration.RegisterUdpLogger(); Common.LogConfiguration.RegisterExceptioneer(); Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication"); Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch"); - - LogManager.Configuration = new XmlLoggingConfiguration(new EnviromentProvider().GetNlogConfigPath(), false); + var dispatch = new CentralDispatch(); Logger.Info("NzbDrone Starting up."); diff --git a/NzbDrone.Web/Properties/AssemblyInfo.cs b/NzbDrone.Web/Properties/AssemblyInfo.cs index 3eccefe42..eca7b7623 100644 --- a/NzbDrone.Web/Properties/AssemblyInfo.cs +++ b/NzbDrone.Web/Properties/AssemblyInfo.cs @@ -9,5 +9,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.0.*")] -[assembly: AssemblyFileVersion("0.6.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.*")] \ No newline at end of file diff --git a/NzbDrone/Properties/AssemblyInfo.cs b/NzbDrone/Properties/AssemblyInfo.cs index af21a197e..4cb98db28 100644 --- a/NzbDrone/Properties/AssemblyInfo.cs +++ b/NzbDrone/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.0.*")] -[assembly: AssemblyFileVersion("0.6.0.*")] \ No newline at end of file +[assembly: AssemblyVersion("0.0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.*")] \ No newline at end of file From fbf7d20c5d09b0fb528cfda18c7102b282df1091 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 19:09:34 -0800 Subject: [PATCH 4/7] Fixed update client path issue --- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 +- ...mUpdateFixture.cs => StartUpdateFixture.cs} | 18 +++++++++--------- NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs | 2 +- NzbDrone.Core/Providers/UpdateProvider.cs | 4 ++-- NzbDrone.Update.Test/ProgramFixture.cs | 2 +- NzbDrone.Update/Program.cs | 4 +++- 6 files changed, 17 insertions(+), 15 deletions(-) rename NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/{PreformUpdateFixture.cs => StartUpdateFixture.cs} (87%) diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8df497f7e..5210dc9d5 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -92,7 +92,7 @@ - + diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs similarity index 87% rename from NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs rename to NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs index d2a9d7932..13e3b7d33 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs @@ -14,7 +14,7 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests { [TestFixture] - internal class PreformUpdateFixture : CoreTest + internal class StartUpdateFixture : CoreTest { private const string SANDBOX_FOLDER = @"C:\Temp\nzbdrone_update\"; @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests Mocker.GetMock().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(true); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true)); @@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests Mocker.GetMock().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(false); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true), Times.Never()); @@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify( @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify( @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify( @@ -108,13 +108,13 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests .SetupGet(c => c.NzbDroneProcessIdFromEnviroment).Returns(12); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify( c => c.Start(It.Is(p => p.FileName == updateClientPath && - p.Arguments == "/12 /" + _clientGuid.ToString()) + p.Arguments == "12 " + _clientGuid.ToString()) )); } @@ -134,7 +134,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests Mocker.Resolve(); Mocker.Resolve(); Mocker.Resolve(); - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); updateSubFolder.Refresh(); //Assert diff --git a/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs b/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs index 58ff10345..f404f7bef 100644 --- a/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs +++ b/NzbDrone.Core/Providers/Jobs/AppUpdateJob.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Providers.Jobs var updatePackage = _updateProvider.GetAvilableUpdate(); - _updateProvider.StartUpgrade(updatePackage); + _updateProvider.StartUpdate(updatePackage); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index 454600020..c675bd606 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Providers return null; } - public virtual void StartUpgrade(UpdatePackage updatePackage) + public virtual void StartUpdate(UpdatePackage updatePackage) { var packageDestination = Path.Combine(_enviromentProvider.GetUpdateSandboxFolder(), updatePackage.FileName); @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Providers var startInfo = new ProcessStartInfo() { FileName = _enviromentProvider.GetUpdateClientExePath(), - Arguments = string.Format("/{0} /{1}", _enviromentProvider.NzbDroneProcessIdFromEnviroment, _configFileProvider.Guid) + Arguments = string.Format("{0} {1}", _enviromentProvider.NzbDroneProcessIdFromEnviroment, _configFileProvider.Guid) }; _processProvider.Start(startInfo); diff --git a/NzbDrone.Update.Test/ProgramFixture.cs b/NzbDrone.Update.Test/ProgramFixture.cs index d5421930c..fd715e0c7 100644 --- a/NzbDrone.Update.Test/ProgramFixture.cs +++ b/NzbDrone.Update.Test/ProgramFixture.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Update.Test _program.Start(new[] { "12", "" }); //Assert - Mocker.GetMock().Verify(c => c.Start(ProcessPath), Times.Once()); + Mocker.GetMock().Verify(c => c.Start(@"C:\NzbDrone"), Times.Once()); } diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 6816547ec..ed3cf0f34 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using NLog; using NzbDrone.Common; @@ -52,7 +53,8 @@ namespace NzbDrone.Update VerfityArguments(args); int processId = ParseProcessId(args); - string appPath = _processProvider.GetProcessById(processId).StartPath; + FileInfo exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath); + string appPath = exeFileInfo.Directory.FullName; logger.Info("Starting update process"); _updateProvider.Start(appPath); From bc5307a4d3791ee7ecfe545418e3959445b0feae Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 19:37:36 -0800 Subject: [PATCH 5/7] Fixed Environment Variable conflict in IISProvider --- NzbDrone.App.Test/IISProviderFixture.cs | 64 +++++++++++++++++++ NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 + NzbDrone.Common.Test/ProcessProviderTests.cs | 15 +++-- NzbDrone.Common/EnviromentProvider.cs | 5 +- .../{Program.cs => DummyApp.cs} | 4 +- .../NzbDrone.Test.Dummy.csproj | 2 +- NzbDrone/Providers/IISProvider.cs | 12 +++- NzbDrone/Providers/MonitoringProvider.cs | 2 +- 8 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 NzbDrone.App.Test/IISProviderFixture.cs rename NzbDrone.Test.Dummy/{Program.cs => DummyApp.cs} (76%) diff --git a/NzbDrone.App.Test/IISProviderFixture.cs b/NzbDrone.App.Test/IISProviderFixture.cs new file mode 100644 index 000000000..8938ab3f1 --- /dev/null +++ b/NzbDrone.App.Test/IISProviderFixture.cs @@ -0,0 +1,64 @@ +using System; +using System.Diagnostics; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using Ninject; +using NzbDrone.Common; +using NzbDrone.Common.Model; +using NzbDrone.Providers; +using NzbDrone.Test.Common; +using NzbDrone.Test.Dummy; + +namespace NzbDrone.App.Test +{ + [TestFixture] + public class IISProviderFixture : TestBase + { + [Test] + public void should_not_set_env_varibles_twice() + { + WithTempAsAppPath(); + + var dummy = StartDummyProcess(); + + Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PID, "Test"); + Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PATH, "Test"); + + Mocker.GetMock() + .Setup(c => c.Start(It.IsAny())) + .Returns(dummy); + + Mocker.Resolve().StartServer(); + } + + [Test] + public void should_set_iis_procces_id() + { + WithTempAsAppPath(); + var dummy = StartDummyProcess(); + + Mocker.GetMock() + .Setup(c => c.Start(It.IsAny())) + .Returns(dummy); + + //act + Mocker.Resolve().StartServer(); + + //assert + Mocker.Resolve().IISProcessId.Should().Be(dummy.Id); + } + + + public Process StartDummyProcess() + { + var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); + startInfo.UseShellExecute = false; + startInfo.RedirectStandardOutput = true; + startInfo.RedirectStandardError = true; + startInfo.CreateNoWindow = true; + return new ProcessProvider().Start(startInfo); + } + + } +} diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 4bb247286..2ce65002a 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -66,6 +66,7 @@ + diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index 9144eb7fc..c62eb1f83 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -4,26 +4,27 @@ using System.Linq; using FluentAssertions; using NUnit.Framework; using NzbDrone.Test.Common; +using NzbDrone.Test.Dummy; namespace NzbDrone.Common.Test { [TestFixture] public class ProcessProviderTests : TestBase { - private const string DummyProccessName = "NzbDrone.Test.Dummy"; + ProcessProvider _processProvider; [SetUp] public void Setup() { - Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill()); + Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill()); _processProvider = new ProcessProvider(); } [TearDown] public void TearDown() { - Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill()); + Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill()); } [TestCase(0)] @@ -58,20 +59,20 @@ namespace NzbDrone.Common.Test [Test] public void Should_be_able_to_start_process() { - var startInfo = new ProcessStartInfo(DummyProccessName + ".exe"); + var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); //Act/Assert - _processProvider.GetProcessByName(DummyProccessName).Should() + _processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() .BeEmpty("Dummy process is already running"); _processProvider.Start(startInfo).Should().NotBeNull(); - _processProvider.GetProcessByName(DummyProccessName).Should() + _processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should() .HaveCount(1, "excepted one dummy process to be already running"); } public Process StartDummyProcess() { - var startInfo = new ProcessStartInfo(DummyProccessName + ".exe"); + var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe"); return _processProvider.Start(startInfo); } diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index 25b055a84..572d3460e 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -9,6 +9,9 @@ namespace NzbDrone.Common { public const string IIS_FOLDER_NAME = "iisexpress"; + public const string NZBDRONE_PATH = "NZBDRONE_PATH"; + public const string NZBDRONE_PID = "NZBDRONE_PID"; + #if DEBUG private static readonly bool isInDebug = true; #else @@ -98,7 +101,7 @@ namespace NzbDrone.Common { get { - var id = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID")); + var id = Convert.ToInt32(Environment.GetEnvironmentVariable(NZBDRONE_PID)); if (id == 0) throw new InvalidOperationException("NZBDRONE_PID isn't a valid environment variable."); diff --git a/NzbDrone.Test.Dummy/Program.cs b/NzbDrone.Test.Dummy/DummyApp.cs similarity index 76% rename from NzbDrone.Test.Dummy/Program.cs rename to NzbDrone.Test.Dummy/DummyApp.cs index 746e7ef5c..87b04f712 100644 --- a/NzbDrone.Test.Dummy/Program.cs +++ b/NzbDrone.Test.Dummy/DummyApp.cs @@ -3,8 +3,10 @@ using System.Diagnostics; namespace NzbDrone.Test.Dummy { - class Program + public class DummyApp { + public const string DUMMY_PROCCESS_NAME = "NzbDrone.Test.Dummy"; + static void Main(string[] args) { Console.WriteLine("Dummy process. ID:{0} Path:{1}", Process.GetCurrentProcess().Id, Process.GetCurrentProcess().MainModule.FileName); diff --git a/NzbDrone.Test.Dummy/NzbDrone.Test.Dummy.csproj b/NzbDrone.Test.Dummy/NzbDrone.Test.Dummy.csproj index add24c10b..e14726179 100644 --- a/NzbDrone.Test.Dummy/NzbDrone.Test.Dummy.csproj +++ b/NzbDrone.Test.Dummy/NzbDrone.Test.Dummy.csproj @@ -43,7 +43,7 @@ - + diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs index de1536f10..e58efec64 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone/Providers/IISProvider.cs @@ -53,9 +53,15 @@ namespace NzbDrone.Providers startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; - //Set Variables for the config file. - startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _enviromentProvider.ApplicationPath); - startInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString()); + if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PATH)) + { + startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PATH, _enviromentProvider.ApplicationPath); + } + + if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PID)) + { + startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PID, Process.GetCurrentProcess().Id.ToString()); + } try { diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs index f28f44230..201e21b8c 100644 --- a/NzbDrone/Providers/MonitoringProvider.cs +++ b/NzbDrone/Providers/MonitoringProvider.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Providers }.Submit(); } - Logger.FatalException("EPIC FAIL: {0}", excepion); + Logger.FatalException("EPIC FAIL: " + excepion.Message, excepion); } } } \ No newline at end of file From ecbf1273210e19e2ea70b533db222e4873887a51 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 20:05:33 -0800 Subject: [PATCH 6/7] Fixed a bug in DiskProvider where it wouldn't copy subfolders properly. --- NzbDrone.Common.Test/DiskProviderTests.cs | 20 ++++++++++++-------- NzbDrone.Common/DiskProvider.cs | 7 ++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Common.Test/DiskProviderTests.cs b/NzbDrone.Common.Test/DiskProviderTests.cs index 8729ae4b4..d2c2a950a 100644 --- a/NzbDrone.Common.Test/DiskProviderTests.cs +++ b/NzbDrone.Common.Test/DiskProviderTests.cs @@ -35,11 +35,7 @@ namespace NzbDrone.Common.Test diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Assert - BinFolder.Refresh(); - BinFolderCopy.Refresh(); - - BinFolder.GetFiles("*.*", SearchOption.AllDirectories) - .Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)); + VerifyCopy(); } [Test] @@ -51,16 +47,24 @@ namespace NzbDrone.Common.Test diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Delete Random File - BinFolderCopy.GetFiles().First().Delete(); + BinFolderCopy.Refresh(); + BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Assert + VerifyCopy(); + } + + private void VerifyCopy() + { BinFolder.Refresh(); BinFolderCopy.Refresh(); - BinFolder.GetFiles("*.*", SearchOption.AllDirectories) - .Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)); + BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories) + .Should().HaveSameCount(BinFolder.GetFiles("*.*", SearchOption.AllDirectories)); + + BinFolderCopy.GetDirectories().Should().HaveSameCount(BinFolder.GetDirectories()); } } } diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index a3f49be2f..340ad3ff7 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -67,7 +67,12 @@ namespace NzbDrone.Common targetFolder.Create(); } - foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.AllDirectories)) + foreach (var subDir in sourceFolder.GetDirectories()) + { + CopyDirectory(subDir.FullName, Path.Combine(target, subDir.Name)); + } + + foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly)) { var destFile = Path.Combine(target, file.Name); file.CopyTo(destFile, true); From 571998e70e0b449724b37dc931cead1e3b1a6390 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 20:22:53 -0800 Subject: [PATCH 7/7] better PID environment variable handling. --- NzbDrone.App.Test/IISProviderFixture.cs | 4 ++-- NzbDrone/Providers/IISProvider.cs | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/NzbDrone.App.Test/IISProviderFixture.cs b/NzbDrone.App.Test/IISProviderFixture.cs index 8938ab3f1..65c11abce 100644 --- a/NzbDrone.App.Test/IISProviderFixture.cs +++ b/NzbDrone.App.Test/IISProviderFixture.cs @@ -16,13 +16,13 @@ namespace NzbDrone.App.Test public class IISProviderFixture : TestBase { [Test] - public void should_not_set_env_varibles_twice() + public void should_update_pid_env_varibles() { WithTempAsAppPath(); var dummy = StartDummyProcess(); - Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PID, "Test"); + Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PID, "0"); Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PATH, "Test"); Mocker.GetMock() diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs index e58efec64..4b5ad3ef7 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone/Providers/IISProvider.cs @@ -53,15 +53,9 @@ namespace NzbDrone.Providers startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; - if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PATH)) - { - startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PATH, _enviromentProvider.ApplicationPath); - } - if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PID)) - { - startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PID, Process.GetCurrentProcess().Id.ToString()); - } + startInfo.EnvironmentVariables[EnviromentProvider.NZBDRONE_PATH] = _enviromentProvider.ApplicationPath; + startInfo.EnvironmentVariables[EnviromentProvider.NZBDRONE_PID] = Process.GetCurrentProcess().Id.ToString(); try {