Example #1
0
        public override Dictionary <string, object> Map(XmlNodeList ruleNodeList)
        {
            Dictionary <string, object> ret     = new Dictionary <string, object>();
            RegexValidatorUnitBuilder   builder = new RegexValidatorUnitBuilder();

            foreach (XmlNode ruleNode in ruleNodeList)
            {
                foreach (XmlAttribute ruleAttr in ruleNode.Attributes)
                {
                    string attrValue = ruleAttr.Value.ToLower();
                    if (attrValue.Equals("pattern"))
                    {
                        string pattern = ruleNode.InnerText;
                        builder.AddPattern(pattern);
                    }
                    else if (attrValue.Equals("summary"))
                    {
                        string summary = ruleNode.InnerText;
                        builder.AddMessage(new ErrorValidateMessage(summary));
                    }
                }
            }
            ret.Add(builder.type, builder.Build());
            return(ret);
        }
        public override Dictionary <string, object> Map(XmlNodeList ruleNodeList)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            for (int i = 0; i < 2; i++)
            {
                RegexValidatorUnitBuilder builder = new RegexValidatorUnitBuilder();
                if (i == 0)
                {
                    builder.AddPattern(MailAndPhoneRuleMapper.EMAIL_ADRRESS_REGEX);
                }
                else
                {
                    builder.AddPattern(MailAndPhoneRuleMapper.PHONE_NUMBER_REGEX);
                }
                foreach (XmlNode ruleNode in ruleNodeList)
                {
                    foreach (XmlAttribute ruleAttr in ruleNode.Attributes)
                    {
                        string attrValue = ruleAttr.Value.ToLower();
                        if (i == 0 && attrValue.Equals("mailerrorsummary"))
                        {
                            string summary = ruleNode.InnerText;
                            builder.AddMessage(new ErrorValidateMessage(summary));
                            break;
                        }
                        else if (i == 1 && attrValue.Equals("phoneerrorsummary"))
                        {
                            string summary = ruleNode.InnerText;
                            builder.AddMessage(new ErrorValidateMessage(summary));
                            break;
                        }
                    }
                }
                string builderType = string.Empty;
                if (i == 0)
                {
                    builderType = builder.type + "::mail";
                }
                else
                {
                    builderType = builder.type + "::phone";
                }
                ret.Add(builderType, builder.Build());
            }
            return(ret);
        }