Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Configuration"/> class.
 /// </summary>
 public Configuration(IConfigurationBuilder <IConfiguration> builder)
 {
     properties_   = builder.Properties;
     repositories_ = builder.Repositories;
     providers_    = builder.Providers;
     xml_elements_ = builder.XmlElements;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Configuration"/> class
 /// that is empty.
 /// </summary>
 public Configuration()
 {
     properties_   = new DictionaryValue();
     repositories_ = new RepositoriesNode();
     providers_    = new ProvidersNode();
     xml_elements_ = new XmlElementsNode();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Copies the configuration data from the specified
 /// <see cref="Configuration"/> object.
 /// </summary>
 /// <param name="configuration">
 /// A <see cref="Configuration"/> object that contains the
 /// configuration data to be copied.
 /// </param>
 public void CopyFrom(Configuration configuration)
 {
     providers_    = configuration.providers_;
     repositories_ = configuration.repositories_;
     xml_elements_ = configuration.xml_elements_;
     log_level_    = configuration.log_level_;
     properties_   = configuration.properties_;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the configuration node using the nohros schema.
        /// </summary>
        /// <param name="element">
        /// A Xml element representing the configuration root node.
        /// </param>
        /// <remarks>
        /// The <paramref name="element"/> does not need to be the nohros
        /// configuration node, but a node with name "nohros" must exists on the
        /// node hierarchy.
        /// </remarks>
        T Parse(XmlElement element)
        {
            XmlElement root_node = GetRootNode(element);

            // the logger is used by some methods above and the level threshold of it
            // could be overloaded by a configuration key. So, we need to do the
            // first logger instantiation here and adjust the threshold level if
            // needed.
            builder.SetLogLevel(GetLogLevel(root_node));

            // parse any internal property
            if (use_dynamic_property_assignment_)
            {
                ParseProperties(element, this);
                ParseProperties(element, builder);
            }

            // parse the know configuration nodes.
            foreach (XmlNode node in root_node.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    string name = node.Name;
                    if (Strings.AreEquals(name, Strings.kRepositoriesNodeName))
                    {
                        builder.SetRepositories(RepositoriesNode.Parse((XmlElement)node,
                                                                       location_));
                    }
                    else if (Strings.AreEquals(name, Strings.kProvidersNodeName))
                    {
                        builder.SetProviders(ProvidersNode.Parse((XmlElement)node,
                                                                 location_));
                    }
                    else if (Strings.AreEquals(name, Strings.kXmlElementsNodeName))
                    {
                        XmlElementsNode xml_elements =
                            XmlElementsNode.Parse((XmlElement)node);

                        // Add the element that was used to configure this class to the
                        // collection of xml elements nodes.
                        xml_elements[Strings.kRootXmlElementName] = element;
                        builder.SetXmlElements(xml_elements);
                    }
                }
            }

            OnParseComplete(this);

            T configuration = CreateConfiguration(builder);

            OnLoadComplete(configuration);

            return(configuration);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Parses the specified <see cref="XmlElement"/> element into a
    /// <see cref="XmlElementsNode"/> object.
    /// </summary>
    /// <param name="element">
    /// A Xml element that contains the xml elements configuration data.
    /// </param>
    /// <returns>
    /// A <see cref="XmlElementsNode"/> containing the configured xml elements.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="element"/> is a <c>null</c> reference.
    /// </exception>
    /// <exception cref="ConfigurationException">
    /// The <paramref name="element"/> contains invalid configuration data.
    /// </exception>
    public static XmlElementsNode Parse(XmlElement element) {
      if (element == null) {
        throw new ArgumentNullException("element");
      }

      XmlElementsNode xml_elements_node = new XmlElementsNode();
      foreach (XmlNode node in element.ChildNodes) {
        if (node.NodeType == XmlNodeType.Element) {
          xml_elements_node.AddChildNode(new XmlElementNode((XmlElement) node));
        }
      }
      return xml_elements_node;
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Parses the specified <see cref="XmlElement"/> element into a
        /// <see cref="XmlElementsNode"/> object.
        /// </summary>
        /// <param name="element">
        /// A Xml element that contains the xml elements configuration data.
        /// </param>
        /// <returns>
        /// A <see cref="XmlElementsNode"/> containing the configured xml elements.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is a <c>null</c> reference.
        /// </exception>
        /// <exception cref="ConfigurationException">
        /// The <paramref name="element"/> contains invalid configuration data.
        /// </exception>
        public static XmlElementsNode Parse(XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            XmlElementsNode xml_elements_node = new XmlElementsNode();

            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    xml_elements_node.AddChildNode(new XmlElementNode((XmlElement)node));
                }
            }
            return(xml_elements_node);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Configuration"/> class.
 /// </summary>
 public Configuration(IConfigurationBuilder<IConfiguration> builder) {
   properties_ = builder.Properties;
   repositories_ = builder.Repositories;
   providers_ = builder.Providers;
   xml_elements_ = builder.XmlElements;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Configuration"/> class
 /// that is empty.
 /// </summary>
 public Configuration() {
   properties_ = new DictionaryValue();
   repositories_ = new RepositoriesNode();
   providers_ = new ProvidersNode();
   xml_elements_ = new XmlElementsNode();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Copies the configuration data from the specified
 /// <see cref="Configuration"/> object.
 /// </summary>
 /// <param name="configuration">
 /// A <see cref="Configuration"/> object that contains the
 /// configuration data to be copied.
 /// </param>
 public void CopyFrom(Configuration configuration) {
   providers_ = configuration.providers_;
   repositories_ = configuration.repositories_;
   xml_elements_ = configuration.xml_elements_;
   log_level_ = configuration.log_level_;
   properties_ = configuration.properties_;
 }