public void ElectronicServiceRecepientValidation(Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResults results) { ValidationResults valResults = null; Microsoft.Practices.EnterpriseLibrary.Validation.Validator validator = null; if (Entity != null) { validator = ValidationFactory.CreateValidator <EntityBasicData>(); } else if (ForeignEntity != null) { validator = ValidationFactory.CreateValidator <ForeignEntityBasicData>(); } else if (ForeignCitizen != null) { validator = ValidationFactory.CreateValidator <ForeignCitizenBasicData>(); } else if (Person != null) { validator = ValidationFactory.CreateValidator <PersonBasicData>(); } if (validator != null) { valResults = validator.Validate(Item); results.AddAllResults(valResults); } }
public ValidationResults Validate(object model) { Validator validator = ValidationFactory.CreateValidator <Transaction>(); var results = new ValidationResults(); validator.Validate(model, results); return(results); }
/// <summary> /// Initializes this object with a message. /// </summary> public ValidationResult(string message, object target, string key, string tag, Validator validator, IEnumerable<ValidationResult> nestedValidationResults) { this.message = message; this.key = key; this.target = target; this.tag = tag; this.validator = validator; this.nestedValidationResults = nestedValidationResults; }
public void ServiceApplicantReceiptDataValidation(Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResults results) { string message; ValidationResults valResults = null; Microsoft.Practices.EnterpriseLibrary.Validation.Validator validator = null; if (!this.ServiceResultReceiptMethodSpecified) { message = string.Format(Resources.Terms._0006_000015, Resources.Fields._0008_000197, Resources.Sections._0009_000141); results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult(message, this, "", "0006-000015", null)); } //Задължителни полета, ако получаването е на гише в администрация if (this.ServiceResultReceiptMethod.Equals(ServiceResultReceiptMethod.PerCounterInMunicipality)) { if (MunicipalityAdministrationAddress != null) { validator = ValidationFactory.CreateValidator <ServiceApplicantReceiptDataMunicipalityAdministrationAdress>(); } } //Задължителни полета, ако получаването е по поща else if (this.ServiceResultReceiptMethod.Equals(ServiceResultReceiptMethod.PerPostOfficeBox)) { if (string.IsNullOrEmpty(PostOfficeBox)) { message = string.Format(Resources.Terms._0006_000015, Resources.Fields._0008_000136, Resources.Sections._0009_000141); results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult(message, this, "", "0006-000015", null)); } } //Задължителни полета, ако получаването е на друг адрес else if (this.ServiceResultReceiptMethod.Equals(ServiceResultReceiptMethod.PerCourierOthers)) { if (ApplicantAddress != null) { validator = ValidationFactory.CreateValidator <ServiceApplicantReceiptDataApplicantAdress>(); } } if (validator != null) { valResults = validator.Validate(Item); results.AddAllResults(valResults); } }
static void CreatingAndUsingValidatorsDirectly() { // Create a Contains Characters Validator and use it to validate a String value. Validator charsValidator = new ContainsCharactersValidator("cat", ContainsCharacters.All, "Value must contain {4} of the characters '{3}'."); Console.WriteLine("Validating a string value using a Contains Characters Validator..."); charsValidator.Tag = "Validating the String value 'disconnected'"; // This overload of the Validate method returns a new ValidationResults // instance populated with any/all of the validation errors. ValidationResults valResults = charsValidator.Validate("disconnected"); // Create a Domain Validator and use it to validate an Integer value. Validator integerValidator = new DomainValidator<int>("Value must be in the list 1, 3, 7, 11, 13.", new int[] { 1, 3, 7, 11, 13 }); integerValidator.Tag = "Validating the Integer value '42'"; Console.WriteLine("Validating an integer value using a Domain Validator..."); // This overload of the Validate method takes an existing ValidationResults // instance and adds any/all of the validation errors to it. integerValidator.Validate(42, valResults); // Create an Or Composite Validator containing two validators. // Note that the NotNullValidator is negated to allow NULL values. Validator[] valArray = new Validator[] { new NotNullValidator(true, "Value can be NULL."), new StringLengthValidator(5, RangeBoundaryType.Inclusive, 5, RangeBoundaryType.Inclusive, "Value must be between {3} ({4}) and {5} ({6}) chars.") }; Validator orValidator = new OrCompositeValidator("Value can be NULL or a string of 5 characters.", valArray); // Validate two strings using the Or Composite Validator. Console.WriteLine("Validating a NULL value using an Or Composite Validator..."); orValidator.Validate(null, valResults); // this will not cause a validation error Console.WriteLine("Validating a string value using an Or Composite Validator..."); orValidator.Validate("MoreThan5Chars", valResults); // Validate a single property of an existing class instance. // First create a Product instance with an invalid ID value. IProduct productWithID = new Product(); PopulateInvalidProduct(productWithID); // Create a Property Value Validator that will use a RegexValidator // to validate the property value. Validator propValidator = new PropertyValueValidator<Product>("ID", new RegexValidator("[A-Z]{2}[0-9]{4}", "Product ID must be 2 capital letters and 4 numbers.")); Console.WriteLine("Validating one property of an object using a Property Value Validator..."); propValidator.Validate(productWithID, valResults); // Now display the results of all the previous validation operations. ShowValidationResults(valResults); }
public void ElectronicStatementAuthorValidation(Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResults results) { Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResults authorResults = null; Microsoft.Practices.EnterpriseLibrary.Validation.Validator validator = null; if ((Item as PersonBasicData) != null) { validator = ValidationFactory.CreateValidator <PersonBasicData>(); } else if ((Item as ForeignCitizenBasicData) != null) { validator = ValidationFactory.CreateValidator <ForeignCitizenBasicData>(); } if (validator != null) { authorResults = validator.Validate(Item); results.AddAllResults(authorResults); } }
public void ActIdentifierValidation(ValidationResults results) { ValidationResults valResults = null; Microsoft.Practices.EnterpriseLibrary.Validation.Validator validator = null; if (StateIdentifier != null) { validator = ValidationFactory.CreateValidator <StatePropertyActIdentifier>(); } else if (MunicipalIdentifier != null) { validator = ValidationFactory.CreateValidator <MunicipalPropertyActIdentifier>(); } if (validator != null) { valResults = validator.Validate(Item); results.AddAllResults(valResults); } }
public void LandPropertyOldIdentifierValidation(ValidationResults results) { string msg; ValidationResults valResults = null; Microsoft.Practices.EnterpriseLibrary.Validation.Validator validator = null; if (UrbanIdentifier != null) { validator = ValidationFactory.CreateValidator <UrbanLandPropertyOldIdentifier>(); } else if (FarmlandIdentifier != null) { validator = ValidationFactory.CreateValidator <FarmlandAndForestLandPropertyOldIdentifier>(); } if (validator != null) { valResults = validator.Validate(Item); results.AddAllResults(valResults); } }
private string GetValidationMessage(Validator validator) { if (validator == null) return ""; var results = validator.Validate(this.target); if (results.IsValid) return ""; var errorTextBuilder = new StringBuilder(); foreach (var result in results) { errorTextBuilder.AppendLine(result.Message); } return errorTextBuilder.ToString(); }
public void Setup() { currentProject = new MockProjectModel("ExistingItem.cs"); itemDoesntExistValidator = new ProjectItemIsUniqueValidator(currentProject, "cs"); }
/// <summary> /// Initializes a new instance of the <see cref="RepeaterValidator"/> class. /// </summary> /// <param name="allControls">The list of all controls.</param> /// <param name="wrappedValidator">The wrapped validator that does the actual validation.</param> /// <param name="controlName">The name of the control validated by the current instance.</param> public RepeaterValidator(ControlList allControls, Validator wrappedValidator, string controlName) : base(allControls, wrappedValidator, controlName) { }
internal void AddValueValidator(Validator valueValidator) { this.valueValidators.Add(valueValidator); }
/// <summary> /// Returns the validator created by the builder. /// </summary> public Validator GetValidator() { this.builtValidator = this.DoGetValidator(); return this.builtValidator; }
public EnterpriseLibraryValidatorWrapper(ModelMetadata metadata, ControllerContext context, Validator validator) : base(metadata, context) { _validator = validator; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// // validation helper methods private void _InitValidation() { var validators = default(ValidatorsContainer); var objectType = this.GetType(); lock (_dataObjectValidatorsGuard) { if (!_dataObjectValidators.TryGetValue(objectType, out validators)) { validators = _CreateValidators(objectType); _dataObjectValidators[objectType] = validators; } } _objectValidator = validators.ObjectValidator; _propertyValidators = validators.PropertyValidators; }
/// <summary> /// Initializes this object with a message. /// </summary> public ValidationResult(string message, object target, string key, string tag, Validator validator) : this(message, target, key, tag, validator, NoNestedValidationResults) { }
private static bool CheckIfValidatorIsAppropiate(Validator validator) { if (IsComposite(validator)) { return CompositeHasValidators(validator); } else { return true; } }
private static bool CompositeHasValidators(Validator validator) { AndCompositeValidator andValidator = validator as AndCompositeValidator; if (andValidator != null) { return ((Validator[])andValidator.Validators).Length > 0; } OrCompositeValidator orValidator = validator as OrCompositeValidator; if (orValidator != null) { return ((Validator[])orValidator.Validators).Length > 0; } return false; }
private static bool IsComposite(Validator validator) { return validator is AndCompositeValidator || validator is OrCompositeValidator; }
/// <summary> /// Adds a value validator to the composite validator. /// </summary> /// <param name="valueValidator">The validator to add.</param> public void AddValueValidator(Validator valueValidator) { this.valueValidators.Add(valueValidator); }
/// <summary> /// Initializes a new instance of the <see cref="ControlValueValidator"/> class. /// </summary> /// <param name="allControls">The list of all controls.</param> /// <param name="wrappedValidator">The wrapped validator that does the actual validation.</param> /// <param name="controlName">The name of the control validated by the current instance.</param> public ControlValueValidator(ControlList allControls, Validator wrappedValidator, string controlName) : base(allControls) { this.WrappedValidator = wrappedValidator; this.ControlName = controlName; }