Some small clean up of the Grid/User servers.

Added T ReadSettingsFromIniFile<T>(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]
GenericGridServerConcept
MW 2009-02-28 13:08:16 +00:00
parent 4fc37a4abd
commit 21e9ad6150
4 changed files with 58 additions and 12 deletions

View File

@ -200,6 +200,7 @@ namespace OpenSim.Framework
m_librariesXMLFile = value; m_librariesXMLFile = value;
} }
} }
protected string m_assetSetsXMLFile; protected string m_assetSetsXMLFile;
public string AssetSetsXMLFile public string AssetSetsXMLFile
{ {

View File

@ -26,6 +26,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -931,5 +932,57 @@ namespace OpenSim.Framework
return displayConnectionString; return displayConnectionString;
} }
public static T ReadSettingsFromIniFile<T>(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;
}
} }
} }

View File

@ -196,7 +196,7 @@ namespace OpenSim.Grid.GridServer
if (null == config) if (null == config)
config = defaultConfig.AddConfig("Startup"); config = defaultConfig.AddConfig("Startup");
config.Set("LoadPlugins", "GridServerPlugin;UserServerPlugin"); config.Set("LoadPlugins", "GridServerPlugin,UserServerPlugin");
config.Set("HttpPort", "8051"); config.Set("HttpPort", "8051");
} }

View File

@ -155,7 +155,9 @@ namespace OpenSim.Grid.UserServer.Modules
protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService) 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 // Get the minimum defaultLevel to access to the grid
// //
@ -167,16 +169,6 @@ namespace OpenSim.Grid.UserServer.Modules
m_eventDispatcher.Initialise(m_core); m_eventDispatcher.Initialise(m_core);
} }
/// <summary>
/// Start up the login service
/// </summary>
/// <param name="inventoryService"></param>
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() protected virtual void PostInitialiseModules()
{ {
m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here