Esempio n. 1
0
        /**
         * xml Element to Rule
         * @param ruleEle
         * @param fieldId
         * @return
         * @throws TopSchemaException
         */
        private static Rule ElementToRule(XmlElement ruleEle, string fieldId)
        {
            if (ruleEle == null)
            {
                return(null);
            }
            String ruleName = XmlUtils.GetAttributeValue(ruleEle, "name");

            if (StringUtil.IsEmpty(ruleName))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31001, fieldId);
            }
            String ruleValue = XmlUtils.GetAttributeValue(ruleEle, "value");

            if (StringUtil.IsEmpty(ruleValue))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31002, fieldId);
            }

            Rule         rule     = null;
            RuleTypeEnum ruleEnum = RuleTypeEnumHelper.GetEnum(ruleName);

            if (ruleEnum != RuleTypeEnum.UNKNOWN)
            {
                rule = SchemaFactory.CreateRule(ruleEnum);
            }
            else
            {
                rule = SchemaFactory.CreateCustomRule(ruleName, ruleValue);
            }

            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.TIP_RULE)) && !StringUtil.IsEmpty(ruleValue))
            {
                String url = XmlUtils.GetAttributeValue(ruleEle, "url");
                ((TipRule)rule).Url = url;
            }
            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.DEV_TIP_RULE)) && !StringUtil.IsEmpty(ruleValue))
            {
                String url = XmlUtils.GetAttributeValue(ruleEle, "url");
                ((DevTipRule)rule).Url = url;
            }

            String unit = XmlUtils.GetAttributeValue(ruleEle, "unit");

            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MAX_TARGET_SIZE_RULE)) &&
                !StringUtil.IsEmpty(ruleValue))
            {
                MaxTargetSizeRule mtsRule = (MaxTargetSizeRule)rule;
                mtsRule.Unit = unit;
            }
            else if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MIN_TARGET_SIZE_RULE)) &&
                     !StringUtil.IsEmpty(ruleValue))
            {
                MinTargetSizeRule misRule = (MinTargetSizeRule)rule;
                misRule.Unit = unit;
            }

            String exProperty = XmlUtils.GetAttributeValue(ruleEle, "exProperty");

            if (!StringUtil.IsEmpty(exProperty))
            {
                rule.ExProperty = exProperty;
            }
            rule.Value = ruleValue;
            XmlElement  dependGroupEle = XmlUtils.GetChildElement(ruleEle, "depend-group");
            DependGroup dependGroup    = ElementToDependGroup(dependGroupEle, fieldId);

            rule.DependGroup = dependGroup;
            return(rule);
        }