public override BrokenRules Validate <T>(T target, ValidationCallContext callContext)
        {
            callContext = callContext ?? ValidationCallContext.AllRules;

            LogValidationRequested(target, callContext);
            ICollection <IValidationProvider <T> > providers = GetValidationProviders <T>();

            LogValidatorsAboutToBeApplied(providers, target);

            var    results       = new List <BrokenRules>();
            double totalDuration = 0d;

            foreach (IValidationProvider <T> provider in providers)
            {
                double duration;
                ValidationProviderResult result = ExecuteValidation(target, callContext, provider, out duration);
                totalDuration += duration;
                LogBrokenRules(result, provider);
                results.Add(result.BrokenRules);
                if (!result.BrokenRules.IsValid && StopOnFirstBrokenRules)
                {
                    break;
                }
            }

            LogValidationFinished(totalDuration);
            return(BrokenRules.Merge(results));
        }
Beispiel #2
0
        public ValidationProviderResult Validate(object target, ValidationCallContext callContext)
        {
            if (!Accepts(target, callContext))
            {
                return(ValidationProviderResult.NotExecuted);
            }

            return(DoValidate(target, callContext));
        }
Beispiel #3
0
        public bool Accepts(object candidate, ValidationCallContext callContext)
        {
            Check.Require(() => Demand.The.Param(() => callContext).IsNotNull());

            if (ReferenceEquals(candidate, null) || !callContext.IsAtLeastOneRulesetInScope(Rulesets))
            {
                return(false);
            }

            return(DoAccepts(candidate, callContext));
        }
Beispiel #4
0
        public override BrokenRules Validate <T>(T target, ValidationCallContext callContext)
        {
            BrokenRules result = BrokenRules.None;

            foreach (var runner in _runners)
            {
                result = BrokenRules.Merge(new[] { result, runner.Validate(target, callContext) });
                if (StopOnFirstBrokenRules)
                {
                    break;
                }
            }
            return(result);
        }
        private ValidationProviderResult ExecuteValidation <T>(T target,
                                                               ValidationCallContext callContext,
                                                               IValidationProvider <T> validator,
                                                               out double duration)
        {
            ValidationProviderResult result = null;

            duration = With.PerformanceCounter(() => {
                result = validator.Validate(target, callContext);
            }) * 1000;
            Logger.DebugFormat("Validator '{0}' executed in '{1}ms'", validator, duration);
            if (PerformanceThresholds.IndividualValidatorInMilliseconds > 0 &&
                PerformanceThresholds.IndividualValidatorInMilliseconds < duration)
            {
                Logger.WarnFormat(
                    "Performance of validator '{0}' exceeds threshold; threshold: '{1}ms', actual: '{2}ms'",
                    validator,
                    PerformanceThresholds.IndividualValidatorInMilliseconds,
                    duration);
            }
            return(result);
        }
Beispiel #6
0
 protected void LogValidationRequested <T>(T target, ValidationCallContext callContext)
 {
     Logger.InfoFormat("Validation requested for: {0}", target);
     Logger.InfoFormat("Validation call context supplied: {0}", callContext);
     Logger.InfoFormat("Validation runner 'StopOnFirstBrokenRules': {0}", StopOnFirstBrokenRules);
 }
Beispiel #7
0
 public abstract BrokenRules Validate <T>(T target, ValidationCallContext callContext);
Beispiel #8
0
 protected abstract ValidationProviderResult DoValidate(object target, ValidationCallContext callContext);
Beispiel #9
0
 protected abstract bool DoAccepts(object candidate, ValidationCallContext callContext);