1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Merge pull request #57 from Taloth/develop

Solved 587-failed-download-history-not-working
This commit is contained in:
Mark McDowall 2014-02-24 16:29:46 -08:00
commit 1f91f05b1a
4 changed files with 71 additions and 11 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Common
{
public static class DictionaryExtensions
{
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
{
TValue value;
return dictionary.TryGetValue(key, out value) ? value : defaultValue;
}
}
}

View File

@ -67,6 +67,7 @@
<Compile Include="Composition\IContainer.cs" /> <Compile Include="Composition\IContainer.cs" />
<Compile Include="Composition\ContainerBuilderBase.cs" /> <Compile Include="Composition\ContainerBuilderBase.cs" />
<Compile Include="DateTimeExtensions.cs" /> <Compile Include="DateTimeExtensions.cs" />
<Compile Include="DictionaryExtensions.cs" />
<Compile Include="Disk\DiskProviderBase.cs" /> <Compile Include="Disk\DiskProviderBase.cs" />
<Compile Include="EnsureThat\Ensure.cs" /> <Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" /> <Compile Include="EnsureThat\EnsureBoolExtensions.cs" />

View File

@ -131,6 +131,54 @@ public void should_not_process_if_matching_history_is_not_found()
VerifyNoFailedDownloads(); VerifyNoFailedDownloads();
} }
[Test]
public void should_not_process_if_grabbed_history_contains_null_downloadclient_id()
{
GivenFailedDownloadClientHistory();
var historyGrabbed = Builder<History.History>.CreateListOfSize(1)
.Build()
.ToList();
historyGrabbed.First().Data.Add("downloadClient", "SabnzbdClient");
historyGrabbed.First().Data.Add("downloadClientId", null);
GivenGrabbedHistory(historyGrabbed);
GivenNoFailedHistory();
Subject.Execute(new CheckForFailedDownloadCommand());
VerifyNoFailedDownloads();
}
[Test]
public void should_process_if_failed_history_contains_null_downloadclient_id()
{
GivenFailedDownloadClientHistory();
var historyGrabbed = Builder<History.History>.CreateListOfSize(1)
.Build()
.ToList();
historyGrabbed.First().Data.Add("downloadClient", "SabnzbdClient");
historyGrabbed.First().Data.Add("downloadClientId", _failed.First().Id);
GivenGrabbedHistory(historyGrabbed);
var historyFailed = Builder<History.History>.CreateListOfSize(1)
.Build()
.ToList();
historyFailed.First().Data.Add("downloadClient", "SabnzbdClient");
historyFailed.First().Data.Add("downloadClientId", null);
GivenFailedHistory(historyFailed);
Subject.Execute(new CheckForFailedDownloadCommand());
VerifyFailedDownloads();
}
[Test] [Test]
public void should_not_process_if_already_added_to_history_as_failed() public void should_not_process_if_already_added_to_history_as_failed()
{ {

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
@ -72,8 +73,7 @@ private void CheckQueue(List<History.History> grabbedHistory, List<History.Histo
continue; continue;
} }
if (failedHistory.Any(h => h.Data.ContainsKey(DOWNLOAD_CLIENT_ID) && if (failedHistory.Any(h => failedLocal.Id.Equals(h.Data.GetValueOrDefault(DOWNLOAD_CLIENT_ID))))
h.Data[DOWNLOAD_CLIENT_ID].Equals(failedLocal.Id)))
{ {
_logger.Trace("Already added to history as failed"); _logger.Trace("Already added to history as failed");
continue; continue;
@ -118,8 +118,7 @@ private void CheckHistory(List<History.History> grabbedHistory, List<History.His
continue; continue;
} }
if (failedHistory.Any(h => h.Data.ContainsKey(DOWNLOAD_CLIENT_ID) && if (failedHistory.Any(h => failedLocal.Id.Equals(h.Data.GetValueOrDefault(DOWNLOAD_CLIENT_ID))))
h.Data[DOWNLOAD_CLIENT_ID].Equals(failedLocal.Id)))
{ {
_logger.Trace("Already added to history as failed"); _logger.Trace("Already added to history as failed");
continue; continue;
@ -137,8 +136,7 @@ private void CheckHistory(List<History.History> grabbedHistory, List<History.His
private List<History.History> GetHistoryItems(List<History.History> grabbedHistory, string downloadClientId) private List<History.History> GetHistoryItems(List<History.History> grabbedHistory, string downloadClientId)
{ {
return grabbedHistory.Where(h => h.Data.ContainsKey(DOWNLOAD_CLIENT_ID) && return grabbedHistory.Where(h => downloadClientId.Equals(h.Data.GetValueOrDefault(DOWNLOAD_CLIENT_ID)))
h.Data[DOWNLOAD_CLIENT_ID].Equals(downloadClientId))
.ToList(); .ToList();
} }
@ -148,17 +146,14 @@ private void PublishDownloadFailedEvent(List<History.History> historyItems, stri
string downloadClient; string downloadClient;
string downloadClientId; string downloadClientId;
historyItem.Data.TryGetValue(DOWNLOAD_CLIENT, out downloadClient);
historyItem.Data.TryGetValue(DOWNLOAD_CLIENT_ID, out downloadClientId);
_eventAggregator.PublishEvent(new DownloadFailedEvent _eventAggregator.PublishEvent(new DownloadFailedEvent
{ {
SeriesId = historyItem.SeriesId, SeriesId = historyItem.SeriesId,
EpisodeIds = historyItems.Select(h => h.EpisodeId).ToList(), EpisodeIds = historyItems.Select(h => h.EpisodeId).ToList(),
Quality = historyItem.Quality, Quality = historyItem.Quality,
SourceTitle = historyItem.SourceTitle, SourceTitle = historyItem.SourceTitle,
DownloadClient = downloadClient, DownloadClient = historyItem.Data.GetValueOrDefault(DOWNLOAD_CLIENT),
DownloadClientId = downloadClientId, DownloadClientId = historyItem.Data.GetValueOrDefault(DOWNLOAD_CLIENT_ID),
Message = message Message = message
}); });
} }