public static CustomValidationExpressionConfiguration GetCustomValidationExpressionConfiguration(string validationType)
        {
            CustomValidationExpressionConfiguration result = null;

            _customValidationExpressionConfigurationsList.TryGetValue(validationType, out result);
            return(result);
        }
 public static void SetCustomValidationExpressionConfiguration(string validationType, CustomValidationExpressionConfiguration customValidationExpression)
 {
     CustomValidationExpressionConfiguration customValidationExpressionConfiguration;
     _customValidationExpressionConfigurationsList.TryGetValue(validationType, out customValidationExpressionConfiguration);
     if (customValidationExpression != null && customValidationExpressionConfiguration == null)
     {
         _customValidationExpressionConfigurationsList.Add(validationType, customValidationExpression);
     }
 }
Ejemplo n.º 3
0
        protected void CreateValidationAttributes(List <ValidationBase> validators, bool?mandatory)
        {
            if (validators != null)
            {
                StringBuilder strValidations        = new StringBuilder();
                StringBuilder strValidationParams   = new StringBuilder();
                StringBuilder strValidationMessages = new StringBuilder();

                foreach (IValidator validation in validators)
                {
                    if (validation.DoValidate)
                    {
                        switch (validation.Type)
                        {
                        case ValidatorsType.Required:
                        {
                            if (mandatory.HasValue && mandatory.Value)
                            {
                                appendValidation(strValidations, ValidatorsType.Required.ToString());
                                appendValidation(strValidationParams, "[]");
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));
                            }
                            break;
                        }

                        case ValidatorsType.SpecialChar:
                        {
                            var validator = validation as ISpecialCharValidator;
                            if (validator != null)
                            {
                                if (validator.Restriction == RestrictionType.Allow)
                                {
                                    appendValidation(strValidations, string.Format("{0}{1}", ValidatorsType.SpecialChar.ToString(), "Allow"));
                                }
                                else
                                {
                                    appendValidation(strValidations, string.Format("{0}{1}", ValidatorsType.SpecialChar.ToString(), "Restrict"));
                                }
                                appendValidation(strValidationParams, string.Format("[{0}]", validator.SpecialChars.Replace("\"", "\\\"")));
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));
                            }
                            break;
                        }

                        case ValidatorsType.Length:
                        {
                            var validator = validation as ILengthValidator;
                            if (validator != null)
                            {
                                appendValidation(strValidations, ValidatorsType.Length.ToString());
                                appendValidation(strValidationParams, string.Format("[{0}|{1}]", validator.MinLength, validator.MaxLength));
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));

                                LengthValidation = validator;
                            }
                            break;
                        }

                        case ValidatorsType.Range:
                        {
                            var validator = validation as IRangeValidator;
                            if (validator != null)
                            {
                                appendValidation(strValidations, ValidatorsType.Range.ToString());
                                appendValidation(strValidationParams, string.Format("[{0}|{1}]", validator.MinValue, validator.MaxValue));
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));
                            }
                            break;
                        }

                        case ValidatorsType.RegExp:
                        {
                            var validator = validation as IRegExValidator;
                            if (validator != null)
                            {
                                appendValidation(strValidations, ValidatorsType.RegExp.ToString());
                                appendValidation(strValidationParams, string.Format("[{0}]", validator.RegExpression));
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));
                            }
                            break;
                        }

                        case ValidatorsType.Custom:
                        {
                            var validator = validation as ICustomValidator;
                            if (validator != null)
                            {
                                appendValidation(strValidations, ValidatorsType.Custom.ToString());

                                //This code will set the default custom validation expression if the user not overriden the expression
                                var validationExpression = validator.Expression;
                                if (string.IsNullOrEmpty(validationExpression))
                                {
                                    CustomValidationExpressionConfiguration customExpression = ControlLibraryConfig.ControlConfigReader.GetCustomValidationExpressionConfiguration(validator.ValidationType.ToString());
                                    if (customExpression != null)
                                    {
                                        validationExpression = customExpression.Expression;
                                    }
                                }
                                appendValidation(strValidationParams, string.Format("[{0}]", validationExpression));

                                //**************************************************************************************************
                                //appendValidation(strValidationParams, string.Format("[{0}]", validator.Expression));
                                appendValidation(strValidationMessages, string.Format("[{0}]", validation.Message));
                            }
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }

                if (false == string.IsNullOrEmpty(strValidations.ToString()))
                {
                    ValidationAttributes.Add(ATTRIBUTE_DATA_VALIDATIONS, strValidations.ToString());
                    ValidationAttributes.Add(ATTRIBUTE_DATA_VALPARAMS, strValidationParams.ToString());
                    ValidationAttributes.Add(ATTRIBUTE_DATA_VALMSGS, strValidationMessages.ToString());
                }
            }
        }
        public static void SetCustomValidationExpressionConfiguration(string validationType, CustomValidationExpressionConfiguration customValidationExpression)
        {
            CustomValidationExpressionConfiguration customValidationExpressionConfiguration;

            _customValidationExpressionConfigurationsList.TryGetValue(validationType, out customValidationExpressionConfiguration);
            if (customValidationExpression != null && customValidationExpressionConfiguration == null)
            {
                _customValidationExpressionConfigurationsList.Add(validationType, customValidationExpression);
            }
        }