/// <summary> /// Parses a XML node and loads the configuration values from it. /// </summary> /// <param name="applicationContext">Context where to load libraries.</param> /// <param name="section">The "phpNet" section node.</param> /// <param name="addedLibraries">List of class libraries to be loaded lazily.</param> internal void Parse(ApplicationContext/*!*/ applicationContext, XmlNode/*!*/ section, LibrariesConfigurationList/*!*/addedLibraries) { // parses XML tree: foreach (XmlNode node in section.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { switch (node.Name) { case ConfigurationSectionHandler.NodeClassLibrary: ConfigUtils.ParseLibraryAssemblyList( node, addedLibraries, Paths.ExtWrappers, Paths.Libraries); break; case ConfigurationSectionHandler.NodeScriptLibrary: ConfigUtils.ParseScriptLibraryAssemblyList(node, applicationContext.ScriptLibraryDatabase); break; case ConfigurationSectionHandler.NodeCompiler: ConfigUtils.ParseNameValueList(node, null, Compiler); break; case ConfigurationSectionHandler.NodeGlobalization: ConfigUtils.ParseNameValueList(node, null, Globalization); break; } } } }
/// <summary> /// Recursively handles loading of the configuration file sections, to handle the inheritance properly /// </summary> /// <param name="appContext">Application context where to load libraries.</param> /// <param name="root">Root to parse child nodes from</param> /// <param name="addedLibraries">List of class libraries that are collected while parsing configuration node.</param> private void ProcessNodes(ApplicationContext appContext, XmlNode root, LibrariesConfigurationList/*!*/addedLibraries) { foreach (XmlNode node in root.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { switch (node.Name) { case Configuration.SectionName: Parse(appContext, node, addedLibraries); break; case Configuration.LocationName: // Recursively parse the Web.config file to include everything in the <location> element ProcessNodes(appContext, node, addedLibraries); break; case "system.web": ParseSystemWebSection(node); break; } } } }
/// <summary> /// Parses list of library assemblies. /// </summary> /// <param name="node">Node containing the list.</param> /// <param name="libraries">List of libraries to be modified by given <paramref name="node"/>.</param> /// <param name="extensionsPath">Full path to the extensions directory.</param> /// <param name="librariesPath">Full path to the libraries directory.</param> /// <remarks> /// The following node type is allowed to be contained in the <paramref name="node"/>: /// <code> /// <add assembly="{string}" [section="{string}"] {additional attributes specific to library} /> /// </code> /// </remarks> public static void ParseLibraryAssemblyList(XmlNode/*!*/ node, LibrariesConfigurationList/*!*/ libraries, FullPath extensionsPath, FullPath librariesPath) { if (node == null) throw new ArgumentNullException("node"); if (libraries == null) throw new ArgumentNullException("libraries"); foreach (XmlNode child in node.ChildNodes) { if (child.Name == "add" || child.Name == "remove") { if (!Configuration.IsValidInCurrentScope(child)) continue; string assembly_name = ConfigUtils.OptionalAttribute(child, "assembly"); string library_name = ConfigUtils.OptionalAttribute(child, "library"); string extension_name = ConfigUtils.OptionalAttribute(child, "extension"); string url = ConfigUtils.OptionalAttribute(child, "url"); string section_name = ConfigUtils.OptionalAttribute(child, "section"); Uri uri = null; if (assembly_name == null && url == null && extension_name == null && library_name == null) throw new ConfigurationErrorsException(CoreResources.GetString("missing_attribute", "assembly"), child); if (library_name != null) { try { uri = new Uri("file:///" + Path.Combine(librariesPath.IsEmpty ? "" : librariesPath, library_name + ".dll")); } catch (UriFormatException) { throw new InvalidAttributeValueException(child, "library"); } } if (extension_name != null) { try { uri = new Uri("file:///" + Externals.GetWrapperPath(extension_name, extensionsPath.IsEmpty ? "" : extensionsPath)); } catch (UriFormatException) { throw new InvalidAttributeValueException(child, "extension"); } } if (url != null) { try { uri = GetUri(node, url); } catch (UriFormatException) { throw new InvalidAttributeValueException(child, "url"); } } if (child.Name == "add") libraries.AddLibrary(assembly_name, uri, section_name, child); else if (child.Name == "remove") libraries.RemoveLibrary(assembly_name, uri); else Debug.Fail(); } else if (child.Name == "clear") { libraries.ClearLibraries(); } else if (child.NodeType == XmlNodeType.Element) { throw new ConfigUtils.InvalidNodeException(child); } } }