Esempio n. 1
0
        private static bool IsChangeSetPublishable(DomainObject domainObject)
        {
            // ignore changes to enum values for now
            // TODO: should probably record changes to enum values
            if (domainObject is EnumValue)
            {
                return(false);
            }

            // check for an attribute - if no attribute, then default is publishable
            var a = AttributeUtils.GetAttribute <PublishInChangeSetsAttribute>(domainObject.GetClass(), true);

            return(a == null || a.IsPublishable);
        }
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
 protected virtual string GetMessage(DomainObject obj)
 {
     return(string.Format(SR.RuleUniqueKey, TerminologyTranslator.Translate(obj.GetClass(), _logicalKeyName),
                          TerminologyTranslator.Translate(_entityClass)));
 }
		protected virtual string GetMessage(DomainObject obj)
		{
			return string.Format(SR.RuleUniqueKey, TerminologyTranslator.Translate(obj.GetClass(), _logicalKeyName),
				TerminologyTranslator.Translate(_entityClass));
		}
Esempio n. 5
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);
			}
		}