// Covers everything VisitSimpleType does not i.e. both enumerations and complex types. private bool VisitComplexType(IValidationStrategy defaultStrategy) { var isValid = true; if (_model != null && _metadata.ValidateChildren) { var strategy = _strategy ?? defaultStrategy; isValid = VisitChildren(strategy); } else if (_model != null) { // Suppress validation for the entries matching this prefix. This will temporarily set // the current node to 'skipped' but we're going to visit it right away, so subsequent // code will set it to 'valid' or 'invalid' SuppressValidation(_key); } // Double-checking HasReachedMaxErrors just in case this model has no properties. if (isValid && !_modelState.HasReachedMaxErrors) { isValid &= ValidateNode(); } return(isValid); }
private bool VisitChildren(IValidationStrategy strategy) { var isValid = true; var enumerator = strategy.GetChildren(_metadata, _key, _model); while (enumerator.MoveNext()) { var metadata = enumerator.Current.Metadata; var model = enumerator.Current.Model; var key = enumerator.Current.Key; // Detached: Do not recursively validate associated properties. bool skip = false; if (metadata.MetadataKind == Metadata.ModelMetadataKind.Property) { PropertyInfo propInfo = _metadata.ModelType.GetRuntimeProperty(enumerator.Current.Metadata.PropertyName); if (propInfo != null) { skip = propInfo.GetCustomAttribute <AssociatedAttribute>() != null || propInfo.GetCustomAttribute <ManyToManyAttribute>() != null; } } // if (!skip) { isValid &= Visit(metadata, key, model); } } return(isValid); }
public void ProcessUploadedFile(IFormFile file, ValidFileTypes fileType) { if (file == null || file.Length < 0) { throw new FileUploadException("No file found"); } string fileExtention = Path.GetExtension(file.FileName); IValidationStrategy validationStrategy = _validationFactory.Make(fileType); ValidationDTO validationDto = validationStrategy.ValidationStrategy(file); if (!validationDto.ValidMimeTypes.Contains(file.ContentType, StringComparer.OrdinalIgnoreCase)) { throw new FileUploadException("Invalid file type"); } if (!validationDto.ValidExtentions.Contains(fileExtention, StringComparer.OrdinalIgnoreCase)) { throw new FileUploadException("Invalid file type"); } if (file.Length > validationDto.MaxFileSize) { throw new FileUploadException("File size to large"); } }
// Covers everything VisitSimpleType does not i.e. both enumerations and complex types. protected virtual bool VisitComplexType(IValidationStrategy defaultStrategy) { var isValid = true; if (Model != null && Metadata.ValidateChildren) { var strategy = Strategy ?? defaultStrategy; isValid = VisitChildren(strategy); } else if (Model != null) { // Suppress validation for the entries matching this prefix. This will temporarily set // the current node to 'skipped' but we're going to visit it right away, so subsequent // code will set it to 'valid' or 'invalid' SuppressValidation(Key); } // Double-checking HasReachedMaxErrors just in case this model has no properties. // If validation has failed for any children, only validate the parent if ValidateComplexTypesIfChildValidationFails is true. if ((isValid || ValidateComplexTypesIfChildValidationFails) && !ModelState.HasReachedMaxErrors) { isValid &= ValidateNode(); } return(isValid); }
protected override bool VisitComplexType(IValidationStrategy defaultStrategy) { if (SkipValidations.Any(v => v.SkipValidation(Model))) { return(true); } return(base.VisitComplexType(defaultStrategy)); }
public IFluentValidationRegistrar AndForStrategy <T>(IValidationStrategy <T> strategy, string name, StrategyMode mode = StrategyMode.OverallOverwrite) { //step 1: build this register BuildMySelf(); //step 2: create a new register return(_parentRegistrar.AndForStrategy(strategy, name, mode)); }
// Covers everything VisitSimpleType does not i.e. both enumerations and complex types. protected virtual bool VisitComplexType(IValidationStrategy defaultStrategy) { var isValid = true; if (Model != null && Metadata !.ValidateChildren) { var strategy = Strategy ?? defaultStrategy; isValid = VisitChildren(strategy); }
public IFluentValidationRegistrar AndForStrategy(IValidationStrategy strategy, StrategyMode mode = StrategyMode.OverallOverwrite) { //step 1: build this register BuildMySelf(); //step 2: create a new register _parentRegistrar.ForStrategy(strategy, mode); return(this); }
public StrategyValidator(IValidationStrategy strategy) { if (strategy is null) { throw new ArgumentNullException(nameof(strategy)); } Handler = ValidationHandler.CreateByStrategy(strategy); Name = $"Strategy Validator for '{strategy.GetType().GetFriendlyName()}'"; }
public EditUserDataAndContactsCommand(IMongoCollection <User> userRepo, IMongoCollection <Account> accountRepo, IValidationStrategy <CreateUserModel> validationStrategy, ILogger logger) { _userRepo = userRepo; _accountRepo = accountRepo; _validationStrategy = validationStrategy; _logger = logger; }
/// <summary> /// Initialize a new <see cref="StateManager"/>. /// </summary> /// <param name="visitor">The visitor.</param> /// <param name="newModel">The model to validate.</param> public StateManager(ValidationVisitor visitor, object newModel) { _visitor = visitor; _container = _visitor.Container; _key = _visitor.Key; _metadata = _visitor.Metadata; _model = _visitor.Model; _strategy = _visitor.Strategy; }
public InvoiceBO(IValidationStrategy <Invoice> validate, IDomesticTaxCalculation <Invoice, Tax, InvoiceTax> calculateDomesticTax, IInternationalTaxCalculation <Invoice, Tax, InvoiceTax> calculateInternationalTax, IInvoiceRetriever <Invoice> invoiceRetriever, ITaxService <Tax> taxService, Dictionary <string, string> serviceSources) { _ValidationType = validate; _CalculateDomesticTax = calculateDomesticTax; _CalculateInternationalTax = calculateInternationalTax; _InvoiceRetriever = invoiceRetriever; _TaxService = taxService; _InvoiceSource = serviceSources["InvoiceFilePath"]; _TaxSource = serviceSources["TaxRatesFilePath"]; }
protected override bool VisitChildren(IValidationStrategy strategy) { // If validting a collection property skip validation if validate children is off. if (!ValidateChildren && Metadata.ValidateChildren && Metadata.IsCollectionType && Metadata.MetadataKind == ModelMetadataKind.Property) { return(true); } return(base.VisitChildren(strategy)); }
public StateManager(DetachedValidationVisitor visitor, object newModel) { _visitor = visitor; _newModel = newModel; _container = _visitor._container; _key = _visitor._key; _metadata = _visitor._metadata; _model = _visitor._model; _strategy = _visitor._strategy; }
protected override bool VisitComplexType(IValidationStrategy defaultStrategy) { bool?customValidate = SignumValidate(); if (customValidate.HasValue) { return(customValidate.Value); } return(base.VisitComplexType(defaultStrategy)); }
public CreateAccountCommand(IMongoCollection <Account> accountRepo, IEmailConfirmationStrategy emailConfirmationStrategy, IPasswordSetStrategy passwordSetStrategy, IValidationStrategy <AccountModel> newAccountValidationStrategy, ILogger logger) { _accountRepo = accountRepo; _emailConfirmationStrategy = emailConfirmationStrategy; _passwordSetStrategy = passwordSetStrategy; _newAccountValidationStrategy = newAccountValidationStrategy; _logger = logger; }
public ChangeAccountEmailCommand(IMongoCollection <Account> accountRepo, IMongoCollection <EmailChangeRecord> emailChangeRecordRepo, IValidationStrategy <ChangeEmailModel> validationStrategy, IEmailConfirmationStrategy emailConfirmationStrategy, ILogger logger) { _accountRepo = accountRepo; _emailChangeRecordRepo = emailChangeRecordRepo; _validationStrategy = validationStrategy; _emailConfirmationStrategy = emailConfirmationStrategy; _logger = logger; }
public CreateUserCommand(IMongoCollection <User> userRepo, IMongoCollection <Account> accountRepo, IMongoCollection <Role> roleRepo, IValidationStrategy <CreateUserModel> newUserValidationStrategy, ILogger logger) { _newUserValidationStrategy = newUserValidationStrategy; _logger = logger; _userRepo = userRepo; _accountRepo = accountRepo; _roleRepo = roleRepo; }
public ChangeAccountPasswordCommand(IMongoCollection <Account> accountRepo, IValidationStrategy <PasswordChangeModel> validationStrategy, ISecretHashHelper secretHashHelper, ISecretGenerator passwordSaltGenerator, ILogger logger) { _accountRepo = accountRepo; _validationStrategy = validationStrategy; _secretHashHelper = secretHashHelper; _passwordSaltGenerator = passwordSaltGenerator; _logger = logger; }
public BooksController( IGetBooksStrategy getBooksStrategy, IGetBookStrategy getBookStrategy, ICreateBookStrategy createBookStrategy, IUpdateBookStrategy updateBookStrategy, IDeleteBookStrategy deleteBookStrategy, IValidationStrategy bookValidationStrategy) { this.getBooksStrategy = getBooksStrategy; this.getBookStrategy = getBookStrategy; this.createBookStrategy = createBookStrategy; this.updateBookStrategy = updateBookStrategy; this.deleteBookStrategy = deleteBookStrategy; this.bookValidationStrategy = bookValidationStrategy; }
private bool VisitChildren(IValidationStrategy strategy) { var isValid = true; var enumerator = strategy.GetChildren(_metadata, _key, _model); while (enumerator.MoveNext()) { var metadata = enumerator.Current.Metadata; var model = enumerator.Current.Model; var key = enumerator.Current.Key; isValid &= Visit(metadata, key, model); } return(isValid); }
public static StateManager Recurse( ValidationVisitor visitor, string key, ModelMetadata metadata, object model, IValidationStrategy strategy) { var recursifier = new StateManager(visitor, model); visitor._container = visitor._model; visitor._key = key; visitor._metadata = metadata; visitor._model = model; visitor._strategy = strategy; return(recursifier); }
public void SetStrategy(string processType) { if (processType.Equals(ProcessTypeConst.CancelCreditShell)) { ValidationStrategy = _validationFactory.GetValidationStrategy <RefundOriginalPaymentValidationStrategy>(_validationFactory); } else if (processType.Equals(ProcessTypeConst.AgencyCancelAndAddPayment)) { // } else if (processType.Equals(ProcessTypeConst.CreateVoluntary)) { // } else if (processType.Equals(ProcessTypeConst.PROCLI)) { // } }
protected override bool VisitChildren(IValidationStrategy strategy) { // If validting a collection property skip validation if validate children is off. // However we can't actually skip it here as otherwise this will affect DataAnnotaitons validation too. // Instead store a list of objects to skip in the context, which the validator will check later. if (!ValidateChildren && Metadata.ValidateChildren && Metadata.IsCollectionType && Metadata.MetadataKind == ModelMetadataKind.Property) { var skip = Context.HttpContext.Items.ContainsKey("_FV_SKIP") ? Context.HttpContext.Items["_FV_SKIP"] as HashSet <object> : null; if (skip == null) { skip = new HashSet <object>(); Context.HttpContext.Items["_FV_SKIP"] = skip; } skip.Add(Model); } return(base.VisitChildren(strategy)); }
private bool VisitComplexType(IValidationStrategy defaultStrategy) { var isValid = true; if (_model != null && _metadata.ValidateChildren) { var strategy = _strategy ?? defaultStrategy; isValid = VisitChildren(strategy); } else if (_model != null) { SuppressValidation(_key); } if (isValid && !_modelState.HasReachedMaxErrors) { isValid &= ValidateNode(); } return(isValid); }
public GameService(GameModuleCollection gameModules, IUserService userService, IBonusService bonusService, IPayoutService payoutService, IGameHistoryService gameHistoryService, IGameTransactionService transactionService, IDistributedCache cache, CachedSettings cachedSettings, IValidationStrategy validator, ILogger <GameService> logger) { this.gameModules = gameModules; this.userService = userService; this.bonusService = bonusService; this.payoutService = payoutService; this.gameHistoryService = gameHistoryService; this.transactionService = transactionService; this.cache = cache; this.cachedSettings = cachedSettings; this.validator = validator; this.logger = logger; }
private bool VisitChildren(IValidationStrategy strategy) { var isValid = true; var enumerator = strategy.GetChildren(_metadata, _key, _model); var parentEntry = new ValidationEntry(_metadata, _key, _model); while (enumerator.MoveNext()) { var entry = enumerator.Current; var metadata = entry.Metadata; var key = entry.Key; if (metadata.PropertyValidationFilter?.ShouldValidateEntry(entry, parentEntry) == false) { SuppressValidation(key); continue; } isValid &= Visit(metadata, key, entry.Model); } return(isValid); }
public void RegisterStrategy <T>(IValidationStrategy strategy) { if (strategy == null) { throw new ArgumentException(); } Type type = typeof(T); if (Strategies.ContainsKey(type)) { if (Strategies[type].Any(str => str.GetType() == strategy.GetType())) { throw new DuplicateStrategyException(); } } else { Strategies.Add(type, new List <IValidationStrategy>()); } Strategies[type].Add(strategy); }
public ValidationContext AddValidationStrategy(IValidationStrategy validationStrategy) { Validators.Add(validationStrategy); return(this); }
public StateManager(ValidationVisitor visitor, object newModel) { _visitor = visitor; _newModel = newModel; _container = _visitor._container; _key = _visitor._key; _metadata = _visitor._metadata; _model = _visitor._model; _strategy = _visitor._strategy; }
public Customer(IValidationStrategy<ICustomer> obj) : base(obj) { }
public static StateManager Recurse( ValidationVisitor visitor, string key, ModelMetadata metadata, object model, IValidationStrategy strategy) { var recursifier = new StateManager(visitor, model); visitor._container = visitor._model; visitor._key = key; visitor._metadata = metadata; visitor._model = model; visitor._strategy = strategy; return recursifier; }
private bool VisitChildren(IValidationStrategy strategy) { var isValid = true; var enumerator = strategy.GetChildren(_metadata, _key, _model); while (enumerator.MoveNext()) { var metadata = enumerator.Current.Metadata; var model = enumerator.Current.Model; var key = enumerator.Current.Key; isValid &= Visit(metadata, key, model); } return isValid; }
public CreateRoleCommand(IMongoCollection <Role> roleRepo, IValidationStrategy <RoleCreateModel> validationStrategy, ILogger logger) { _roleRepo = roleRepo; _validationStrategy = validationStrategy; _logger = logger; }
public CustomerBase(IValidationStrategy<ICustomer> _Validate) { _ValidationType = _Validate; }
public CSharpCompiler(IValidationStrategy strategy) { this.strategy = strategy; }
public CustomerBase(IValidationStrategy<ICustomer> validate) { ValidationType = validate; }
public HeroValidator(List<IHero> heroes, GameTypes gameType) { this.Heroes = heroes; this.GameType = gameType; this.Validator = ValidationStrategyFactory.GetValidatorFor(GameType); }
public CredCardProcessor(IValidationStrategy vs) { validationStrategy = vs; }