public static Task CanUpdate(UpdateRule command, IAppProvider appProvider) { Guard.NotNull(command, nameof(command)); return(Validate.It(() => "Cannot update rule.", async error => { if (command.Trigger == null && command.Action == null) { error(new ValidationError("Either trigger or action must be defined.", nameof(command.Trigger), nameof(command.Action))); } if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Name, command.Trigger, appProvider); errors.Foreach(error); } if (command.Action != null) { var errors = await RuleActionValidator.ValidateAsync(command.Action); errors.Foreach(error); } })); }
public static Task CanCreate(CreateRule command, ISchemaProvider schemas) { Guard.NotNull(command, nameof(command)); return(Validate.It(() => "Cannot create rule.", async error => { if (command.Trigger == null) { error(new ValidationError("Trigger must be defined.", nameof(command.Trigger))); } else { var errors = await RuleTriggerValidator.ValidateAsync(command.Trigger, schemas); errors.Foreach(error); } if (command.Action == null) { error(new ValidationError("Trigger must be defined.", nameof(command.Action))); } else { var errors = await RuleActionValidator.ValidateAsync(command.Action); errors.Foreach(error); } })); }
public static Task <IEnumerable <ValidationError> > ValidateAsync(RuleTrigger action, ISchemaProvider schemas) { Guard.NotNull(action, nameof(action)); Guard.NotNull(schemas, nameof(schemas)); var visitor = new RuleTriggerValidator(schemas); return(action.Accept(visitor)); }
public static Task <IEnumerable <ValidationError> > ValidateAsync(string appName, RuleTrigger action, IAppProvider appProvider) { Guard.NotNull(action, nameof(action)); Guard.NotNull(appProvider, nameof(appProvider)); var visitor = new RuleTriggerValidator(x => appProvider.GetSchemaAsync(appName, x)); return(action.Accept(visitor)); }