From ed69e84874b710c2cc3b8af94dd00cf725cf6d03 Mon Sep 17 00:00:00 2001 From: mingchen Date: Thu, 19 Jul 2007 20:39:33 +0000 Subject: *Moved XmlConfiguration to its own project *Made it possible to load a configuration interface by DLL *Deleted the 1024 config files until they are updated --- .../General/Configuration/ConfigurationMember.cs | 52 +++++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/General/Configuration/ConfigurationMember.cs') diff --git a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs index e93a576..4546683 100644 --- a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs +++ b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Text; @@ -7,6 +8,7 @@ using System.Net; using libsecondlife; using OpenSim.Framework.Console; +using OpenSim.Framework.Configuration.Interfaces; namespace OpenSim.Framework.Configuration { @@ -22,12 +24,14 @@ namespace OpenSim.Framework.Configuration private ConfigurationOptionsLoad loadFunction; private ConfigurationOptionResult resultFunction; + private IGenericConfig configurationPlugin = null; public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) { this.configurationFilename = configuration_filename; this.configurationDescription = configuration_description; this.loadFunction = load_function; this.resultFunction = result_function; + this.configurationPlugin = this.LoadConfigDll("OpenSim.Framework.Configuration.XML.dll"); } public void setConfigurationFilename(string filename) @@ -91,18 +95,19 @@ namespace OpenSim.Framework.Configuration } bool useFile = true; - XmlConfiguration xmlConfig = null; - if (configurationFilename.Trim() != "") + if (configurationPlugin == null) { - xmlConfig = new XmlConfiguration(configurationFilename); - + MainLog.Instance.Error("Configuration Plugin NOT LOADED!"); + return; } - if(xmlConfig != null) + if (configurationFilename.Trim() != "") { - xmlConfig.LoadData(); + configurationPlugin.SetFileName(configurationFilename); + configurationPlugin.LoadData(); useFile = true; } + else { MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); @@ -124,7 +129,7 @@ namespace OpenSim.Framework.Configuration { if (!ignoreNextFromConfig) { - attribute = xmlConfig.GetAttribute(configOption.configurationKey); + attribute = configurationPlugin.GetAttribute(configOption.configurationKey); } else { @@ -304,7 +309,7 @@ namespace OpenSim.Framework.Configuration { if (useFile) { - xmlConfig.SetAttribute(configOption.configurationKey, console_result); + configurationPlugin.SetAttribute(configOption.configurationKey, console_result); } @@ -333,9 +338,34 @@ namespace OpenSim.Framework.Configuration if(useFile) { - xmlConfig.Commit(); - xmlConfig.Close(); + configurationPlugin.Commit(); + configurationPlugin.Close(); } - } + } + + private IGenericConfig LoadConfigDll(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + IGenericConfig plug = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IGenericConfig", true); + + if (typeInterface != null) + { + plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + } + } + } + } + + pluginAssembly = null; + return plug; + } } } -- cgit v1.1