Example #1
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            try {
                string componentsXml;
                if (section.Name == "components")
                {
                    componentsXml = section.OuterXml;
                }
                else
                {
                    StringBuilder tmpsb = new StringBuilder();
                    tmpsb.Append("<components>");
                    tmpsb.Append(section.InnerXml);
                    tmpsb.Append("</components>");
                    componentsXml = tmpsb.ToString();
                }

                string rootDir = GetAppBasePath();
                if (section.Attributes["includebasepath"] != null)
                {
                    var explicitBase = section.Attributes["includebasepath"].Value;
                    rootDir = Path.IsPathRooted(explicitBase) ? explicitBase : Path.Combine(rootDir, explicitBase);
                }

                var xmlRdr = XmlReader.Create(new StringReader(componentsXml), null,
                                              new XmlParserContext(null, null, null, XmlSpace.Default)
                {
                    BaseURI = rootDir
                });
                Mvp.Xml.XInclude.XIncludingReader xmlContentRdr = new Mvp.Xml.XInclude.XIncludingReader(xmlRdr);
                LocalFileManager fileManager = new LocalFileManager(rootDir);
                xmlContentRdr.XmlResolver = new FileManagerXmlResolver(fileManager, "./");
                XPathDocument xmlXPathDoc = new XPathDocument(xmlContentRdr);

                IModifyXmlDocumentHandler preprocessor = GetPreprocessor(section.Name, fileManager);

                XmlComponentsConfig config = new XmlComponentsConfig(
                    xmlXPathDoc.CreateNavigator().OuterXml, preprocessor);
                return(config);
            } catch (Exception ex) {
                throw new ConfigurationException(ex.Message, ex);
            }
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            try {
                string componentsXml;
                if (section.Name=="components") {
                    componentsXml = section.OuterXml;
                } else {
                    StringBuilder tmpsb = new StringBuilder();
                    tmpsb.Append("<components>");
                    tmpsb.Append(section.InnerXml);
                    tmpsb.Append("</components>");
                    componentsXml = tmpsb.ToString();
                }

                string rootDir = GetAppBasePath();
                if (section.Attributes["includebasepath"] != null) {
                    var explicitBase = section.Attributes["includebasepath"].Value;
                    rootDir = Path.IsPathRooted(explicitBase) ? explicitBase : Path.Combine(rootDir, explicitBase);
                }

                var xmlRdr = XmlReader.Create(new StringReader(componentsXml), null,
                        new XmlParserContext(null, null, null, XmlSpace.Default) { BaseURI = rootDir });
                Mvp.Xml.XInclude.XIncludingReader xmlContentRdr = new Mvp.Xml.XInclude.XIncludingReader(xmlRdr);
                LocalFileManager fileManager = new LocalFileManager(rootDir);
                xmlContentRdr.XmlResolver = new FileManagerXmlResolver(fileManager,"./");
                XPathDocument xmlXPathDoc = new XPathDocument(xmlContentRdr);

                IModifyXmlDocumentHandler preprocessor = GetPreprocessor(section.Name, fileManager);

                XmlComponentsConfig config = new XmlComponentsConfig(
                    xmlXPathDoc.CreateNavigator().OuterXml, preprocessor);
                return config;
            } catch (Exception ex) {
                throw new ConfigurationException(ex.Message, ex);
            }
        }