///<summary>Name check validates that the name has only alpha, digits, space or '</summary> protected void CheckName(ValidatorAttribute Source, ValidatingSerializerEventArgs e) { if (ExCheckName.IsMatch(LastName) == true) { e.Error = new ErrorInfo(Source, e.Field); } }
///<summary>Validator deligate checks that there are no duplicate entries.</summary> protected void CheckDuplicate(ValidatorAttribute Source, ValidatingSerializerEventArgs e) { bool IsValid = true; string key = String.Empty; System.Collections.Specialized.HybridDictionary CheckList = new System.Collections.Specialized.HybridDictionary(); foreach (InsuranceLineItem C in this) { key = C.ProductType.ToString() + " " + C.Policy + " " + C.RevenueType.ToString(); if (CheckList.Contains(key)) { IsValid = false; } else { CheckList.Add(key, C.RevenueType); } if (IsValid == false) { e.Error = new ErrorInfo(Source, "Duplicates"); } } }
private ValidationResult GetValidationResult(ActionContext actionContext, Dictionary <string, object> propertyValuePaires, T dto) { var validationResult = new ValidationResult(); // Needed so we can call the get the validator. ValidatorAttribute validatorAttribute = typeof(T).GetCustomAttribute(typeof(ValidatorAttribute)) as ValidatorAttribute; if (validatorAttribute != null) { Type validatorType = validatorAttribute.ValidatorType; // We need to pass the http method because there are some differences between the validation rules for post and put // We need to pass the propertyValuePaires from the passed json because there are cases in which one field is required // on post, but it is a valid case not to pass it when doing a put request. var validator = Activator.CreateInstance(validatorType, new object[] { //TODO: find this actionContext.HttpContext.Request.Method, propertyValuePaires }); // We know that the validator will be AbstractValidator<T> which means it will have Validate method. validationResult = validatorType.GetMethod("Validate", new[] { typeof(T) }) .Invoke(validator, new[] { dto }) as ValidationResult; } return(validationResult); }
public void IsValid_applies_to_numeric_comparisons_to_zero(ValidatorAttribute attr, int y) { var validator = attr.CreateValidator(""); Assert.True( validator.Validate(y).IsEmpty ); }
//MAIG - CH2 - End - Added the below fields to update the AgencyID and AgencyName #endregion ///<summary>Validator delegate to validate userid</summary> protected void ValidateUserId(ValidatorAttribute Source, ValidatingSerializerEventArgs e) { //CHG0078293 - PT Enhancement - Modified the below condition to check the minimum length of user ID from 5 to 4 digits if (UserId.Length < 4) { e.Error = new ErrorInfo(Source, e.Field); } }
private bool IsPropertyValidator(PropertyInfo property, MethodInfo method) { if (method.GetCustomAttribute <ValidatorAttribute>() != null) { ValidatorAttribute validator = method.GetCustomAttribute <ValidatorAttribute>(); return(!validator.ClassScope && validator.Validate.ToLower() == property.Name.ToLower()); } return(false); }
public override void OnEntry(MethodExecutionArgs args) { if (args.Arguments == null || args.Arguments.Count == 0) { throw new InvalidOperationException("A method without and parameters cannot be validated."); } MethodInfo methodInfo = args.Method as MethodInfo; if (methodInfo == null) { throw new InvalidOperationException("Cannot get method info from PostSharp."); } if (!methodInfo.ReturnType.IsSubclassOf(typeof(BaseResponse))) { throw new InvalidOperationException("Only methods that return a type that's inherited from BaseResponse can be validates with this attribute."); } foreach (object argument in args.Arguments) { if (argument == null) { BaseResponse response = Activator.CreateInstance(methodInfo.ReturnType) as BaseResponse; response.AddErrorMessage("Invalid request."); args.FlowBehavior = FlowBehavior.Return; args.ReturnValue = response; return; } Type requestType = argument.GetType(); ValidatorAttribute validatorAttribute = requestType.GetCustomAttribute <ValidatorAttribute>(); if (validatorAttribute != null) { IValidator validator = (IValidator)Activator.CreateInstance(validatorAttribute.ValidatorType); ValidationResult validationResult = validator.Validate(args.Arguments[0]); if (!validationResult.IsValid) { BaseResponse response = Activator.CreateInstance(methodInfo.ReturnType) as BaseResponse; if (response == null) { throw new InvalidOperationException($"Cannot initialize a BaseResponse for type {methodInfo.ReturnType.Name}."); } response.Messages = validationResult.GetErrors(); args.FlowBehavior = FlowBehavior.Return; args.ReturnValue = response; return; } } } }
public static void TestValidator <T>( TestContext testContext, ValidatorAttribute attribute, T value, bool isValid) { TestValidator <T>(testContext, attribute, value, isValid, false); TestValidator <T>(testContext, attribute, value, !isValid, true); }
internal static IValidator <T> GetValidatorFromModelAttribute <T>() { ValidatorAttribute validatorAttribute = (ValidatorAttribute)typeof(T).GetCustomAttribute(typeof(ValidatorAttribute)); Assert.IsNotNull(validatorAttribute, "Model have validator"); IValidator <T> validator = (IValidator <T>)Activator.CreateInstance(validatorAttribute.ValidatorType); return(validator); }
/// <summary> /// 尝试获取特性 /// </summary> /// <param name="type"></param> /// <param name="attribute"></param> /// <returns></returns> public static bool TryGetAttribute(Type type, out ValidatorAttribute attribute) { if (all.TryGetValue(type, out var value)) { attribute = value?.Item1; return(true); } attribute = null; return(false); }
public ClientVdtAttribute2(ValidatorAttribute validatorAttribute, PropertyInfo pi) { //this.tag = validatorAttribute.Tag; this.messageTemplate = validatorAttribute.MessageTemplate; //add by Fenglilei,2011/11/7 //modified by Fenglilei,2012/2/27 if (validatorAttribute.Validator != null && validatorAttribute.Validator is IClientValidatable) { this.clientValidateMethodName = ((IClientValidatable)validatorAttribute.Validator).ClientValidateMethodName; } }
public static PropertyValidatorBase GetValidator(this ValidatorAttribute attr) { PropertyValidatorBase validator; if (_validatorsByAttributeType.TryGetValue(attr.GetType(), out validator)) { return(validator); } else { return(null); } }
//67811A0 - PCI Remediation for Payment systems.CH2: START- Validation for Western United products to check for missing policystate and policy prefix in order detail info ///<summary>Validates the Partner club products to check for policystate and policy prefix</summary> protected void ValidatePolicystatePrefix(ValidatorAttribute Source, ValidatingSerializerEventArgs e) { //MAIG - BEGIN - CH2 - Commeneted the code as part of Common Product Change /*if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1) * { * string[] strsplitpolicy; * strsplitpolicy = Policy.Split('-'); * string PolicyState = strsplitpolicy[0].Trim(); * string PolicyPrefix = strsplitpolicy[1].Trim(); * if (PolicyPrefix == "" || PolicyState == "") e.Error = new ErrorInfo(Source, e.Field); * }*/ //MAIG - END - CH2 - Commeneted the code as part of Common Product Change }
private ValidationDto CheckValidation(TDto model) { var attrs = typeof(TDto).GetCustomAttributes(true); ValidatorAttribute attr = (ValidatorAttribute)Attribute.GetCustomAttribute(typeof(TDto), typeof(ValidatorAttribute)); if (attr != null) { IValidator validator = ResolverFactory.CreateInstance <IValidator>(attr.ValidatorType.AssemblyQualifiedName); return(new ValidationDto(validator.Validate(model))); } else { return(new ValidationDto()); } }
public static IValidator GetValidator(Type type) { if (type == null) { return(null); } ValidatorAttribute va = (ValidatorAttribute) Attribute.GetCustomAttribute(type, typeof(ValidatorAttribute)); if (va == null || va.ValidatorType == null) { return(null); } return((IValidator)Activator.CreateInstance(va.ValidatorType)); }
static void TestValidator <T>( TestContext testContext, ValidatorAttribute attribute, T value, bool isValid, bool negated) { var results = new ValidationResults(); try { var wrappedAttribute = new PrivateObject(attribute); if (negated) { wrappedAttribute.SetProperty("Negated", true); } var validator = wrappedAttribute.Invoke("DoCreateValidator", typeof(T)) as Validator; Assert.IsNotNull(validator); var validatorAccessor = new PrivateObject(validator); validatorAccessor.Invoke( "DoValidate", value, null, null, results); Assert.AreEqual(isValid, results.IsValid); } catch (UnitTestAssertException) { throw; } catch (Exception x) { testContext.WriteLine("{0}", x.DumpString()); throw; } finally { testContext.WriteLine("{0}", results.DumpString()); } }
/// <summary> /// Gets the validator. /// </summary> /// <param name="control">The control.</param> /// <param name="attr">The attr.</param> /// <returns></returns> private static IValidatorCreator GetValidator(Control control, ValidatorAttribute attr) { RequiredValidatorAttribute reqAttr = attr as RequiredValidatorAttribute; if (reqAttr != null) { return(new RequiredValidatorCreator(reqAttr, control)); } LengthValidatorAttribute lengthAttr = attr as LengthValidatorAttribute; if (lengthAttr != null) { return(new LengthValidatorCreator(lengthAttr, control)); } RangeValidatorAttribute rangeAttr = attr as RangeValidatorAttribute; if (rangeAttr != null) { return(new RangeValidatorCreator(rangeAttr, control)); } RegexValidatorAttribute regexAttr = attr as RegexValidatorAttribute; if (regexAttr != null) { return(new RegexValidatorCreator(regexAttr, control)); } CompareValidatorAttribute compareAttr = attr as CompareValidatorAttribute; if (compareAttr != null) { return(new CompareValidatorCreator(compareAttr, control)); } if (attr is CustomValidatorAttribute) { return(null); } throw new ArgumentException("The attribute does not derive from ValidatorAttribute.", "attr"); }
private object GetModelWithValidateAttribute(System.Collections.Generic.Dictionary <string, object> dictionary) { object model = null; foreach (var item in dictionary) { Type t = item.Value.GetType(); ValidatorAttribute attribute = (ValidatorAttribute)Attribute.GetCustomAttribute(t, typeof(ValidatorAttribute)); if (attribute != null) { model = dictionary[item.Key]; break; } } return(model); }
IEnumerable <IValidatorDescriptor> IValidatedElement.GetValidatorDescriptors() { if (this.memberInfo != null) { try { object[] customAttributes = this.memberInfo.GetCustomAttributes(typeof(ValidatorAttribute), false); for (int i = 0; i < customAttributes.Length; i++) { ValidatorAttribute attribute = (ValidatorAttribute)customAttributes[i]; if (this.ruleset.Equals(attribute.Ruleset)) { yield return((IValidatorDescriptor)attribute); } } } finally { } } }
/// <summary> /// /// </summary> /// <param name="targetType"></param> /// <returns></returns> /// <exclude /> protected override Validator DoCreateValidator(Type targetType) { try { BaseRuntimeTreeNode node = FunctionFacade.BuildTree(XElement.Parse(FunctionMarkup)); IPropertyValidatorBuilder propertyValidatorBuilder = node.GetValue <IPropertyValidatorBuilder>(); ValidatorAttribute validatorAttribute = (ValidatorAttribute)propertyValidatorBuilder.GetAttribute(); Validator validator = (Validator)DoCreateValidatorMethodInfo.Invoke(validatorAttribute, new object[] { targetType }); return(validator); } catch (Exception ex) { string message = string.Format("Validator function markup parse / execution failed with the following error: '{0}'. The validator attribute is dropped.", ex.Message); Log.LogError("LazyFunctionProviedPropertyAttribute", message); } return(new LazyFunctionProviedPropertyValidator()); }
public override IValidator CreateInstance(Type validatorType) { if (validatorType == null) { throw new ArgumentNullException("validatorType"); } if (!validatorType.IsGenericType || validatorType.GetGenericTypeDefinition() != typeof(IValidator <>)) { throw new ArgumentException("validatorType must implement IValidator<>"); } Type modelType = validatorType.GetGenericArguments().Single(); ValidatorAttribute validatorAttribute = modelType.GetAttribute <ValidatorAttribute>(); if (validatorAttribute == null) // if a model doesn't have a validator attribute, that model type shouldn't be validated. { return(kernel.Resolve <IValidator <dynamic> >()); // we resolve a generic null validator in this case. } else { return((IValidator)kernel.Resolve(validatorType)); // resolve the validator implementation. } }
public ClientVdtAttribute(ValidatorAttribute validatorAttribute, PropertyInfo pi) { //this.tag = validatorAttribute.Tag; this.messageTemplate = validatorAttribute.MessageTemplate; //add by Fenglilei,2011/11/7 //modified by Fenglilei,2012/2/27 if (validatorAttribute.Validator != null && validatorAttribute.Validator is IClientValidatable) { this.clientValidateMethodName = ((IClientValidatable)validatorAttribute.Validator).ClientValidateMethodName; } if (validatorAttribute is IntegerRangeValidatorAttribute) { //IntegerRangeValidatorAttribute currval = validatorAttribute as IntegerRangeValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.Int; } else if (validatorAttribute is RegexValidatorAttribute) { //RegexValidatorAttribute currval = validatorAttribute as RegexValidatorAttribute; //this.vType = ValidateType.Expession; //this.expression = currval.Pattern; } else if (validatorAttribute is StringLengthValidatorAttribute) { //StringLengthValidatorAttribute currval = validatorAttribute as StringLengthValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.Length; } else if (validatorAttribute is DateTimeRangeValidatorAttribute) { //DateTimeRangeValidatorAttribute currval = validatorAttribute as DateTimeRangeValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString("yyyy-MM-dd HH:mm:ss"); //this.upperBound = currval.UpperBound.ToString("yyyy-MM-dd HH:mm:ss"); //this.DType = ValidteDataType.DateTime; } else if (validatorAttribute is DoubleRangeValidatorAttribute) { //DoubleRangeValidatorAttribute currval = validatorAttribute as DoubleRangeValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.Float; } else if (validatorAttribute is FloatRangeValidatorAttribute) { //FloatRangeValidatorAttribute currval = validatorAttribute as FloatRangeValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.Float; } else if (validatorAttribute is DecimalRangeValidatorAttribute) { //DecimalRangeValidatorAttribute currval = validatorAttribute as DecimalRangeValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.Float; } else if (validatorAttribute is StringByteLengthValidatorAttribute) { //StringByteLengthValidatorAttribute currval = validatorAttribute as StringByteLengthValidatorAttribute; //this.vType = ValidateType.Range; //this.lowerBound = currval.LowerBound.ToString(); //this.upperBound = currval.UpperBound.ToString(); //this.DType = ValidteDataType.StringByteLength; } else if (validatorAttribute is StringEmptyValidatorAttribute) { //this.vType = ValidateType.Empty; //this.DType = ValidteDataType.String; } else if (validatorAttribute is DateTimeEmptyValidatorAttribute) { //this.vType = ValidateType.Empty; //this.DType = ValidteDataType.DateTime; } else if (validatorAttribute is ObjectNullValidatorAttribute) { //this.vType = ValidateType.Empty; //this.DType = ValidteDataType.Object; } else if (validatorAttribute is EnumDefaultValueValidatorAttribute) { //this.vType = ValidateType.Empty; //this.DType = ValidteDataType.Enum; //if (pi.PropertyType.IsEnum) //{ // object defaultValue = Activator.CreateInstance(pi.PropertyType); // this.tag = ((int)defaultValue).ToString(); //} } }
// 67811A0 - PCI Remediation for Payment systems.CH4:END ///<summary>Validates the policy number check digit</summary> protected void ValidPolicy(ValidatorAttribute Source, ValidatingSerializerEventArgs e) { //CSAA.com - added the condition toupper to prevent the policy validation failure for the Leacy and exigen polices by cognizant on 12/23/2011 Policy = Policy.ToUpper(); bool IsValid = true; bool IsExigenValid = true; bool IsPupValid = true; //Security Defect- CH2 -START -Added the below code to validate the fields in insurance line item if (FirstName.Trim() == "") { AddError(new ErrorInfo("50008", "Valdiation failed in FirstName", "FirstName")); } if (LastName.Trim() == "") { AddError(new ErrorInfo("50009", "Valdiation failed in LastName", "LastName")); } if (Description.Trim().Length > 100) { AddError(new ErrorInfo("50004", "Valdiation failed in Description", "Description")); } if (Price.ToString() == "" || Price <= 0 || Price > 25000 || !CSAAWeb.Validate.IsDecimal(Price.ToString())) { AddError(new ErrorInfo("50016", "Valdiation failed in Price", "Price")); } if (Amount.ToString() == "" || Amount <= 0 || Amount > 25000 || !CSAAWeb.Validate.IsDecimal(Amount.ToString())) { AddError(new ErrorInfo("50016", "Valdiation failed in Amount", "Amount")); } //if (Tax_Amount.ToString() == "" || Tax_Amount <= 0 || Tax_Amount > 25000 || !CSAAWeb.Validate.IsDecimal(Tax_Amount.ToString())) //{ // AddError(new ErrorInfo("50016", "Valdiation failed in Tax_Amount", "Tax_Amount")); //} if (Quantity.ToString() == "" || Quantity <= 0 || Quantity > 10 || !CSAAWeb.Validate.IsDecimal(Quantity.ToString())) { AddError(new ErrorInfo("50017", "Valdiation failed in Quantity", "Quantity")); } if (RevenueType == "" || RevenueType.Length > 40 || junkValidation(RevenueType.ToString())) { AddError(new ErrorInfo("50018", "Valdiation failed in RevenueType", "RevenueType")); } //MAIG - CH1 - BEGIN - Modified the logic to Support Common Product Types and to check if it is an valid policy number, Also commenented the unwanted logic //Security Defect- CH2 -END -Added the below code to validate the fields in insurance line item //AZ PAS Conversion and PC integration - START - Added the below code to assign the policy number alone to the Policy variable in case of non PCP transactions from UI Policy = Policy.Trim(); if (ProductType.Equals("PA") || ProductType.Equals("HO")) { if (!(CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim())) || (Policy.Length < 4 || Policy.Length > 13)) { IsValid = false; } } else if (ProductType.Equals("PU")) { //MAIG - CH3 - BEGIN - Added condition to skip validation if the policy length is 13, for an PAS Home Policy if (!(Policy.Trim().Length == 13 && CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim()))) { if (!CSAAWeb.Validate.IsAllNumeric(Policy.Trim())) { IsValid = false; e.Error = new ErrorInfo("INVALID_CHARACTERS", CSAAWeb.Constants.PUP_NUMERIC_VALID, "Policy"); return; } else if (Policy.Length != 7) { IsValid = false; e.Error = new ErrorInfo("INVALID_LENGTH", CSAAWeb.Constants.POLICY_LENGTH_HOME_MESSAGE, "Policy"); return; } } //MAIG - CH3 - END - Added condition to skip validation if the policy length is 13, for an PAS Home Policy } else if (ProductType.Equals("DF") || ProductType.Equals("MC") || ProductType.Equals("WC")) { //MAIG - CH4 - BEGIN - Added condition to skip validation if the policy length is 13, for an PAS Home Policy if (!(ProductType.Equals("DF") && Policy.Trim().Length == 13 && CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim()))) { if (Policy.Length < 4 || Policy.Length > 9) { IsValid = false; } else if (!CSAAWeb.Validate.IsAllNumeric(Policy)) { IsValid = false; e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be Numeric.", "Policy"); return; } } //MAIG - CH4 - END - Added condition to skip validation if the policy length is 13, for an PAS Home Policy } /* * * if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) <= -1) * { * string[] StrSplitPolicy; * StrSplitPolicy = Policy.Split('-'); * if (StrSplitPolicy[0] != null) * { * Policy = StrSplitPolicy[0].Trim(); * } * } * //AZ PAS Conversion and PC integration -END - Added the below code to assign the policy number alone to the Policy variable in case of non PCP transactions from UI * //if (Policy.Length >16) * //{ * // AddError(new ErrorInfo("50052", "Valdiation failed in Policy", "Policy")); * //} * // 67811A0 - PCI Remediation for Payment systems.CH3:START- Validate Partner Club Products of lengh between 4 to 10 and numeric * if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1 ) * { * if (Splitpolicynumber(Policy).Length >= 4 && Splitpolicynumber(Policy).Length <= 9) * { * //* 67811A0 - PCI Remediation for Payment systems.CH6 : To validate the HO6 policy sequence for CEA product code * if (((ConfigurationSettings.AppSettings["PCP.StatePrefixCEA"]).IndexOf(Convert.ToString(StrPrefix)) > -1) && ((ConfigurationSettings.AppSettings["PCP.ProductTypeCEA"]).IndexOf(Convert.ToString(ProductType)) > -1)) * //if ((StrPrefix == "HO6") && (ProductType.Trim() == "CEA")) * { * InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance(); * * * if ((bool)I.ValidateCheckDigit(Splitpolicynumber(Policy))) * { * IsValid = true; * } * else * { * IsValid = false; * e.Error = new ErrorInfo("INVALID_Policy", "Policy Number Sequence is Invalid for Home policy", "Policy"); * * return; * } * * } * else if (CSAAWeb.Validate.IsAllNumeric(Splitpolicynumber(Policy))) * { * IsValid = true; * } * else * { * IsValid = false; * e.Error = new ErrorInfo("INVALID_Policy", "Policy Number must be Numeric for Western United Products.", "Policy"); * return; * } * * * } * else * { * IsValid = false; * e.Error = new ErrorInfo("INVALID_LENGTH", "Policy Number Length must be between 4 to 9 for Western United Products.", "Policy"); * return; * //* 67811A0 - PCI Remediation for Payment systems.CH6 : To validate the HO6 policy sequence for CEA product code * } * } * // 67811A0 - PCI Remediation for Payment systems.CH3:END * //Start Added by Cognizant on 11/8/2004 * else if (Policy != "" && validateRequired) * { * //Q4-Retrofit.Ch2-START: Added to check IsHUONAuto property to identify if it is HUON Auto * if (IsHUONAuto) * { * //For HUON Auto products, the policy number is checked to see if it is purely numeric * IsValid = CSAAWeb.Validate.IsAllNumeric(Policy); * if (!IsValid) * { * e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be Numeric.", "Policy"); * return; * } * } * //PUP CH1:Start added new validator for validating pup policy by cognizant on 1/10/2011 * //PUP CH4:Modified the condition for converting the first 3 chararcters Toupper case - by cognizant on 03/18/2011 * else if (Policy.Length == 10 && Policy.Substring(0, 3).ToUpper() == "PUP") * { * string puPolicyno = Policy.Substring(3, 7); * if (!CSAAWeb.Validate.IsAllNumeric(puPolicyno)) * { * IsPupValid = false; * e.Error = new ErrorInfo("INVALID_CHARACTERS", CSAAWeb.Constants.PUP_NUMERIC_VALID, "Policy"); * return; * } * IsPupValid = true; * } * //PUP CH1:END added new validator for validating pup policy by cognizant on 1/10/2011 * else if (GetIsExigenAuto() == true) * { * // MP2.0.Ch2 - Start of Code - New Validation has been added for exigen on 1/6/2010 by Cognizant * if (Policy.Length == 13) * { * * string stateCode = Policy.Substring(0, 2); * string prodCode = Policy.Substring(2, 2); * string exPolicyNo = Policy.Substring(4, 9); * * string stateCodeValues = string.Empty; * string prodCodeValues = string.Empty; * * // MP 2.0 defect # 904 - new code added to fix the bug - by Cognizant on 07/30/2010 * string allowedExigenPolicyValues = string.Empty; * string stateProductCode = string.Empty; * stateProductCode = Policy.Substring(0, 4); * * * if (ConfigurationSettings.AppSettings["AllowedExigenPolicies"] != null && ConfigurationSettings.AppSettings["AllowedExigenPolicies"].ToString() != string.Empty) * { * allowedExigenPolicyValues = ConfigurationSettings.AppSettings["AllowedExigenPolicies"].ToString(); * } * * //CHG0104053 - PAS HO CH1 - START : Added the below code to allow all states,no validation, since it is available in RBPS 6/26/2014 * if (!ProductType.Equals("AAASSH")) * { * if (allowedExigenPolicyValues.IndexOf(stateProductCode) < 0) * { * IsExigenValid = false; * e.Error = new ErrorInfo("INVALID_POLICY", "Invalid Policy. Please enter a valid policy and try again", "Policy"); * return; * } * } * //CHG0104053 - PAS HO CH1 - END : Added the below code to allow all states,no validation, since it is available in RBPS 6/26/2014 * //End Issue 904 * * if (!CSAAWeb.Validate.IsAllNumeric(exPolicyNo)) * { * IsExigenValid = false; * e.Error = new ErrorInfo("INVALID_CHARACTERS", "The last 9 characters of the Policy No must be Numeric.", "Policy"); * return; * } * * } * else * { * IsExigenValid = false; * e.Error = new ErrorInfo("INVALID_LENGTH", "Policy Number must be of length 13", "Policy"); * return; * } * // MP2.0.Ch2 - End of Code - New Validation has been added for exigen on 1/6/2010 by Cognizant * } * else * { * //AlphaNumeric validation with Dashes * IsValid = Regex.IsMatch(Policy.ToUpper(), @"^[A-Z0-9\-]+$"); * if (!IsValid) * { * e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be AlphaNumeric.", "Policy"); * return; * } * //Q4-Retrofit.Ch2-END * * //Format Validation with dashes(ex:"12-34-56-7") * * if ((Policy.Replace("-", "").Length == 7) && (Policy.IndexOf("-") >= 0)) * { * //Match the format "12-34-56-7" * IsValid = (Regex.IsMatch(Policy.ToUpper(), @"^[0123456789ABCDEJKLNRPTVWXYFFHMU]{2,2}-[0-9]{2,2}-[0-9]{2,2}-[0-9]{1,1}$")); * * if (IsValid) * Policy = Policy.Replace("-", ""); * else * { * e.Error = new ErrorInfo("INVALID_POLICY", "The policy format is not valid.", "Policy"); * return; * } * } * } * * * } * //END * if (Policy != "") * { * InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance(); * //Start Added by Cognizant on 24-06-2004 for stopping validation for WU products * //Q4-Retrofit.Ch2-START: Added a check for IsHUONAuto to call HUON Check digit validation if it is HUON Auto product * if (validateRequired) * { * * if (IsHUONAuto) * IsValid = (bool)I.ValidateHUONCheckDigit(Policy); * else if (GetIsExigenAuto() == true) // MP2.0.Ch1 - new method added for Exigen policy validation - added by Cognizant on 27/05/2020 * IsValid = IsExigenValid; * //PUP CH2:Added the condition to check policy number for valid PUP policy by cognizant on 01/12/2011. * //PUP CH3:Modified the condition for converting the first 3 chararcters Toupper case - by cognizant on 03/18/2011 * else if (Policy.Length == 10 && Policy.Substring(0, 3).ToUpper() == "PUP") * { * IsValid = IsPupValid; * } * //AZ PAS conversion and PC integration - CH2 - Added the below code to validate Highlimit policy * else if (Policy.Length == 10 && ProductType == Config.Setting("ProductCode.HighLimit") && CSAAWeb.Validate.IsAllNumeric((Policy))) * { * IsValid = true; * } * //AZ PAS conversion and PC integration - CH2 - Added the below code to validate Highlimit policy * // * 67811A0 - PCI Remediation for Payment systems.CH5 START Check if it is not a PCP product type. * else if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) < 0) * // * 67811A0 - PCI Remediation for Payment systems.CH5 End Check if it is not a PCP product type. * { * IsValid = (bool)I.ValidateCheckDigit(Policy); * } * } * //Q4-Retrofit.Ch2-END * //else if(Policy.Length==12) * // * 67811A0 - PCI Remediation for Payment systems.CH5 :START Check if it is not a PCP product type. * else if ((Policy.Length == 12) && (!validateRequired) && (ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) < 0) * IsValid = true; * // * 67811A0 - PCI Remediation for Payment systems.CH5 :END * // 67811A0 - PCI Remediation for Payment systems.CH3:START- Validate Partner Club Products of lengh between 4 to 10 and numeric * else if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1) * { * //* 67811A0 - PCI Remediation for Payment systems.CH7 Start : To validate the HO6 policy sequence for CEA product code * if (((ConfigurationSettings.AppSettings["PCP.StatePrefixCEA"]).IndexOf(Convert.ToString(StrPrefix.ToUpper())) > -1) && ((ConfigurationSettings.AppSettings["PCP.ProductTypeCEA"]).IndexOf(Convert.ToString(ProductType.ToUpper())) > -1)) * //if ((StrPrefix == "HO6") && (ProductType == "CEA")) * { * // InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance(); * * * if ((bool)I.ValidateCheckDigit(Splitpolicynumber(Policy))) * { * IsValid = true; * } * else * { * IsValid = false; * e.Error = new ErrorInfo("INVALID_Policy", "Policy Number Sequence is Invalid for Home policy", "Policy"); * return; * } * * } * else if (CSAAWeb.Validate.IsAllNumeric(Splitpolicynumber(Policy))) * { * IsValid = true; * } * else * { * IsValid = false; * e.Error = new ErrorInfo("INVALID_Policy", "Policy Number must be Numeric for Western United Products.", "Policy"); * return; * } * * * //* 67811A0 - PCI Remediation for Payment systems.CH7 END : To validate the HO6 policy sequence for CEA product code * } * // 67811A0 - PCI Remediation for Payment systems.CH3:END * * else * { * IsValid = false; * //throw new CSAAWeb.BusinessRuleException("Policy (" + Policy + ") not valid."); * } * * * //END * I.Close(); * } */ //MAIG - CH1 - END - Modified the logic to Support Common Product Types and to check if it is an valid policy number, Also commenented the unwanted logic if (IsValid == false) { e.Error = new ErrorInfo(Source, e.Field); } }
/// <summary> /// Carrega a lista das propriedades mapeadas. /// </summary> /// <param name="type"></param> /// <param name="mapping">Lista para armazenar a propriedades mapeadas.</param> /// <param name="fkMapping"></param> /// <param name="fmMapping">Mapeamento dos membros estrangeiros.</param> private static void LoadPersistencePropertyAttributes(Type type, List <Mapper> mapping, List <GroupOfRelationshipInfo> fkMapping, List <ForeignMemberMapper> fmMapping) { PropertyInfo[] properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); var classMapping = Mapping.MappingData.GetMapping(type); foreach (PropertyInfo property in properties) { Mapping.PropertyMapping pMapping = null; if (classMapping != null) { pMapping = classMapping.Properties.Find(f => f.Name == property.Name); } PersistencePropertyAttribute ppa = GetPersistenceProperty(property); Mapper currentMapper = null; if (ppa != null) { currentMapper = new Mapper(type, ppa, property); mapping.Add(currentMapper); } object[] attrs = property.GetCustomAttributes(typeof(PersistenceForeignKeyAttribute), true); if ((attrs == null || attrs.Length == 0) && pMapping != null && pMapping.ForeignKey != null) { attrs = new object[] { pMapping.ForeignKey.GetPersistenceForeignKey() } } ; foreach (object obj in attrs) { PersistenceForeignKeyAttribute fk = (PersistenceForeignKeyAttribute)obj; GroupOfRelationshipInfo group = new GroupOfRelationshipInfo(type, fk.TypeOfClassRelated, fk.GroupOfRelationship); int index = fkMapping.FindIndex(delegate(GroupOfRelationshipInfo gri) { return(gri == group); }); if (index < 0) { fkMapping.Add(group); } else { group = fkMapping[index]; } ForeignKeyMapper fkm = new ForeignKeyMapper(fk, property); group.AddForeignKey(fkm); if (currentMapper != null) { currentMapper.AddForeignKey(fkm); } } attrs = property.GetCustomAttributes(typeof(ValidatorAttribute), true); if ((attrs == null || attrs.Length == 0) && pMapping != null && pMapping.Validators.Count > 0) { attrs = new object[pMapping.Validators.Count]; for (int i = 0; i < attrs.Length; i++) { attrs[i] = pMapping.Validators[i].GetValidator(); } } if (attrs.Length > 0) { ValidatorAttribute[] vAttrs = new ValidatorAttribute[attrs.Length]; for (int i = 0; i < attrs.Length; i++) { vAttrs[i] = (ValidatorAttribute)attrs[i]; } currentMapper.Validation = new ValidationMapper(currentMapper, vAttrs); } attrs = property.GetCustomAttributes(typeof(PersistenceForeignMemberAttribute), true); if ((attrs == null || attrs.Length == 0) && pMapping != null && pMapping.ForeignMember != null) { attrs = new object[] { pMapping.ForeignMember.GetPersistenceForeignMember() } } ; if (attrs.Length > 0) { fmMapping.Add(new ForeignMemberMapper((PersistenceForeignMemberAttribute)attrs[0], property)); } } if (!type.IsInterface) { Type[] interfaces = type.GetInterfaces(); PersistenceClassAttribute pca; for (int i = 0; i < interfaces.Length; i++) { pca = GetPersistenceClassAttribute(interfaces[i]); if (pca != null) { LoadPersistencePropertyAttributes(interfaces[i], mapping, fkMapping, fmMapping); } } } }
public ValidatorMetaInfo(ValidatorAttribute attribute, IValidator validator) { _attribute = attribute; _validator = validator; }
protected override bool IsArray => false; // we don't allow non serialized array drawing at the moment /// <inheritdoc /> protected override void ValidateField(ValueRunner validator, ValidatorAttribute attribute) { validator.Run(this, attribute); }
protected abstract void ValidateField(ValueRunner validator, ValidatorAttribute attribute);