Exemple #1
0
        public ValidationResult Execute(ValidationRequest request)
        {
            TArgs args = _argsFactory(this, request);

            Execute(args);
            return(args.Result);
        }
        public ValidationResult Validate(IBehaviorContext context, ValidationRequest request)
        {
            Seal();

            var result        = _compositeValidator.Execute(request);
            var parentResults = InvokeParentBehaviorsOf(context.VM, request);

            return(ValidationResult.Join(result, parentResults));
        }
Exemple #3
0
        internal static ViewModelValidationArgs <TOwnerVM, TTargetVM> Create(
            IValidator validator,
            ValidationRequest request
            )
        {
            Path path = request.TargetPath;

            var owner  = (TOwnerVM)path[0].ViewModel;
            var target = (TTargetVM)path[path.Length - 1].ViewModel;

            return(new ViewModelValidationArgs <TOwnerVM, TTargetVM>(validator, owner, target));
        }
Exemple #4
0
        internal static CollectionValidationArgs <TOwnerVM, TItemVM> Create(
            IValidator validator,
            ValidationRequest request
            )
        {
            var path = request.TargetPath;

            var owner      = (TOwnerVM)path[0].ViewModel;
            var collection = (IVMCollection <TItemVM>)path[path.Length - 1].Collection;

            return(new CollectionValidationArgs <TOwnerVM, TItemVM>(
                       validator,
                       owner,
                       collection
                       ));
        }
        public bool IsTrue(ValidationRequest request)
        {
            TOwnerVM owner = (TOwnerVM)request
                             .TargetPath[0]
                             .ViewModel;

            TTargetVM target = (TTargetVM)request
                               .TargetPath[_pathTargetIndex]
                               .ViewModel;

            Check.Requires <InvalidOperationException>(owner != null);
            Check.Requires <InvalidOperationException>(target != null);

            var args = new ValidatorConditionArgs <TOwnerVM, TTargetVM>(owner, target);

            return(_predicate(args));
        }
Exemple #6
0
        internal static PropertyValidationArgs <TOwnerVM, TTargetVM, TValue> Create(
            IValidator validator,
            ValidationRequest request
            )
        {
            Path path = request.TargetPath;

            var owner          = (TOwnerVM)path[0].ViewModel;
            var targetVM       = (TTargetVM)path[path.Length - 2].ViewModel;
            var targetProperty = (IVMPropertyDescriptor <TValue>)path[path.Length - 1].Property;

            return(new PropertyValidationArgs <TOwnerVM, TTargetVM, TValue>(
                       validator,
                       request.Step,
                       owner,
                       targetVM,
                       targetProperty
                       ));
        }
        private ValidationResult InvokeParentBehaviorsOf(IViewModel vm, ValidationRequest request)
        {
            var result = ValidationResult.Valid;

            foreach (IViewModel parent in vm.Kernel.Parents)
            {
                var parentRequest = request.PrependAncestor(parent);

                ValidatorExecutorBehavior b;
                bool parentHasBehavior = parent
                                         .Descriptor
                                         .Behaviors
                                         .TryGetBehavior(out b);

                var parentResult = parentHasBehavior ?
                                   b.Validate(parent.GetContext(), parentRequest) :
                                   InvokeParentBehaviorsOf(parent, parentRequest);

                result = ValidationResult.Join(result, parentResult);
            }

            return(result);
        }
Exemple #8
0
 public ValidationResult Execute(ValidationRequest request)
 {
     return(_condition.IsTrue(request) ?
            _inner.Execute(request) :
            ValidationResult.Valid);
 }
Exemple #9
0
 public ValidationResult Execute(ValidationRequest request)
 {
     return(ValidationResult.Join(
                _validators.Select(x => x.Execute(request))
                ));
 }