Ejemplo n.º 1
0
        public static Task CanUpdate(UpdateRule command, Guid appId, IAppProvider appProvider, Rule rule)
        {
            Guard.NotNull(command);

            return(Validate.It(() => "Cannot update rule.", async e =>
            {
                if (command.Trigger == null && command.Action == null && command.Name == null)
                {
                    e(Not.Defined("Either trigger, action or name"), nameof(command.Trigger), nameof(command.Action));
                }

                if (command.Trigger != null)
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(appId, command.Trigger, appProvider);

                    errors.Foreach(x => x.AddTo(e));
                }

                if (command.Action != null)
                {
                    var errors = command.Action.Validate();

                    errors.Foreach(x => x.AddTo(e));
                }

                if (command.Name != null && string.Equals(rule.Name, command.Name))
                {
                    e(Not.New("Rule", "name"), nameof(command.Name));
                }
            }));
        }
Ejemplo n.º 2
0
        public static Task CanCreate(CreateRule command, IAppProvider appProvider)
        {
            Guard.NotNull(command);

            return(Validate.It(() => "Cannot create rule.", async e =>
            {
                if (command.Trigger == null)
                {
                    e(Not.Defined("Trigger"), nameof(command.Trigger));
                }
                else
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider);

                    errors.Foreach(x => x.AddTo(e));
                }

                if (command.Action == null)
                {
                    e(Not.Defined("Action"), nameof(command.Action));
                }
                else
                {
                    var errors = command.Action.Validate();

                    errors.Foreach(x => x.AddTo(e));
                }
            }));
        }
Ejemplo n.º 3
0
        public static Task CanUpdate(UpdateRule command, Guid appId, 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 is required.", nameof(command.Trigger), nameof(command.Action)));
                }

                if (command.Trigger != null)
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(appId, command.Trigger, appProvider);

                    errors.Foreach(error);
                }

                if (command.Action != null)
                {
                    var errors = await RuleActionValidator.ValidateAsync(command.Action);

                    errors.Foreach(error);
                }
            }));
        }
Ejemplo n.º 4
0
        public static Task CanCreate(CreateRule command, IAppProvider appProvider)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(() => "Cannot create rule.", async error =>
            {
                if (command.Trigger == null)
                {
                    error(new ValidationError("Trigger is required.", nameof(command.Trigger)));
                }
                else
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider);

                    errors.Foreach(error);
                }

                if (command.Action == null)
                {
                    error(new ValidationError("Trigger is required.", nameof(command.Action)));
                }
                else
                {
                    var errors = await RuleActionValidator.ValidateAsync(command.Action);

                    errors.Foreach(error);
                }
            }));
        }
Ejemplo n.º 5
0
        public static Task <IEnumerable <ValidationError> > ValidateAsync(Guid appId, RuleTrigger action, IAppProvider appProvider)
        {
            Guard.NotNull(action);
            Guard.NotNull(appProvider);

            var visitor = new RuleTriggerValidator(x => appProvider.GetSchemaAsync(appId, x));

            return(action.Accept(visitor));
        }
Ejemplo n.º 6
0
        public static Task CanUpdate(UpdateRule command, IRuleEntity rule, IAppProvider appProvider)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(async e =>
            {
                if (command.Trigger != null)
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(rule.AppId.Id, command.Trigger, appProvider);

                    errors.Foreach((x, _) => x.AddTo(e));
                }

                if (command.Action != null)
                {
                    var errors = command.Action.Validate();

                    errors.Foreach((x, _) => x.AddTo(e));
                }
            }));
        }