From 21e9ad6150eef73eef6ab9ad08786cfe1b94ace2 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 28 Feb 2009 13:08:16 +0000 Subject: [PATCH] Some small clean up of the Grid/User servers. Added T ReadSettingsFromIniFile(IConfig configSection, T settingsClass) to OpenSim.Framework.Util, which will try to read values for the public fields and properties (read/writable properties) in the settingsclass from the nini config section. By looking in the ConfigSection for entries matching the names of the properties/fields. It currently supports fields/properties of the types, string, bool, int, float. [Note this method used reflection so it comes with the normal performance overhead of that] --- OpenSim/Framework/ConfigSettings.cs | 1 + OpenSim/Framework/Util.cs | 53 +++++++++++++++++++ .../GridServer/GridConfigurationLoader.cs | 2 +- .../UserServer.Modules/UserServerPlugin.cs | 14 ++--- 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/OpenSim/Framework/ConfigSettings.cs b/OpenSim/Framework/ConfigSettings.cs index 5f5e16f4e2..0e40441867 100644 --- a/OpenSim/Framework/ConfigSettings.cs +++ b/OpenSim/Framework/ConfigSettings.cs @@ -200,6 +200,7 @@ namespace OpenSim.Framework m_librariesXMLFile = value; } } + protected string m_assetSetsXMLFile; public string AssetSetsXMLFile { diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 4fce4ac4d6..5ac6754950 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; @@ -931,5 +932,57 @@ namespace OpenSim.Framework return displayConnectionString; } + + public static T ReadSettingsFromIniFile(IConfig config, T settingsClass) + { + Type settingsType = settingsClass.GetType(); + + FieldInfo[] fieldInfos = settingsType.GetFields(); + foreach (FieldInfo fieldInfo in fieldInfos) + { + if (fieldInfo.FieldType == typeof(System.String)) + { + fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass))); + } + if (fieldInfo.FieldType == typeof(System.Boolean)) + { + fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass))); + } + if (fieldInfo.FieldType == typeof(System.Int32)) + { + fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass))); + } + if (fieldInfo.FieldType == typeof(System.Single)) + { + fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass))); + } + } + + PropertyInfo[] propertyInfos = settingsType.GetProperties(); + foreach (PropertyInfo propInfo in propertyInfos) + { + if ((propInfo.CanRead) && (propInfo.CanWrite)) + { + if (propInfo.PropertyType == typeof(System.String)) + { + propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null); + } + if (propInfo.PropertyType == typeof(System.Boolean)) + { + propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null); + } + if (propInfo.PropertyType == typeof(System.Int32)) + { + propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null); + } + if (propInfo.PropertyType == typeof(System.Single)) + { + propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null); + } + } + } + + return settingsClass; + } } } diff --git a/OpenSim/Grid/GridServer/GridConfigurationLoader.cs b/OpenSim/Grid/GridServer/GridConfigurationLoader.cs index 8c2b806088..adfbee9895 100644 --- a/OpenSim/Grid/GridServer/GridConfigurationLoader.cs +++ b/OpenSim/Grid/GridServer/GridConfigurationLoader.cs @@ -196,7 +196,7 @@ namespace OpenSim.Grid.GridServer if (null == config) config = defaultConfig.AddConfig("Startup"); - config.Set("LoadPlugins", "GridServerPlugin;UserServerPlugin"); + config.Set("LoadPlugins", "GridServerPlugin,UserServerPlugin"); config.Set("HttpPort", "8051"); } diff --git a/OpenSim/Grid/UserServer.Modules/UserServerPlugin.cs b/OpenSim/Grid/UserServer.Modules/UserServerPlugin.cs index e3d1f84b7a..70d4708a8f 100644 --- a/OpenSim/Grid/UserServer.Modules/UserServerPlugin.cs +++ b/OpenSim/Grid/UserServer.Modules/UserServerPlugin.cs @@ -155,7 +155,9 @@ namespace OpenSim.Grid.UserServer.Modules protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService) { - StartupLoginService(inventoryService); + m_loginService = new UserLoginService( + m_userDataBaseService, inventoryService, new LibraryRootFolder(m_cfg.LibraryXmlfile), m_cfg, m_cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); + // // Get the minimum defaultLevel to access to the grid // @@ -167,16 +169,6 @@ namespace OpenSim.Grid.UserServer.Modules m_eventDispatcher.Initialise(m_core); } - /// - /// Start up the login service - /// - /// - protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService) - { - m_loginService = new UserLoginService( - m_userDataBaseService, inventoryService, new LibraryRootFolder(m_cfg.LibraryXmlfile), m_cfg, m_cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); - } - protected virtual void PostInitialiseModules() { m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here