mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-11 23:57:11 -07:00
PathProvider. visit us for all of your pathing needs.
This commit is contained in:
parent
c503b497ed
commit
633f0b6197
24 changed files with 315 additions and 188 deletions
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,6 @@ namespace NzbDrone.Common.Test
|
||||||
enviromentController.IsUserInteractive.Should().BeTrue();
|
enviromentController.IsUserInteractive.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Log_path_should_not_be_empty()
|
|
||||||
{
|
|
||||||
enviromentController.LogPath.Should().NotBeBlank();
|
|
||||||
Path.IsPathRooted(enviromentController.LogPath).Should().BeTrue("Path is not rooted");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void StartupPath_should_not_be_empty()
|
public void StartupPath_should_not_be_empty()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,6 @@ namespace NzbDrone.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual String LogPath
|
|
||||||
{
|
|
||||||
get { return Environment.CurrentDirectory; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool IsUserInteractive
|
public virtual bool IsUserInteractive
|
||||||
{
|
{
|
||||||
get { return Environment.UserInteractive; }
|
get { return Environment.UserInteractive; }
|
||||||
|
@ -68,25 +63,6 @@ namespace NzbDrone.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string WebRoot
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Path.Combine(ApplicationPath, "NzbDrone.Web");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string AppDataPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var path = Path.Combine(WebRoot, "App_Data");
|
|
||||||
if (!Directory.Exists(path))
|
|
||||||
Directory.CreateDirectory(path);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string StartUpPath
|
public virtual string StartUpPath
|
||||||
{
|
{
|
||||||
|
@ -111,15 +87,6 @@ namespace NzbDrone.Common
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual String TempPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Path.GetTempPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ContainsIIS(DirectoryInfo dir)
|
private static bool ContainsIIS(DirectoryInfo dir)
|
||||||
{
|
{
|
||||||
return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0;
|
return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0;
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ConsoleProvider.cs" />
|
<Compile Include="ConsoleProvider.cs" />
|
||||||
|
<Compile Include="PathProvider.cs" />
|
||||||
<Compile Include="DiskProvider.cs" />
|
<Compile Include="DiskProvider.cs" />
|
||||||
<Compile Include="EnviromentProvider.cs" />
|
<Compile Include="EnviromentProvider.cs" />
|
||||||
<Compile Include="ExceptioneerTarget.cs" />
|
<Compile Include="ExceptioneerTarget.cs" />
|
||||||
|
|
111
NzbDrone.Common/PathProvider.cs
Normal file
111
NzbDrone.Common/PathProvider.cs
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common
|
||||||
|
{
|
||||||
|
public class PathProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private const string WEB_FOLDER = "NzbDrone.Web";
|
||||||
|
private const string APP_DATA = "App_Data";
|
||||||
|
|
||||||
|
private const string LOG_CONFIG_FILE = "log.config";
|
||||||
|
private const string APP_CONFIG_FILE = "config.xml";
|
||||||
|
|
||||||
|
private const string NZBDRONE_DB_FILE = "nzbdrone.sdf";
|
||||||
|
private const string LOG_DB_FILE = "log.sdf";
|
||||||
|
|
||||||
|
public const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update";
|
||||||
|
|
||||||
|
private readonly string _applicationPath;
|
||||||
|
|
||||||
|
|
||||||
|
public PathProvider(EnviromentProvider enviromentProvider)
|
||||||
|
{
|
||||||
|
_applicationPath = enviromentProvider.ApplicationPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathProvider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual String LogPath
|
||||||
|
{
|
||||||
|
get { return Environment.CurrentDirectory; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string WebRoot
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Path.Combine(_applicationPath, WEB_FOLDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string AppData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var path = Path.Combine(WebRoot, APP_DATA);
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string NzbDronoeDbFile
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
return Path.Combine(AppData, NZBDRONE_DB_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string LogDbFile
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
return Path.Combine(AppData, LOG_DB_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual String SystemTemp
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Path.GetTempPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LogConfigFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(WebRoot, LOG_CONFIG_FILE); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AppConfigFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(_applicationPath, APP_CONFIG_FILE); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string BannerPath
|
||||||
|
{
|
||||||
|
get { return Path.Combine(WebRoot, "Content", "Images", "Banners"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CacheFolder
|
||||||
|
{
|
||||||
|
get { return Path.Combine(AppData, "Cache"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UpdateSandboxFolder
|
||||||
|
{
|
||||||
|
get { return Path.Combine(SystemTemp, UPDATE_SANDBOX_FOLDER_NAME); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,22 +4,22 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
//[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
//public class Fixtures : LoggingFixtures
|
||||||
{
|
//{
|
||||||
[SetUp]
|
// //[SetUp]
|
||||||
public void SetUp()
|
// //public void SetUp()
|
||||||
{
|
// //{
|
||||||
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
// // var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
foreach (var file in oldDbFiles)
|
// // foreach (var file in oldDbFiles)
|
||||||
{
|
// // {
|
||||||
try
|
// // try
|
||||||
{
|
// // {
|
||||||
File.Delete(file);
|
// // File.Delete(file);
|
||||||
}
|
// // }
|
||||||
catch { }
|
// // catch { }
|
||||||
}
|
// // }
|
||||||
|
|
||||||
MockLib.CreateDataBaseTemplate();
|
// // MockLib.CreateDataBaseTemplate();
|
||||||
}
|
// //}
|
||||||
}
|
//}
|
||||||
|
|
|
@ -1,13 +1,47 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using AutoMoq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ninject;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
public class TestBase
|
public class TestBase : LoggingTest
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static TestBase()
|
||||||
|
{
|
||||||
|
InitLogging();
|
||||||
|
|
||||||
|
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
|
foreach (var file in oldDbFiles)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
MockLib.CreateDataBaseTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StandardKernel LiveKernel = null;
|
||||||
|
protected AutoMoqer Mocker = null;
|
||||||
|
|
||||||
|
protected string VirtualPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
|
||||||
|
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
|
||||||
|
|
||||||
|
return virtualPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public virtual void SetupBase()
|
public virtual void SetupBase()
|
||||||
{
|
{
|
||||||
|
@ -18,6 +52,9 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(TempFolder);
|
Directory.CreateDirectory(TempFolder);
|
||||||
|
|
||||||
|
LiveKernel = new StandardKernel();
|
||||||
|
Mocker = new AutoMoqer();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
|
@ -27,6 +64,16 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void WithTempAsStartUpPath()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<EnviromentProvider>()
|
||||||
|
.SetupGet(c => c.ApplicationPath)
|
||||||
|
.Returns(VirtualPath);
|
||||||
|
|
||||||
|
Mocker.Resolve<PathProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected string TempFolder
|
protected string TempFolder
|
||||||
{
|
{
|
||||||
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
|
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
|
||||||
|
|
|
@ -92,7 +92,8 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var path = Path.Combine(new EnviromentProvider().WebRoot, "Content", "Images", "Banners");
|
|
||||||
|
var pathProvider = Mocker.Resolve<PathProvider>();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
mocker.Resolve<EnviromentProvider>();
|
mocker.Resolve<EnviromentProvider>();
|
||||||
|
@ -104,42 +105,42 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
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(pathProvider.BannerPath, "1.jpg")))
|
||||||
.Throws(new WebException());
|
.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(pathProvider.BannerPath, "2.jpg")));
|
||||||
|
|
||||||
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(pathProvider.BannerPath, "3.jpg")))
|
||||||
.Throws(new WebException());
|
.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(pathProvider.BannerPath, "4.jpg")));
|
||||||
|
|
||||||
|
|
||||||
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(pathProvider.BannerPath, "5.jpg")))
|
||||||
.Throws(new WebException());
|
.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(pathProvider.BannerPath, "6.jpg")));
|
||||||
|
|
||||||
|
|
||||||
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(pathProvider.BannerPath, "7.jpg")))
|
||||||
.Throws(new WebException());
|
.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(pathProvider.BannerPath, "8.jpg")));
|
||||||
|
|
||||||
|
|
||||||
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(pathProvider.BannerPath, "9.jpg")))
|
||||||
.Throws(new WebException());
|
.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(pathProvider.BannerPath, "10.jpg")));
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
mocker.GetMock<DiskProvider>()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using AutoMoq;
|
using AutoMoq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -15,14 +16,15 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
|
WithTempAsStartUpPath();
|
||||||
|
|
||||||
//Reset config file
|
//Reset config file
|
||||||
var mocker = new AutoMoqer();
|
var configFile = Mocker.Resolve<PathProvider>().AppConfigFile;
|
||||||
var configFile = mocker.Resolve<ConfigFileProvider>().ConfigFile;
|
|
||||||
|
|
||||||
if (File.Exists(configFile))
|
if (File.Exists(configFile))
|
||||||
File.Delete(configFile);
|
File.Delete(configFile);
|
||||||
|
|
||||||
mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
|
Mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -31,10 +33,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const string value = "8989";
|
const string value = "8989";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -46,10 +46,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const int value = 8989;
|
const int value = 8989;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -64,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
|
@ -76,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(true);
|
result.Should().Be(true);
|
||||||
|
@ -87,10 +85,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
const int value = 8989;
|
const int value = 8989;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -102,13 +98,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "LaunchBrowser";
|
const string key = "LaunchBrowser";
|
||||||
const bool value = false;
|
const bool value = false;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +112,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const int value = 12345;
|
const int value = 12345;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +126,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Hello";
|
const string key = "Hello";
|
||||||
const string value = "World";
|
const string value = "World";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -149,10 +139,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Hello";
|
const string key = "Hello";
|
||||||
const string value = "World";
|
const string value = "World";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -161,10 +149,9 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAuthenticationType_No_Existing_Value()
|
public void GetAuthenticationType_No_Existing_Value()
|
||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(AuthenticationType.Anonymous);
|
result.Should().Be(AuthenticationType.Anonymous);
|
||||||
|
@ -173,11 +160,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAuthenticationType_Windows()
|
public void GetAuthenticationType_Windows()
|
||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(AuthenticationType.Windows);
|
result.Should().Be(AuthenticationType.Windows);
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ninject;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -16,30 +17,31 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class TvDbProviderTest : TestBase
|
public class TvDbProviderTest : TestBase
|
||||||
{
|
{
|
||||||
|
private TvDbProvider tvDbProvider;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
tvDbProvider = LiveKernel.Get<TvDbProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase("The Simpsons")]
|
[TestCase("The Simpsons")]
|
||||||
[TestCase("Family Guy")]
|
[TestCase("Family Guy")]
|
||||||
[TestCase("South Park")]
|
[TestCase("South Park")]
|
||||||
public void successful_search(string title)
|
public void successful_search(string title)
|
||||||
{
|
{
|
||||||
var result = new TvDbProvider(new EnviromentProvider()).SearchSeries(title);
|
var result = tvDbProvider.SearchSeries(title);
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result[0].SeriesName.Should().Be(title);
|
result[0].SeriesName.Should().Be(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void no_search_result()
|
public void no_search_result()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.SearchSeries(Guid.NewGuid().ToString());
|
var result = tvDbProvider.SearchSeries(Guid.NewGuid().ToString());
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
|
@ -49,11 +51,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void none_unique_season_episode_number()
|
public void none_unique_season_episode_number()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.GetSeries(75978, true);//Family guy
|
var result = tvDbProvider.GetSeries(75978, true);//Family guy
|
||||||
|
|
||||||
//Asserts that when episodes are grouped by Season/Episode each group contains maximum of
|
//Asserts that when episodes are grouped by Season/Episode each group contains maximum of
|
||||||
//one item.
|
//one item.
|
||||||
|
@ -65,11 +64,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void American_dad_fix()
|
public void American_dad_fix()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.GetSeries(73141, true);
|
var result = tvDbProvider.GetSeries(73141, true);
|
||||||
|
|
||||||
var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber)
|
var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber)
|
||||||
.Distinct().ToList();
|
.Distinct().ToList();
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
public void setup()
|
public void setup()
|
||||||
{
|
{
|
||||||
_mocker = new AutoMoqer(MockBehavior.Strict);
|
_mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
_mocker.GetMock<EnviromentProvider>()
|
_mocker.GetMock<PathProvider>()
|
||||||
.SetupGet(c => c.TempPath).Returns(TempFolder);
|
.SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
};
|
};
|
||||||
|
|
||||||
_mocker.GetMock<HttpProvider>().Setup(
|
_mocker.GetMock<HttpProvider>().Setup(
|
||||||
c => c.DownloadFile(updatePackage.Url, Path.Combine(TempFolder, UpdateProvider.SandboxFolderName ,updatePackage.FileName)));
|
c => c.DownloadFile(updatePackage.Url, Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME, updatePackage.FileName)));
|
||||||
|
|
||||||
_mocker.GetMock<DiskProvider>().Setup(
|
_mocker.GetMock<DiskProvider>().Setup(
|
||||||
c => c.ExtractArchive(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName, updatePackage.FileName),
|
c => c.ExtractArchive(Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME, updatePackage.FileName),
|
||||||
Path.Combine(TempFolder, UpdateProvider.SandboxFolderName)));
|
Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME)));
|
||||||
|
|
||||||
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
|
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
public void Should_download_and_extract_to_temp_folder()
|
public void Should_download_and_extract_to_temp_folder()
|
||||||
{
|
{
|
||||||
|
|
||||||
var updateSubFolder = new DirectoryInfo(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName));
|
var updateSubFolder = new DirectoryInfo(Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME));
|
||||||
|
|
||||||
var updatePackage = new UpdatePackage
|
var updatePackage = new UpdatePackage
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,9 @@ namespace NzbDrone.Core
|
||||||
{
|
{
|
||||||
BindKernel();
|
BindKernel();
|
||||||
|
|
||||||
MigrationsHelper.Run(Connection.MainConnectionString, true);
|
var mainConnectionString = _kernel.Get<Connection>().MainConnectionString;
|
||||||
|
|
||||||
|
MigrationsHelper.Run(mainConnectionString, true);
|
||||||
|
|
||||||
LogConfiguration.RegisterDatabaseLogger(_kernel.Get<DatabaseTarget>());
|
LogConfiguration.RegisterDatabaseLogger(_kernel.Get<DatabaseTarget>());
|
||||||
|
|
||||||
|
@ -59,9 +61,11 @@ namespace NzbDrone.Core
|
||||||
Logger.Debug("Binding Ninject's Kernel");
|
Logger.Debug("Binding Ninject's Kernel");
|
||||||
_kernel = new StandardKernel();
|
_kernel = new StandardKernel();
|
||||||
|
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InTransientScope();
|
var connection = _kernel.Get<Connection>();
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InSingletonScope();
|
_kernel.Bind<IDatabase>().ToMethod(c => connection.GetMainPetaPocoDb()).InTransientScope();
|
||||||
|
_kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb(false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
||||||
|
_kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb()).WhenInjectedInto<LogProvider>().InSingletonScope();
|
||||||
|
|
||||||
_kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
_kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,35 @@ using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public static class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
private static EnviromentProvider _enviromentProvider = new EnviromentProvider();
|
private readonly PathProvider _pathProvider;
|
||||||
|
|
||||||
|
public Connection(PathProvider pathProvider)
|
||||||
|
{
|
||||||
|
_pathProvider = pathProvider;
|
||||||
|
}
|
||||||
|
|
||||||
static Connection()
|
static Connection()
|
||||||
{
|
{
|
||||||
Database.Mapper = new CustomeMapper();
|
Database.Mapper = new CustomeMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String MainConnectionString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetConnectionString(_pathProvider.NzbDronoeDbFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String LogConnectionString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetConnectionString(_pathProvider.LogDbFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetConnectionString(string path)
|
public static string GetConnectionString(string path)
|
||||||
{
|
{
|
||||||
|
@ -26,22 +46,15 @@ namespace NzbDrone.Core.Datastore
|
||||||
return String.Format("Data Source={0}", path);
|
return String.Format("Data Source={0}", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String MainConnectionString
|
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
|
||||||
{
|
{
|
||||||
get
|
return GetPetaPocoDb(MainConnectionString, profiled);
|
||||||
{
|
|
||||||
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "nzbdrone.sdf"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String LogConnectionString
|
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
|
||||||
{
|
{
|
||||||
get
|
return GetPetaPocoDb(LogConnectionString, profiled);
|
||||||
{
|
|
||||||
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "log.sdf"));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,17 +7,23 @@ using NzbDrone.Core.Providers;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Core.Instrumentation
|
||||||
{
|
{
|
||||||
public static class LogConfiguration
|
public class LogConfiguration
|
||||||
{
|
{
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
|
|
||||||
public static void Setup()
|
public LogConfiguration(PathProvider pathProvider)
|
||||||
|
{
|
||||||
|
_pathProvider = pathProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
if (Common.EnviromentProvider.IsProduction)
|
if (Common.EnviromentProvider.IsProduction)
|
||||||
{
|
{
|
||||||
LogManager.ThrowExceptions = false;
|
LogManager.ThrowExceptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().WebRoot, "log.config"), false);
|
LogManager.Configuration = new XmlLoggingConfiguration(_pathProvider.LogConfigFile, false);
|
||||||
|
|
||||||
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
||||||
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
||||||
|
|
|
@ -9,12 +9,13 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
{
|
{
|
||||||
public class ConfigFileProvider
|
public class ConfigFileProvider
|
||||||
{
|
{
|
||||||
private string _configFile = Path.Combine(new EnviromentProvider().AppDataPath, "Config.xml");
|
private readonly PathProvider _pathProvider;
|
||||||
|
|
||||||
public string ConfigFile
|
private readonly string _configFile;
|
||||||
|
public ConfigFileProvider(PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
get { return _configFile; }
|
_pathProvider = pathProvider;
|
||||||
set { _configFile = value; }
|
_configFile = _pathProvider.AppConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int Port
|
public virtual int Port
|
||||||
|
@ -37,7 +38,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
|
|
||||||
public virtual string GetValue(string key, object defaultValue, string parent = null)
|
public virtual string GetValue(string key, object defaultValue, string parent = null)
|
||||||
{
|
{
|
||||||
var xDoc = XDocument.Load(ConfigFile);
|
var xDoc = XDocument.Load(_configFile);
|
||||||
var config = xDoc.Descendants("Config").Single();
|
var config = xDoc.Descendants("Config").Single();
|
||||||
|
|
||||||
var parentContainer = config;
|
var parentContainer = config;
|
||||||
|
@ -50,7 +51,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
SetValue(key, defaultValue, parent);
|
SetValue(key, defaultValue, parent);
|
||||||
|
|
||||||
//Reload the configFile
|
//Reload the configFile
|
||||||
xDoc = XDocument.Load(ConfigFile);
|
xDoc = XDocument.Load(_configFile);
|
||||||
config = xDoc.Descendants("Config").Single();
|
config = xDoc.Descendants("Config").Single();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
|
|
||||||
public virtual void SetValue(string key, object value, string parent = null)
|
public virtual void SetValue(string key, object value, string parent = null)
|
||||||
{
|
{
|
||||||
var xDoc = XDocument.Load(ConfigFile);
|
var xDoc = XDocument.Load(_configFile);
|
||||||
var config = xDoc.Descendants("Config").Single();
|
var config = xDoc.Descendants("Config").Single();
|
||||||
|
|
||||||
var parentContainer = config;
|
var parentContainer = config;
|
||||||
|
@ -105,18 +106,18 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
else
|
else
|
||||||
parentContainer.Descendants(key).Single().Value = value.ToString();
|
parentContainer.Descendants(key).Single().Value = value.ToString();
|
||||||
|
|
||||||
xDoc.Save(ConfigFile);
|
xDoc.Save(_configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void CreateDefaultConfigFile()
|
public virtual void CreateDefaultConfigFile()
|
||||||
{
|
{
|
||||||
if (!File.Exists(ConfigFile))
|
if (!File.Exists(_configFile))
|
||||||
{
|
{
|
||||||
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
||||||
|
|
||||||
xDoc.Add(new XElement("Config"));
|
xDoc.Add(new XElement("Config"));
|
||||||
|
|
||||||
xDoc.Save(ConfigFile);
|
xDoc.Save(_configFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,20 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
private readonly HttpProvider _httpProvider;
|
private readonly HttpProvider _httpProvider;
|
||||||
private readonly DiskProvider _diskProvider;
|
private readonly DiskProvider _diskProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
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, EnviromentProvider enviromentProvider)
|
public BannerDownloadJob(SeriesProvider seriesProvider, HttpProvider httpProvider, DiskProvider diskProvider,
|
||||||
|
EnviromentProvider enviromentProvider, PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
_seriesProvider = seriesProvider;
|
_seriesProvider = seriesProvider;
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
|
_pathProvider = pathProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BannerDownloadJob()
|
public BannerDownloadJob()
|
||||||
|
@ -51,8 +53,8 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
{
|
{
|
||||||
Logger.Debug("Starting banner download job");
|
Logger.Debug("Starting banner download job");
|
||||||
|
|
||||||
_bannerPath = Path.Combine(_enviromentProvider.WebRoot, "Content", "Images", "Banners");
|
|
||||||
_diskProvider.CreateDirectory(_bannerPath);
|
_diskProvider.CreateDirectory(_pathProvider.BannerPath);
|
||||||
|
|
||||||
if (targetId > 0)
|
if (targetId > 0)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +78,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
|
||||||
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
||||||
{
|
{
|
||||||
var bannerFilename = String.Format("{0}{1}{2}.jpg", _bannerPath, Path.DirectorySeparatorChar, series.SeriesId);
|
var bannerFilename = Path.Combine(_pathProvider.BannerPath, series.SeriesId.ToString(), ".jpg");
|
||||||
|
|
||||||
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,15 @@ 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]
|
[Inject]
|
||||||
public TvDbProvider(EnviromentProvider enviromentProvider)
|
public TvDbProvider(PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
_enviromentProvider = enviromentProvider;
|
_handler = new TvdbHandler(new XmlCacheProvider(pathProvider.CacheFolder), TVDB_APIKEY);
|
||||||
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppDataPath + @"\cache\tvdb"), TVDB_APIKEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TvDbProvider()
|
public TvDbProvider()
|
||||||
|
|
|
@ -18,19 +18,22 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly HttpProvider _httpProvider;
|
private readonly HttpProvider _httpProvider;
|
||||||
private readonly ConfigProvider _configProvider;
|
private readonly ConfigProvider _configProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
private readonly DiskProvider _diskProvider;
|
private readonly DiskProvider _diskProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
|
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public const string SandboxFolderName = "nzbdrone_update";
|
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, EnviromentProvider enviromentProvider, DiskProvider diskProvider)
|
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, EnviromentProvider enviromentProvider,
|
||||||
|
PathProvider pathProvider, DiskProvider diskProvider)
|
||||||
{
|
{
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_configProvider = configProvider;
|
_configProvider = configProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
|
_pathProvider = pathProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,15 +76,14 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
public virtual void PreformUpdate(UpdatePackage updatePackage)
|
public virtual void PreformUpdate(UpdatePackage updatePackage)
|
||||||
{
|
{
|
||||||
var tempSubFolder = Path.Combine(_enviromentProvider.TempPath, SandboxFolderName);
|
var packageDestination = Path.Combine(_pathProvider.UpdateSandboxFolder, updatePackage.FileName);
|
||||||
var packageDestination = Path.Combine(tempSubFolder, updatePackage.FileName);
|
|
||||||
|
|
||||||
Logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
Logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||||
Logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
Logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||||
|
|
||||||
Logger.Info("Extracting Update package");
|
Logger.Info("Extracting Update package");
|
||||||
_diskProvider.ExtractArchive(packageDestination, tempSubFolder);
|
_diskProvider.ExtractArchive(packageDestination, _pathProvider.UpdateSandboxFolder);
|
||||||
Logger.Info("Update package extracted successfully");
|
Logger.Info("Update package extracted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,9 @@ using NzbDrone.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Test.Common
|
namespace NzbDrone.Test.Common
|
||||||
{
|
{
|
||||||
public abstract class LoggingFixtures
|
public abstract class LoggingTest
|
||||||
{
|
{
|
||||||
|
protected static void InitLogging()
|
||||||
[SetUp]
|
|
||||||
public void SetUpBase()
|
|
||||||
{
|
{
|
||||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||||
LogConfiguration.RegisterUdpLogger();
|
LogConfiguration.RegisterUdpLogger();
|
|
@ -69,7 +69,7 @@
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
||||||
<Compile Include="ExceptionVerification.cs" />
|
<Compile Include="ExceptionVerification.cs" />
|
||||||
<Compile Include="LoggingFixtures.cs" />
|
<Compile Include="LoggingTest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,12 @@ namespace NzbDrone.Web
|
||||||
|
|
||||||
protected override IKernel CreateKernel()
|
protected override IKernel CreateKernel()
|
||||||
{
|
{
|
||||||
LogConfiguration.Setup();
|
var kernel = CentralDispatch.NinjectKernel;
|
||||||
|
kernel.Get<LogConfiguration>().Setup();
|
||||||
Logger.Info("NZBDrone Starting up.");
|
Logger.Info("NZBDrone Starting up.");
|
||||||
|
|
||||||
CentralDispatch.DedicateToHost();
|
CentralDispatch.DedicateToHost();
|
||||||
|
|
||||||
var kernel = CentralDispatch.NinjectKernel;
|
|
||||||
|
|
||||||
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
|
|
||||||
kernel.Load(Assembly.GetExecutingAssembly());
|
kernel.Load(Assembly.GetExecutingAssembly());
|
||||||
return kernel;
|
return kernel;
|
||||||
}
|
}
|
||||||
|
|
2
config.xml
Normal file
2
config.xml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<Config />
|
Loading…
Add table
Add a link
Reference in a new issue