Update fixes.

This commit is contained in:
kay.one 2011-11-20 18:59:42 -08:00
parent b74ef12a4c
commit 508be34ebc
9 changed files with 87 additions and 70 deletions

3
.gitignore vendored
View File

@ -41,4 +41,5 @@ NzbDrone.Web/NzbDrone.Web.Publish.xml
_rawPackage/
NzbDrone.zip
NzbDrone.sln.DotSettings.user*
config.xml
config.xml
UpdateLogs/

View File

@ -40,6 +40,7 @@
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="Ninject, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL" />
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>

View File

@ -1,20 +1,21 @@
using System;
using System.Linq;
using System;
using System.Diagnostics;
using System.IO;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using Ninject.Activation.Strategies;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
internal class StartUpdateFixture : CoreTest
internal class AppUpdateJobFixture : CoreTest
{
private const string SANDBOX_FOLDER = @"C:\Temp\nzbdrone_update\";
@ -32,6 +33,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{
Mocker.GetMock<EnviromentProvider>().SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
Mocker.GetMock<ConfigFileProvider>().SetupGet(c => c.Guid).Returns(_clientGuid);
Mocker.GetMock<UpdateProvider>().Setup(c => c.GetAvilableUpdate()).Returns(updatePackage);
}
@ -41,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
Mocker.GetMock<DiskProvider>().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(true);
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<DiskProvider>().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true));
@ -53,7 +55,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
Mocker.GetMock<DiskProvider>().Setup(c => c.FolderExists(SANDBOX_FOLDER)).Returns(false);
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<DiskProvider>().Verify(c => c.DeleteFolder(SANDBOX_FOLDER, true), Times.Never());
@ -65,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName);
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<HttpProvider>().Verify(
@ -78,7 +80,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
var updateArchive = Path.Combine(SANDBOX_FOLDER, updatePackage.FileName);
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<ArchiveProvider>().Verify(
@ -91,7 +93,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
var updateClientFolder = Mocker.GetMock<EnviromentProvider>().Object.GetUpdateClientFolder();
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<DiskProvider>().Verify(
@ -108,7 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
.SetupGet(c => c.NzbDroneProcessIdFromEnviroment).Returns(12);
//Act
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
//Assert
Mocker.GetMock<ProcessProvider>().Verify(
@ -134,7 +136,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
Mocker.Resolve<HttpProvider>();
Mocker.Resolve<DiskProvider>();
Mocker.Resolve<ArchiveProvider>();
Mocker.Resolve<UpdateProvider>().StartUpdate(updatePackage);
StartUpdate();
updateSubFolder.Refresh();
//Assert
@ -143,5 +145,10 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
updateSubFolder.GetDirectories().Should().HaveCount(1);
updateSubFolder.GetFiles().Should().HaveCount(1);
}
private void StartUpdate()
{
Mocker.Resolve<AppUpdateJob>().Start(MockNotification, 0, 0);
}
}
}

View File

@ -95,7 +95,7 @@
<Compile Include="JobTests\SearchJobTest.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDownloadFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\TestJobs.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\StartUpdateFixture.cs" />
<Compile Include="JobTests\AppUpdateJobFixture.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
<Compile Include="SortHelperTest.cs" />
<Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" />

View File

@ -1,14 +1,35 @@
using NzbDrone.Core.Model.Notification;
using System.Diagnostics;
using System.IO;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Jobs
{
public class AppUpdateJob : IJob
{
private readonly UpdateProvider _updateProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly DiskProvider _diskProvider;
private readonly HttpProvider _httpProvider;
private readonly ProcessProvider _processProvider;
private readonly ArchiveProvider _archiveProvider;
private readonly ConfigFileProvider _configFileProvider;
public AppUpdateJob(UpdateProvider updateProvider)
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public AppUpdateJob(UpdateProvider updateProvider, EnviromentProvider enviromentProvider, DiskProvider diskProvider,
HttpProvider httpProvider, ProcessProvider processProvider, ArchiveProvider archiveProvider, ConfigFileProvider configFileProvider)
{
_updateProvider = updateProvider;
_enviromentProvider = enviromentProvider;
_diskProvider = diskProvider;
_httpProvider = httpProvider;
_processProvider = processProvider;
_archiveProvider = archiveProvider;
_configFileProvider = configFileProvider;
}
public string Name
@ -27,7 +48,38 @@ namespace NzbDrone.Core.Providers.Jobs
var updatePackage = _updateProvider.GetAvilableUpdate();
_updateProvider.StartUpdate(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);
notification.CurrentMessage = "Downloading Update " + updatePackage.Version;
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
logger.Info("Extracting Update package");
notification.CurrentMessage = "Extracting Update";
_archiveProvider.ExtractArchive(packageDestination, _enviromentProvider.GetUpdateSandboxFolder());
logger.Info("Update package extracted successfully");
logger.Info("Preparing client");
notification.CurrentMessage = "Preparing to start Update";
_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)
};
var updateProcess = _processProvider.Start(startInfo);
logger.Info("Update in progress. NzbDrone will restart shortly.");
}
}
}

View File

@ -77,39 +77,5 @@ namespace NzbDrone.Core.Providers
logger.Trace("No updates available");
return null;
}
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);
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);
}
}
}

View File

@ -35,6 +35,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ninject, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL" />
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>

View File

@ -4,6 +4,7 @@ using System.Linq;
using NLog;
using NLog.Config;
using NLog.Targets;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Update.Providers;
@ -13,6 +14,7 @@ namespace NzbDrone.Update
{
private readonly UpdateProvider _updateProvider;
private readonly ProcessProvider _processProvider;
private static StandardKernel _kernel;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
@ -29,18 +31,10 @@ namespace NzbDrone.Update
Console.WriteLine("Starting NzbDrone Update Client");
InitLoggers();
logger.Info("Initializing update application");
var enviromentProvider = new EnviromentProvider();
var processProvider = new ProcessProvider();
var serviceProvider = new ServiceProvider();
var diskProvider = new DiskProvider();
var iisProvider = new IISProvider();
var updateProvider = new UpdateProvider(diskProvider, serviceProvider, processProvider, enviromentProvider, iisProvider);
new Program(updateProvider, processProvider).Start(args);
_kernel = new StandardKernel();
_kernel.Get<Program>().Start(args);
}
catch (Exception e)
{
@ -55,8 +49,8 @@ namespace NzbDrone.Update
{
try
{
var enviromentProvider = new EnviromentProvider();
var diskProvider = new DiskProvider();
var enviromentProvider = _kernel.Get<EnviromentProvider>();
var diskProvider = _kernel.Get<DiskProvider>();
logger.Info("Copying log tiles to application directory.");
diskProvider.CopyDirectory(enviromentProvider.GetSandboxLogFolder(), enviromentProvider.GetUpdateLogFolder());
}
@ -70,18 +64,19 @@ namespace NzbDrone.Update
{
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
LogConfiguration.RegisterUdpLogger();
LogConfiguration.RegisterExceptioneer();
var lastUpgradeLog = new FileTarget();
lastUpgradeLog.AutoFlush = true;
lastUpgradeLog.ConcurrentWrites = false;
lastUpgradeLog.FileName = Path.Combine(PathExtentions.UPDATE_LOG_FOLDER_NAME, DateTime.Now.ToString("yyyy.MM.dd-H-mm") + ".txt");
lastUpgradeLog.KeepFileOpen = false;
lastUpgradeLog.Layout = "${longdate} - ${logger}: ${message} ${exception}";
lastUpgradeLog.Layout = "${longdate} - ${logger}: ${message} ${exception:format=ToString}";
LogManager.Configuration.AddTarget(lastUpgradeLog.GetType().Name, lastUpgradeLog);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, lastUpgradeLog));
LogConfiguration.RegisterExceptioneer();
LogConfiguration.Reload();
}

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Config>
<Port>8989</Port>
<AuthenticationType>0</AuthenticationType>
<LaunchBrowser>true</LaunchBrowser>
</Config>