diff --git a/NzbDrone.App.Test/IISProviderFixture.cs b/NzbDrone.App.Test/IISProviderFixture.cs new file mode 100644 index 000000000..65c11abce --- /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_update_pid_env_varibles() + { + WithTempAsAppPath(); + + var dummy = StartDummyProcess(); + + Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PID, "0"); + 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 7fe0e878b..2ce65002a 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 @@ -65,6 +66,7 @@ + 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.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.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/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/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); 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.Common/LogConfiguration.cs b/NzbDrone.Common/LogConfiguration.cs index 7d7ede948..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)); @@ -68,7 +74,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.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.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/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 3d735ff29..ebfa4a2c6 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -93,7 +93,7 @@ - + diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs similarity index 56% rename from NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs rename to NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs index fdf863b3c..13e3b7d33 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/StartUpdateFixture.cs @@ -14,10 +14,12 @@ 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\"; + private readonly Guid _clientGuid = Guid.NewGuid(); + private readonly UpdatePackage updatePackage = new UpdatePackage { FileName = "NzbDrone.kay.one.0.6.0.2031.zip", @@ -29,9 +31,33 @@ 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); } + [Test] + public void should_delete_sandbox_before_update_if_folder_exists() + { + Mocker.GetMock().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(true); + + //Act + Mocker.Resolve().StartUpdate(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().StartUpdate(updatePackage); + + //Assert + Mocker.GetMock().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true), Times.Never()); + } [Test] public void Should_download_update_package() @@ -39,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( @@ -47,33 +73,49 @@ 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); //Act - Mocker.Resolve().StartUpgrade(updatePackage); + Mocker.Resolve().StartUpdate(updatePackage); //Assert Mocker.GetMock().Verify( 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().StartUpdate(updatePackage); + + //Assert + Mocker.GetMock().Verify( + c => c.CopyDirectory(updateClientFolder, SANDBOX_FOLDER)); + } + [Test] 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); + Mocker.Resolve().StartUpdate(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] @@ -92,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/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 831fb6ac7..1e0fd30cb 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -92,6 +92,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 787c1b986..9044ead71 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -220,6 +220,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..f404f7bef --- /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.StartUpdate(updatePackage); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index e9863b636..c675bd606 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; @@ -12,12 +13,15 @@ using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { - class UpdateProvider + public 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 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); @@ -25,13 +29,16 @@ 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, DiskProvider diskProvider) { _httpProvider = httpProvider; _configProvider = configProvider; + _configFileProvider = configFileProvider; _enviromentProvider = enviromentProvider; _archiveProvider = archiveProvider; + _processProvider = processProvider; + _diskProvider = diskProvider; } public UpdateProvider() @@ -71,10 +78,16 @@ 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); + 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); @@ -82,6 +95,20 @@ namespace NzbDrone.Core.Providers logger.Info("Extracting Update package"); _archiveProvider.ExtractArchive(packageDestination, _enviromentProvider.GetUpdateSandboxFolder()); logger.Info("Update package extracted successfully"); + + logger.Info("Preparing client"); + _diskProvider.CopyDirectory(_enviromentProvider.GetUpdateClientFolder(), _enviromentProvider.GetUpdateSandboxFolder()); + + + 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.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 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.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.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/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/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); 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.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/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 diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs index de1536f10..4b5ad3ef7 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone/Providers/IISProvider.cs @@ -53,9 +53,9 @@ 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()); + + startInfo.EnvironmentVariables[EnviromentProvider.NZBDRONE_PATH] = _enviromentProvider.ApplicationPath; + startInfo.EnvironmentVariables[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 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