Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            object  result        = parent;
            XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file");

            result = NameValueSectionHandler.CreateStatic(result, section);
            if (fileAttribute != null && fileAttribute.Value.Length != 0)
            {
                string         sectionName   = fileAttribute.Value;
                IConfigXmlNode configXmlNode = fileAttribute as IConfigXmlNode;
                if (configXmlNode == null)
                {
                    return(null);
                }
                string sourceFileFullPath = Path.Combine(Path.GetDirectoryName(configXmlNode.Filename), sectionName);
                if (File.Exists(sourceFileFullPath))
                {
                    ConfigXmlDocument configXmlDocument = new ConfigXmlDocument();
                    try
                    {
                        configXmlDocument.Load(sourceFileFullPath);
                    }
                    catch (XmlException e)
                    {
                        throw new ConfigurationException(e.Message, e, sourceFileFullPath, e.LineNumber);
                    }
                    if (section.Name != configXmlDocument.DocumentElement.Name)
                    {
                        throw new ConfigurationException("Config NameValueFile Section: Invalid root", configXmlDocument.DocumentElement);
                    }
                    result = NameValueSectionHandler.CreateStatic(result, configXmlDocument.DocumentElement);
                }
            }
            return(result);
        }
        internal static string InternalGetXmlNodeFilename(XmlNode node)
        {
            IConfigXmlNode configNode = node as IConfigXmlNode;

            if (configNode != null)
            {
                return(configNode.Filename);
            }
            return("");
        }
        //
        // Internal XML Error Info Helpers
        //
        /// <include file='doc\ConfigurationException.uex' path='docs/doc[@for="ConfigurationException.GetXmlNodeLineNumber"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static int GetXmlNodeLineNumber(XmlNode node)
        {
            IConfigXmlNode configNode = node as IConfigXmlNode;

            if (configNode != null)
            {
                return(configNode.LineNumber);
            }
            return(0);
        }
Пример #4
0
        /// <include file='doc\ConfigurationException.uex' path='docs/doc[@for="ConfigurationException.GetXmlNodeFilename"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static string GetXmlNodeFilename(XmlNode node)
        {
            IConfigXmlNode configNode = node as IConfigXmlNode;

            if (configNode != null)
            {
                return(configNode.Filename);
            }
            return(string.Empty);
        }
Пример #5
0
        // Get the line number from an XmlNode object.
        public static int GetXmlNodeLineNumber(XmlNode node)
        {
            IConfigXmlNode cnode = (node as IConfigXmlNode);

            if (cnode != null)
            {
                return(cnode.LineNumber);
            }
            else
            {
                return(0);
            }
        }
Пример #6
0
        // Get the filename from an XmlNode object.
        public static String GetXmlNodeFilename(XmlNode node)
        {
            IConfigXmlNode cnode = (node as IConfigXmlNode);

            if (cnode != null)
            {
                return(cnode.Filename);
            }
            else
            {
                return(String.Empty);
            }
        }
Пример #7
0
        /// <include file='doc\NameValueFileSectionHandler.uex' path='docs/doc[@for="NameValueFileSectionHandler.Create"]/*' />
        public object Create(object parent, object configContext, XmlNode section)
        {
            object result = parent;

            // parse XML
            XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file");

            result = NameValueSectionHandler.CreateStatic(result, section);

            if (fileAttribute != null && fileAttribute.Value.Length != 0)
            {
                string filename = null;
                filename = fileAttribute.Value;
                IConfigXmlNode configXmlNode = fileAttribute as IConfigXmlNode;
                if (configXmlNode == null)
                {
                    return(null);
                }

                string configFile         = configXmlNode.Filename;
                string directory          = Path.GetDirectoryName(configFile);
                string sourceFileFullPath = Path.Combine(directory, filename);

                if (File.Exists(sourceFileFullPath))
                {
                    ConfigXmlDocument doc = new ConfigXmlDocument();
                    try {
                        doc.Load(sourceFileFullPath);
                    }
                    catch (XmlException e) {
                        throw new ConfigurationException(e.Message, e, sourceFileFullPath, e.LineNumber);
                    }

                    if (section.Name != doc.DocumentElement.Name)
                    {
                        throw new ConfigurationException(
                                  SR.GetString(SR.Config_name_value_file_section_file_invalid_root, section.Name),
                                  doc.DocumentElement);
                    }

                    result = NameValueSectionHandler.CreateStatic(result, doc.DocumentElement);
                }
            }

            return(result);
        }