Display names for Notifications

This commit is contained in:
Mark McDowall 2015-04-25 09:02:17 -07:00
parent ecd941a6e5
commit 9a629c2fc6
29 changed files with 258 additions and 36 deletions

View File

@ -5,11 +5,11 @@ namespace NzbDrone.Api.Notifications
{ {
public class NotificationResource : ProviderResource public class NotificationResource : ProviderResource
{ {
public String Link { get; set; } public string Link { get; set; }
public Boolean OnGrab { get; set; } public bool OnGrab { get; set; }
public Boolean OnDownload { get; set; } public bool OnDownload { get; set; }
public Boolean OnUpgrade { get; set; } public bool OnUpgrade { get; set; }
public String TestCommand { get; set; } public string TestCommand { get; set; }
public HashSet<Int32> Tags { get; set; } public HashSet<int> Tags { get; set; }
} }
} }

View File

@ -55,9 +55,9 @@ namespace NzbDrone.Api
private List<TProviderResource> GetAll() private List<TProviderResource> GetAll()
{ {
var providerDefinitions = _providerFactory.All(); var providerDefinitions = _providerFactory.All().OrderBy(p => p.ImplementationName);
var result = new List<TProviderResource>(providerDefinitions.Count); var result = new List<TProviderResource>(providerDefinitions.Count());
foreach (var definition in providerDefinitions) foreach (var definition in providerDefinitions)
{ {
@ -124,7 +124,7 @@ namespace NzbDrone.Api
private Response GetTemplates() private Response GetTemplates()
{ {
var defaultDefinitions = _providerFactory.GetDefaultDefinitions().ToList(); var defaultDefinitions = _providerFactory.GetDefaultDefinitions().OrderBy(p => p.ImplementationName).ToList();
var result = new List<TProviderResource>(defaultDefinitions.Count()); var result = new List<TProviderResource>(defaultDefinitions.Count());

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
@ -7,11 +6,12 @@ namespace NzbDrone.Api
{ {
public class ProviderResource : RestResource public class ProviderResource : RestResource
{ {
public String Name { get; set; } public string Name { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
public String Implementation { get; set; } public string ImplementationName { get; set; }
public String ConfigContract { get; set; } public string Implementation { get; set; }
public String InfoLink { get; set; } public string ConfigContract { get; set; }
public string InfoLink { get; set; }
public List<ProviderResource> Presets { get; set; } public List<ProviderResource> Presets { get; set; }
} }

View File

@ -3,6 +3,7 @@ using System.Reflection;
using Marr.Data; using Marr.Data;
using Marr.Data.Mapping; using Marr.Data.Mapping;
using NzbDrone.Common.Reflection; using NzbDrone.Common.Reflection;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Datastore.Extensions namespace NzbDrone.Core.Datastore.Extensions
{ {
@ -16,7 +17,11 @@ namespace NzbDrone.Core.Datastore.Extensions
.AutoMapPropertiesWhere(IsMappableProperty); .AutoMapPropertiesWhere(IsMappableProperty);
} }
public static ColumnMapBuilder<T> RegisterDefinition<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder, string tableName = null) where T : ProviderDefinition, new()
{
return RegisterModel(mapBuilder, tableName).Ignore(c => c.ImplementationName);
}
public static ColumnMapBuilder<T> RegisterModel<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder, string tableName = null) where T : ModelBase, new() public static ColumnMapBuilder<T> RegisterModel<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder, string tableName = null) where T : ModelBase, new()
{ {
return mapBuilder.Table.MapTable(tableName) return mapBuilder.Table.MapTable(tableName)
@ -55,7 +60,5 @@ namespace NzbDrone.Core.Datastore.Extensions
return false; return false;
} }
} }
} }

View File

@ -45,18 +45,18 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<Config>().RegisterModel("Config"); Mapper.Entity<Config>().RegisterModel("Config");
Mapper.Entity<RootFolder>().RegisterModel("RootFolders").Ignore(r => r.FreeSpace); Mapper.Entity<RootFolder>().RegisterModel("RootFolders").Ignore(r => r.FreeSpace);
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks");
Mapper.Entity<IndexerDefinition>().RegisterModel("Indexers") Mapper.Entity<IndexerDefinition>().RegisterDefinition("Indexers")
.Ignore(i => i.Enable) .Ignore(i => i.Enable)
.Ignore(i => i.Protocol) .Ignore(i => i.Protocol)
.Ignore(i => i.SupportsRss) .Ignore(i => i.SupportsRss)
.Ignore(i => i.SupportsSearch); .Ignore(i => i.SupportsSearch);
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks"); Mapper.Entity<NotificationDefinition>().RegisterDefinition("Notifications");
Mapper.Entity<NotificationDefinition>().RegisterModel("Notifications"); Mapper.Entity<MetadataDefinition>().RegisterDefinition("Metadata");
Mapper.Entity<MetadataDefinition>().RegisterModel("Metadata");
Mapper.Entity<DownloadClientDefinition>().RegisterModel("DownloadClients") Mapper.Entity<DownloadClientDefinition>().RegisterDefinition("DownloadClients")
.Ignore(d => d.Protocol); .Ignore(d => d.Protocol);
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings"); Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");

View File

@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
@ -21,6 +20,14 @@ namespace NzbDrone.Core.Download
protected readonly IRemotePathMappingService _remotePathMappingService; protected readonly IRemotePathMappingService _remotePathMappingService;
protected readonly Logger _logger; protected readonly Logger _logger;
public string Name
{
get
{
return GetType().Name;
}
}
public Type ConfigContract public Type ConfigContract
{ {
get get

View File

@ -19,6 +19,14 @@ namespace NzbDrone.Core.Indexers
protected readonly IParsingService _parsingService; protected readonly IParsingService _parsingService;
protected readonly Logger _logger; protected readonly Logger _logger;
public string Name
{
get
{
return GetType().Name;
}
}
public abstract DownloadProtocol Protocol { get; } public abstract DownloadProtocol Protocol { get; }
public abstract Boolean SupportsRss { get; } public abstract Boolean SupportsRss { get; }

View File

@ -10,6 +10,14 @@ namespace NzbDrone.Core.Metadata
{ {
public abstract class MetadataBase<TSettings> : IMetadata where TSettings : IProviderConfig, new() public abstract class MetadataBase<TSettings> : IMetadata where TSettings : IProviderConfig, new()
{ {
public string Name
{
get
{
return GetType().Name;
}
}
public Type ConfigContract public Type ConfigContract
{ {
get get

View File

@ -40,6 +40,14 @@ namespace NzbDrone.Core.Notifications.Email
{ {
} }
public override string Name
{
get
{
return "Email";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -37,6 +37,14 @@ namespace NzbDrone.Core.Notifications.Growl
{ {
} }
public override string Name
{
get
{
return "Growl";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -53,6 +53,14 @@ namespace NzbDrone.Core.Notifications.MediaBrowser
} }
} }
public override string Name
{
get
{
return "Emby (Media Browser)";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -8,6 +8,8 @@ namespace NzbDrone.Core.Notifications
{ {
public abstract class NotificationBase<TSettings> : INotification where TSettings : IProviderConfig, new() public abstract class NotificationBase<TSettings> : INotification where TSettings : IProviderConfig, new()
{ {
public abstract string Name { get; }
public Type ConfigContract public Type ConfigContract
{ {
get get

View File

@ -38,6 +38,14 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{ {
} }
public override string Name
{
get
{
return "Notify My Android";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -35,6 +35,14 @@ namespace NzbDrone.Core.Notifications.Plex
{ {
} }
public override string Name
{
get
{
return "Plex Media Center";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications.Plex
{
public class PlexHomeTheater : NotificationBase<PlexHomeTheaterSettings>
{
private readonly IXbmcService _xbmcService;
private readonly Logger _logger;
public PlexHomeTheater(IXbmcService xbmcService, Logger logger)
{
_xbmcService = xbmcService;
_logger = logger;
}
public override string Link
{
get { return "https://plex.tv/"; }
}
public override void OnGrab(string message)
{
const string header = "Sonarr - Grabbed";
Notify(Settings, header, message);
}
public override void OnDownload(DownloadMessage message)
{
const string header = "Sonarr - Downloaded";
Notify(Settings, header, message.Message);
}
public override void AfterRename(Series series)
{
}
public override string Name
{
get
{
return "Plex Home Theater";
}
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_xbmcService.Test(Settings, "Success! PHT has been successfully configured!"));
return new ValidationResult(failures);
}
private void Notify(XbmcSettings settings, string header, string message)
{
try
{
if (Settings.Notify)
{
_xbmcService.Notify(Settings, header, message);
}
}
catch (SocketException ex)
{
var logMessage = String.Format("Unable to connect to PHT Host: {0}:{1}", Settings.Host, Settings.Port);
_logger.DebugException(logMessage, ex);
}
}
}
}

View File

@ -0,0 +1,13 @@
using NzbDrone.Core.Notifications.Xbmc;
namespace NzbDrone.Core.Notifications.Plex
{
public class PlexHomeTheaterSettings : XbmcSettings
{
public PlexHomeTheaterSettings()
{
DisplayTime = 5;
Port = 3005;
}
}
}

View File

@ -41,6 +41,14 @@ namespace NzbDrone.Core.Notifications.Plex
} }
} }
public override string Name
{
get
{
return "Plex Media Server";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -38,6 +38,14 @@ namespace NzbDrone.Core.Notifications.Prowl
{ {
} }
public override string Name
{
get
{
return "Prowl";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -37,6 +37,14 @@ namespace NzbDrone.Core.Notifications.PushBullet
{ {
} }
public override string Name
{
get
{
return "Pushbullet";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -38,6 +38,14 @@ namespace NzbDrone.Core.Notifications.Pushalot
{ {
} }
public override string Name
{
get
{
return "Pushalot";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -37,6 +37,14 @@ namespace NzbDrone.Core.Notifications.Pushover
{ {
} }
public override string Name
{
get
{
return "Pushover";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -53,6 +53,14 @@ namespace NzbDrone.Core.Notifications.Synology
} }
} }
public override string Name
{
get
{
return "Synology Indexer";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

View File

@ -45,11 +45,19 @@ namespace NzbDrone.Core.Notifications.Xbmc
UpdateAndClean(series); UpdateAndClean(series);
} }
public override string Name
{
get
{
return "Kodi (XBMC)";
}
}
public override ValidationResult Test() public override ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_xbmcService.Test(Settings)); failures.AddIfNotNull(_xbmcService.Test(Settings, "Success! XBMC has been successfully configured!"));
return new ValidationResult(failures); return new ValidationResult(failures);
} }

View File

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
void Notify(XbmcSettings settings, string title, string message); void Notify(XbmcSettings settings, string title, string message);
void Update(XbmcSettings settings, Series series); void Update(XbmcSettings settings, Series series);
void Clean(XbmcSettings settings); void Clean(XbmcSettings settings);
ValidationFailure Test(XbmcSettings settings); ValidationFailure Test(XbmcSettings settings, string message);
} }
public class XbmcService : IXbmcService public class XbmcService : IXbmcService
@ -101,13 +101,13 @@ namespace NzbDrone.Core.Notifications.Xbmc
return apiProvider; return apiProvider;
} }
public ValidationFailure Test(XbmcSettings settings) public ValidationFailure Test(XbmcSettings settings, string message)
{ {
_xbmcVersionCache.Clear(); _xbmcVersionCache.Clear();
try try
{ {
_logger.Debug("Determining version of XBMC Host: {0}", settings.Address); _logger.Debug("Determining version of Host: {0}", settings.Address);
var version = GetJsonVersion(settings); var version = GetJsonVersion(settings);
_logger.Debug("Version is: {0}", version); _logger.Debug("Version is: {0}", version);
@ -116,7 +116,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
throw new InvalidXbmcVersionException("Version received from XBMC is invalid, please correct your settings."); throw new InvalidXbmcVersionException("Version received from XBMC is invalid, please correct your settings.");
} }
Notify(settings, "Test Notification", "Success! XBMC has been successfully configured!"); Notify(settings, "Test Notification", message);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -665,6 +665,8 @@
<Compile Include="Metadata\MetadataType.cs" /> <Compile Include="Metadata\MetadataType.cs" />
<Compile Include="MetadataSource\IProvideSeriesInfo.cs" /> <Compile Include="MetadataSource\IProvideSeriesInfo.cs" />
<Compile Include="MetadataSource\ISearchForNewSeries.cs" /> <Compile Include="MetadataSource\ISearchForNewSeries.cs" />
<Compile Include="Notifications\Plex\PlexHomeTheater.cs" />
<Compile Include="Notifications\Plex\PlexHomeTheaterSettings.cs" />
<Compile Include="Notifications\Synology\SynologyException.cs" /> <Compile Include="Notifications\Synology\SynologyException.cs" />
<Compile Include="Notifications\Synology\SynologyIndexer.cs" /> <Compile Include="Notifications\Synology\SynologyIndexer.cs" />
<Compile Include="Notifications\Synology\SynologyIndexerProxy.cs" /> <Compile Include="Notifications\Synology\SynologyIndexerProxy.cs" />

View File

@ -6,6 +6,7 @@ namespace NzbDrone.Core.ThingiProvider
{ {
public interface IProvider public interface IProvider
{ {
string Name { get; }
Type ConfigContract { get; } Type ConfigContract { get; }
IEnumerable<ProviderDefinition> DefaultDefinitions { get; } IEnumerable<ProviderDefinition> DefaultDefinitions { get; }

View File

@ -1,5 +1,4 @@
using System; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.ThingiProvider namespace NzbDrone.Core.ThingiProvider
{ {
@ -7,10 +6,11 @@ namespace NzbDrone.Core.ThingiProvider
{ {
private IProviderConfig _settings; private IProviderConfig _settings;
public String Name { get; set; } public string Name { get; set; }
public String Implementation { get; set; } public string ImplementationName { get; set; }
public String ConfigContract { get; set; } public string Implementation { get; set; }
public virtual Boolean Enable { get; set; } public string ConfigContract { get; set; }
public virtual bool Enable { get; set; }
public IProviderConfig Settings public IProviderConfig Settings
{ {

View File

@ -140,6 +140,8 @@ namespace NzbDrone.Core.ThingiProvider
public virtual TProviderDefinition GetProviderCharacteristics(TProvider provider, TProviderDefinition definition) public virtual TProviderDefinition GetProviderCharacteristics(TProvider provider, TProviderDefinition definition)
{ {
definition.ImplementationName = provider.Name;
return definition; return definition;
} }

View File

@ -1,6 +1,6 @@
<div class="add-thingy"> <div class="add-thingy">
<div> <div>
{{implementation}} {{implementationName}}
</div> </div>
<div class="pull-right"> <div class="pull-right">
{{#if_gt presets.length compare=0}} {{#if_gt presets.length compare=0}}