can now read/write provider config to db.
This commit is contained in:
parent
08e2d60f20
commit
4046d35604
|
@ -1,23 +1,31 @@
|
|||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Test.Datastore;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.Notifications.Email;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Test.ThingiProvider
|
||||
{
|
||||
|
||||
public class ProviderRepositoryFixture : DbTest<DownloadProviderRepository, DownloadProviderModel>
|
||||
public class ProviderRepositoryFixture : DbTest<NotificationProviderRepository, NotificationProviderModel>
|
||||
{
|
||||
[Test]
|
||||
public void should_read_write_download_provider()
|
||||
{
|
||||
var model = new DownloadProviderModel();
|
||||
var model = Builder<NotificationProviderModel>.CreateNew().BuildNew();
|
||||
var emailSettings = Builder<EmailSettings>.CreateNew().Build();
|
||||
model.Settings = emailSettings;
|
||||
Subject.Insert(model);
|
||||
|
||||
model.Config = new DownloadProviderConfig();
|
||||
var storedProvider = Subject.Single();
|
||||
|
||||
storedProvider.Settings.Should().BeOfType<EmailSettings>();
|
||||
|
||||
//Subject.Insert(new )
|
||||
var storedSetting = (EmailSettings) storedProvider.Settings;
|
||||
|
||||
storedSetting.ShouldHave().AllProperties().EqualTo(emailSettings);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Marr.Data.Converters;
|
||||
using Marr.Data.Mapping;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
|
@ -26,7 +28,8 @@ namespace NzbDrone.Core.Datastore.Converters
|
|||
|
||||
var implementation = context.DataRecord.GetString(ordinal);
|
||||
|
||||
var impType = Type.GetType(implementation, true, true);
|
||||
|
||||
var impType = typeof(IProviderConfig).Assembly.GetTypes().Single(c => c.Name == implementation);
|
||||
|
||||
return Json.Deserialize(stringValue, impType);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(22)]
|
||||
public class move_notification_to_generic_provider : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("Notifications").AddColumn("ConfigContract").AsString().Nullable();
|
||||
|
||||
//Execute.WithConnection(ConvertSeasons);
|
||||
}
|
||||
|
||||
private void ConvertSeasons(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
using (IDbCommand allSeriesCmd = conn.CreateCommand())
|
||||
{
|
||||
allSeriesCmd.Transaction = tran;
|
||||
allSeriesCmd.CommandText = @"SELECT Id FROM Series";
|
||||
using (IDataReader allSeriesReader = allSeriesCmd.ExecuteReader())
|
||||
{
|
||||
while (allSeriesReader.Read())
|
||||
{
|
||||
int seriesId = allSeriesReader.GetInt32(0);
|
||||
var seasons = new List<dynamic>();
|
||||
|
||||
using (IDbCommand seasonsCmd = conn.CreateCommand())
|
||||
{
|
||||
seasonsCmd.Transaction = tran;
|
||||
seasonsCmd.CommandText = String.Format(@"SELECT SeasonNumber, Monitored FROM Seasons WHERE SeriesId = {0}", seriesId);
|
||||
|
||||
using (IDataReader seasonReader = seasonsCmd.ExecuteReader())
|
||||
{
|
||||
while (seasonReader.Read())
|
||||
{
|
||||
int seasonNumber = seasonReader.GetInt32(0);
|
||||
bool monitored = seasonReader.GetBoolean(1);
|
||||
|
||||
if (seasonNumber == 0)
|
||||
{
|
||||
monitored = false;
|
||||
}
|
||||
|
||||
seasons.Add(new { seasonNumber, monitored });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (IDbCommand updateCmd = conn.CreateCommand())
|
||||
{
|
||||
var text = String.Format("UPDATE Series SET Seasons = '{0}' WHERE Id = {1}", seasons.ToJson() , seriesId);
|
||||
|
||||
updateCmd.Transaction = tran;
|
||||
updateCmd.CommandText = text;
|
||||
updateCmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Marr.Data;
|
||||
using Marr.Data.Mapping;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DataAugmentation.Scene;
|
||||
using NzbDrone.Core.Datastore.Converters;
|
||||
|
@ -15,6 +16,7 @@ using NzbDrone.Core.Organizer;
|
|||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.SeriesStats;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
|
@ -34,6 +36,7 @@ namespace NzbDrone.Core.Datastore
|
|||
Mapper.Entity<IndexerDefinition>().RegisterModel("Indexers");
|
||||
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks");
|
||||
Mapper.Entity<NotificationDefinition>().RegisterModel("Notifications");
|
||||
Mapper.Entity<NotificationProviderModel>().RegisterModel("Notifications");
|
||||
|
||||
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");
|
||||
|
||||
|
@ -69,6 +72,7 @@ namespace NzbDrone.Core.Datastore
|
|||
private static void RegisterMappers()
|
||||
{
|
||||
RegisterEmbeddedConverter();
|
||||
RegisterProviderSettingConverter();
|
||||
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(Int32), new Int32Converter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(DateTime), new UtcConverter());
|
||||
|
@ -78,10 +82,20 @@ namespace NzbDrone.Core.Datastore
|
|||
MapRepository.Instance.RegisterTypeConverter(typeof(Dictionary<string, string>), new EmbeddedDocumentConverter());
|
||||
}
|
||||
|
||||
private static void RegisterProviderSettingConverter()
|
||||
{
|
||||
var settingTypes = typeof(IProviderConfig).Assembly.ImplementationsOf<IProviderConfig>();
|
||||
|
||||
var providerSettingConverter = new ProviderSettingConverter();
|
||||
foreach (var embeddedType in settingTypes)
|
||||
{
|
||||
MapRepository.Instance.RegisterTypeConverter(embeddedType, providerSettingConverter);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterEmbeddedConverter()
|
||||
{
|
||||
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.GetTypes()
|
||||
.Where(c => c.GetInterfaces().Any(i => i == typeof(IEmbeddedDocument)));
|
||||
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.ImplementationsOf<IEmbeddedDocument>();
|
||||
|
||||
|
||||
var embeddedConvertor = new EmbeddedDocumentConverter();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Email
|
||||
{
|
||||
public class EmailSettings : INotifcationSettings
|
||||
public class EmailSettings : IProviderConfig
|
||||
{
|
||||
public EmailSettings()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Growl
|
||||
{
|
||||
public class GrowlSettings : INotifcationSettings
|
||||
public class GrowlSettings : IProviderConfig
|
||||
{
|
||||
public GrowlSettings()
|
||||
{
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
public interface INotifcationSettings
|
||||
{
|
||||
bool IsValid { get; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
namespace NzbDrone.Core.Notifications
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
public class Notification
|
||||
{
|
||||
|
@ -8,7 +10,7 @@
|
|||
public string Link { get; set; }
|
||||
public bool OnGrab { get; set; }
|
||||
public bool OnDownload { get; set; }
|
||||
public INotifcationSettings Settings { get; set; }
|
||||
public IProviderConfig Settings { get; set; }
|
||||
public INotification Instance { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
public abstract class NotificationBase<TSetting> : INotification where TSetting : class, INotifcationSettings, new()
|
||||
public abstract class NotificationBase<TSetting> : INotification where TSetting : class, IProviderConfig, new()
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
public abstract string ImplementationName { get; }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
|
@ -11,4 +12,11 @@ namespace NzbDrone.Core.Notifications
|
|||
public String Settings { get; set; }
|
||||
public String Implementation { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class NotificationProviderModel : Provider
|
||||
{
|
||||
public Boolean OnGrab { get; set; }
|
||||
public Boolean OnDownload { get; set; }
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ using NzbDrone.Common.Serializer;
|
|||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Tv;
|
||||
using Omu.ValueInjecter;
|
||||
|
||||
|
@ -71,7 +72,7 @@ namespace NzbDrone.Core.Notifications
|
|||
|
||||
var instanceType = newNotification.Instance.GetType();
|
||||
var baseGenArgs = instanceType.BaseType.GetGenericArguments();
|
||||
newNotification.Settings = (INotifcationSettings)Activator.CreateInstance(baseGenArgs[0]);
|
||||
newNotification.Settings = (IProviderConfig)Activator.CreateInstance(baseGenArgs[0]);
|
||||
newNotification.Implementation = type.Name;
|
||||
|
||||
notifications.Add(newNotification);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
public interface INotificationSettingsProvider
|
||||
{
|
||||
TSetting Get<TSetting>(INotification indexer) where TSetting : INotifcationSettings, new();
|
||||
TSetting Get<TSetting>(INotification indexer) where TSetting : IProviderConfig, new();
|
||||
}
|
||||
|
||||
public class NotificationSettingsProvider : INotificationSettingsProvider
|
||||
|
@ -16,7 +17,7 @@ namespace NzbDrone.Core.Notifications
|
|||
_notificationRepository = notificationRepository;
|
||||
}
|
||||
|
||||
public TSetting Get<TSetting>(INotification indexer) where TSetting : INotifcationSettings, new()
|
||||
public TSetting Get<TSetting>(INotification indexer) where TSetting : IProviderConfig, new()
|
||||
{
|
||||
var indexerDef = _notificationRepository.Find(indexer.Name);
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.NotifyMyAndroid
|
||||
{
|
||||
public class NotifyMyAndroidSettings : INotifcationSettings
|
||||
public class NotifyMyAndroidSettings : IProviderConfig
|
||||
{
|
||||
[FieldDefinition(0, Label = "API Key", HelpLink = "http://www.notifymyandroid.com/")]
|
||||
public String ApiKey { get; set; }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Plex
|
||||
{
|
||||
public class PlexClientSettings : INotifcationSettings
|
||||
public class PlexClientSettings : IProviderConfig
|
||||
{
|
||||
public PlexClientSettings()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Plex
|
||||
{
|
||||
public class PlexServerSettings : INotifcationSettings
|
||||
public class PlexServerSettings : IProviderConfig
|
||||
{
|
||||
public PlexServerSettings()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Prowl
|
||||
{
|
||||
public class ProwlSettings : INotifcationSettings
|
||||
public class ProwlSettings : IProviderConfig
|
||||
{
|
||||
[FieldDefinition(0, Label = "API Key", HelpLink = "https://www.prowlapp.com/api_settings.php")]
|
||||
public String ApiKey { get; set; }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.PushBullet
|
||||
{
|
||||
public class PushBulletSettings : INotifcationSettings
|
||||
public class PushBulletSettings : IProviderConfig
|
||||
{
|
||||
[FieldDefinition(0, Label = "API Key", HelpLink = "https://www.pushbullet.com/")]
|
||||
public String ApiKey { get; set; }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Pushover
|
||||
{
|
||||
public class PushoverSettings : INotifcationSettings
|
||||
public class PushoverSettings : IProviderConfig
|
||||
{
|
||||
[FieldDefinition(0, Label = "User Key", HelpLink = "https://pushover.net/")]
|
||||
public String UserKey { get; set; }
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc
|
||||
{
|
||||
public class XbmcSettings : INotifcationSettings
|
||||
public class XbmcSettings : IProviderConfig
|
||||
{
|
||||
public XbmcSettings()
|
||||
{
|
||||
|
|
|
@ -171,6 +171,7 @@
|
|||
<Compile Include="Datastore\Migration\019_restore_unique_constraints.cs" />
|
||||
<Compile Include="Datastore\Migration\020_add_year_and_seasons_to_series.cs" />
|
||||
<Compile Include="Datastore\Migration\021_drop_seasons_table.cs" />
|
||||
<Compile Include="Datastore\Migration\022_move_notification_to_generic_provider.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
|
||||
|
@ -370,7 +371,6 @@
|
|||
<Compile Include="MetadataSource\Trakt\Images.cs" />
|
||||
<Compile Include="MetadataSource\Trakt\Season.cs" />
|
||||
<Compile Include="MetadataSource\Trakt\FullShow.cs" />
|
||||
<Compile Include="Notifications\INotifcationSettings.cs" />
|
||||
<Compile Include="Notifications\Plex\TestPlexServerCommand.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexServer.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexClientSettings.cs" />
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Notifications;
|
||||
|
||||
namespace NzbDrone.Core.ThingiProvider
|
||||
{
|
||||
|
@ -14,36 +15,44 @@ namespace NzbDrone.Core.ThingiProvider
|
|||
}
|
||||
}
|
||||
|
||||
public class DownloadProviderModel : Provider<DownloadProviderConfig>
|
||||
|
||||
public class NotificationProviderRepository : BasicRepository<NotificationProviderModel>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class DownloadProviderConfig : ProviderSetting
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public abstract class Provider<TSettings> : ModelBase
|
||||
where TSettings : ProviderSetting
|
||||
{
|
||||
public string Implementation { get; set; }
|
||||
public TSettings Config { get; set; }
|
||||
}
|
||||
|
||||
public abstract class ProviderSetting : IEmbeddedDocument
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract class ProviderBase<TSettings> where TSettings : ProviderSetting
|
||||
{
|
||||
public TSettings Settings { get; private set; }
|
||||
|
||||
public void LoadSettings(TSettings setting)
|
||||
public NotificationProviderRepository(IDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
Settings = setting;
|
||||
}
|
||||
}
|
||||
|
||||
public class DownloadProviderModel : Provider
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public abstract class Provider : ModelBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
|
||||
public string ConfigContract
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Settings == null) return null;
|
||||
return Settings.GetType().Name;
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IProviderConfig Settings { get; set; }
|
||||
}
|
||||
|
||||
public interface IProviderConfig
|
||||
{
|
||||
bool IsValid { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue