Ejemplo n.º 1
0
        public ValidationCollectorMergeResult Merge(IEnumerable <IEnumerable <ValidationCollectorInfo> > validationCollectorInfos)
        {
            ArgumentUtility.CheckNotNull("validationCollectorInfos", validationCollectorInfos);

            var collectorInfos = validationCollectorInfos.ToArray();

            var beforeMergeLog = string.Empty;

            if (_logger.IsInfoEnabled())
            {
                beforeMergeLog = GetLogBefore(collectorInfos);
            }

            var validationCollectorMergeResult = _validationCollectorMerger.Merge(collectorInfos);

            var afterMergeLog = string.Empty;

            if (_logger.IsInfoEnabled())
            {
                afterMergeLog = GetLogAfter(validationCollectorMergeResult.CollectedRules, validationCollectorMergeResult.LogContext);
            }

            if (_logger.IsInfoEnabled())
            {
                //"after"-output provides better initial diagnostics.
                //"before"-output is usually only analyzed when the problem is not obvious from the "after"-output.
                _logger.Info(afterMergeLog);
                _logger.Info(beforeMergeLog);
            }

            return(validationCollectorMergeResult);
        }
Ejemplo n.º 2
0
        public IValidator BuildValidator(Type validatedType)
        {
            ArgumentUtility.CheckNotNull("validatedType", validatedType);

            var allCollectors = _validationCollectorProvider.GetValidationCollectors(new[] { validatedType }).Select(c => c.ToArray()).ToArray();

            ValidateCollectors(allCollectors.SelectMany(c => c));
            var validationCollectorMergeResult = _validationCollectorMerger.Merge(allCollectors);

            ValidateMetaRules(allCollectors, validationCollectorMergeResult.CollectedRules);

            ApplyTechnicalPropertyNames(validationCollectorMergeResult.CollectedRules.OfType <PropertyRule>());
            ApplyLocalization(validationCollectorMergeResult.CollectedRules, validatedType);

            return(new Validator(validationCollectorMergeResult.CollectedRules, validatedType));
        }