Esempio n. 1
0
 public void ValidateContextName(ValidationFunctionContext context)
 {
     if (VariableContextLogic.Instance.VariableContextCollection.Contexts.Any(c => c.Name.Equals(context.Value, StringComparison.OrdinalIgnoreCase)))
     {
         context.IsValid = false;
         context.Message = string.Format("The context name '{0}' is already being used"
                                         , context.Value);
     }
 }
Esempio n. 2
0
        public void ValidateVariableName(ValidationFunctionContext context)
        {
            if (context.Value.Length > 20)
            {
                context.IsValid = false;
            }

            if (!context.IsValid)
            {
                context.Message = "The variable name must be less than 21 characters in length.";
            }
        }
        private void ValidateParameterValues()
        {
            var definition = Command.GetType().DescribeInputCommand();

            foreach (var param in definition.Parameters.Where(p =>
                                                              (p.UseAutoCompleteForValidation && !string.IsNullOrWhiteSpace(p.AutoCompleteValuesFunction)) ||
                                                              !string.IsNullOrWhiteSpace(p.ValidationFunction)))
            {
                // get parameter value

                string value = param.PropertyInfo.GetValue(Command)?.ToString();

                if (value != null) // compare to validation values
                {
                    // get validation values

                    try
                    {
                        bool   isValid           = false;
                        string validationMessage = null;

                        if (param.UseAutoCompleteForValidation)
                        {
                            var methodInfo = Command.GetType().GetMethod(param.AutoCompleteValuesFunction);

                            var context = new AutoCompleteValuesFunctionContext();
                            methodInfo.Invoke(Command, new object[] { context });
                            isValid = context.Values.Contains(value, StringComparer.OrdinalIgnoreCase);
                        }
                        else
                        {
                            var methodInfo = Command.GetType().GetMethod(param.ValidationFunction);

                            var context = new ValidationFunctionContext(value);
                            methodInfo.Invoke(Command, new object[] { context });
                            isValid           = context.IsValid;
                            validationMessage = context.Message;
                        }



                        // evaluate

                        if (!isValid)
                        {
                            Errors.Add(new CommandValidatorError()
                            {
                                Type       = CommandValidationType.InvalidParameterValue,
                                Parameters = new List <ParameterDef>()
                                {
                                    param
                                },
                                Message = validationMessage ?? string.Format("The value of parameter {0} is invalid", param.Name)
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        Errors.Add(new CommandValidatorError()
                        {
                            Type       = CommandValidationType.InvalidValidationValuesFunction,
                            Parameters = new List <ParameterDef>()
                            {
                                param
                            },
                            Message = string.Format("An error occured during the invocation of the validation values function for parameter {0}", param.Name),
                            Error   = ex
                        });
                    }
                }
            }
        }