1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

starting to move indexers to generic provider.

This commit is contained in:
kay.one 2013-09-21 00:09:26 -07:00 committed by kayone
parent 4046d35604
commit 0b179a6086
27 changed files with 116 additions and 109 deletions

View File

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

View File

@ -8,11 +8,11 @@
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 @@ private void ConvertSeasons(IDbConnection conn, IDbTransaction tran)
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;

View File

@ -36,7 +36,6 @@ public static void Map()
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");

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@
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 @@ public class Indexer
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 @@ public Indexer Create(Indexer indexer)
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 @@ public Indexer Update(Indexer indexer)
{
var definition = _indexerRepository.Get(indexer.Id);
definition.InjectFrom(indexer);
definition.Settings = indexer.Settings.ToJson();
definition.Settings = indexer.Settings;
_indexerRepository.Update(definition);
return indexer;

View File

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

View File

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

View File

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

View File

@ -51,7 +51,7 @@ public override IEnumerable<IndexerDefinition> DefaultDefinitions
}
}
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 @@ private string GetSettings(string url, List<int> categories)
settings.Categories = categories;
}
return settings.ToJson();
return settings;
}
public override IEnumerable<string> RecentFeed

View File

@ -3,6 +3,7 @@
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 @@ public NewznabSettingsValidator()
}
public class NewznabSettings : IIndexerSetting
public class NewznabSettings : IProviderConfig
{
private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator();

View File

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

View File

@ -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 @@ public OmgwtfnzbsSettingsValidator()
}
}
public class OmgwtfnzbsSettings : IIndexerSetting
public class OmgwtfnzbsSettings : IProviderConfig
{
private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator();

View File

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

View File

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

View File

@ -14,7 +14,7 @@ public class NotificationDefinition : ModelBase
}
public class NotificationProviderModel : Provider
public class NotificationProviderModel : ProviderDefinition
{
public Boolean OnGrab { get; set; }
public Boolean OnDownload { get; set; }

View File

@ -19,7 +19,7 @@ public interface INotificationService
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 @@ public Notification Create(Notification notification)
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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 @@ public bool IsValid
return !string.IsNullOrWhiteSpace(Host) && Port > 0;
}
}
public ValidationResult Validate()
{
throw new NotImplementedException();
}
}
}

View File

@ -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" />

View File

@ -1,22 +1,13 @@

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 DownloadProviderRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
public class NotificationProviderRepository : BasicRepository<NotificationProviderModel>
public class NotificationProviderRepository : BasicRepository<NotificationDefinition>
{
public NotificationProviderRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
@ -24,13 +15,21 @@ public NotificationProviderRepository(IDatabase database, IEventAggregator event
}
}
public class DownloadProviderModel : Provider
{
public class IndexerProviderRepository : BasicRepository<IndexerDefinition>
{
public IndexerProviderRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
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 @@ public string ConfigContract
}
set
{
}
}
@ -53,6 +52,16 @@ public string ConfigContract
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();
}
}
}