public ValidatorResponse IsValid(string validateControlName, object validateValue)
        {
            ValidatorResponse response = new ValidatorResponse();

            if (!this.config.ruleNodeList.ContainsKey(validateControlName))
            {
                ValidatorResponseEntity entity = new ValidatorResponseEntity();
                entity.result  = false;
                entity.message = new ErrorValidateMessage("nothing validate parameter.");
                response.responseList.Add(entity);
                return(response);
            }
            XmlNodeList         nodeList   = this.config.ruleNodeList[validateControlName];
            ValidatorUnitEntity unitEntity = ValidatorUnitFactory.FactoryMethod(nodeList);

            foreach (string validatorType in unitEntity.validatorUnitList.Keys)
            {
                Dictionary <string, object> validatorUnitList = unitEntity.validatorUnitList[validatorType];
                BaseValidator     validator    = ValidatorFactory.FactoryMethod(validatorType);
                ValidatorResponse unitResponse = validator.IsValid(validateValue, validatorUnitList);
                foreach (ValidatorResponseEntity entity in unitResponse.responseList)
                {
                    if (!entity.result)
                    {
                        response.responseList.Add(entity);
                        break;
                    }
                }
                if (0 != response.responseList.Count)
                {
                    break;
                }
            }
            return(response);
        }
Beispiel #2
0
        public static ValidatorUnitEntity FactoryMethod(XmlNodeList ruleXmlNodeList)
        {
            ValidatorUnitEntity vfr = new ValidatorUnitEntity();

            foreach (XmlNode ruleNode in ruleXmlNodeList)
            {
                foreach (XmlAttribute ruleAttr in ruleNode.Attributes)
                {
                    if (ruleAttr.Name.ToLower().Equals("type"))
                    {
                        string         attrValue  = ruleAttr.Value.ToLower();
                        BaseRuleMapper ruleMapper = RuleMapperFactory.FactoryMethod(attrValue);
                        vfr.validatorUnitList[attrValue] = ruleMapper.Map(ruleNode.ChildNodes);
                    }
                }
            }
            return(vfr);
        }