Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
Issue FritzAndFriends#8 Cron validation in RecurringSchedule.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
marblekirby committed Jul 13, 2019
1 parent 32f46bb commit b841a47
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Fritz.ResourceManagement.Domain/RecurringSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using CronEspresso.NETCore.Utils;

namespace Fritz.ResourceManagement.Domain
{
Expand Down Expand Up @@ -31,8 +31,9 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex

var results = new List<ValidationResult>();

if(!Regex.IsMatch(CronPattern, @"^((\*|\?|\d+((\/|\-){0,1}(\d+))*)\s*){6}$"))
results.Add(new ValidationResult($"{nameof(CronPattern)} is not a valid cron pattern", new[] { nameof(CronPattern) }));
var cronValidationResult = CronHelpers.ValidateCron(CronPattern);
if (!cronValidationResult.IsValidCron)
results.Add(new ValidationResult($"{nameof(CronPattern) } is not a valid Cron pattern, {cronValidationResult.ValidationMessage}", new[] { nameof(CronPattern) }));

if (string.IsNullOrWhiteSpace(Name))
results.Add(new ValidationResult($"{nameof(Name)} cannot be null, empty or consist of only whitespace", new[] { nameof(Name) }));
Expand Down

0 comments on commit b841a47

Please sign in to comment.