Exemple #1
0
        /// <summary>
        /// Parse a included configuration reference.
        /// </summary>
        /// <param name="parent">Parent Config Node</param>
        /// <param name="elem">XML Element</param>
        private void AddIncludeNode(ConfigPathNode parent, XmlElement elem)
        {
            string configName = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);

            if (String.IsNullOrWhiteSpace(configName))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);
            }
            string path = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);

            if (String.IsNullOrWhiteSpace(path))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);
            }
            string st = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);

            if (String.IsNullOrWhiteSpace(st))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            EUriScheme type = EUriScheme.none.ParseScheme(st);

            if (type == EUriScheme.none)
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            string vs = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);

            if (String.IsNullOrWhiteSpace(vs))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);
            }
            Version version = Version.Parse(vs);

            ConfigIncludeNode node = new ConfigIncludeNode(configuration, parent);

            node.Name       = elem.Name;
            node.ConfigName = configName;
            node.Path       = ReaderTypeHelper.ParseUri(path);
            node.ReaderType = type;
            node.Version    = version;

            using (AbstractReader reader = ReaderTypeHelper.GetReader(type, node.Path))
            {
                reader.Open();
                XmlConfigParser parser = new XmlConfigParser();
                parser.Parse(node.ConfigName, reader, node.Version, settings);
                Configuration config = parser.GetConfiguration();
                node.Reference = config;
                node.Node      = config.RootConfigNode;
                node.UpdateConfiguration(configuration);
            }
            parent.AddChildNode(node);
        }
Exemple #2
0
 /// <summary>
 /// Write a configuration node.
 /// </summary>
 /// <param name="writer">XML Writer</param>
 /// <param name="node">Node To write</param>
 /// <param name="settings">Configuration Settings.</param>
 private void WriteNode(XmlWriter writer, AbstractConfigNode node, ConfigurationSettings settings)
 {
     if (node.GetType() == typeof(ConfigPathNode))
     {
         ConfigPathNode pnode = (ConfigPathNode)node;
         writer.WriteStartElement(node.Name);
         {
             ConfigAttributesNode attrs = pnode.GetAttributes();
             if (attrs != null)
             {
                 Dictionary <string, ConfigValueNode> values = attrs.GetValues();
                 if (values != null && values.Count > 0)
                 {
                     foreach (string key in values.Keys)
                     {
                         ConfigValueNode vn = values[key];
                         if (vn != null)
                         {
                             writer.WriteAttributeString(vn.Name, vn.GetValue());
                         }
                     }
                 }
             }
             Dictionary <string, AbstractConfigNode> nodes = pnode.GetChildren();
             foreach (string key in nodes.Keys)
             {
                 AbstractConfigNode cnode = nodes[key];
                 if (cnode.Name == settings.AttributesNodeName)
                 {
                     continue;
                 }
                 WriteNode(writer, cnode, settings);
             }
         }
         writer.WriteEndElement();
     }
     else if (node.GetType() == typeof(ConfigValueNode))
     {
         ConfigValueNode vn = (ConfigValueNode)node;
         writer.WriteStartElement(vn.Name);
         writer.WriteString(vn.GetValue());
         writer.WriteEndElement();
     }
     else if (node.GetType() == typeof(ConfigParametersNode) || node.GetType() == typeof(ConfigPropertiesNode))
     {
         string name = null;
         if (node.GetType() == typeof(ConfigParametersNode))
         {
             name = settings.ParametersNodeName;
         }
         else
         {
             name = settings.PropertiesNodeName;
         }
         ConfigKeyValueNode kvnode = (ConfigKeyValueNode)node;
         WriteKeyValueNode(writer, kvnode, name);
     }
     else if (node.GetType() == typeof(ConfigListValueNode))
     {
         WriteListValueNode(writer, (ConfigListValueNode)node);
     }
     else if (node.GetType() == typeof(ConfigElementListNode))
     {
         WriteListElementNode(writer, (ConfigElementListNode)node, settings);
     }
     else if (node.GetType() == typeof(ConfigIncludeNode))
     {
         ConfigIncludeNode inode = (ConfigIncludeNode)node;
         WriteNode(writer, inode.Node, settings);
     }
     else if (typeof(ConfigResourceNode).IsAssignableFrom(node.GetType()))
     {
         ConfigResourceNode rnode = (ConfigResourceNode)node;
         WriteResourceNode(writer, rnode);
     }
 }