Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Defines operations related to validating cron expressions.
- /// </summary>
- public interface ICronValidator
- {
- /// <summary>
- /// Validates the given cron expression.
- /// </summary>
- /// <param name="cronExpression">The cron expression to validate.</param>
- /// <param name="errorMessage">An error message that will be set if the expression is invalid.</param>
- /// <returns>True if the cron expression is valid, otherwise false.</returns>
- bool ValidateCronExpression(string cronExpression, out string errorMessage);
- }
- /// <summary>
- /// A class that validates cron expressions using the cron expression API of Quartz.
- /// </summary>
- public class QuartzCronValidator : ICronValidator
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="QuartzCronValidator"/> class.
- /// </summary>
- public QuartzCronValidator()
- {
- }
- /// <summary>
- /// Validates the given cron expression.
- /// </summary>
- /// <param name="cronExpression">The cron expression to validate.</param>
- /// <param name="errorMessage">An error message that will be set if the expression is invalid.</param>
- /// <returns>True if the cron expression is valid, otherwise false.</returns>
- public bool ValidateCronExpression(string cronExpression, out string errorMessage)
- {
- // There doesn't appear to be any other way to do this with Quartz.NET.
- try
- {
- new CronExpression(cronExpression);
- }
- catch (FormatException ex)
- {
- errorMessage = ex.Message;
- return false;
- }
- errorMessage = null;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment