public RuleValidationResult Validate(object message)
        {
            var result = new RuleValidationResult();
            Type validatorType = typeof (AbstractValidator<>).MakeGenericType(message.GetType());
            var validator = (IValidator) ServiceLocator.Current.GetInstance(validatorType);
            ValidationResult validationResult = validator.Validate(message);

            if (!validationResult.IsValid)
            {
                foreach (ValidationFailure error in validationResult.Errors)
                {
                    var failure = new RuleValidationFailure(error.ErrorMessage, error.PropertyName);
                    result.AddValidationFailure(failure);
                }
            }

            return result;
        }
Example #2
0
        public RuleValidationResult AssociateResults(RuleValidationResult ruleValidationResult, ConversionResult conversionResult)
        {
            RuleValidationResult result = ruleValidationResult;

            if (conversionResult.AssociationConfiguration != null && !ruleValidationResult.IsValid)
            {
                var mappedMessageValidationResult = new RuleValidationResult();

                // translate properties
                foreach (RuleValidationFailure failure in ruleValidationResult.Failures)
                {
                    string originalPropertyName =
                        conversionResult.AssociationConfiguration.GetSourcePropertyNameFor(failure.PropertyName);
                    mappedMessageValidationResult.AddValidationFailure(new RuleValidationFailure(failure.Message,
                                                                                             originalPropertyName));
                    result = mappedMessageValidationResult;
                }
            }

            return result;
        }