Added some abstraction for settings.

pull/2/head
Leonardo Galli 8 years ago
parent b02944a3b2
commit 734a36de06

@ -6,17 +6,10 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.IMDbWatchList namespace NzbDrone.Core.NetImport.IMDbWatchList
{ {
public class IMDbWatchListSettingsValidator : AbstractValidator<IMDbWatchListSettings>
{
public IMDbWatchListSettingsValidator()
{
RuleFor(c => c.Link).NotEmpty();
}
}
public class IMDbWatchListSettings : IProviderConfig public class IMDbWatchListSettings : NetImportBaseSettings
{ {
private static readonly IMDbWatchListSettingsValidator Validator = new IMDbWatchListSettingsValidator(); //private const string helpLink = "https://imdb.com";
public IMDbWatchListSettings() public IMDbWatchListSettings()
{ {
@ -24,17 +17,7 @@ namespace NzbDrone.Core.NetImport.IMDbWatchList
ProfileId = 1; ProfileId = 1;
} }
[FieldDefinition(0, Label = "Watch List RSS link", HelpLink = "http://rss.imdb.com/list/")] [FieldDefinition(0, Label = "RSS Link", HelpText = "Link to the rss feed of movies.")]
public string Link { get; set; } public new string Link { get; set; }
[FieldDefinition(1, Label = "Quality", Type = FieldType.Select, SelectOptions = typeof(Profile), HelpText = "Quality of all imported movies")]
public int ProfileId { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(Link);
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
} }
} }

@ -0,0 +1,40 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport
{
public class NetImportBaseSettingsValidator : AbstractValidator<NetImportBaseSettings>
{
public NetImportBaseSettingsValidator()
{
RuleFor(c => c.Link).NotEmpty();
}
}
public class NetImportBaseSettings : IProviderConfig
{
private static readonly NetImportBaseSettingsValidator Validator = new NetImportBaseSettingsValidator();
public NetImportBaseSettings()
{
Link = "http://rss.imdb.com/list/";
ProfileId = 1;
}
[FieldDefinition(0, Label = "Link", HelpText = "Link to the list of movies.")]
public string Link { get; set; }
[FieldDefinition(1, Label = "Quality", Type = FieldType.Select, SelectOptions = typeof(Profile), HelpText = "Quality of all imported movies")]
public int ProfileId { get; set; }
public bool IsValid => !string.IsNullOrWhiteSpace(Link);
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}

@ -126,6 +126,7 @@
<Compile Include="NetImport\Exceptions\NetImportException.cs" /> <Compile Include="NetImport\Exceptions\NetImportException.cs" />
<Compile Include="NetImport\HttpNetImportBase.cs" /> <Compile Include="NetImport\HttpNetImportBase.cs" />
<Compile Include="NetImport\IProcessNetImportResponse.cs" /> <Compile Include="NetImport\IProcessNetImportResponse.cs" />
<Compile Include="NetImport\NetImportBaseSettings.cs" />
<Compile Include="NetImport\NetImportPageableRequest.cs" /> <Compile Include="NetImport\NetImportPageableRequest.cs" />
<Compile Include="NetImport\NetImportPageableRequestChain.cs" /> <Compile Include="NetImport\NetImportPageableRequestChain.cs" />
<Compile Include="NetImport\INetImportRequestGenerator.cs" /> <Compile Include="NetImport\INetImportRequestGenerator.cs" />

Loading…
Cancel
Save