Introducing interface for our needs of a CronTabParser. And inject it where needed
Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -42,17 +42,7 @@ namespace Umbraco.Core.Configuration.Models.Validation
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ValidateOptionalCronTab(string configPath, string value, out string message)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value) && !value.IsValidCronTab())
|
||||
{
|
||||
message = $"Configuration entry {configPath} contains an invalid cron expression.";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ namespace Umbraco.Core.Configuration.Models.Validation
|
||||
{
|
||||
public class HealthChecksSettingsValidator : ConfigurationValidatorBase, IValidateOptions<HealthChecksSettings>
|
||||
{
|
||||
private readonly ICronTabParser _cronTabParser;
|
||||
|
||||
public HealthChecksSettingsValidator(ICronTabParser cronTabParser)
|
||||
{
|
||||
_cronTabParser = cronTabParser;
|
||||
}
|
||||
|
||||
public ValidateOptionsResult Validate(string name, HealthChecksSettings options)
|
||||
{
|
||||
if (!ValidateNotificationFirstRunTime(options.Notification.FirstRunTime, out var message))
|
||||
@@ -18,5 +25,17 @@ namespace Umbraco.Core.Configuration.Models.Validation
|
||||
{
|
||||
return ValidateOptionalCronTab($"{Constants.Configuration.ConfigHealthChecks}:{nameof(HealthChecksSettings.Notification)}:{nameof(HealthChecksSettings.Notification.FirstRunTime)}", value, out message);
|
||||
}
|
||||
|
||||
public bool ValidateOptionalCronTab(string configPath, string value, out string message)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value) && !_cronTabParser.IsValidCronTab(value))
|
||||
{
|
||||
message = $"Configuration entry {configPath} contains an invalid cron expression.";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user