示例#1
0
        private void ConfigureFilters(string config)
        {
            var doc = new XmlDocument();

            doc.Load(config);
            var filterNodes = doc.SelectNodes("//errorFilter");

            foreach (XmlNode filterNode in filterNodes)
            {
                var notList   = new List <string>();
                var notifiers = filterNode.SelectNodes("//notifier");
                {
                    foreach (XmlElement notifier in notifiers)
                    {
                        var name = notifier.Attributes["name"]?.Value;
                        if (name != null)
                        {
                            notList.Add(name);
                        }
                    }
                }
                var assertionNode = (XmlElement)filterNode.SelectSingleNode("test/*");

                if (assertionNode != null)
                {
                    var a      = AssertionFactory.Create(assertionNode);
                    var filter = new ErrorFilter(a, notList);
                    Filtering += filter.OnErrorModuleFiltering;
                    _filters.Add(filter);
                }
            }
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            //
            // Either inherit the incoming parent configuration (for example
            // from the machine configuration file) or start with a fresh new
            // one.
            //

            ErrorFilterConfiguration config;

            if (parent != null)
            {
                ErrorFilterConfiguration parentConfig = (ErrorFilterConfiguration)parent;
                config = (ErrorFilterConfiguration)((ICloneable)parentConfig).Clone();
            }
            else
            {
                config = new ErrorFilterConfiguration();
            }

            //
            // Take the first child of <test> and turn it into the
            // assertion.
            //

            XmlElement assertionNode = (XmlElement)section.SelectSingleNode("test/*");

            if (assertionNode != null)
            {
                config.SetAssertion(AssertionFactory.Create(assertionNode));
            }

            return(config);
        }
示例#3
0
        static IAssertion TryLoadAssertion(Func <Stream> opener)
        {
            using (var stream = opener() ?? Stream.Null)
                using (var reader = new StreamReader(stream))
                {
                    var content = reader.ReadToEnd();
                    var trimmed = content.Trim();
                    if (trimmed.Length == 0)
                    {
                        return(null);
                    }

                    XmlElement element;

                    if (trimmed[0] == '<') // Assume XML
                    {
                        var config = new XmlDocument();
                        config.LoadXml(content);
                        element = (XmlElement)config.SelectSingleNode("errorFilter/test/*")
                                  ?? (XmlElement)config.SelectSingleNode("test/*")
                                  ?? config.DocumentElement;
                    }
                    else                // Assume JScript expression
                    {
                        var config     = new XmlDocument();
                        var expression = config.CreateElement("expression");
                        expression.AppendChild(config.CreateTextNode(content));
                        var jscript = config.CreateElement("jscript");
                        jscript.AppendChild(expression);
                        config.AppendChild(jscript);
                        element = config.DocumentElement;
                    }

                    return(AssertionFactory.Create(element));
                }
        }