mirror of https://github.com/Sonarr/Sonarr
Cleaned up progress notification.
This commit is contained in:
parent
6e9a6313ff
commit
0a70c836df
|
@ -84,6 +84,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
||||
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
||||
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchProviderTests\PerformSearchFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchProviderTests\ProcessSearchResultsFixture.cs" />
|
||||
<Compile Include="ProviderTests\NewznabProviderTest.cs" />
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.NotificationProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationProviderFixture
|
||||
{
|
||||
NotificationProvider _notificationProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_notificationProvider = new NotificationProvider();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void current_notification_should_return_null_at_start()
|
||||
{
|
||||
_notificationProvider.GetCurrent().Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_current_on_active_notifications()
|
||||
{
|
||||
var fakeNotification = new ProgressNotification("Title");
|
||||
_notificationProvider.Register(fakeNotification);
|
||||
|
||||
_notificationProvider.GetCurrent().Should().Be(fakeNotification);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_last_if_recently_completed()
|
||||
{
|
||||
var fakeNotification = new ProgressNotification("Title");
|
||||
_notificationProvider.Register(fakeNotification);
|
||||
fakeNotification.Dispose();
|
||||
|
||||
_notificationProvider.GetCurrent().Should().Be(fakeNotification);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_if_completed_long_time_ago()
|
||||
{
|
||||
var fakeNotification = new ProgressNotification("Title");
|
||||
_notificationProvider.Register(fakeNotification);
|
||||
fakeNotification.Dispose();
|
||||
|
||||
Thread.Sleep(4000);
|
||||
|
||||
_notificationProvider.GetCurrent().Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void new_notification_should_replace_old_one()
|
||||
{
|
||||
var oldNotification = new ProgressNotification("Title");
|
||||
_notificationProvider.Register(oldNotification);
|
||||
|
||||
var newNotification = new ProgressNotification("Title");
|
||||
_notificationProvider.Register(newNotification);
|
||||
|
||||
_notificationProvider.GetCurrent().Should().Be(newNotification);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ namespace NzbDrone.Core.Model.Notification
|
|||
/// <summary>
|
||||
/// Gets the completed time.
|
||||
/// </summary>
|
||||
public DateTime CompletedTime { get; private set; }
|
||||
public Nullable<DateTime> CompletedTime { get; private set; }
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
|
|
|
@ -7,42 +7,21 @@ namespace NzbDrone.Core.Providers
|
|||
{
|
||||
public class NotificationProvider
|
||||
{
|
||||
private static ProgressNotification _currentNotification;
|
||||
|
||||
private static readonly Object _lock = new object();
|
||||
|
||||
private static readonly Dictionary<Guid, ProgressNotification> _progressNotification =
|
||||
new Dictionary<Guid, ProgressNotification>();
|
||||
|
||||
public virtual List<ProgressNotification> ProgressNotifications
|
||||
public virtual ProgressNotification GetCurrent()
|
||||
{
|
||||
get
|
||||
if (_currentNotification == null || _currentNotification.CompletedTime < DateTime.Now.AddSeconds(-3))
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var activeNotification =
|
||||
_progressNotification.Values.Where(p => p.Status == ProgressNotificationStatus.InProgress).
|
||||
ToList();
|
||||
|
||||
if (activeNotification.Count == 0)
|
||||
{
|
||||
//Get notifications that were recently done
|
||||
activeNotification =
|
||||
_progressNotification.Values.Where(p => p.CompletedTime >= DateTime.Now.AddSeconds(-3)).
|
||||
OrderByDescending(c => c.CompletedTime).ToList();
|
||||
|
||||
}
|
||||
|
||||
return activeNotification.ToList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return _currentNotification;
|
||||
}
|
||||
|
||||
public virtual void Register(ProgressNotification notification)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_progressNotification.Add(notification.Id, notification);
|
||||
}
|
||||
_currentNotification = notification;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,13 +9,14 @@ namespace NzbDrone.Web.Controllers
|
|||
{
|
||||
public class NotificationController : Controller
|
||||
{
|
||||
private readonly NotificationProvider _notifications;
|
||||
private readonly NotificationProvider _notificationProvider;
|
||||
|
||||
//
|
||||
// GET: /Notification/
|
||||
|
||||
public NotificationController(NotificationProvider notificationProvider)
|
||||
{
|
||||
_notifications = notificationProvider;
|
||||
_notificationProvider = notificationProvider;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
@ -36,11 +37,10 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
private string GetCurrentMessage()
|
||||
{
|
||||
var notes = _notifications.ProgressNotifications;
|
||||
|
||||
if (_notifications.ProgressNotifications.Count > 0)
|
||||
return _notifications.ProgressNotifications[0].CurrentMessage;
|
||||
var notification = _notificationProvider.GetCurrent();
|
||||
|
||||
if (notification != null)
|
||||
return notification.CurrentMessage;
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue