New: Make VIP Check Generic

pull/420/head
Qstick 3 years ago
parent c72222a696
commit 03f821f484

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Localization; using NzbDrone.Core.Localization;
using NzbDrone.Core.ThingiProvider.Events; using NzbDrone.Core.ThingiProvider.Events;
@ -12,11 +11,11 @@ namespace NzbDrone.Core.HealthCheck.Checks
[CheckOn(typeof(ProviderAddedEvent<IIndexer>))] [CheckOn(typeof(ProviderAddedEvent<IIndexer>))]
[CheckOn(typeof(ProviderUpdatedEvent<IIndexer>))] [CheckOn(typeof(ProviderUpdatedEvent<IIndexer>))]
[CheckOn(typeof(ProviderDeletedEvent<IIndexer>))] [CheckOn(typeof(ProviderDeletedEvent<IIndexer>))]
public class NewznabVIPCheck : HealthCheckBase public class IndexerVIPCheck : HealthCheckBase
{ {
private readonly IIndexerFactory _indexerFactory; private readonly IIndexerFactory _indexerFactory;
public NewznabVIPCheck(IIndexerFactory indexerFactory, ILocalizationService localizationService) public IndexerVIPCheck(IIndexerFactory indexerFactory, ILocalizationService localizationService)
: base(localizationService) : base(localizationService)
{ {
_indexerFactory = indexerFactory; _indexerFactory = indexerFactory;
@ -25,13 +24,20 @@ namespace NzbDrone.Core.HealthCheck.Checks
public override HealthCheck Check() public override HealthCheck Check()
{ {
var enabled = _indexerFactory.Enabled(false); var enabled = _indexerFactory.Enabled(false);
var newznabProviders = enabled.Where(i => i.Definition.Implementation == typeof(Newznab).Name);
var expiringProviders = new List<IIndexer>(); var expiringProviders = new List<IIndexer>();
var expiredProviders = new List<IIndexer>(); var expiredProviders = new List<IIndexer>();
foreach (var provider in newznabProviders) foreach (var provider in enabled)
{ {
var expiration = ((NewznabSettings)provider.Definition.Settings).VipExpiration; var settingsType = provider.Definition.Settings.GetType();
var vipProp = settingsType.GetProperty("VipExpiration");
if (vipProp == null)
{
continue;
}
var expiration = (string)vipProp.GetValue(provider.Definition.Settings);
if (expiration.IsNullOrWhiteSpace()) if (expiration.IsNullOrWhiteSpace())
{ {
@ -53,18 +59,18 @@ namespace NzbDrone.Core.HealthCheck.Checks
{ {
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("NewznabVipCheckExpiringClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiringClientMessage"),
string.Join(", ", expiringProviders.Select(v => v.Definition.Name))), string.Join(", ", expiringProviders.Select(v => v.Definition.Name))),
"#newznab-vip-expiring"); "#indexer-vip-expiring");
} }
if (!expiredProviders.Empty()) if (!expiredProviders.Empty())
{ {
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("NewznabVipCheckExpiredClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"),
string.Join(", ", expiredProviders.Select(v => v.Definition.Name))), string.Join(", ", expiredProviders.Select(v => v.Definition.Name))),
"#newznab-vip-expired"); "#indexer-vip-expired");
} }
return new HealthCheck(GetType()); return new HealthCheck(GetType());

@ -239,8 +239,8 @@
"Name": "Name", "Name": "Name",
"NetCore": ".NET", "NetCore": ".NET",
"New": "New", "New": "New",
"NewznabVipCheckExpiredClientMessage": "Indexer VIP benefits have expired: {0}", "IndexerVipCheckExpiredClientMessage": "Indexer VIP benefits have expired: {0}",
"NewznabVipCheckExpiringClientMessage": "Indexer VIP benefits expiring soon: {0}", "IndexerVipCheckExpiringClientMessage": "Indexer VIP benefits expiring soon: {0}",
"NoBackupsAreAvailable": "No backups are available", "NoBackupsAreAvailable": "No backups are available",
"NoChange": "No Change", "NoChange": "No Change",
"NoChanges": "No Changes", "NoChanges": "No Changes",

Loading…
Cancel
Save