Ejemplo n.º 1
0
        private void ProcessEmbeddedValueAttribute(PropertyInfo property, Attribute attr)
        {
            var innerBuiler = new ValidationBuilder(property.PropertyType);

            if (innerBuiler.LowLevelRules.Rules.Count > 0)
            {
                _lowLevelRules.Add(new EmbeddedValueRuleSet(property, new ValidationRuleSet(innerBuiler.LowLevelRules.Rules), false));
            }
        }
Ejemplo n.º 2
0
        private void ProcessEmbeddedValueCollectionAttribute(PropertyInfo property, Attribute attr)
        {
            var ca          = (EmbeddedValueCollectionAttribute)attr;
            var innerBuiler = new ValidationBuilder(ca.ElementType);

            if (innerBuiler.LowLevelRules.Rules.Count > 0)
            {
                _lowLevelRules.Add(new EmbeddedValueRuleSet(property, new ValidationRuleSet(innerBuiler.LowLevelRules.Rules), true));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the high-level rule-set, which may include both hard-coded high-level rules,
        /// and custom rules specified in XML.
        /// </summary>
        /// <param name="domainClass"></param>
        /// <returns></returns>
        internal static ValidationRuleSet GetHighLevelRules(Type domainClass)
        {
            // get the static rules
            var builder     = new ValidationBuilder(domainClass);
            var staticRules = builder.HighLevelRules;

            // get the custom rules
            // Because custom rules may potentially be modified by an administrator,
            // they are cached using the Cache object with an absolute expiry time,
            // which should be relatively short (a few minutes).
            // This ensures that changes made to these rules will be applied eventually, when the cache expires.
            ValidationRuleSet customRules;

            if (Cache.IsSupported())
            {
                using (var cacheClient = Cache.CreateClient(CacheId))
                {
                    // check the cache for a compiled ruleset
                    customRules = (ValidationRuleSet)cacheClient.Get(domainClass.FullName, new CacheGetOptions(CacheRegion));
                    if (customRules == null)
                    {
                        // no cached, so compile the ruleset from source
                        customRules = BuildCustomRules(domainClass);

                        // cache the ruleset if desired
                        var settings = new EntityValidationSettings();
                        var ttl      = TimeSpan.FromSeconds(settings.CustomRulesCachingTimeToLiveSeconds);
                        if (ttl > TimeSpan.Zero)
                        {
                            cacheClient.Put(domainClass.FullName, customRules, new CachePutOptions(CacheRegion, ttl, false));
                        }
                    }
                }
            }
            else
            {
                // if the Cache object is not available in this environment, then we have no choice but to build from source
                Platform.Log(LogLevel.Warn, "Caching of custom rules is not supported in this configuration - rules are being compiled from source.");
                customRules = BuildCustomRules(domainClass);
            }
            return(new ValidationRuleSet(new[] { staticRules, customRules }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the low-level rule-set (rules for things like required fields, unique constraints, field lengths).
        /// </summary>
        /// <param name="domainClass"></param>
        /// <returns></returns>
        internal static ValidationRuleSet GetLowLevelRules(Type domainClass)
        {
            lock (_lowLevelRuleSets)
            {
                ValidationRuleSet rules;

                // return cached rules if possible
                if (_lowLevelRuleSets.TryGetValue(domainClass, out rules))
                {
                    return(rules);
                }

                // build rules for domainClass
                var builder = new ValidationBuilder(domainClass);
                rules = builder.LowLevelRules;

                // cache for future use
                _lowLevelRuleSets.Add(domainClass, rules);
                return(rules);
            }
        }
Ejemplo n.º 5
0
		private void ProcessEmbeddedValueCollectionAttribute(PropertyInfo property, Attribute attr)
		{
			var ca = (EmbeddedValueCollectionAttribute)attr;
			var innerBuiler = new ValidationBuilder(ca.ElementType);

			if (innerBuiler.LowLevelRules.Rules.Count > 0)
			{
				_lowLevelRules.Add(new EmbeddedValueRuleSet(property, new ValidationRuleSet(innerBuiler.LowLevelRules.Rules), true));
			}
		}
Ejemplo n.º 6
0
		private void ProcessEmbeddedValueAttribute(PropertyInfo property, Attribute attr)
		{
			var innerBuiler = new ValidationBuilder(property.PropertyType);
			if (innerBuiler.LowLevelRules.Rules.Count > 0)
			{
				_lowLevelRules.Add(new EmbeddedValueRuleSet(property, new ValidationRuleSet(innerBuiler.LowLevelRules.Rules), false));
			}
		}