aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorDev Random2014-02-25 08:24:22 -0500
committerJustin Clark-Casey (justincc)2014-02-26 23:39:45 +0000
commit6955190c7db2563927bc53fd47ed0b47094be45c (patch)
treef1194c1d68f79887df86abf766bcad104516879d /OpenSim/Framework/Util.cs
parentAdd some regression tests for previous commit 0e23374 (diff)
downloadopensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.zip
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.gz
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.bz2
opensim-SC_OLD-6955190c7db2563927bc53fd47ed0b47094be45c.tar.xz
Add Util method to load OpSys env vars
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs170
1 files changed, 87 insertions, 83 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index c7377b8..65cf177 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -946,11 +946,12 @@ namespace OpenSim.Framework
946 } 946 }
947 947
948 #region Nini (config) related Methods 948 #region Nini (config) related Methods
949
949 public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName) 950 public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName)
950 { 951 {
951 if (!File.Exists(fileName)) 952 if (!File.Exists(fileName))
952 { 953 {
953 //create new file 954 // create new file
954 } 955 }
955 XmlConfigSource config = new XmlConfigSource(fileName); 956 XmlConfigSource config = new XmlConfigSource(fileName);
956 AddDataRowToConfig(config, row); 957 AddDataRowToConfig(config, row);
@@ -968,25 +969,6 @@ namespace OpenSim.Framework
968 } 969 }
969 } 970 }
970 971
971 public static string GetConfigVarWithDefaultSection(IConfigSource config, string varname, string section)
972 {
973 // First, check the Startup section, the default section
974 IConfig cnf = config.Configs["Startup"];
975 if (cnf == null)
976 return string.Empty;
977 string val = cnf.GetString(varname, string.Empty);
978
979 // Then check for an overwrite of the default in the given section
980 if (!string.IsNullOrEmpty(section))
981 {
982 cnf = config.Configs[section];
983 if (cnf != null)
984 val = cnf.GetString(varname, val);
985 }
986
987 return val;
988 }
989
990 /// <summary> 972 /// <summary>
991 /// Gets the value of a configuration variable by looking into 973 /// Gets the value of a configuration variable by looking into
992 /// multiple sections in order. The latter sections overwrite 974 /// multiple sections in order. The latter sections overwrite
@@ -1039,6 +1021,91 @@ namespace OpenSim.Framework
1039 return (T)val; 1021 return (T)val;
1040 } 1022 }
1041 1023
1024 public static void MergeEnvironmentToConfig(IConfigSource ConfigSource)
1025 {
1026 IConfig enVars = ConfigSource.Configs["Environment"];
1027 // if section does not exist then user isn't expecting them, so don't bother.
1028 if( enVars != null )
1029 {
1030 // load the values from the environment
1031 EnvConfigSource envConfigSource = new EnvConfigSource();
1032 // add the requested keys
1033 string[] env_keys = enVars.GetKeys();
1034 foreach ( string key in env_keys )
1035 {
1036 envConfigSource.AddEnv(key, string.Empty);
1037 }
1038 // load the values from environment
1039 envConfigSource.LoadEnv();
1040 // add them in to the master
1041 ConfigSource.Merge(envConfigSource);
1042 ConfigSource.ExpandKeyValues();
1043 }
1044 }
1045
1046 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
1047 {
1048 Type settingsType = settingsClass.GetType();
1049
1050 FieldInfo[] fieldInfos = settingsType.GetFields();
1051 foreach (FieldInfo fieldInfo in fieldInfos)
1052 {
1053 if (!fieldInfo.IsStatic)
1054 {
1055 if (fieldInfo.FieldType == typeof(System.String))
1056 {
1057 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
1058 }
1059 else if (fieldInfo.FieldType == typeof(System.Boolean))
1060 {
1061 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
1062 }
1063 else if (fieldInfo.FieldType == typeof(System.Int32))
1064 {
1065 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
1066 }
1067 else if (fieldInfo.FieldType == typeof(System.Single))
1068 {
1069 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
1070 }
1071 else if (fieldInfo.FieldType == typeof(System.UInt32))
1072 {
1073 fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
1074 }
1075 }
1076 }
1077
1078 PropertyInfo[] propertyInfos = settingsType.GetProperties();
1079 foreach (PropertyInfo propInfo in propertyInfos)
1080 {
1081 if ((propInfo.CanRead) && (propInfo.CanWrite))
1082 {
1083 if (propInfo.PropertyType == typeof(System.String))
1084 {
1085 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
1086 }
1087 else if (propInfo.PropertyType == typeof(System.Boolean))
1088 {
1089 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
1090 }
1091 else if (propInfo.PropertyType == typeof(System.Int32))
1092 {
1093 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
1094 }
1095 else if (propInfo.PropertyType == typeof(System.Single))
1096 {
1097 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
1098 }
1099 if (propInfo.PropertyType == typeof(System.UInt32))
1100 {
1101 propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
1102 }
1103 }
1104 }
1105
1106 return settingsClass;
1107 }
1108
1042 #endregion 1109 #endregion
1043 1110
1044 public static float Clip(float x, float min, float max) 1111 public static float Clip(float x, float min, float max)
@@ -1411,69 +1478,6 @@ namespace OpenSim.Framework
1411 return displayConnectionString; 1478 return displayConnectionString;
1412 } 1479 }
1413 1480
1414 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
1415 {
1416 Type settingsType = settingsClass.GetType();
1417
1418 FieldInfo[] fieldInfos = settingsType.GetFields();
1419 foreach (FieldInfo fieldInfo in fieldInfos)
1420 {
1421 if (!fieldInfo.IsStatic)
1422 {
1423 if (fieldInfo.FieldType == typeof(System.String))
1424 {
1425 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
1426 }
1427 else if (fieldInfo.FieldType == typeof(System.Boolean))
1428 {
1429 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
1430 }
1431 else if (fieldInfo.FieldType == typeof(System.Int32))
1432 {
1433 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
1434 }
1435 else if (fieldInfo.FieldType == typeof(System.Single))
1436 {
1437 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
1438 }
1439 else if (fieldInfo.FieldType == typeof(System.UInt32))
1440 {
1441 fieldInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
1442 }
1443 }
1444 }
1445
1446 PropertyInfo[] propertyInfos = settingsType.GetProperties();
1447 foreach (PropertyInfo propInfo in propertyInfos)
1448 {
1449 if ((propInfo.CanRead) && (propInfo.CanWrite))
1450 {
1451 if (propInfo.PropertyType == typeof(System.String))
1452 {
1453 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
1454 }
1455 else if (propInfo.PropertyType == typeof(System.Boolean))
1456 {
1457 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
1458 }
1459 else if (propInfo.PropertyType == typeof(System.Int32))
1460 {
1461 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
1462 }
1463 else if (propInfo.PropertyType == typeof(System.Single))
1464 {
1465 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
1466 }
1467 if (propInfo.PropertyType == typeof(System.UInt32))
1468 {
1469 propInfo.SetValue(settingsClass, Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
1470 }
1471 }
1472 }
1473
1474 return settingsClass;
1475 }
1476
1477 public static string Base64ToString(string str) 1481 public static string Base64ToString(string str)
1478 { 1482 {
1479 Decoder utf8Decode = Encoding.UTF8.GetDecoder(); 1483 Decoder utf8Decode = Encoding.UTF8.GetDecoder();