public XmlPatternProvider2(string xml, Func<INotifyAction, string, NotifyRequest, IPattern> getpattern)
        {
            GetPatternMethod = getpattern;

            var xdoc = new XmlDocument();
            xdoc.LoadXml(xml);

            var xformatter = xdoc.SelectSingleNode("/patterns/formatter") as XmlElement;
            if (xformatter != null)
            {
                var type = xformatter.GetAttribute("type");
                if (!string.IsNullOrEmpty(type))
                {
                    formatter = (IPatternFormatter)Activator.CreateInstance(Type.GetType(type, true));
                }
            }

            var references = new Dictionary<string, string>();

            foreach (XmlElement xpattern in xdoc.SelectNodes("/patterns/pattern"))
            {
                var id = xpattern.GetAttribute("id");
                var sender = xpattern.GetAttribute("sender");
                var reference = xpattern.GetAttribute("reference");

                if (string.IsNullOrEmpty(reference))
                {
                    var subject = GetResource(GetElementByTagName(xpattern, "subject"));

                    var xbody = GetElementByTagName(xpattern, "body");
                    var body = GetResource(xbody);
                    if (string.IsNullOrEmpty(body) && xbody != null && xbody.FirstChild is XmlText)
                    {
                        body = xbody.FirstChild.Value ?? string.Empty;
                    }

                    var styler = xbody != null ? xbody.GetAttribute("styler") : string.Empty;

                    patterns[id + sender] = new Pattern(id, subject, body, Pattern.HTMLContentType) { Styler = styler };
                }
                else
                {
                    references[id + sender] = reference + sender;
                }
            }

            foreach (var pair in references)
            {
                patterns[pair.Key] = patterns[pair.Value];
            }
        }
        private void LoadXml(XmlReader xmlReader)
        {
            XPathNavigator nav     = new XPathDocument(xmlReader).CreateNavigator();
            var            manager = new XmlNamespaceManager(nav.NameTable);

            manager.AddNamespace("pt", "urn:asc.notify.pattern.xsd");
            var result = new List <KeyValuePair <IPattern, IPatternFormatter> >();
            XPathNodeIterator nodes = nav.Select("pt:catalog/block", manager);

            while (nodes.MoveNext())
            {
                XPathNavigator    blockNav          = nodes.Current;
                string            blockContentType  = blockNav.GetAttribute("contentType", "");
                XPathNodeIterator formatterNode     = blockNav.SelectChildren("formatter", "");
                string            formatterTypeName = "";
                if (formatterNode.MoveNext())
                {
                    formatterTypeName = formatterNode.Current.GetAttribute("type", "");
                }
                Type formatterType = Type.GetType(formatterTypeName, true);
                var  formatter     = (IPatternFormatter)formatterType.Assembly.CreateInstance(formatterType.FullName);

                XPathNodeIterator patternsNodes = nodes.Current.Select("./patterns/pattern", manager);
                while (patternsNodes.MoveNext())
                {
                    XPathNodeIterator subjectNode = patternsNodes.Current.SelectChildren("subject", "");
                    string            subject     = "";
                    if (subjectNode.MoveNext())
                    {
                        subject = GetValue(subjectNode);
                    }
                    XPathNodeIterator bodyNode   = patternsNodes.Current.SelectChildren("body", "");
                    string            body       = "";
                    string            bodyStyler = "";
                    if (bodyNode.MoveNext())
                    {
                        body = GetValue(bodyNode);
                        if (bodyNode.Current != null)
                        {
                            bodyStyler = bodyNode.Current.GetAttribute("styler", "");
                        }
                    }
                    string patternContentType = patternsNodes.Current.GetAttribute("contentType", "");
                    if (String.IsNullOrEmpty(patternContentType))
                    {
                        patternContentType = blockContentType;
                    }
                    IPattern newpattern = new Pattern(
                        patternsNodes.Current.GetAttribute("id", ""),
                        patternsNodes.Current.GetAttribute("name", ""),
                        subject,
                        body,
                        patternContentType
                        )
                    {
                        Styler = bodyStyler
                    };
                    result.Add(new KeyValuePair <IPattern, IPatternFormatter>(newpattern, formatter));
                }
            }

            constProvider = new ConstPatternProvider(result.ToArray());
        }