1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

Cleaned up Notifications a bit

This commit is contained in:
Mark McDowall 2013-05-19 19:43:22 -07:00
parent 922d4becc5
commit a153599d50
14 changed files with 23 additions and 62 deletions

View File

@ -24,6 +24,8 @@ public CommandModule(IMessageAggregator messageAggregator, IContainer container)
private CommandResource RunCommand(CommandResource resource) private CommandResource RunCommand(CommandResource resource)
{ {
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(new RemoteEpisode()));
var commandType = var commandType =
_container.GetImplementations(typeof(ICommand)) _container.GetImplementations(typeof(ICommand))
.Single(c => c.Name.Replace("Command", "") .Single(c => c.Name.Replace("Command", "")

View File

@ -5,7 +5,7 @@
namespace NzbDrone.Core.Notifications.Growl namespace NzbDrone.Core.Notifications.Growl
{ {
public class Growl : NotificationWithSetting<GrowlSettings> public class Growl : NotificationBase<GrowlSettings>
{ {
private readonly GrowlProvider _growlProvider; private readonly GrowlProvider _growlProvider;

View File

@ -9,22 +9,4 @@ public interface INotifcationSettings
{ {
bool IsValid { get; } bool IsValid { get; }
} }
public class NullSetting : INotifcationSettings
{
public static NullSetting Instance = new NullSetting();
private NullSetting()
{
}
public bool IsValid
{
get
{
return true;
}
}
}
} }

View File

@ -1,10 +1,11 @@
using System; using System;
using NLog; using NLog;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications namespace NzbDrone.Core.Notifications
{ {
public abstract class NotificationBase : INotification public abstract class NotificationBase<TSetting> : INotification where TSetting : class, INotifcationSettings, new()
{ {
public abstract string Name { get; } public abstract string Name { get; }
@ -13,5 +14,14 @@ public abstract class NotificationBase : INotification
public abstract void OnGrab(string message); public abstract void OnGrab(string message);
public abstract void OnDownload(string message, Series series); public abstract void OnDownload(string message, Series series);
public abstract void AfterRename(Series series); public abstract void AfterRename(Series series);
public TSetting Settings { get; private set; }
public TSetting ImportSettingsFromJson(string json)
{
Settings = Json.Deserialize<TSetting>(json) ?? new TSetting();
return Settings;
}
} }
} }

View File

@ -39,6 +39,7 @@ public NotificationService(INotificationRepository notificationRepository,
public List<Notification> All() public List<Notification> All()
{ {
var test = _notificationRepository.All();//.Select(ToNotification).ToList();
return _notificationRepository.All().Select(ToNotification).ToList(); return _notificationRepository.All().Select(ToNotification).ToList();
} }
@ -50,15 +51,7 @@ private Notification ToNotification(NotificationDefinition definition)
notification.OnDownload = definition.OnDownload; notification.OnDownload = definition.OnDownload;
notification.Instance = GetInstance(definition); notification.Instance = GetInstance(definition);
notification.Name = definition.Name; notification.Name = definition.Name;
if (notification.Instance.GetType().GetMethod("ImportSettingsFromJson") != null)
{
notification.Settings = ((dynamic)notification.Instance).ImportSettingsFromJson(definition.Settings); notification.Settings = ((dynamic)notification.Instance).ImportSettingsFromJson(definition.Settings);
}
else
{
notification.Settings = NullSetting.Instance;
}
return notification; return notification;
} }

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Notifications
{
public abstract class NotificationWithSetting<TSetting> : NotificationBase where TSetting : class, INotifcationSettings, new()
{
public TSetting Settings { get; private set; }
public TSetting ImportSettingsFromJson(string json)
{
Settings = Json.Deserialize<TSetting>(json) ?? new TSetting();
return Settings;
}
}
}

View File

@ -4,7 +4,7 @@
namespace NzbDrone.Core.Notifications.Plex namespace NzbDrone.Core.Notifications.Plex
{ {
public class PlexClient : NotificationWithSetting<PlexClientSettings> public class PlexClient : NotificationBase<PlexClientSettings>
{ {
private readonly PlexProvider _plexProvider; private readonly PlexProvider _plexProvider;

View File

@ -4,7 +4,7 @@
namespace NzbDrone.Core.Notifications.Plex namespace NzbDrone.Core.Notifications.Plex
{ {
public class PlexServer : NotificationWithSetting<PlexServerSettings> public class PlexServer : NotificationBase<PlexServerSettings>
{ {
private readonly PlexProvider _plexProvider; private readonly PlexProvider _plexProvider;

View File

@ -3,7 +3,7 @@
namespace NzbDrone.Core.Notifications.Prowl namespace NzbDrone.Core.Notifications.Prowl
{ {
public class Prowl : NotificationWithSetting<ProwlSettings> public class Prowl : NotificationBase<ProwlSettings>
{ {
private readonly ProwlProvider _prowlProvider; private readonly ProwlProvider _prowlProvider;

View File

@ -12,13 +12,13 @@ public class ProwlSettings : INotifcationSettings
public String ApiKey { get; set; } public String ApiKey { get; set; }
[FieldDefinition(1, Label = "Priority", HelpText = "Priority to send messages at")] [FieldDefinition(1, Label = "Priority", HelpText = "Priority to send messages at")]
public Int32 Priority { get; set; } public Nullable<Int32> Priority { get; set; }
public bool IsValid public bool IsValid
{ {
get get
{ {
return !string.IsNullOrWhiteSpace(ApiKey) && Priority > 0; return !string.IsNullOrWhiteSpace(ApiKey) && Priority != null & Priority >= -2 && Priority <= 2;
} }
} }
} }

View File

@ -5,7 +5,7 @@
namespace NzbDrone.Core.Notifications.Smtp namespace NzbDrone.Core.Notifications.Smtp
{ {
public class Smtp : NotificationWithSetting<SmtpSettings> public class Smtp : NotificationBase<SmtpSettings>
{ {
private readonly SmtpProvider _smtpProvider; private readonly SmtpProvider _smtpProvider;

View File

@ -3,7 +3,7 @@
namespace NzbDrone.Core.Notifications.Xbmc namespace NzbDrone.Core.Notifications.Xbmc
{ {
public class Xbmc : NotificationWithSetting<XbmcSettings> public class Xbmc : NotificationBase<XbmcSettings>
{ {
private readonly XbmcProvider _xbmcProvider; private readonly XbmcProvider _xbmcProvider;

View File

@ -313,7 +313,6 @@
<Compile Include="MetadataSource\Trakt\Season.cs" /> <Compile Include="MetadataSource\Trakt\Season.cs" />
<Compile Include="MetadataSource\Trakt\Show.cs" /> <Compile Include="MetadataSource\Trakt\Show.cs" />
<Compile Include="Notifications\INotifcationSettings.cs" /> <Compile Include="Notifications\INotifcationSettings.cs" />
<Compile Include="Notifications\NotificationWithSetting.cs" />
<Compile Include="Notifications\Plex\PlexServer.cs" /> <Compile Include="Notifications\Plex\PlexServer.cs" />
<Compile Include="Notifications\Plex\PlexClientSettings.cs" /> <Compile Include="Notifications\Plex\PlexClientSettings.cs" />
<Compile Include="Notifications\Plex\PlexServerSettings.cs" /> <Compile Include="Notifications\Plex\PlexServerSettings.cs" />

View File

@ -8,7 +8,6 @@
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Notifications;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
@ -27,7 +26,6 @@ public static IContainer BuildContainer()
private MainAppContainerBuilder() private MainAppContainerBuilder()
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api") : base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
{ {
AutoRegisterImplementations<NotificationBase>();
AutoRegisterImplementations<NzbDronePersistentConnection>(); AutoRegisterImplementations<NzbDronePersistentConnection>();
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)); Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>));
@ -36,9 +34,6 @@ private MainAppContainerBuilder()
Container.Register<INancyBootstrapper, NancyBootstrapper>(); Container.Register<INancyBootstrapper, NancyBootstrapper>();
InitDatabase(); InitDatabase();
} }
private void InitDatabase() private void InitDatabase()