Exemple #1
0
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            ValidatorProperties validatorProperties = ValidationRule.Validator.GetValidatorProperties();
            string message = ValidationRule.GetValidationMessage(Metadata.Model);

            yield return(new ModelClientValidationRangeRule(message, null, validatorProperties.GetPropertyValue(Constants.ValidationMessageParameterNames.VALUE_TO_COMPARE)));
        }
Exemple #2
0
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule    entityValidationRule    = ValidationRule;
            IEntityPropertyValidator entityPropertyValidator = entityValidationRule.Validator;
            ValidatorProperties      validatorProperties     = entityPropertyValidator.GetValidatorProperties();
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);

            yield return(new ModelClientValidationRegexRule(message, validatorProperties.GetPropertyValue <string>(Constants.ValidationMessageParameterNames.REGEX)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NotEqualToValidator"/> class.
        /// </summary>
        /// <param name="valueToCompare">The value to compare.</param>
        /// <param name="comparer">The comparer.</param>
        /// <exception cref="System.ArgumentNullException">valueToCompare</exception>
        public NotEqualToValidator(object valueToCompare, IEqualityComparer comparer = null)
        {
            if (valueToCompare == null)
            {
                throw new ArgumentNullException("valueToCompare");
            }

            m_EqualToValidator = new EqualToValidator(valueToCompare, comparer);
            m_ValidatorProperties = new ValidatorProperties { { Constants.ValidationMessageParameterNames.VALUE_TO_COMPARE, ValueToCompare } };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GreaterThanValidator"/> class.
        /// </summary>
        /// <param name="valueToCompare">The value to compare.</param>
        /// <exception cref="System.ArgumentNullException">valueToCompare</exception>
        public GreaterThanValidator(IComparable valueToCompare)
        {
            if (valueToCompare == null)
            {
                throw new ArgumentNullException("valueToCompare");
            }

            m_ValueToCompare = valueToCompare;
            m_ValidatorProperties = new ValidatorProperties { { Constants.ValidationMessageParameterNames.VALUE_TO_COMPARE, ValueToCompare } };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PredicateValidator"/> class.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <exception cref="System.ArgumentNullException">predicate</exception>
        public PredicateValidator(Predicate<object> predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            m_Predicate = predicate;
            m_ValidatorProperties = new ValidatorProperties();
        }
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule entityValidationRule = ValidationRule;
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);
            ValidatorProperties validatorProperties = entityValidationRule.Validator.GetValidatorProperties();

            yield return
                (new ModelClientValidationRangeRule(
                     message,
                     validatorProperties.GetPropertyValue(Constants.ValidationMessageParameterNames.FROM_VALUE),
                     validatorProperties.GetPropertyValue(Constants.ValidationMessageParameterNames.TO_VALUE)));
        }
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule entityValidationRule = ValidationRule;
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);
            ValidatorProperties validatorProperties = entityValidationRule.Validator.GetValidatorProperties();

            yield return
                (new ModelClientValidationStringLengthRule(
                     message,
                     validatorProperties.GetPropertyValue <int>(Constants.ValidationMessageParameterNames.MIN),
                     validatorProperties.GetPropertyValue <int>(Constants.ValidationMessageParameterNames.MAX)));
        }
Exemple #8
0
        protected void AddClientValidator(ValidatorProperties validator, int validatorIndex)
        {
            var sb = new StringBuilder();

            validator.CreateClientValidator(Page, sb,
                                            ID + "_" + validatorIndex,
                                            RenderContext.EditClientID,
                                            ValidatorDisplay.Dynamic,
                                            RenderContext.ValidationGroup,
                                            GetColumnValue());
            Controls.Add(new Literal {
                Text = sb.ToString()
            });
        }
Exemple #9
0
        public virtual void AddValidator(ValidatorProperties validator)
        {
            var editComponent = EditColtrol as IRenderComponent;

            if (editComponent != null)
            {
                editComponent.AddValidator(validator);
            }
            else
            {
                ValidatorProperties.Add(validator);
                AddClientValidator(validator, ValidatorProperties.Count);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RegexValidator"/> class.
        /// </summary>
        /// <param name="validationMessageResourceName">Name of the validation message resource.</param>
        /// <param name="expression">The expression.</param>
        /// <param name="regexOptions">The regex options.</param>
        /// <exception cref="System.ArgumentNullException">expression</exception>
        public RegexValidator(string validationMessageResourceName, string expression, RegexOptions regexOptions = RegexOptions.None)
        {
            if (validationMessageResourceName == null)
            {
                throw new ArgumentNullException("validationMessageResourceName");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            m_Regex = new Regex(expression, RegexOptions.Compiled | regexOptions);
            m_ValidationMessageResourceName = validationMessageResourceName;
            m_ValidatorProperties = new ValidatorProperties { { Constants.ValidationMessageParameterNames.REGEX, expression } };
        }
Exemple #11
0
        /// <summary>
        /// Sets the validator properties.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <returns>The validator properties.</returns>
        public IValidationMessageBuilderParameterSetter SetValidatorProperties(ValidatorProperties properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IEnumerator <KeyValuePair <string, object> > enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <string, object> validatorProperty = enumerator.Current;
                SetParameter(validatorProperty.Key, validatorProperty.Value.ToString());
            }

            return(this);
        }
Exemple #12
0
        public virtual void AddValidators(IEnumerable <ValidatorProperties> validators)
        {
            var editComponent = EditColtrol as IRenderComponent;

            if (editComponent != null)
            {
                editComponent.AddValidators(validators);
            }
            else
            {
                foreach (var validator in validators)
                {
                    ValidatorProperties.Add(validator);
                    AddClientValidator(validator, ValidatorProperties.Count);
                }
            }
        }
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            ValidatorProperties validatorProperties       = ValidationRule.Validator.GetValidatorProperties();
            MemberInfo          memberToCompareMemberInfo = validatorProperties.GetPropertyValue <MemberInfo>(Constants.ValidationMessageParameterNames.MEMBER_TO_COMPARE_MEMBER_INFO);
            PropertyInfo        propertyInfoToCompare     = memberToCompareMemberInfo as PropertyInfo;

            if (propertyInfoToCompare != null)
            {
                string message   = ValidationRule.GetValidationMessage(Metadata.Model);
                Type   ownerType = validatorProperties.GetPropertyValue <Type>(Constants.ValidationMessageParameterNames.OWNER_TYPE);

                string validationModelPropertyName = propertyInfoToCompare.Name;
                string propertyName = GetTransformedPropertyName(validationModelPropertyName, ownerType) ?? validationModelPropertyName;

                string propertyForClientValidation = CompareAttribute.FormatPropertyForClientValidation(propertyName);
                yield return(new ModelClientValidationEqualToRule(message, propertyForClientValidation));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LengthValidator"/> class.
        /// </summary>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// min;Min should be larger than -1.
        /// or
        /// max;Max should be larger than min.
        /// </exception>
        public LengthValidator(int min, int max = -1)
        {
            if (min < 0)
            {
                throw new ArgumentOutOfRangeException("min", "Min should be larger than -1.");
            }

            if (max != -1 && max < min)
            {
                throw new ArgumentOutOfRangeException("max", "Max should be larger than min.");
            }

            m_Min = min;
            m_Max = max;

            m_ValidatorProperties = new ValidatorProperties
                                        {
                                            { Constants.ValidationMessageParameterNames.MIN, Min },
                                            { Constants.ValidationMessageParameterNames.MAX, Max }
                                        };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotNullValidator"/> class.
 /// </summary>
 public NotNullValidator()
 {
     m_ValidatorProperties = new ValidatorProperties();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BetweenValidator"/> class.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">The automatic.</param>
        public BetweenValidator(IComparable @from, IComparable to)
        {
            if (@from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            if (!to.GetType().IsInstanceOfType(@from))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "'To' value should be type of '{0}'", @from.GetType().FullName));
            }

            if (to.CompareTo(@from) == -1)
            {
                throw new ArgumentOutOfRangeException("to", "'To' should be larger than 'from'.");
            }

            m_From = @from;
            m_To = to;

            m_ValidatorProperties = new ValidatorProperties
                                        {
                                            { Constants.ValidationMessageParameterNames.FROM_VALUE, FromValue },
                                            { Constants.ValidationMessageParameterNames.TO_VALUE, ToValue }
                                        };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotEmptyValidator"/> class.
 /// </summary>
 public NotEmptyValidator()
 {
     m_ValidatorProperties = new ValidatorProperties();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EqualToEntityPropertyValidator"/> class.
        /// </summary>
        /// <param name="memberToCompareFunc">The member to compare function.</param>
        /// <param name="member">The member.</param>
        /// <param name="ownerType">The owner type.</param>
        /// <param name="confirmProperty">if set to <c>true</c> [confirm property].</param>
        /// <param name="comparer">The comparer.</param>
        /// <exception cref="System.ArgumentNullException">
        /// memberToCompareFunc
        /// or
        /// member
        /// or
        /// ownerType
        /// </exception>
        public EqualToEntityPropertyValidator(Func<object, object> memberToCompareFunc, MemberInfo member, Type ownerType, bool confirmProperty = true, IEqualityComparer comparer = null)
        {
            if (memberToCompareFunc == null)
            {
                throw new ArgumentNullException("memberToCompareFunc");
            }

            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }

            OwnerType = ownerType;
            m_MemberToCompareFunc = memberToCompareFunc;
            m_MemberToCompareMemberInfo = member;
            m_ConfirmProperty = confirmProperty;
            m_Comparer = comparer;
            m_ValidatorProperties = new ValidatorProperties
                                        {
                                            { Constants.ValidationMessageParameterNames.MEMBER_TO_COMPARE_MEMBER_INFO, m_MemberToCompareMemberInfo },
                                            { Constants.ValidationMessageParameterNames.OWNER_TYPE, ownerType }
                                        };
        }
        /// <summary>
        /// Sets the validator properties.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <returns>The validator properties.</returns>
        public IValidationMessageBuilderParameterSetter SetValidatorProperties(ValidatorProperties properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IEnumerator<KeyValuePair<string, object>> enumerator = properties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                KeyValuePair<string, object> validatorProperty = enumerator.Current;
                SetParameter(validatorProperty.Key, validatorProperty.Value.ToString());
            }

            return this;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreditCardValidator"/> class.
 /// </summary>
 public CreditCardValidator()
 {
     m_ValidatorProperties = new ValidatorProperties();
 }