2019-04-13 03:25:58 +00:00
|
|
|
using System;
|
2013-10-12 18:44:40 +00:00
|
|
|
using System.Collections.Generic;
|
2014-07-04 08:09:48 +00:00
|
|
|
using FluentValidation.Results;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2013-05-19 23:17:32 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Notifications
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
public abstract class NotificationBase<TSettings> : INotification
|
|
|
|
where TSettings : IProviderConfig, new()
|
2013-05-19 23:17:32 +00:00
|
|
|
{
|
2019-04-13 03:25:58 +00:00
|
|
|
protected const string MOVIE_GRABBED_TITLE = "Movie Grabbed";
|
|
|
|
protected const string MOVIE_DOWNLOADED_TITLE = "Movie Downloaded";
|
2019-11-04 20:44:33 +00:00
|
|
|
protected const string HEALTH_ISSUE_TITLE = "Health Check Failure";
|
2019-04-13 03:25:58 +00:00
|
|
|
|
|
|
|
protected const string MOVIE_GRABBED_TITLE_BRANDED = "Radarr - " + MOVIE_GRABBED_TITLE;
|
|
|
|
protected const string MOVIE_DOWNLOADED_TITLE_BRANDED = "Radarr - " + MOVIE_DOWNLOADED_TITLE;
|
2019-11-04 20:44:33 +00:00
|
|
|
protected const string HEALTH_ISSUE_TITLE_BRANDED = "Radarr - " + HEALTH_ISSUE_TITLE;
|
2019-04-13 03:25:58 +00:00
|
|
|
|
2015-04-25 16:02:17 +00:00
|
|
|
public abstract string Name { get; }
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public Type ConfigContract => typeof(TSettings);
|
2013-10-12 18:44:40 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public virtual ProviderMessage Message => null;
|
2015-06-28 21:06:03 +00:00
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public IEnumerable<ProviderDefinition> DefaultDefinitions => new List<ProviderDefinition>();
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2013-10-12 18:44:40 +00:00
|
|
|
public ProviderDefinition Definition { get; set; }
|
2014-07-04 08:09:48 +00:00
|
|
|
public abstract ValidationResult Test();
|
2013-10-12 18:44:40 +00:00
|
|
|
|
|
|
|
public abstract string Link { get; }
|
2013-05-19 23:17:32 +00:00
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public virtual void OnGrab(GrabMessage grabMessage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnDownload(DownloadMessage message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnMovieRename(Movie movie)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-04 20:44:33 +00:00
|
|
|
public virtual void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public bool SupportsOnGrab => HasConcreteImplementation("OnGrab");
|
|
|
|
public bool SupportsOnRename => HasConcreteImplementation("OnMovieRename");
|
|
|
|
public bool SupportsOnDownload => HasConcreteImplementation("OnDownload");
|
|
|
|
public bool SupportsOnUpgrade => SupportsOnDownload;
|
2019-11-04 20:44:33 +00:00
|
|
|
public bool SupportsOnHealthIssue => HasConcreteImplementation("OnHealthIssue");
|
2013-05-20 02:43:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
protected TSettings Settings => (TSettings)Definition.Settings;
|
2013-05-20 02:43:22 +00:00
|
|
|
|
2013-10-12 18:44:40 +00:00
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return GetType().Name;
|
2013-05-20 02:43:22 +00:00
|
|
|
}
|
2015-03-29 05:30:58 +00:00
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
public virtual object RequestAction(string action, IDictionary<string, string> query)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2019-04-13 03:25:58 +00:00
|
|
|
|
|
|
|
private bool HasConcreteImplementation(string methodName)
|
|
|
|
{
|
|
|
|
var method = GetType().GetMethod(methodName);
|
|
|
|
|
|
|
|
if (method == null)
|
|
|
|
{
|
|
|
|
throw new MissingMethodException(GetType().Name, Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return !method.DeclaringType.IsAbstract;
|
|
|
|
}
|
2013-05-19 23:17:32 +00:00
|
|
|
}
|
|
|
|
}
|