mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-18 23:48:35 +02:00
87cafe0035
Port 0 is not really a valid port. Using it will most likely dynamically allocate a port to listen on.
41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
using System.Text.RegularExpressions;
|
|
using FluentValidation;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Core.Parser;
|
|
|
|
namespace NzbDrone.Core.Validation
|
|
{
|
|
public static class RuleBuilderExtensions
|
|
{
|
|
public static IRuleBuilderOptions<T, int> ValidId<T>(this IRuleBuilder<T, int> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new GreaterThanValidator(0));
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, int> IsZero<T>(this IRuleBuilder<T, int> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new EqualValidator(0));
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, string> HaveHttpProtocol<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(s)?://", RegexOptions.IgnoreCase)).WithMessage("must start with http:// or https://");
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, string> ValidRootUrl<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
|
return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(?:s)?://[a-z0-9-.]+", RegexOptions.IgnoreCase)).WithMessage("must be valid URL that");
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, int> ValidPort<T>(this IRuleBuilder<T, int> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new InclusiveBetweenValidator(1, 65535));
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, Language> ValidLanguage<T>(this IRuleBuilder<T, Language> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new LangaugeValidator());
|
|
}
|
|
}
|
|
} |