starting to move indexers to generic provider.

pull/6/head
kay.one 11 years ago committed by kayone
parent 4046d35604
commit 0b179a6086

@ -1,31 +1,31 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Notifications;
using NzbDrone.Core.Notifications.Email;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Test.ThingiProvider
{
public class ProviderRepositoryFixture : DbTest<NotificationProviderRepository, NotificationProviderModel>
public class ProviderRepositoryFixture : DbTest<IndexerProviderRepository, IndexerDefinition>
{
[Test]
public void should_read_write_download_provider()
{
var model = Builder<NotificationProviderModel>.CreateNew().BuildNew();
var emailSettings = Builder<EmailSettings>.CreateNew().Build();
model.Settings = emailSettings;
var model = Builder<IndexerDefinition>.CreateNew().BuildNew();
var newznabSettings = Builder<NewznabSettings>.CreateNew().Build();
model.Settings = newznabSettings;
Subject.Insert(model);
var storedProvider = Subject.Single();
storedProvider.Settings.Should().BeOfType<EmailSettings>();
var storedSetting = (EmailSettings) storedProvider.Settings;
storedSetting.ShouldHave().AllProperties().EqualTo(emailSettings);
storedProvider.Settings.Should().BeOfType<NewznabSettings>();
var storedSetting = (NewznabSettings)storedProvider.Settings;
storedSetting.ShouldHave().AllProperties().EqualTo(newznabSettings);
}
}
}

@ -8,11 +8,11 @@ using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(22)]
public class move_notification_to_generic_provider : NzbDroneMigrationBase
public class move_indexer_to_generic_provider : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Notifications").AddColumn("ConfigContract").AsString().Nullable();
Alter.Table("Indexers").AddColumn("ConfigContract").AsString().Nullable();
//Execute.WithConnection(ConvertSeasons);
}
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Datastore.Migration
using (IDbCommand updateCmd = conn.CreateCommand())
{
var text = String.Format("UPDATE Series SET Seasons = '{0}' WHERE Id = {1}", seasons.ToJson() , seriesId);
var text = String.Format("UPDATE Series SET Seasons = '{0}' WHERE Id = {1}", seasons.ToJson(), seriesId);
updateCmd.Transaction = tran;
updateCmd.CommandText = text;

@ -36,7 +36,6 @@ 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");

@ -1,9 +0,0 @@
using FluentValidation.Results;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerSetting
{
ValidationResult Validate();
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
@ -22,7 +23,7 @@ namespace NzbDrone.Core.Indexers
Name = Name,
Enable = EnableByDefault,
Implementation = GetType().Name,
Settings = String.Empty
Settings = NullSetting.Instance
};
}
}

@ -1,13 +1,11 @@
using System;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public class IndexerDefinition : ModelBase
public class IndexerDefinition : ProviderDefinition
{
public Boolean Enable { get; set; }
public String Name { get; set; }
public String Settings { get; set; }
public String Implementation { get; set; }
}
}

@ -7,6 +7,7 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Indexers
@ -16,7 +17,7 @@ namespace NzbDrone.Core.Indexers
public int Id { get; set; }
public string Name { get; set; }
public bool Enable { get; set; }
public IIndexerSetting Settings { get; set; }
public IProviderConfig Settings { get; set; }
public IIndexer Instance { get; set; }
public string Implementation { get; set; }
}
@ -107,7 +108,7 @@ namespace NzbDrone.Core.Indexers
Name = indexer.Name,
Enable = indexer.Enable,
Implementation = indexer.Implementation,
Settings = indexer.Settings.ToJson()
Settings = indexer.Settings
};
var instance = ToIndexer(definition).Instance;
@ -123,7 +124,7 @@ namespace NzbDrone.Core.Indexers
{
var definition = _indexerRepository.Get(indexer.Id);
definition.InjectFrom(indexer);
definition.Settings = indexer.Settings.ToJson();
definition.Settings = indexer.Settings;
_indexerRepository.Update(definition);
return indexer;

@ -1,31 +0,0 @@
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Indexers
{
public interface IProviderIndexerSetting
{
TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new();
}
public class IndexerSettingProvider : IProviderIndexerSetting
{
private readonly IIndexerRepository _indexerRepository;
public IndexerSettingProvider(IIndexerRepository indexerRepository)
{
_indexerRepository = indexerRepository;
}
public TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new()
{
var indexerDef = _indexerRepository.Find(indexer.Name);
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
{
return new TSetting();
}
return Json.Deserialize<TSetting>(indexerDef.Settings);
}
}
}

@ -1,13 +1,14 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public class IndexerSettingUpdatedEvent : IEvent
{
public string IndexerName { get; private set; }
public IIndexerSetting IndexerSetting { get; private set; }
public IProviderConfig IndexerSetting { get; private set; }
public IndexerSettingUpdatedEvent(string indexerName, IIndexerSetting indexerSetting)
public IndexerSettingUpdatedEvent(string indexerName, IProviderConfig indexerSetting)
{
IndexerName = indexerName;
IndexerSetting = indexerSetting;

@ -1,8 +1,9 @@
using NzbDrone.Common.Serializer;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public abstract class IndexerWithSetting<TSetting> : IndexerBase where TSetting : class, IIndexerSetting, new()
public abstract class IndexerWithSetting<TSetting> : IndexerBase where TSetting : class, IProviderConfig, new()
{
public TSetting Settings { get; set; }

@ -51,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Newznab
}
}
private string GetSettings(string url, List<int> categories)
private NewznabSettings GetSettings(string url, List<int> categories)
{
var settings = new NewznabSettings { Url = url };
@ -60,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Newznab
settings.Categories = categories;
}
return settings.ToJson();
return settings;
}
public override IEnumerable<string> RecentFeed

@ -3,6 +3,7 @@ using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Newznab
@ -16,7 +17,7 @@ namespace NzbDrone.Core.Indexers.Newznab
}
public class NewznabSettings : IIndexerSetting
public class NewznabSettings : IProviderConfig
{
private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator();

@ -1,14 +0,0 @@
using FluentValidation.Results;
namespace NzbDrone.Core.Indexers
{
public class NullSetting : IIndexerSetting
{
public static readonly NullSetting Instance = new NullSetting();
public ValidationResult Validate()
{
return new ValidationResult();
}
}
}

@ -2,6 +2,7 @@
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers.Omgwtfnzbs
{
@ -14,7 +15,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
}
}
public class OmgwtfnzbsSettings : IIndexerSetting
public class OmgwtfnzbsSettings : IProviderConfig
{
private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator();

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -39,5 +40,10 @@ namespace NzbDrone.Core.Notifications.Email
return !string.IsNullOrWhiteSpace(Server) && Port > 0 && !string.IsNullOrWhiteSpace(From) && !string.IsNullOrWhiteSpace(To);
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -27,5 +28,10 @@ namespace NzbDrone.Core.Notifications.Growl
return !string.IsNullOrWhiteSpace(Host) && !string.IsNullOrWhiteSpace(Password) && Port > 0;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Notifications
}
public class NotificationProviderModel : Provider
public class NotificationProviderModel : ProviderDefinition
{
public Boolean OnGrab { get; set; }
public Boolean OnDownload { get; set; }

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Notifications
Notification Get(int id);
List<Notification> Schema();
Notification Create(Notification notification);
Notification Update(Notification notification);
void Update(Notification notification);
void Delete(int id);
}
@ -94,15 +94,13 @@ namespace NzbDrone.Core.Notifications
return notification;
}
public Notification Update(Notification notification)
public void Update(Notification notification)
{
var definition = _notificationRepository.Get(notification.Id);
definition.InjectFrom(notification);
definition.Settings = notification.Settings.ToJson();
_notificationRepository.Update(definition);
return notification;
}
public void Delete(int id)

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -19,5 +20,10 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
return !String.IsNullOrWhiteSpace(ApiKey) && Priority != null & Priority >= -1 && Priority <= 2;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -30,5 +31,10 @@ namespace NzbDrone.Core.Notifications.Plex
return !string.IsNullOrWhiteSpace(Host);
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -27,5 +28,10 @@ namespace NzbDrone.Core.Notifications.Plex
return !string.IsNullOrWhiteSpace(Host);
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -19,5 +20,10 @@ namespace NzbDrone.Core.Notifications.Prowl
return !string.IsNullOrWhiteSpace(ApiKey) && Priority != null & Priority >= -2 && Priority <= 2;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -19,5 +20,10 @@ namespace NzbDrone.Core.Notifications.PushBullet
return !String.IsNullOrWhiteSpace(ApiKey) && DeviceId > 0;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,5 @@
using System;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -19,5 +20,10 @@ namespace NzbDrone.Core.Notifications.Pushover
return !string.IsNullOrWhiteSpace(UserKey) && Priority != null & Priority >= -1 && Priority <= 2;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using FluentValidation.Results;
using Newtonsoft.Json;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -52,5 +53,10 @@ namespace NzbDrone.Core.Notifications.Xbmc
return !string.IsNullOrWhiteSpace(Host) && Port > 0;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

@ -246,7 +246,6 @@
<Compile Include="Indexers\Newznab\NewznabException.cs" />
<Compile Include="Indexers\Newznab\NewznabPreProcessor.cs" />
<Compile Include="Indexers\Newznab\SizeParsingException.cs" />
<Compile Include="Indexers\NullSetting.cs" />
<Compile Include="Indexers\RssSyncCommand.cs" />
<Compile Include="Indexers\XElementExtensions.cs" />
<Compile Include="Instrumentation\Commands\ClearLogCommand.cs" />
@ -343,13 +342,11 @@
<Compile Include="Indexers\IndexerBase.cs" />
<Compile Include="Indexers\IndexerDefinition.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\IndexerSettingProvider.cs" />
<Compile Include="Indexers\Newznab\Newznab.cs" />
<Compile Include="Indexers\Newznab\NewznabSettings.cs" />
<Compile Include="Indexers\Newznab\NewznabParser.cs" />
<Compile Include="Indexers\Omgwtfnzbs\Omgwtfnzbs.cs" />
<Compile Include="Indexers\Omgwtfnzbs\OmgwtfnzbsParser.cs" />
<Compile Include="Indexers\IIndexerSetting.cs" />
<Compile Include="Indexers\Omgwtfnzbs\OmgwtfnzbsSettings.cs" />
<Compile Include="Indexers\Wombles\Wombles.cs" />
<Compile Include="Indexers\Wombles\WomblesParser.cs" />

@ -1,36 +1,35 @@

using FluentValidation.Results;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Notifications;
namespace NzbDrone.Core.ThingiProvider
{
public class DownloadProviderRepository : BasicRepository<DownloadProviderModel>
public class NotificationProviderRepository : BasicRepository<NotificationDefinition>
{
public DownloadProviderRepository(IDatabase database, IEventAggregator eventAggregator)
public NotificationProviderRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
public class NotificationProviderRepository : BasicRepository<NotificationProviderModel>
public class IndexerProviderRepository : BasicRepository<IndexerDefinition>
{
public NotificationProviderRepository(IDatabase database, IEventAggregator eventAggregator)
public IndexerProviderRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
public class DownloadProviderModel : Provider
public abstract class ProviderBase
{
public ProviderDefinition Definition { get; set; }
}
public abstract class Provider : ModelBase
public abstract class ProviderDefinition : ModelBase
{
public string Name { get; set; }
public string Implementation { get; set; }
@ -44,7 +43,7 @@ namespace NzbDrone.Core.ThingiProvider
}
set
{
}
}
@ -53,6 +52,16 @@ namespace NzbDrone.Core.ThingiProvider
public interface IProviderConfig
{
bool IsValid { get; }
ValidationResult Validate();
}
public class NullSetting : IProviderConfig
{
public static readonly NullSetting Instance = new NullSetting();
public ValidationResult Validate()
{
return new ValidationResult();
}
}
}
Loading…
Cancel
Save