Cleaned up Notifications a bit

pull/6/head
Mark McDowall 12 years ago
parent 922d4becc5
commit a153599d50

@ -24,6 +24,8 @@ namespace NzbDrone.Api.Commands
private CommandResource RunCommand(CommandResource resource)
{
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(new RemoteEpisode()));
var commandType =
_container.GetImplementations(typeof(ICommand))
.Single(c => c.Name.Replace("Command", "")

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

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

@ -1,10 +1,11 @@
using System;
using NLog;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Tv;
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; }
@ -13,5 +14,14 @@ namespace NzbDrone.Core.Notifications
public abstract void OnGrab(string message);
public abstract void OnDownload(string message, 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;
}
}
}

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

@ -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;
}
}
}

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

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

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

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

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

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

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

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

Loading…
Cancel
Save