Example #1
0
        /// <summary>
        /// Populates the object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute idRefattribute = node.Attributes["rule-id"];

            if (idRefattribute != null && !string.IsNullOrWhiteSpace(idRefattribute.Value))
            {
                if (!MAConfig.Rules.Contains(idRefattribute.Value))
                {
                    throw new ArgumentException(string.Format("The referenced rule '{0}' does not exist", idRefattribute.Value));
                }
                else
                {
                    this.RuleSet = MAConfig.Rules[idRefattribute.Value];
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds any referenced rules to the collection
        /// </summary>
        public void AddReferencedRulesToCollection()
        {
            XmlNodeList nodes = this.xmlNode.SelectNodes("rule-ref");

            if (nodes != null)
            {
                foreach (XmlNode child in nodes)
                {
                    XmlAttribute ruleIdAttribute = child.Attributes["rule-id"];

                    if (ruleIdAttribute == null || string.IsNullOrWhiteSpace(ruleIdAttribute.Value))
                    {
                        continue;
                    }

                    IEvaluableRuleObject rule = MAConfig.Rules[ruleIdAttribute.Value];

                    if (rule is RuleBase)
                    {
                        this.Rules.Add(rule as RuleBase);
                    }
                    else if (rule is RuleGroup)
                    {
                        if (rule != this)
                        {
                            this.RuleGroups.Add(rule as RuleGroup);
                        }
                    }
                }
            }

            if (this.RuleGroups == null)
            {
                return;
            }
            else
            {
                foreach (RuleGroup group in this.RuleGroups)
                {
                    group.AddReferencedRulesToCollection();
                }
            }
        }