예제 #1
0
        public DynamicValidationTestResponse Test([Required, FromBody] DynamicValidationTestRequest request)
        {
            IDynamicValidationEvaluator evaluator;

            try
            {
                evaluator = request.dynamicValidation.Eval.Algorithm;
            }
            catch (Exception e)
            {
                return(new DynamicValidationTestResponse
                {
                    compileError = e.Message
                });
            }


            var pr         = request.dynamicValidation.SubEntity?.ToPropertyRoute() ?? PropertyRoute.Root(TypeLogic.EntityToType.GetOrThrow(request.dynamicValidation.EntityType));
            var candidates = GraphExplorer.FromRootEntity(request.exampleEntity)
                             .Where(a => a is ModifiableEntity me && pr.MatchesEntity(me) == true)
                             .Cast <ModifiableEntity>();

            var properties = Entities.Validator.GetPropertyValidators(pr.Type).Values.Select(a => a.PropertyInfo).ToList();

            try
            {
                return(new DynamicValidationTestResponse
                {
                    validationResult = candidates
                                       .SelectMany(me => properties.Select(pi => new DynamicValidationResult
                    {
                        propertyName = pi.NiceName(),
                        validationResult = evaluator.EvaluateUntyped(me, pi),
                    }))
                                       .ToArray()
                });
            }
            catch (Exception e)
            {
                return(new DynamicValidationTestResponse
                {
                    validationException = e.Message
                });
            }
        }
예제 #2
0
        public DynamicValidationTestResponse Test(DynamicValidationTestRequest request)
        {
            IDynamicValidationEvaluator evaluator;

            try
            {
                evaluator = request.dynamicValidation.Eval.Algorithm;
            }
            catch (Exception e)
            {
                return(new DynamicValidationTestResponse
                {
                    compileError = e.Message
                });
            }


            var pr         = request.dynamicValidation.PropertyRoute.ToPropertyRoute();
            var candidates = GraphExplorer.FromRootEntity(request.exampleEntity)
                             .Where(a => a.GetType() == pr.Parent.Type && pr.MatchesProperty((ModifiableEntity)a, pr.PropertyInfo) == true)
                             .Cast <ModifiableEntity>();

            try
            {
                return(new DynamicValidationTestResponse
                {
                    validationResult = candidates.Select(me => evaluator.EvaluateUntyped(me, pr.PropertyInfo)).ToArray()
                });
            }
            catch (Exception e)
            {
                return(new DynamicValidationTestResponse
                {
                    validationException = e.Message
                });
            }
        }
        public DynamicValidationTestResponse ValidationTest(DynamicValidationTestRequest request)
        {
            IDynamicValidationEvaluator evaluator;
            try
            {
                evaluator = request.dynamicValidation.Eval.Algorithm;
            }
            catch(Exception e)
            {
                return new DynamicValidationTestResponse
                {
                    compileError = e.Message
                };
            }


            var pr = request.dynamicValidation.PropertyRoute.ToPropertyRoute();
            var candidates = GraphExplorer.FromRootEntity(request.exampleEntity)
                .Where(a => a.GetType() == pr.Parent.Type && pr.MatchesProperty((ModifiableEntity)a, pr.PropertyInfo) == true)
                .Cast<ModifiableEntity>();

            try
            {
                return new DynamicValidationTestResponse
                {
                    validationResult = candidates.Select(me => evaluator.EvaluateUntyped(me, pr.PropertyInfo)).ToArray()
                };
            }
            catch (Exception e)
            {
                return new DynamicValidationTestResponse
                {
                    validationException = e.Message
                };
            }
        }