Compare commits

...

9 Commits

19 changed files with 285 additions and 126 deletions

View File

@ -7,11 +7,12 @@ using NzbDrone.Core.Download.Clients.DownloadStation;
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
{
[TestFixture]
public class SerialNumberProviderFixture : CoreTest<SerialNumberProvider>
public class DSMInfoProviderFixture : CoreTest<DSMInfoProvider>
{
protected DownloadStationSettings _settings;
@ -24,17 +25,27 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
private void GivenValidResponse()
{
Mocker.GetMock<IDSMInfoProxy>()
.Setup(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
.Returns("serial");
.Setup(d => d.GetInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DSMInfoResponse() { SerialNumber = "serial", Version = "DSM 6.0.1" });
}
private void GivenInvalidResponse()
{
Mocker.GetMock<IDSMInfoProxy>()
.Setup(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
.Setup(d => d.GetInfo(It.IsAny<DownloadStationSettings>()))
.Throws(new DownloadClientException("Serial response invalid"));
}
[Test]
public void should_return_version()
{
GivenValidResponse();
var version = Subject.GetDSMVersion(_settings);
version.Should().Be(new Version("6.0.1"));
}
[Test]
public void should_return_hashedserialnumber()
{
@ -46,7 +57,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
serial.Should().Be("50DE66B735D30738618568294742FCF1DFA52A47");
Mocker.GetMock<IDSMInfoProxy>()
.Verify(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()), Times.Once());
.Verify(d => d.GetInfo(It.IsAny<DownloadStationSettings>()), Times.Once());
}
[Test]
@ -60,7 +71,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
serial2.Should().Be(serial1);
Mocker.GetMock<IDSMInfoProxy>()
.Verify(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()), Times.Once());
.Verify(d => d.GetInfo(It.IsAny<DownloadStationSettings>()), Times.Once());
}
[Test]

View File

@ -12,6 +12,7 @@ using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
using NzbDrone.Core.MediaFiles.TorrentInfo;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Test.Common;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
{
@ -280,6 +281,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
.Returns(_downloadStationConfigItems);
}
protected void GivenApiVersions()
{
Mocker.GetMock<IDownloadStationTaskProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "Task", MinVersion = 1, MaxVersion = 2 });
Mocker.GetMock<IDownloadStationInfoProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "Info", MinVersion = 1, MaxVersion = 3 });
Mocker.GetMock<IFileStationProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "File", MinVersion = 1, MaxVersion = 2 });
}
protected void GivenSharedFolder()
{
Mocker.GetMock<ISharedFolderResolver>()
@ -289,7 +305,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
protected void GivenSerialNumber()
{
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
.Returns(_serialNumber);
}
@ -359,6 +375,26 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
return tasks.Count;
}
protected void GivenDSMVersion(string version)
{
Mocker.GetMock<IDSMInfoProvider>()
.Setup(d => d.GetDSMVersion(It.IsAny<DownloadStationSettings>()))
.Returns(new Version(version));
}
[TestCase("6.0.0", 0)]
[TestCase("5.0.0", 1)]
public void TestConnection_should_return_validation_failure_as_expected(string version, int count)
{
GivenApiVersions();
GivenDSMVersion(version);
var result = Subject.Test();
result.Errors.Should().HaveCount(count);
}
[Test]
public void Download_with_TvDirectory_should_force_directory()
{
@ -460,7 +496,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
[Test]
public void GetItems_should_throw_if_serial_number_unavailable()
{
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(_settings))
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
@ -476,7 +512,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
{
var remoteEpisode = CreateRemoteEpisode();
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(_settings))
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));

View File

@ -182,6 +182,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
.Returns(_downloadStationConfigItems);
}
protected void GivenApiVersions()
{
Mocker.GetMock<IDownloadStationTaskProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "Task", MinVersion = 1, MaxVersion = 2 });
Mocker.GetMock<IDownloadStationInfoProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "Info", MinVersion = 1, MaxVersion = 3 });
Mocker.GetMock<IFileStationProxy>()
.Setup(s => s.GetApiInfo(It.IsAny<DownloadStationSettings>()))
.Returns(new DiskStationApiInfo() { Name = "File", MinVersion = 1, MaxVersion = 2 });
}
protected void GivenSharedFolder()
{
Mocker.GetMock<ISharedFolderResolver>()
@ -191,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
protected void GivenSerialNumber()
{
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
.Returns(_serialNumber);
}
@ -245,6 +260,25 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Mocker.GetMock<IDownloadStationTaskProxy>()
.Setup(d => d.GetTasks(_settings))
.Returns(tasks);
}
protected void GivenDSMVersion(string version)
{
Mocker.GetMock<IDSMInfoProvider>()
.Setup(d => d.GetDSMVersion(It.IsAny<DownloadStationSettings>()))
.Returns(new Version(version));
}
[TestCase("6.0.0", 0)]
[TestCase("5.0.0", 1)]
public void TestConnection_should_return_validation_failure_as_expected(string version, int count)
{
GivenApiVersions();
GivenDSMVersion(version);
var result = Subject.Test();
result.Errors.Should().HaveCount(count);
}
[Test]
@ -348,7 +382,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
[Test]
public void GetItems_should_throw_if_serial_number_unavailable()
{
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(_settings))
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
@ -364,7 +398,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
{
var remoteEpisode = CreateRemoteEpisode();
Mocker.GetMock<ISerialNumberProvider>()
Mocker.GetMock<IDSMInfoProvider>()
.Setup(s => s.GetSerialNumber(_settings))
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));

View File

@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
Mocker.GetMock<IDownloadClientStatusRepository>()
.Verify(v => v.UpdateMany(
It.Is<List<DownloadClientStatus>>(i => i.All(
s => s.InitialFailure.Value < DateTime.UtcNow))
s => s.InitialFailure.Value <= DateTime.UtcNow))
)
);
}
@ -85,7 +85,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
Mocker.GetMock<IDownloadClientStatusRepository>()
.Verify(v => v.UpdateMany(
It.Is<List<DownloadClientStatus>>(i => i.All(
s => s.MostRecentFailure.Value < DateTime.UtcNow))
s => s.MostRecentFailure.Value <= DateTime.UtcNow))
)
);
}
@ -116,4 +116,4 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
}
}
}

View File

@ -176,7 +176,7 @@
<Compile Include="Download\DownloadClientTests\DelugeTests\DelugeFixture.cs" />
<Compile Include="Download\DownloadClientTests\DownloadClientFixtureBase.cs" />
<Compile Include="Download\DownloadClientTests\DownloadStationTests\TorrentDownloadStationFixture.cs" />
<Compile Include="Download\DownloadClientTests\DownloadStationTests\SerialNumberProviderFixture.cs" />
<Compile Include="Download\DownloadClientTests\DownloadStationTests\DSMInfoProviderFixture.cs" />
<Compile Include="Download\DownloadClientTests\DownloadStationTests\SharedFolderResolverFixture.cs" />
<Compile Include="Download\DownloadClientTests\DownloadStationTests\UsenetDownloadStationFixture.cs" />
<Compile Include="Download\DownloadClientTests\HadoukenTests\HadoukenFixture.cs" />

View File

@ -0,0 +1,62 @@
using System;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Crypto;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Download.Clients.DownloadStation
{
public interface IDSMInfoProvider
{
string GetSerialNumber(DownloadStationSettings settings);
Version GetDSMVersion(DownloadStationSettings settings);
}
public class DSMInfoProvider : IDSMInfoProvider
{
private readonly IDSMInfoProxy _proxy;
private ICached<DSMInfoResponse> _cache;
private readonly ILogger _logger;
public DSMInfoProvider(ICacheManager cacheManager,
IDSMInfoProxy proxy,
Logger logger)
{
_proxy = proxy;
_cache = cacheManager.GetCache<DSMInfoResponse>(GetType());
_logger = logger;
}
private DSMInfoResponse GetInfo(DownloadStationSettings settings)
{
return _cache.Get(settings.Host, () => _proxy.GetInfo(settings), TimeSpan.FromMinutes(5));
}
public string GetSerialNumber(DownloadStationSettings settings)
{
try
{
return HashConverter.GetHash(GetInfo(settings).SerialNumber).ToHexString();
}
catch (Exception ex)
{
_logger.Warn(ex, "Could not get the serial number from Download Station {0}:{1}", settings.Host, settings.Port);
throw;
}
}
public Version GetDSMVersion(DownloadStationSettings settings)
{
var info = GetInfo(settings);
Regex regex = new Regex(@"DSM (?<version>[\d.]*)");
var dsmVersion = regex.Match(info.Version).Groups["version"].Value;
return new Version(dsmVersion);
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

View File

@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace NzbDrone.Core.Download.Clients.DownloadStation
{

View File

@ -1,10 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static NzbDrone.Core.Download.Clients.DownloadStation.DownloadStationTask;
namespace NzbDrone.Core.Download.Clients.DownloadStation
{

View File

@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using NLog;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
public interface IDSMInfoProxy
public interface IDSMInfoProxy : IDiskStationProxy
{
string GetSerialNumber(DownloadStationSettings settings);
DSMInfoResponse GetInfo(DownloadStationSettings settings);
}
public class DSMInfoProxy : DiskStationProxyBase, IDSMInfoProxy
@ -19,15 +17,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
}
public string GetSerialNumber(DownloadStationSettings settings)
public DSMInfoResponse GetInfo(DownloadStationSettings settings)
{
var info = GetApiInfo(settings);
var requestBuilder = BuildRequest(settings, "getinfo", info.MinVersion);
var response = ProcessRequest<DSMInfoResponse>(requestBuilder, "get serial number", settings);
var response = ProcessRequest<DSMInfoResponse>(requestBuilder, "get info", settings);
return response.Data.SerialNumber;
return response.Data;
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using NLog;
using NzbDrone.Common.Cache;
@ -161,7 +160,9 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
if (apiInfo.NeedsAuthentication)
{
requestBuilder.AddFormParameter("_sid", _sessionCache.Get(GenerateSessionCacheKey(settings), () => AuthenticateClient(settings), TimeSpan.FromHours(6)));
var sid = _sessionCache.Get(GenerateSessionCacheKey(settings), () => AuthenticateClient(settings), TimeSpan.FromHours(6));
_logger.Debug("DownloadStation Session sid={0}", sid);
requestBuilder.AddFormParameter("_sid", sid);
}
requestBuilder.AddFormParameter("api", apiInfo.Name);
@ -172,7 +173,9 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
if (apiInfo.NeedsAuthentication)
{
requestBuilder.AddQueryParam("_sid", _sessionCache.Get(GenerateSessionCacheKey(settings), () => AuthenticateClient(settings), TimeSpan.FromHours(6)));
var sid = _sessionCache.Get(GenerateSessionCacheKey(settings), () => AuthenticateClient(settings), TimeSpan.FromHours(6));
_logger.Debug("DownloadStation Session sid={0}", sid);
requestBuilder.AddQueryParam("_sid", sid);
}
requestBuilder.AddQueryParam("api", apiInfo.Name);

View File

@ -1,7 +1,7 @@
using NLog;
using NzbDrone.Common.Http;
using System.Collections.Generic;
using System.Collections.Generic;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{

View File

@ -0,0 +1,8 @@
namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
public class ExpectedVersion
{
public int Version { get; set; }
public IDiskStationProxy Proxy { get; set; }
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Cache;
@ -18,11 +17,17 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
public class FileStationProxy : DiskStationProxyBase, IFileStationProxy
{
public FileStationProxy(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
private IDSMInfoProvider _dsmInfoProvider;
public FileStationProxy(IDSMInfoProvider dsmInfoProvider,
IHttpClient httpClient,
ICacheManager cacheManager,
Logger logger)
: base(DiskStationApi.FileStationList, "SYNO.FileStation.List", httpClient, cacheManager, logger)
{
_dsmInfoProvider = dsmInfoProvider;
}
public SharedFolderMapping GetSharedFolderMapping(string sharedFolder, DownloadStationSettings settings)
{
var info = GetInfoFileOrDirectory(sharedFolder, settings);
@ -34,13 +39,16 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
public FileStationListFileInfoResponse GetInfoFileOrDirectory(string path, DownloadStationSettings settings)
{
var requestBuilder = BuildRequest(settings, "getinfo", 2);
var dsmVersion = _dsmInfoProvider.GetDSMVersion(settings);
var requestBuilder = BuildRequest(settings, "getinfo", dsmVersion >= new Version(6, 0, 0) ? 2 : 1);
requestBuilder.AddQueryParam("path", new[] { path }.ToJson());
requestBuilder.AddQueryParam("additional", "[\"real_path\"]");
var response = ProcessRequest<FileStationListResponse>(requestBuilder, $"get info of {path}", settings);
return response.Data.Files.First();
}
}
}

View File

@ -6,5 +6,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Responses
{
[JsonProperty("serial")]
public string SerialNumber { get; set; }
[JsonProperty("version_string")]
public string Version { get; set; }
}
}

View File

@ -1,49 +0,0 @@
using System;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Crypto;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
namespace NzbDrone.Core.Download.Clients.DownloadStation
{
public interface ISerialNumberProvider
{
string GetSerialNumber(DownloadStationSettings settings);
}
public class SerialNumberProvider : ISerialNumberProvider
{
private readonly IDSMInfoProxy _proxy;
private ICached<string> _cache;
private readonly ILogger _logger;
public SerialNumberProvider(ICacheManager cacheManager,
IDSMInfoProxy proxy,
Logger logger)
{
_proxy = proxy;
_cache = cacheManager.GetCache<string>(GetType());
_logger = logger;
}
public string GetSerialNumber(DownloadStationSettings settings)
{
try
{
return _cache.Get(settings.Host, () => GetHashedSerialNumber(settings), TimeSpan.FromMinutes(5));
}
catch (Exception ex)
{
_logger.Warn(ex, "Could not get the serial number from Download Station {0}:{1}", settings.Host, settings.Port);
throw;
}
}
private string GetHashedSerialNumber(DownloadStationSettings settings)
{
var serialNumber = _proxy.GetSerialNumber(settings);
return HashConverter.GetHash(serialNumber).ToHexString();
}
}
}

View File

@ -22,11 +22,11 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
protected readonly IDownloadStationInfoProxy _dsInfoProxy;
protected readonly IDownloadStationTaskProxy _dsTaskProxy;
protected readonly ISharedFolderResolver _sharedFolderResolver;
protected readonly ISerialNumberProvider _serialNumberProvider;
protected readonly IDSMInfoProvider _dsmInfoProvider;
protected readonly IFileStationProxy _fileStationProxy;
public TorrentDownloadStation(ISharedFolderResolver sharedFolderResolver,
ISerialNumberProvider serialNumberProvider,
IDSMInfoProvider dsmInfoProvider,
IFileStationProxy fileStationProxy,
IDownloadStationInfoProxy dsInfoProxy,
IDownloadStationTaskProxy dsTaskProxy,
@ -42,7 +42,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
_dsTaskProxy = dsTaskProxy;
_fileStationProxy = fileStationProxy;
_sharedFolderResolver = sharedFolderResolver;
_serialNumberProvider = serialNumberProvider;
_dsmInfoProvider = dsmInfoProvider;
}
public override string Name => "Download Station";
@ -55,7 +55,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
public override IEnumerable<DownloadClientItem> GetItems()
{
var torrents = GetTasks();
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var serialNumber = _dsmInfoProvider.GetSerialNumber(Settings);
var items = new List<DownloadClientItem>();
@ -149,7 +149,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink)
{
var hashedSerialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var hashedSerialNumber = _dsmInfoProvider.GetSerialNumber(Settings);
_dsTaskProxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(), Settings);
@ -168,7 +168,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string hash, string filename, byte[] fileContent)
{
var hashedSerialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var hashedSerialNumber = _dsmInfoProvider.GetSerialNumber(Settings);
_dsTaskProxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings);
@ -191,6 +191,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
failures.AddIfNotNull(TestConnection());
if (failures.Any()) return;
failures.AddIfNotNull(TestDSMVersion());
failures.AddIfNotNull(TestOutputPath());
failures.AddIfNotNull(TestGetTorrents());
}
@ -303,7 +304,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
return new NzbDroneValidationFailure(fieldName, $"Shared folder does not exist")
{
DetailedDescription = $"The Diskstation does not have a Shared Folder with the name '{sharedFolder}', are you sure you specified it correctly?"
DetailedDescription = $"The Diskstation does not have a Shared Folder with the name '{downloadDir}', are you sure you specified it correctly?"
};
}
@ -334,7 +335,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
try
{
return ValidateVersion();
return TestProxiesVersions();
}
catch (DownloadClientAuthenticationException ex)
{
@ -363,16 +364,40 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
}
}
protected ValidationFailure ValidateVersion()
protected ValidationFailure TestDSMVersion()
{
var info = _dsTaskProxy.GetApiInfo(Settings);
var dsmversion = _dsmInfoProvider.GetDSMVersion(Settings);
_logger.Debug("Download Station api version information: Min {0} - Max {1}", info.MinVersion, info.MaxVersion);
if (info.MinVersion > 2 || info.MaxVersion < 2)
if (dsmversion < new Version(6, 0, 0))
{
return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {info.MinVersion} to {info.MaxVersion}");
return new NzbDroneValidationFailure(string.Empty, $"DSM Version {dsmversion} not fully supported. We recommend version 6.0.0 or above.") { IsWarning = true };
}
return null;
}
protected ValidationFailure TestProxiesVersions()
{
var dsmVersion = _dsmInfoProvider.GetDSMVersion(Settings);
var expectedVersions = new List<ExpectedVersion>()
{
new ExpectedVersion { Version = 2, Proxy = _dsTaskProxy },
new ExpectedVersion { Version = (dsmVersion >= new Version(6,0,0))? 2 : 1, Proxy = _fileStationProxy },
new ExpectedVersion { Version = 1, Proxy = _dsInfoProxy }
};
foreach (var expectedVersion in expectedVersions)
{
DiskStationApiInfo apiInfo = expectedVersion.Proxy.GetApiInfo(Settings);
_logger.Debug("{1} api version information: Min {1} - Max {2} - Expected {3}", apiInfo.Name, apiInfo.MinVersion, apiInfo.MaxVersion, expectedVersion.Version);
if (apiInfo.MinVersion > expectedVersion.Version || apiInfo.MaxVersion < expectedVersion.Version)
{
return new NzbDroneValidationFailure(string.Empty, $"{apiInfo.Name} API version not supported, should be at least {expectedVersion.Version}. It supports from {apiInfo.MinVersion} to {apiInfo.MaxVersion}");
}
}
return null;

View File

@ -20,11 +20,11 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
protected readonly IDownloadStationInfoProxy _dsInfoProxy;
protected readonly IDownloadStationTaskProxy _dsTaskProxy;
protected readonly ISharedFolderResolver _sharedFolderResolver;
protected readonly ISerialNumberProvider _serialNumberProvider;
protected readonly IDSMInfoProvider _dsmInfoProvider;
protected readonly IFileStationProxy _fileStationProxy;
public UsenetDownloadStation(ISharedFolderResolver sharedFolderResolver,
ISerialNumberProvider serialNumberProvider,
IDSMInfoProvider dsmInfoProvider,
IFileStationProxy fileStationProxy,
IDownloadStationInfoProxy dsInfoProxy,
IDownloadStationTaskProxy dsTaskProxy,
@ -40,7 +40,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
_dsTaskProxy = dsTaskProxy;
_fileStationProxy = fileStationProxy;
_sharedFolderResolver = sharedFolderResolver;
_serialNumberProvider = serialNumberProvider;
_dsmInfoProvider = dsmInfoProvider;
}
public override string Name => "Download Station";
@ -53,7 +53,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
public override IEnumerable<DownloadClientItem> GetItems()
{
var nzbTasks = GetTasks();
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var serialNumber = _dsmInfoProvider.GetSerialNumber(Settings);
var items = new List<DownloadClientItem>();
@ -163,7 +163,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContent)
{
var hashedSerialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var hashedSerialNumber = _dsmInfoProvider.GetSerialNumber(Settings);
_dsTaskProxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings);
@ -186,6 +186,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
failures.AddIfNotNull(TestConnection());
if (failures.Any()) return;
failures.AddIfNotNull(TestDSMVersion());
failures.AddIfNotNull(TestOutputPath());
failures.AddIfNotNull(TestGetNZB());
}
@ -217,7 +218,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
return new NzbDroneValidationFailure(fieldName, $"Shared folder does not exist")
{
DetailedDescription = $"The Diskstation does not have a Shared Folder with the name '{sharedFolder}', are you sure you specified it correctly?"
DetailedDescription = $"The Diskstation does not have a Shared Folder with the name '{downloadDir}', are you sure you specified it correctly?"
};
}
@ -248,7 +249,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{
try
{
return ValidateVersion();
return TestProxiesVersions();
}
catch (DownloadClientAuthenticationException ex)
{
@ -269,24 +270,48 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
DetailedDescription = "Please verify the hostname and port."
};
}
return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message);
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
}
catch (Exception ex)
{
_logger.Error(ex, "Error testing Torrent Download Station");
return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message);
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
}
}
protected ValidationFailure ValidateVersion()
protected ValidationFailure TestDSMVersion()
{
var info = _dsTaskProxy.GetApiInfo(Settings);
var dsmversion = _dsmInfoProvider.GetDSMVersion(Settings);
_logger.Debug("Download Station api version information: Min {0} - Max {1}", info.MinVersion, info.MaxVersion);
if (info.MinVersion > 2 || info.MaxVersion < 2)
if (dsmversion < new Version(6, 0, 0))
{
return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {info.MinVersion} to {info.MaxVersion}");
return new NzbDroneValidationFailure(string.Empty, $"DSM Version {dsmversion} not fully supported. We recommend version 6.0.0 or above.") { IsWarning = true };
}
return null;
}
protected ValidationFailure TestProxiesVersions()
{
var dsmVersion = _dsmInfoProvider.GetDSMVersion(Settings);
var expectedVersions = new List<ExpectedVersion>()
{
new ExpectedVersion { Version = 2, Proxy = _dsTaskProxy },
new ExpectedVersion { Version = (dsmVersion >= new Version(6,0,0))? 2 : 1, Proxy = _fileStationProxy },
new ExpectedVersion { Version = 1, Proxy = _dsInfoProxy }
};
foreach (var expectedVersion in expectedVersions)
{
DiskStationApiInfo apiInfo = expectedVersion.Proxy.GetApiInfo(Settings);
_logger.Debug("{1} api version information: Min {1} - Max {2} - Expected {3}", apiInfo.Name, apiInfo.MinVersion, apiInfo.MaxVersion, expectedVersion.Version);
if (apiInfo.MinVersion > expectedVersion.Version || apiInfo.MaxVersion < expectedVersion.Version)
{
return new NzbDroneValidationFailure(string.Empty, $"{apiInfo.Name} API version not supported, should be at least {expectedVersion.Version}. It supports from {apiInfo.MinVersion} to {apiInfo.MaxVersion}");
}
}
return null;
@ -377,7 +402,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
}
catch (Exception ex)
{
return new NzbDroneValidationFailure(string.Empty, "Failed to get the list of NZBs: " + ex.Message);
return new NzbDroneValidationFailure(string.Empty, $"Failed to get the list of NZBs: {ex.Message}");
}
}

View File

@ -371,7 +371,9 @@
<Compile Include="Download\Clients\DownloadClientAuthenticationException.cs" />
<Compile Include="Download\Clients\DownloadClientUnavailableException.cs" />
<Compile Include="Download\Clients\DownloadClientException.cs" />
<Compile Include="Download\Clients\DownloadStation\DSMInfoProvider.cs" />
<Compile Include="Download\Clients\DownloadStation\Proxies\DownloadStationInfoProxy.cs" />
<Compile Include="Download\Clients\DownloadStation\Proxies\ExpectedVersion.cs" />
<Compile Include="Download\Clients\DownloadStation\TorrentDownloadStation.cs" />
<Compile Include="Download\Clients\DownloadStation\Proxies\DownloadStationTaskProxy.cs" />
<Compile Include="Download\Clients\DownloadStation\DownloadStationSettings.cs" />
@ -390,7 +392,6 @@
<Compile Include="Download\Clients\DownloadStation\Responses\DiskStationResponse.cs" />
<Compile Include="Download\Clients\DownloadStation\Responses\DownloadStationTaskInfoResponse.cs" />
<Compile Include="Download\Clients\DownloadStation\DiskStationApiInfo.cs" />
<Compile Include="Download\Clients\DownloadStation\SerialNumberProvider.cs" />
<Compile Include="Download\Clients\DownloadStation\SharedFolderMapping.cs" />
<Compile Include="Download\Clients\DownloadStation\SharedFolderResolver.cs" />
<Compile Include="Download\Clients\DownloadStation\DiskStationApi.cs" />