Esempio n. 1
0
        public ValidationRuleSet GetRuleSet(Type domainClass)
        {
            var ruleSetNodes = FindRulesetNodes(domainClass.FullName);

            // return a single rule set that combines all rule sets
            return(ValidationRuleSet.Add(CollectionUtils.Map <XmlElement, ValidationRuleSet>(ruleSetNodes, CompileRuleset)));
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the specified domain object, ignoring any rules that do not satisfy the filter.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="level"></param>
        /// <param name="ruleFilter"></param>
        /// <exception cref="EntityValidationException">Validation failed.</exception>
        private void Validate(DomainObject obj, RuleLevel level, Predicate <ISpecification> ruleFilter)
        {
            var domainClass = obj.GetClass();

            var ruleSets = new List <ISpecification>();

            if (CheckLevel(level, RuleLevel.Low))
            {
                // first check for a cached rule-set
                ValidationRuleSet lowLevelRules;
                if (!_lowLevelRuleSets.TryGetValue(domainClass, out lowLevelRules))
                {
                    // otherwise build it
                    lowLevelRules = IsValidationEnabled(domainClass) ?
                                    ValidationRuleSetCache.GetLowLevelRules(domainClass)
                                                : new ValidationRuleSet();

                    // cache for future use
                    _lowLevelRuleSets.Add(domainClass, lowLevelRules);
                }
                ruleSets.Add(lowLevelRules);
            }

            if (CheckLevel(level, RuleLevel.High))
            {
                // first check for a cached rule-set
                ValidationRuleSet highLevelRules;
                if (!_highLevelRuleSets.TryGetValue(domainClass, out highLevelRules))
                {
                    // otherwise build it
                    highLevelRules = IsValidationEnabled(domainClass) ?
                                     ValidationRuleSetCache.GetHighLevelRules(domainClass)
                                                : new ValidationRuleSet();

                    // cache for future use
                    _highLevelRuleSets.Add(domainClass, highLevelRules);
                }
                ruleSets.Add(highLevelRules);
            }

            var rules  = new ValidationRuleSet(ruleSets);
            var result = rules.Test(obj, ruleFilter);

            if (result.Fail)
            {
                var message = string.Format(SR.ExceptionInvalidEntity, TerminologyTranslator.Translate(obj.GetClass()));
                throw new EntityValidationException(message, result.Reasons);
            }
        }
Esempio n. 3
0
 internal EmbeddedValueRuleSet(PropertyInfo property, ValidationRuleSet innerRules, bool collection)
     : base(property)
 {
     _innerRules = innerRules;
     _collection = collection;
 }
Esempio n. 4
0
		/// <summary>
		/// Validates the specified domain object, ignoring any rules that do not satisfy the filter.
		/// </summary>
		/// <param name="obj"></param>
		/// <param name="level"></param>
		/// <param name="ruleFilter"></param>
		/// <exception cref="EntityValidationException">Validation failed.</exception>
		private void Validate(DomainObject obj, RuleLevel level, Predicate<ISpecification> ruleFilter)
		{
			var domainClass = obj.GetClass();

			var ruleSets = new List<ISpecification>();

			if (CheckLevel(level, RuleLevel.Low))
			{
				// first check for a cached rule-set
				ValidationRuleSet lowLevelRules;
				if (!_lowLevelRuleSets.TryGetValue(domainClass, out lowLevelRules))
				{
					// otherwise build it
					lowLevelRules = IsValidationEnabled(domainClass) ?
						ValidationRuleSetCache.GetLowLevelRules(domainClass)
						: new ValidationRuleSet();

					// cache for future use
					_lowLevelRuleSets.Add(domainClass, lowLevelRules);
				}
				ruleSets.Add(lowLevelRules);
			}

			if (CheckLevel(level, RuleLevel.High))
			{
				// first check for a cached rule-set
				ValidationRuleSet highLevelRules;
				if (!_highLevelRuleSets.TryGetValue(domainClass, out highLevelRules))
				{
					// otherwise build it
						highLevelRules = IsValidationEnabled(domainClass) ?
							ValidationRuleSetCache.GetHighLevelRules(domainClass)
						: new ValidationRuleSet();

						// cache for future use
						_highLevelRuleSets.Add(domainClass, highLevelRules);
					}
					ruleSets.Add(highLevelRules);
				}

			var rules = new ValidationRuleSet(ruleSets);
			var result = rules.Test(obj, ruleFilter);
			if (result.Fail)
			{
				var message = string.Format(SR.ExceptionInvalidEntity, TerminologyTranslator.Translate(obj.GetClass()));
				throw new EntityValidationException(message, result.Reasons);
			}
		}
		internal EmbeddedValueRuleSet(PropertyInfo property, ValidationRuleSet innerRules, bool collection)
			:base(property)
		{
			_innerRules = innerRules;
			_collection = collection;
		}
Esempio n. 6
0
 /// <summary>
 /// Returns a new rule set representing the addition of this rule set and the other.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public ValidationRuleSet Add(ValidationRuleSet other)
 {
     return(new ValidationRuleSet(new[] { this, other }));
 }
Esempio n. 7
0
		/// <summary>
		/// Returns a new rule set representing the addition of this rule set and the other.
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public ValidationRuleSet Add(ValidationRuleSet other)
		{
			return new ValidationRuleSet(new[] { this, other });
		}