public InvalidMessageTransformer(ConstraintValidatorContext constraintContext, ICollection <object> activeTags, System.Type @class, string propertyName, object value, object entity, ValidatorDef validatorDef, DefaultMessageInterpolatorAggregator defaultInterpolator, IMessageInterpolator userInterpolator) { if (constraintContext == null) { throw new ArgumentNullException("constraintContext"); } if (@class == null) { throw new ArgumentNullException("class"); } if (validatorDef == null) { throw new ArgumentNullException("validatorDef"); } if (defaultInterpolator == null) { throw new ArgumentNullException("defaultInterpolator"); } this.constraintContext = constraintContext; this.activeTags = activeTags; this.@class = @class; this.propertyName = propertyName; this.value = value; this.entity = entity; this.validatorDef = validatorDef; this.defaultInterpolator = defaultInterpolator; this.userInterpolator = userInterpolator; }
internal ClassValidator(System.Type clazz, IConstraintValidatorFactory constraintValidatorFactory, IDictionary <System.Type, IClassValidator> childClassValidators, IClassValidatorFactory factory) { if (!clazz.ShouldNeedValidation()) { throw new ArgumentOutOfRangeException("clazz", clazz, "Create a validator for a unsupported type."); } entityType = clazz; this.constraintValidatorFactory = constraintValidatorFactory; this.factory = factory; messageBundle = factory.ResourceManager ?? GetDefaultResourceManager(); defaultMessageBundle = GetDefaultResourceManager(); culture = factory.Culture; userInterpolator = factory.UserInterpolator; if (userInterpolator != null) { userInterpolatorType = factory.UserInterpolator.GetType(); } this.childClassValidators = childClassValidators; validatorMode = factory.ValidatorMode; //Initialize the ClassValidator InitValidator(entityType, childClassValidators); }
public StateFullClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { }
public InvalidMessageTransformer(ConstraintValidatorContext constraintContext, ICollection<object> activeTags, System.Type @class, string propertyName, object value, object entity, ValidatorDef validatorDef, DefaultMessageInterpolatorAggregator defaultInterpolator, IMessageInterpolator userInterpolator) { if (constraintContext == null) { throw new ArgumentNullException("constraintContext"); } if (@class == null) { throw new ArgumentNullException("class"); } if (validatorDef == null) { throw new ArgumentNullException("validatorDef"); } if (defaultInterpolator == null) { throw new ArgumentNullException("defaultInterpolator"); } this.constraintContext = constraintContext; this.activeTags = activeTags; this.@class = @class; this.propertyName = propertyName; this.value = value; this.entity = entity; this.validatorDef = validatorDef; this.defaultInterpolator = defaultInterpolator; this.userInterpolator = userInterpolator; }
public InvalidMessageTransformer(ConstraintValidatorContext constraintContext, List<InvalidValue> results, System.Type @class, string propertyName /* nullable */, object value /* nullable */, object entity /* nullable */, IValidator validator, DefaultMessageInterpolatorAggregator defaultInterpolator, IMessageInterpolator userInterpolator /* nullable */) { if (constraintContext == null) throw new ArgumentNullException("constraintContext"); if (results == null) throw new ArgumentNullException("results"); if (@class == null) throw new ArgumentNullException("class"); if (validator == null) throw new ArgumentNullException("valitor"); if (defaultInterpolator == null) throw new ArgumentNullException("defaultInterpolator"); this.constraintContext = constraintContext; this.results = results; this.@class = @class; this.propertyName = propertyName; this.value = value; this.entity = entity; this.validator = validator; this.defaultInterpolator = defaultInterpolator; this.userInterpolator = userInterpolator; }
public JITClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector) { classMappingFactory = new JITClassMappingFactory(); }
public AbstractClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode) { this.constraintValidatorFactory = constraintValidatorFactory; this.resourceManager = resourceManager; this.culture = culture; this.userInterpolator = userInterpolator; this.validatorMode = validatorMode; }
public InterpolationInfo(System.Type entity, object entityInstance, string propertyName, IValidator validator, IMessageInterpolator defaultInterpolator, string message) { EntityInstance = entityInstance; Validator = validator; DefaultInterpolator = defaultInterpolator; Entity = entity; PropertyName = propertyName; Message = message; }
protected AbstractClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory, ResourceManager resourceManager, CultureInfo culture, IMessageInterpolator userInterpolator, ValidatorMode validatorMode, IEntityTypeInspector entityTypeInspector) { this.constraintValidatorFactory = constraintValidatorFactory; this.resourceManager = resourceManager; this.culture = culture; this.userInterpolator = userInterpolator; this.validatorMode = validatorMode; EntityTypeInspector = entityTypeInspector; }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { if (message.StartsWith("{")) message = message.Substring(1, message.Length - 1); if (message.EndsWith("}")) message = message.Substring(0, message.Length - 1); var validatorMessage = resourceManager.GetString(message) ?? message; return defaultInterpolator.Interpolate(validatorMessage, entity, validator, defaultInterpolator); }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { CheckInitialized(); DefaultMessageInterpolator defaultMessageInterpolator; if (!interpolators.TryGetValue(validator, out defaultMessageInterpolator)) { return message; } return defaultMessageInterpolator.Interpolate(message, entity, validator, defaultInterpolator); }
public ClassValidator(SerializationInfo info, StreamingContext ctxt) { var interpolatorType = (System.Type)info.GetValue("interpolator", typeof(System.Type)); if (interpolatorType != null) { userInterpolator = (IMessageInterpolator)Activator.CreateInstance(interpolatorType); } entityType = (System.Type)info.GetValue("entityType", typeof(System.Type)); entityValidators = (List <ValidatorDef>)info.GetValue("entityValidators", typeof(List <ValidatorDef>)); membersToValidate = (List <Member>)info.GetValue("membersToValidate", typeof(List <Member>)); childClassValidators = (IDictionary <System.Type, IClassValidator>)info.GetValue("childClassValidators", typeof(IDictionary <System.Type, IClassValidator>)); childGetters = (List <MemberInfo>)info.GetValue("childGetters", typeof(List <MemberInfo>)); membersAttributesDictionary = (Dictionary <MemberInfo, List <Attribute> >) info.GetValue("membersAttributesDictionary", typeof(Dictionary <MemberInfo, List <Attribute> >)); defaultMessageBundle = GetDefaultResourceManager(); messageBundle = GetDefaultResourceManager(); culture = CultureInfo.CurrentCulture; defaultInterpolator = (DefaultMessageInterpolatorAggregator)info.GetValue("defaultInterpolator", typeof(DefaultMessageInterpolatorAggregator)); defaultInterpolator.Initialize(messageBundle, defaultMessageBundle, culture); }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { return "prefix_" + defaultInterpolator.Interpolate(message, entity, validator, defaultInterpolator); }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { bool same = attributeMessage.Equals(message); if (same && interpolateMessage != null && !message.Contains("${")) { return interpolateMessage; //short cut } string result; result = Replace(message,entity); if (same) { interpolateMessage = result; //short cut in next iteration } return result; }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { throw new Exception("The method or operation is not implemented."); }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { return message; }
/// <summary> /// Configure NHibernate.Validator using the specified <see cref="INHVConfiguration"/>. /// </summary> /// <param name="config">The <see cref="INHVConfiguration"/> that is the configuration reader to configure NHibernate.Validator.</param> /// <param name="mappingLoader">The <see cref="XmlMappingLoader"/> instance.</param> /// <remarks> /// Calling Configure(INHVConfiguration) will overwrite the values set in app.config or web.config /// </remarks> public virtual void Configure(INHVConfiguration config, IMappingLoader mappingLoader) { if (config == null) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator.", new ArgumentNullException("config")); } Clear(); applyToDDL = PropertiesHelper.GetBoolean(Environment.ApplyToDDL, config.Properties, true); autoRegisterListeners = PropertiesHelper.GetBoolean(Environment.AutoregisterListeners, config.Properties, true); defaultMode = CfgXmlHelper.ValidatorModeConvertFrom(PropertiesHelper.GetString(Environment.ValidatorMode, config.Properties, string.Empty)); interpolator = GetImplementation <IMessageInterpolator>( PropertiesHelper.GetString(Environment.MessageInterpolatorClass, config.Properties, string.Empty), "message interpolator"); if (Environment.ConstraintValidatorFactory == null) { constraintValidatorFactory = GetImplementation <IConstraintValidatorFactory>( PropertiesHelper.GetString(Environment.ConstraintValidatorFactoryClass, config.Properties, string.Empty), "Constraint Validator Factory") ?? new DefaultConstraintValidatorFactory(); } else { constraintValidatorFactory = Environment.ConstraintValidatorFactory; } var inspectorsTypes = new HashSet <System.Type>(config.EntityTypeInspectors) { typeof(DefaultEntityTypeInspector) }; if (inspectorsTypes.Count > 1) { var inspectors = config.EntityTypeInspectors.Select(typeInspector => Instatiate <IEntityTypeInspector>(typeInspector)).ToArray(); entityTypeInspector = new MultiEntityTypeInspector(inspectors); } else { entityTypeInspector = new DefaultEntityTypeInspector(); } ResourceManager customResourceManager = null; var customResourceManagerBaseName = PropertiesHelper.GetString(Environment.CustomResourceManager, config.Properties, null); if (!string.IsNullOrEmpty(customResourceManagerBaseName)) { var resourceAndAssembly = TypeNameParser.Parse(customResourceManagerBaseName); try { var assembly = Assembly.Load(resourceAndAssembly.Assembly); customResourceManager = new ResourceManager(resourceAndAssembly.Type, assembly); } catch (Exception e) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator (custom resource manager).", e); } } factory = new StateFullClassValidatorFactory(constraintValidatorFactory, customResourceManager, null, interpolator, defaultMode, entityTypeInspector); // UpLoad Mappings if (mappingLoader == null) { // Configured or Default loader (XmlMappingLoader) mappingLoader = GetImplementation <IMappingLoader>( PropertiesHelper.GetString(Environment.MappingLoaderClass, config.Properties, string.Empty), "mapping loader") ?? new XmlMappingLoader(); } mappingLoader.LoadMappings(config.Mappings); Initialize(mappingLoader); }
public string Interpolate(string message, object entity, IValidator validator, IMessageInterpolator defaultInterpolator) { throw new NotImplementedException(); }
/// <summary> /// Create the validator engine for a particular entity class, using a resource bundle /// for message rendering on violation /// </summary> /// <remarks> /// Used in Unit Testing. /// </remarks> /// <param name="entityType">entity type</param> /// <param name="resourceManager"></param> /// <param name="userInterpolator">Custom interpolator.</param> /// <param name="culture">The CultureInfo for the <paramref name="entityType"/>.</param> /// <param name="validatorMode">Validator definition mode</param> public ClassValidator(System.Type entityType, ResourceManager resourceManager, IMessageInterpolator userInterpolator, CultureInfo culture, ValidatorMode validatorMode) : this( entityType, new DefaultConstraintValidatorFactory(), new Dictionary <System.Type, IClassValidator>(), new JITClassValidatorFactory(new DefaultConstraintValidatorFactory(), resourceManager, culture, userInterpolator, validatorMode, new DefaultEntityTypeInspector())) { }
internal ClassValidator(System.Type clazz, IConstraintValidatorFactory constraintValidatorFactory, IDictionary<System.Type, IClassValidator> childClassValidators, IClassValidatorFactory factory) { if (!clazz.ShouldNeedValidation()) { throw new ArgumentOutOfRangeException("clazz", clazz, "Create a validator for a unsupported type."); } entityType = clazz; this.constraintValidatorFactory = constraintValidatorFactory; this.factory = factory; messageBundle = factory.ResourceManager ?? GetDefaultResourceManager(); defaultMessageBundle = GetDefaultResourceManager(); culture = factory.Culture; userInterpolator = factory.UserInterpolator; if (userInterpolator != null) { userInterpolatorType = factory.UserInterpolator.GetType(); } this.childClassValidators = childClassValidators; validatorMode = factory.ValidatorMode; //Initialize the ClassValidator InitValidator(entityType, childClassValidators); }
public ClassValidator(SerializationInfo info, StreamingContext ctxt) { var interpolatorType = (System.Type)info.GetValue("interpolator", typeof(System.Type)); if(interpolatorType != null) userInterpolator = (IMessageInterpolator)Activator.CreateInstance(interpolatorType); entityType = (System.Type)info.GetValue("entityType", typeof(System.Type)); entityValidators = (List<ValidatorDef>)info.GetValue("entityValidators", typeof(List<ValidatorDef>)); membersToValidate = (List<Member>)info.GetValue("membersToValidate", typeof(List<Member>)); childClassValidators = (IDictionary<System.Type, IClassValidator>)info.GetValue("childClassValidators", typeof(IDictionary<System.Type, IClassValidator>)); childGetters = (List<MemberInfo>)info.GetValue("childGetters", typeof(List<MemberInfo>)); membersAttributesDictionary = (Dictionary<MemberInfo, List<Attribute>>) info.GetValue("membersAttributesDictionary", typeof (Dictionary<MemberInfo, List<Attribute>>)); defaultMessageBundle = GetDefaultResourceManager(); messageBundle = GetDefaultResourceManager(); culture = CultureInfo.CurrentCulture; defaultInterpolator = (DefaultMessageInterpolatorAggregator)info.GetValue("defaultInterpolator", typeof(DefaultMessageInterpolatorAggregator)); defaultInterpolator.Initialize(messageBundle,defaultMessageBundle,culture); }
/// <summary> /// Create the validator engine for a particular entity class, using a resource bundle /// for message rendering on violation /// </summary> /// <remarks> /// Used in Unit Testing. /// </remarks> /// <param name="entityType">entity type</param> /// <param name="resourceManager"></param> /// <param name="userInterpolator">Custom interpolator.</param> /// <param name="culture">The CultureInfo for the <paramref name="entityType"/>.</param> /// <param name="validatorMode">Validator definition mode</param> public ClassValidator(System.Type entityType, ResourceManager resourceManager, IMessageInterpolator userInterpolator, CultureInfo culture, ValidatorMode validatorMode) : this(entityType, new DefaultConstraintValidatorFactory(), new Dictionary<System.Type, IClassValidator>(), new JITClassValidatorFactory(new DefaultConstraintValidatorFactory(), resourceManager, culture, userInterpolator, validatorMode, new DefaultEntityTypeInspector())) { }