1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Added some update APIs to check for updates and download and extract the update package.

Todo: apply updated, UI.
This commit is contained in:
kay.one 2011-10-20 22:04:26 -07:00
parent e5c4f34e0e
commit 8f9946eb63
31 changed files with 18597 additions and 95 deletions

View File

@ -84,17 +84,5 @@ public void quality_profile_initialized()
{ {
CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2); CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2);
} }
[Test]
public void get_version()
{
CentralDispatch.Version.Should().NotBeNull();
}
[Test]
public void BuildDate_should_be_within_the_hour()
{
CentralDispatch.BuildDateTime.Should().BeWithin(TimeSpan.FromHours(1));
}
} }
} }

Binary file not shown.

View File

@ -4,6 +4,7 @@
using NLog.Config; using NLog.Config;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core; using NzbDrone.Core;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
[SetUpFixture] [SetUpFixture]
@ -20,7 +21,7 @@ public void SetUp()
{ {
try try
{ {
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"), false);
LogManager.ThrowExceptions = true; LogManager.ThrowExceptions = true;
var exceptionVerification = new ExceptionVerification(); var exceptionVerification = new ExceptionVerification();

View File

@ -1,4 +1,5 @@
using NUnit.Framework; using System.IO;
using NUnit.Framework;
using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Providers.Jobs;
namespace NzbDrone.Core.Test.Framework namespace NzbDrone.Core.Test.Framework
@ -11,8 +12,10 @@ public class TestBase
public void Setup() public void Setup()
{ {
ExceptionVerification.Reset(); ExceptionVerification.Reset();
if (Directory.Exists(TempFolder))
{
Directory.Delete(TempFolder, true);
}
} }
[TearDown] [TearDown]
@ -22,5 +25,20 @@ public void TearDown()
ExceptionVerification.AssertNoUnexcpectedLogs(); ExceptionVerification.AssertNoUnexcpectedLogs();
} }
protected string TempFolder
{
get { return Path.Combine(Directory.GetCurrentDirectory(), "_temp"); }
}
protected string GetTestFilePath(string fileName)
{
return Path.Combine(@".\Files\", fileName);
}
protected string ReadTestFile(string fileName)
{
return File.ReadAllText(GetTestFilePath(fileName));
}
} }
} }

View File

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using System.Net;
using AutoMoq; using AutoMoq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using Moq; using Moq;
@ -24,6 +25,7 @@ public void BannerDownload_all()
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download"); var notification = new ProgressNotification("Banner Download");
@ -32,8 +34,7 @@ public void BannerDownload_all()
.Returns(fakeSeries); .Returns(fakeSeries);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>())) .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
.Returns(true);
mocker.GetMock<DiskProvider>() mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>())) .Setup(S => S.CreateDirectory(It.IsAny<string>()))
@ -58,6 +59,7 @@ public void BannerDownload_some_null_BannerUrl()
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download"); var notification = new ProgressNotification("Banner Download");
@ -66,8 +68,7 @@ public void BannerDownload_some_null_BannerUrl()
.Returns(fakeSeries); .Returns(fakeSeries);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>())) .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
.Returns(true);
mocker.GetMock<DiskProvider>() mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>())) .Setup(S => S.CreateDirectory(It.IsAny<string>()))
@ -89,9 +90,10 @@ public void BannerDownload_some_failed_download()
var fakeSeries = Builder<Series>.CreateListOfSize(10) var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build(); .Build();
var path = Path.Combine(CentralDispatch.AppPath, "Content", "Images", "Banners"); var path = Path.Combine(new EnviromentProvider().AppPath, "Content", "Images", "Banners");
var mocker = new AutoMoqer(MockBehavior.Strict); var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download"); var notification = new ProgressNotification("Banner Download");
@ -101,43 +103,42 @@ public void BannerDownload_some_failed_download()
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg")))
.Returns(false); .Throws(new WebException());
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg")));
.Returns(true);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg")))
.Returns(false); .Throws(new WebException());
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg")));
.Returns(true);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg")))
.Returns(false); .Throws(new WebException());
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg")));
.Returns(true);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg")))
.Returns(false); .Throws(new WebException());
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg")));
.Returns(true);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg")))
.Returns(false); .Throws(new WebException());
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg"))) .Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg")));
.Returns(true);
mocker.GetMock<DiskProvider>() mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>())) .Setup(S => S.CreateDirectory(It.IsAny<string>()))
@ -160,6 +161,7 @@ public void BannerDownload_all_failed_download()
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download"); var notification = new ProgressNotification("Banner Download");
@ -169,7 +171,7 @@ public void BannerDownload_all_failed_download()
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>())) .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Returns(false); .Throws(new WebException());
mocker.GetMock<DiskProvider>() mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>())) .Setup(S => S.CreateDirectory(It.IsAny<string>()))
@ -193,6 +195,7 @@ public void BannerDownload_single_banner()
.Build(); .Build();
var mocker = new AutoMoqer(MockBehavior.Strict); var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download"); var notification = new ProgressNotification("Banner Download");
@ -202,7 +205,7 @@ public void BannerDownload_single_banner()
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>())) .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Returns(true); .Throws(new WebException());
mocker.GetMock<DiskProvider>() mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>())) .Setup(S => S.CreateDirectory(It.IsAny<string>()))
@ -231,7 +234,7 @@ public void Download_Banner()
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>())) .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Returns(true); .Throws(new WebException());
//Act //Act
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries); mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);

View File

@ -92,8 +92,11 @@
<Compile Include="JobTests\BannerDownloadJobTest.cs" /> <Compile Include="JobTests\BannerDownloadJobTest.cs" />
<Compile Include="ProviderTests\ConfigFileProviderTest.cs" /> <Compile Include="ProviderTests\ConfigFileProviderTest.cs" />
<Compile Include="Framework\AutoMoq\TestBaseTests.cs" /> <Compile Include="Framework\AutoMoq\TestBaseTests.cs" />
<Compile Include="ProviderTests\DiskProviderTests\ExtractArchiveFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTest.cs" /> <Compile Include="ProviderTests\PostDownloadProviderTest.cs" />
<Compile Include="JobTests\SearchJobTest.cs" /> <Compile Include="JobTests\SearchJobTest.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\PreformUpdateFixture.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
<Compile Include="SortHelperTest.cs" /> <Compile Include="SortHelperTest.cs" />
<Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" /> <Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
<Compile Include="ProviderTests\InventoryProvider_IsAcceptableSizeTest.cs" /> <Compile Include="ProviderTests\InventoryProvider_IsAcceptableSizeTest.cs" />
@ -213,6 +216,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<None Include="Files\TestArchive.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -0,0 +1,29 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
using System.IO;
namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
{
[TestFixture]
public class ExtractArchiveFixture : TestBase
{
[Test]
public void Should_extract_to_correct_folder()
{
var diskProvider = new DiskProvider();
var destination = Path.Combine(TempFolder, "destination");
diskProvider.ExtractArchive(GetTestFilePath("TestArchive.zip"), destination);
var destinationFolder = new DirectoryInfo(destination);
destinationFolder.Exists.Should().BeTrue();
destinationFolder.GetDirectories().Should().HaveCount(1);
destinationFolder.GetDirectories("*", SearchOption.AllDirectories).Should().HaveCount(3);
destinationFolder.GetFiles("*.*", SearchOption.AllDirectories).Should().HaveCount(6);
}
}
}

View File

@ -20,6 +20,8 @@ namespace NzbDrone.Core.Test.ProviderTests
public class LogProviderTest : TestBase public class LogProviderTest : TestBase
{ {
private const string loggerName ="Core.Test.ProviderTests.LogProviderTest";
[Test] [Test]
public void write_log() public void write_log()
@ -46,7 +48,7 @@ public void write_log()
var logItem = db.Fetch<Log>().First(); var logItem = db.Fetch<Log>().First();
Assert.AreNotEqual(new DateTime(), logItem.Time); Assert.AreNotEqual(new DateTime(), logItem.Time);
Assert.AreEqual(message, logItem.Message); Assert.AreEqual(message, logItem.Message);
Assert.AreEqual("Core.Test.LogProviderTest", logItem.Logger); Assert.AreEqual(loggerName, logItem.Logger);
Logger.Name.Should().EndWith(logItem.Logger); Logger.Name.Should().EndWith(logItem.Logger);
@ -143,7 +145,7 @@ public void write_log_exception()
var logItem = db.Fetch<Log>().First(); var logItem = db.Fetch<Log>().First();
Assert.AreNotEqual(new DateTime(), logItem.Time); Assert.AreNotEqual(new DateTime(), logItem.Time);
Assert.AreEqual(message + ": " + ex.Message, logItem.Message); Assert.AreEqual(message + ": " + ex.Message, logItem.Message);
Assert.AreEqual("Core.Test.LogProviderTest", logItem.Logger); Assert.AreEqual(loggerName, logItem.Logger);
Assert.AreEqual(LogLevel.Error.Name, logItem.Level); Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType); Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
Assert.AreEqual(ex.ToString(), logItem.Exception); Assert.AreEqual(ex.ToString(), logItem.Exception);
@ -177,7 +179,7 @@ public void write_log_exception_no_message_should_use_exception_message()
var logItem = db.Fetch<Log>().First(); var logItem = db.Fetch<Log>().First();
Assert.AreNotEqual(new DateTime(), logItem.Time); Assert.AreNotEqual(new DateTime(), logItem.Time);
Assert.AreEqual(ex.Message, logItem.Message); Assert.AreEqual(ex.Message, logItem.Message);
Assert.AreEqual("Core.Test.LogProviderTest", logItem.Logger); Assert.AreEqual(loggerName, logItem.Logger);
Assert.AreEqual(LogLevel.Error.Name, logItem.Level); Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType); Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
Assert.AreEqual(ex.ToString(), logItem.Exception); Assert.AreEqual(ex.ToString(), logItem.Exception);

View File

@ -20,7 +20,7 @@ public class TvDbProviderTest : TestBase
[TestCase("South Park")] [TestCase("South Park")]
public void successful_search(string title) public void successful_search(string title)
{ {
var result = new TvDbProvider().SearchSeries(title); var result = new TvDbProvider(new EnviromentProvider()).SearchSeries(title);
result.Should().NotBeEmpty(); result.Should().NotBeEmpty();
result[0].SeriesName.Should().Be(title); result[0].SeriesName.Should().Be(title);
@ -35,7 +35,7 @@ public void successful_search(string title)
public void no_search_result() public void no_search_result()
{ {
//setup //setup
var tvdbProvider = new TvDbProvider(); var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//act //act
var result = tvdbProvider.SearchSeries(Guid.NewGuid().ToString()); var result = tvdbProvider.SearchSeries(Guid.NewGuid().ToString());
@ -49,7 +49,7 @@ public void no_search_result()
public void none_unique_season_episode_number() public void none_unique_season_episode_number()
{ {
//setup //setup
var tvdbProvider = new TvDbProvider(); var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//act //act
var result = tvdbProvider.GetSeries(75978, true);//Family guy var result = tvdbProvider.GetSeries(75978, true);//Family guy
@ -65,7 +65,7 @@ public void none_unique_season_episode_number()
public void American_dad_fix() public void American_dad_fix()
{ {
//setup //setup
var tvdbProvider = new TvDbProvider(); var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//act //act
var result = tvdbProvider.GetSeries(73141, true); var result = tvdbProvider.GetSeries(73141, true);

View File

@ -0,0 +1,66 @@
using System;
using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{
class GetAvilableUpdateFixture : TestBase
{
private AutoMoqer _mocker = null;
private static Version _latestsTestVersion = new Version("0.6.0.3");
private static string _latestsTestUrl = "http://update.nzbdrone.com/_test/NzbDrone.master.0.6.0.3.zip";
private static string _latestsTestFileName = "NzbDrone.master.0.6.0.3.zip";
[SetUp]
public void setup()
{
_mocker = new AutoMoqer(MockBehavior.Strict);
_mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/_test/");
_mocker.Resolve<HttpProvider>();
}
[TestCase("0.6.0.9")]
[TestCase("0.7.0.1")]
[TestCase("1.0.0.0")]
public void should_return_null_if_latests_is_lower_than_current_version(string currentVersion)
{
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion));
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().BeNull();
}
[Test]
public void should_return_null_if_latests_is_equal_to_current_version()
{
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(_latestsTestVersion);
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().BeNull();
}
[TestCase("0.0.0.0")]
[TestCase("0.0.0.1")]
[TestCase("0.0.10.10")]
public void should_return_update_if_latests_is_higher_than_current_version(string currentVersion)
{
_mocker.GetMock<EnviromentProvider>().SetupGet(c => c.Version).Returns(new Version(currentVersion));
var updatePackage = _mocker.Resolve<UpdateProvider>().GetAvilableUpdate();
updatePackage.Should().NotBeNull();
updatePackage.Version.Should().Be(_latestsTestVersion);
updatePackage.FileName.Should().BeEquivalentTo(_latestsTestFileName);
updatePackage.Url.Should().BeEquivalentTo(_latestsTestUrl);
}
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.IO;
using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{
[TestFixture]
internal class PreformUpdateFixture : TestBase
{
private AutoMoqer _mocker = null;
[SetUp]
public void setup()
{
_mocker = new AutoMoqer(MockBehavior.Strict);
_mocker.GetMock<EnviromentProvider>()
.SetupGet(c => c.TempPath).Returns(TempFolder);
}
[Test]
public void Should_call_download_file_using_correct_arguments()
{
//Act
var updatePackage = new UpdatePackage
{
FileName = "NzbDrone.kay.one.0.6.0.2031.zip",
Url = "http://update.nzbdrone.com/kayone/NzbDrone.kay.one.0.6.0.2031.zip",
Version = new Version("0.6.0.2031")
};
_mocker.GetMock<HttpProvider>().Setup(
c => c.DownloadFile(updatePackage.Url, Path.Combine(TempFolder, updatePackage.FileName)));
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
}
[Test]
public void Should_download_and_extract_to_temp_folder()
{
var updateSubFolder = new DirectoryInfo(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName));
var updatePackage = new UpdatePackage
{
FileName = "NzbDrone.kay.one.0.6.0.2031.zip",
Url = "http://update.nzbdrone.com/_test/NzbDrone.zip",
Version = new Version("0.6.0.2031")
};
//Act
updateSubFolder.Exists.Should().BeFalse();
_mocker.Resolve<HttpProvider>();
_mocker.Resolve<DiskProvider>();
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
updateSubFolder.Refresh();
//Assert
updateSubFolder.Exists.Should().BeTrue();
updateSubFolder.GetDirectories("nzbdrone").Should().HaveCount(1);
updateSubFolder.GetDirectories().Should().HaveCount(1);
updateSubFolder.GetFiles().Should().HaveCount(1);
}
}
}

View File

@ -23,35 +23,6 @@ public static class CentralDispatch
private static readonly Object KernelLock = new object(); private static readonly Object KernelLock = new object();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static Version Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version; }
}
public static DateTime BuildDateTime
{
get
{
var fileLocation = Assembly.GetCallingAssembly().Location;
return new FileInfo(fileLocation).CreationTime;
}
}
public static String AppPath
{
get
{
if (!String.IsNullOrWhiteSpace(HostingEnvironment.ApplicationPhysicalPath))
{
return HostingEnvironment.ApplicationPhysicalPath;
}
return Directory.GetCurrentDirectory();
}
}
public static StandardKernel NinjectKernel public static StandardKernel NinjectKernel
{ {
get get

View File

@ -4,13 +4,14 @@
using System.Data.SqlServerCe; using System.Data.SqlServerCe;
using System.IO; using System.IO;
using MvcMiniProfiler.Data; using MvcMiniProfiler.Data;
using NzbDrone.Core.Providers;
using PetaPoco; using PetaPoco;
namespace NzbDrone.Core.Datastore namespace NzbDrone.Core.Datastore
{ {
public static class Connection public static class Connection
{ {
private static readonly DirectoryInfo AppDataPath = new DirectoryInfo(Path.Combine(CentralDispatch.AppPath, "App_Data")); private static readonly DirectoryInfo AppDataPath = new DirectoryInfo(Path.Combine(new EnviromentProvider().AppPath, "App_Data"));
static Connection() static Connection()
{ {

View File

@ -3,6 +3,7 @@
using Ninject; using Ninject;
using NLog; using NLog;
using NLog.Config; using NLog.Config;
using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Instrumentation namespace NzbDrone.Core.Instrumentation
{ {
@ -15,7 +16,7 @@ public static void Setup()
LogManager.ThrowExceptions = true; LogManager.ThrowExceptions = true;
} }
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"),
false); false);
LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging()); LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging());

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model
{
public class UpdatePackage
{
public string Url { get; set; }
public string FileName { get; set; }
public Version Version { get; set; }
}
}

View File

@ -125,6 +125,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath> <HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="Migrator, Version=0.9.1.26254, Culture=neutral, PublicKeyToken=3b3586e9632ecfce, processorArchitecture=x86"> <Reference Include="Migrator, Version=0.9.1.26254, Culture=neutral, PublicKeyToken=3b3586e9632ecfce, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@ -203,12 +206,14 @@
<Compile Include="Model\SabnzbdInfoModel.cs" /> <Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Model\Search\SearchModel.cs" /> <Compile Include="Model\Search\SearchModel.cs" />
<Compile Include="Model\Search\SearchType.cs" /> <Compile Include="Model\Search\SearchType.cs" />
<Compile Include="Model\UpdatePackage.cs" />
<Compile Include="Model\Xbmc\ActionType.cs" /> <Compile Include="Model\Xbmc\ActionType.cs" />
<Compile Include="Model\Xbmc\ActivePlayersResult.cs" /> <Compile Include="Model\Xbmc\ActivePlayersResult.cs" />
<Compile Include="Model\Xbmc\ErrorResult.cs" /> <Compile Include="Model\Xbmc\ErrorResult.cs" />
<Compile Include="Model\Xbmc\IconType.cs" /> <Compile Include="Model\Xbmc\IconType.cs" />
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" /> <Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
<Compile Include="Providers\Converting\HandbrakeProvider.cs" /> <Compile Include="Providers\Converting\HandbrakeProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
<Compile Include="Providers\Core\ConfigFileProvider.cs" /> <Compile Include="Providers\Core\ConfigFileProvider.cs" />
<Compile Include="Providers\Core\UdpProvider.cs" /> <Compile Include="Providers\Core\UdpProvider.cs" />
<Compile Include="Providers\Jobs\BacklogSearchJob.cs" /> <Compile Include="Providers\Jobs\BacklogSearchJob.cs" />
@ -222,6 +227,7 @@
<Compile Include="Providers\PostDownloadProvider.cs" /> <Compile Include="Providers\PostDownloadProvider.cs" />
<Compile Include="Providers\QualityTypeProvider.cs" /> <Compile Include="Providers\QualityTypeProvider.cs" />
<Compile Include="Providers\SearchProvider.cs" /> <Compile Include="Providers\SearchProvider.cs" />
<Compile Include="Providers\UpdateProvider.cs" />
<Compile Include="Providers\Xbmc\ResourceManager.cs" /> <Compile Include="Providers\Xbmc\ResourceManager.cs" />
<Compile Include="Model\Xbmc\TvShowResult.cs" /> <Compile Include="Model\Xbmc\TvShowResult.cs" />
<Compile Include="Model\Xbmc\Params.cs" /> <Compile Include="Model\Xbmc\Params.cs" />

View File

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Providers.Core
{ {
public class ConfigFileProvider public class ConfigFileProvider
{ {
private string _configFile = Path.Combine(CentralDispatch.AppPath, "App_Data", "Config.xml"); private string _configFile = Path.Combine(new EnviromentProvider().AppPath, "App_Data", "Config.xml");
public string ConfigFile public string ConfigFile
{ {
@ -113,7 +113,7 @@ public virtual void SetValue(string key, object value, string parent = null)
public virtual void CreateDefaultConfigFile() public virtual void CreateDefaultConfigFile()
{ {
//Create the config file here //Create the config file here
Directory.CreateDirectory(Path.Combine(CentralDispatch.AppPath, "App_Data")); Directory.CreateDirectory(Path.Combine(new EnviromentProvider().AppPath, "App_Data"));
if (!File.Exists(ConfigFile)) if (!File.Exists(ConfigFile))
{ {

View File

@ -305,6 +305,12 @@ public virtual string XbmcPassword
set { SetValue("XbmcPassword", value); } set { SetValue("XbmcPassword", value); }
} }
public virtual string UpdateUrl
{
get { return GetValue("UpdateUrl", @"http://update.nzbdrone.com/master/"); }
set { SetValue("UpdateUrl", value); }
}
private string GetValue(string key) private string GetValue(string key)
{ {
return GetValue(key, String.Empty); return GetValue(key, String.Empty);

View File

@ -2,11 +2,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Ionic.Zip;
using NLog;
namespace NzbDrone.Core.Providers.Core namespace NzbDrone.Core.Providers.Core
{ {
public class DiskProvider public class DiskProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public virtual bool FolderExists(string path) public virtual bool FolderExists(string path)
{ {
return Directory.Exists(path); return Directory.Exists(path);
@ -74,6 +78,18 @@ public virtual void MoveDirectory(string source, string destination)
Directory.Move(source, destination); Directory.Move(source, destination);
} }
public virtual void ExtractArchive(string compressedFile, string destination)
{
Logger.Trace("Extracting archive [{0}] to [{1}]", compressedFile, destination);
using (ZipFile zipFile = ZipFile.Read(compressedFile))
{
zipFile.ExtractAll(destination);
}
Logger.Trace("Extraction complete.");
}
public virtual void InheritFolderPermissions(string filename) public virtual void InheritFolderPermissions(string filename)
{ {
var fs = File.GetAccessControl(filename); var fs = File.GetAccessControl(filename);

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
@ -50,19 +51,29 @@ public virtual Stream DownloadStream(string url, NetworkCredential credential)
return response.GetResponseStream(); return response.GetResponseStream();
} }
public virtual bool DownloadFile(string address, string fileName) public virtual void DownloadFile(string url, string fileName)
{ {
try try
{ {
var fileInfo = new FileInfo(fileName);
if (!fileInfo.Directory.Exists)
{
fileInfo.Directory.Create();
}
Logger.Trace("Downloading [{0}] to [{1}]", url, fileName);
var stopWatch = Stopwatch.StartNew();
var webClient = new WebClient(); var webClient = new WebClient();
webClient.DownloadFile(address, fileName); webClient.DownloadFile(url, fileName);
return true; stopWatch.Stop();
Logger.Trace("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Warn("Failed to get response from: {0}", address); Logger.Warn("Failed to get response from: {0}", url);
Logger.TraceException(ex.Message, ex); Logger.TraceException(ex.Message, ex);
return false; throw;
} }
} }

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Hosting;
using NLog;
using Ninject;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers
{
public class EnviromentProvider
{
public virtual Version Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version; }
}
public virtual DateTime BuildDateTime
{
get
{
var fileLocation = Assembly.GetCallingAssembly().Location;
return new FileInfo(fileLocation).CreationTime;
}
}
public virtual String AppPath
{
get
{
if (!String.IsNullOrWhiteSpace(HostingEnvironment.ApplicationPhysicalPath))
{
return HostingEnvironment.ApplicationPhysicalPath;
}
return Directory.GetCurrentDirectory();
}
}
public virtual String TempPath
{
get
{
return Path.GetTempPath();
}
}
}
}

View File

@ -15,17 +15,19 @@ public class BannerDownloadJob : IJob
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly HttpProvider _httpProvider; private readonly HttpProvider _httpProvider;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly EnviromentProvider _enviromentProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private string _bannerPath = ""; private string _bannerPath = "";
private const string _bannerUrlPrefix = "http://www.thetvdb.com/banners/"; private const string _bannerUrlPrefix = "http://www.thetvdb.com/banners/";
[Inject] [Inject]
public BannerDownloadJob(SeriesProvider seriesProvider, HttpProvider httpProvider, DiskProvider diskProvider) public BannerDownloadJob(SeriesProvider seriesProvider, HttpProvider httpProvider, DiskProvider diskProvider, EnviromentProvider enviromentProvider)
{ {
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
_httpProvider = httpProvider; _httpProvider = httpProvider;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_enviromentProvider = enviromentProvider;
} }
public BannerDownloadJob() public BannerDownloadJob()
@ -47,7 +49,7 @@ public virtual void Start(ProgressNotification notification, int targetId, int s
{ {
Logger.Debug("Starting banner download job"); Logger.Debug("Starting banner download job");
_bannerPath = Path.Combine(CentralDispatch.AppPath, "Content", "Images", "Banners"); _bannerPath = Path.Combine(_enviromentProvider.AppPath, "Content", "Images", "Banners");
_diskProvider.CreateDirectory(_bannerPath); _diskProvider.CreateDirectory(_bannerPath);
if (targetId > 0) if (targetId > 0)
@ -76,10 +78,12 @@ public virtual void DownloadBanner(ProgressNotification notification, Series ser
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title); notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
if (_httpProvider.DownloadFile(_bannerUrlPrefix + series.BannerUrl, bannerFilename)) try
{
_httpProvider.DownloadFile(_bannerUrlPrefix + series.BannerUrl, bannerFilename);
notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title); notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title);
}
else catch (Exception)
{ {
Logger.Debug("Failed to download banner for '{0}'", series.Title); Logger.Debug("Failed to download banner for '{0}'", series.Title);
notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title); notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title);

View File

@ -278,7 +278,7 @@ private void Execute(Type jobType, int targetId = 0, int secondaryTargetId = 0)
settings.Success = true; settings.Success = true;
sw.Stop(); sw.Stop();
Logger.Debug("Job '{0}' successfully completed in {1}.{2} seconds.", jobImplementation.Name, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds / 100, Logger.Debug("Job '{0}' successfully completed in {1:0}.{2} seconds.", jobImplementation.Name, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
sw.Elapsed.Seconds); sw.Elapsed.Seconds);
} }
catch (Exception e) catch (Exception e)

View File

@ -3,6 +3,7 @@
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NLog; using NLog;
using Ninject;
using TvdbLib; using TvdbLib;
using TvdbLib.Cache; using TvdbLib.Cache;
using TvdbLib.Data; using TvdbLib.Data;
@ -11,14 +12,22 @@ namespace NzbDrone.Core.Providers
{ {
public class TvDbProvider public class TvDbProvider
{ {
private readonly EnviromentProvider _enviromentProvider;
private const string TVDB_APIKEY = "5D2D188E86E07F4F"; private const string TVDB_APIKEY = "5D2D188E86E07F4F";
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly TvdbHandler _handler; private readonly TvdbHandler _handler;
[Inject]
public TvDbProvider(EnviromentProvider enviromentProvider)
{
_enviromentProvider = enviromentProvider;
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppPath + @"\cache\tvdb"), TVDB_APIKEY);
}
public TvDbProvider() public TvDbProvider()
{ {
_handler = new TvdbHandler(new XmlCacheProvider(CentralDispatch.AppPath + @"\cache\tvdb"), TVDB_APIKEY);
} }
public virtual IList<TvdbSearchResult> SearchSeries(string title) public virtual IList<TvdbSearchResult> SearchSeries(string title)

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NLog;
using Ninject;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers
{
class UpdateProvider
{
private readonly HttpProvider _httpProvider;
private readonly ConfigProvider _configProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly DiskProvider _diskProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
public const string SandboxFolderName = "nzbdrone_update";
[Inject]
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, EnviromentProvider enviromentProvider, DiskProvider diskProvider)
{
_httpProvider = httpProvider;
_configProvider = configProvider;
_enviromentProvider = enviromentProvider;
_diskProvider = diskProvider;
}
public UpdateProvider()
{
}
private List<UpdatePackage> GetAvailablePackages()
{
var updateList = new List<UpdatePackage>();
var rawUpdateList = _httpProvider.DownloadString(_configProvider.UpdateUrl);
var matches = ParseRegex.Matches(rawUpdateList);
foreach (Match match in matches)
{
var updatePackage = new UpdatePackage();
updatePackage.FileName = match.Groups["filename"].Value;
updatePackage.Url = _configProvider.UpdateUrl + updatePackage.FileName;
updatePackage.Version = new Version(match.Groups["version"].Value);
updateList.Add(updatePackage);
}
return updateList;
}
public virtual UpdatePackage GetAvilableUpdate()
{
var latestAvailable = GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault();
if (latestAvailable != null && latestAvailable.Version > _enviromentProvider.Version)
{
Logger.Debug("An update is available ({0}) => ({1})", _enviromentProvider.Version, latestAvailable.Version);
return latestAvailable;
}
Logger.Trace("No updates available");
return null;
}
public virtual void PreformUpdate(UpdatePackage updatePackage)
{
var tempSubFolder = Path.Combine(_enviromentProvider.TempPath, SandboxFolderName);
var packageDestination = Path.Combine(tempSubFolder, updatePackage.FileName);
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");
_diskProvider.ExtractArchive(packageDestination, tempSubFolder);
Logger.Info("Update package extracted successfully");
}
}
}

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="DotNetZip" version="1.9.1.8" />
<package id="MiniProfiler" version="1.9" /> <package id="MiniProfiler" version="1.9" />
<package id="Ninject" version="2.2.1.4" /> <package id="Ninject" version="2.2.1.4" />
<package id="SqlServerCompact" version="4.0.8482.1" />
<package id="NLog" version="2.0.0.2000" /> <package id="NLog" version="2.0.0.2000" />
<package id="SqlServerCompact" version="4.0.8482.1" />
</packages> </packages>

View File

@ -1,5 +1,5 @@
@using NzbDrone.Core @using NzbDrone.Core
<div> <div>
NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy")) @*NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy"))*@
</div> </div>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.