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)); }
public ValidationProviderResult Validate(object target, ValidationCallContext callContext) { if (!Accepts(target, callContext)) { return(ValidationProviderResult.NotExecuted); } return(DoValidate(target, callContext)); }
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)); }
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); }
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); }
public abstract BrokenRules Validate <T>(T target, ValidationCallContext callContext);
protected abstract ValidationProviderResult DoValidate(object target, ValidationCallContext callContext);
protected abstract bool DoAccepts(object candidate, ValidationCallContext callContext);