Failed Download detection now ignores history without unique download client id.

This commit is contained in:
Taloth Saldono 2014-02-24 21:50:00 +01:00
parent 9c7eaf0043
commit 4786bc0c34
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\ContainerBuilderBase.cs" />
<Compile Include="DateTimeExtensions.cs" />
<Compile Include="DictionaryExtensions.cs" />
<Compile Include="Disk\DiskProviderBase.cs" />
<Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />

View File

@ -131,6 +131,54 @@ namespace NzbDrone.Core.Test.Download
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]
public void should_not_process_if_already_added_to_history_as_failed()
{

View File

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