Пример #1
0
        /// <summary>
        /// Creates a <see cref="RuleBook"/> by parsing the content of the
        /// indicated configuration file.
        /// </summary>
        /// <param name="filename">The configuration filename.</param>
        /// <returns>A <see cref="RuleBook"/> instance created using the
        ///	details in the configuration file.</returns>
        public static RuleBook Load(string filename)
        {
            RuleBook ruleBook = new RuleBook();

            FileStream  stream   = File.OpenRead(Application.PathTo(filename));
            XmlDocument document = XmlUtility.NonValidatingParse(stream);

            XmlNodeList list = DOM.GetChildElements(document.DocumentElement);

            foreach (XmlElement context in list)
            {
                if (context.LocalName.Equals("identifier"))
                {
                    string name = context.GetAttribute("name");

                    Property [] properties = LoadProperties(XPath.Paths(context, "property"));
                    IFormatter  formatter  = (IFormatter)LoadClass(XPath.Paths(context, "formatter"));

                    ruleBook.Add(new IdentifierRule(name, properties, formatter));
                }
                else
                {
                    log.Warn("Unexpected element '" + context.LocalName + "'");
                }
            }

            return(ruleBook);
        }
Пример #2
0
        public void RegisterRule(IEventRule eventRule)
        {
            foreach (EventType eventType in eventRule.EventTypes)
            {
                if (RuleBook.ContainsKey(eventType))
                {
                    var page = RuleBook[eventType];

                    if (!page[eventRule.RuleType].Contains(eventRule))
                    {
                        page[eventRule.RuleType].Add(eventRule);
                    }
                }
                else
                {
                    var page = new RulePage();
                    RuleBook.Add(eventType, page);
                    page[eventRule.RuleType].Add(eventRule);
                }
            }
        }