public StateFullClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory,
     ResourceManager resourceManager, CultureInfo culture,
     IMessageInterpolator userInterpolator, ValidatorMode validatorMode,
     IEntityTypeInspector entityTypeInspector)
     : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector)
 {
 }
Пример #2
0
        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);
        }
Пример #3
0
 public StateFullClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory,
                                       ResourceManager resourceManager, CultureInfo culture,
                                       IMessageInterpolator userInterpolator, ValidatorMode validatorMode,
                                       IEntityTypeInspector entityTypeInspector)
     : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector)
 {
 }
Пример #4
0
 public ValidatorEngine()
 {
     constraintValidatorFactory = Environment.ConstraintValidatorFactory ?? new DefaultConstraintValidatorFactory();
     entityTypeInspector        = new DefaultEntityTypeInspector();
     factory = new StateFullClassValidatorFactory(constraintValidatorFactory, null, null, null, ValidatorMode.UseAttribute,
                                                  entityTypeInspector);
 }
Пример #5
0
 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;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RandomCombinationGenerator"/> class.
        /// </summary>
        public CreateCombinationsService(
            IConstraintValidatorFactory constraintValidatorFactory,
            IRandomCombinationGenerator randomCombinationGenerator)
        {
            ArgumentChecks.AssertNotNull(constraintValidatorFactory, nameof(constraintValidatorFactory));
            ArgumentChecks.AssertNotNull(randomCombinationGenerator, nameof(randomCombinationGenerator));

            this._constraintValidatorFactory = constraintValidatorFactory;
            this._randomCombinationGenerator = randomCombinationGenerator;
        }
 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;
 }
Пример #9
0
 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;
 }
Пример #10
0
            public JITClassValidatorFactory(IConstraintValidatorFactory constraintValidatorFactory,
			                                ResourceManager resourceManager, CultureInfo culture,
			                                IMessageInterpolator userInterpolator, ValidatorMode validatorMode,
			                                IEntityTypeInspector entityTypeInspector)
                : base(constraintValidatorFactory, resourceManager, culture, userInterpolator, validatorMode, entityTypeInspector)
            {
                classMappingFactory = new JITClassMappingFactory();
            }
Пример #11
0
        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);
        }
Пример #12
0
        /// <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);
        }