diff options
author | mingchen | 2007-11-03 15:09:21 +0000 |
---|---|---|
committer | mingchen | 2007-11-03 15:09:21 +0000 |
commit | 51488ee7f415950583ba389582692900a2c32831 (patch) | |
tree | 7b63fdbb54e9a1bbb3ae7a6ed8d6eac8933e8dbb /OpenSim/Framework/ConfigurationMember.cs | |
parent | testing different rest post method/class for Grid asset client. (possible tha... (diff) | |
download | opensim-SC_OLD-51488ee7f415950583ba389582692900a2c32831.zip opensim-SC_OLD-51488ee7f415950583ba389582692900a2c32831.tar.gz opensim-SC_OLD-51488ee7f415950583ba389582692900a2c32831.tar.bz2 opensim-SC_OLD-51488ee7f415950583ba389582692900a2c32831.tar.xz |
*Moved region loading into its own interface IRegionLoader
*Added ability to load regioninfo remotely from a webserver from a single file. See share/RegionLoading/HOWTO_REMOTE_REGION_LOADING.txt for more info and an example file.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/ConfigurationMember.cs | 131 |
1 files changed, 60 insertions, 71 deletions
diff --git a/OpenSim/Framework/ConfigurationMember.cs b/OpenSim/Framework/ConfigurationMember.cs index b68896c..19275b3 100644 --- a/OpenSim/Framework/ConfigurationMember.cs +++ b/OpenSim/Framework/ConfigurationMember.cs | |||
@@ -27,49 +27,57 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Reflection; | ||
31 | using System.Collections; | ||
30 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
31 | using System.Globalization; | 33 | using System.Text; |
32 | using System.Net; | 34 | using System.Net; |
33 | using System.Reflection; | 35 | using System.Xml; |
36 | |||
34 | using libsecondlife; | 37 | using libsecondlife; |
38 | |||
35 | using OpenSim.Framework.Console; | 39 | using OpenSim.Framework.Console; |
40 | using OpenSim.Framework; | ||
41 | using System.Globalization; | ||
36 | 42 | ||
37 | namespace OpenSim.Framework | 43 | namespace OpenSim.Framework |
38 | { | 44 | { |
39 | public class ConfigurationMember | 45 | public class ConfigurationMember |
40 | { | 46 | { |
41 | public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); | 47 | public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); |
42 | |||
43 | public delegate void ConfigurationOptionsLoad(); | 48 | public delegate void ConfigurationOptionsLoad(); |
44 | 49 | ||
45 | private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); | 50 | private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); |
46 | private string configurationFilename = ""; | 51 | private string configurationFilename = ""; |
47 | private string configurationDescription = ""; | 52 | private string configurationDescription = ""; |
48 | 53 | private XmlNode configurationFromXMLNode = null; | |
49 | private ConfigurationOptionsLoad loadFunction; | 54 | private ConfigurationOptionsLoad loadFunction; |
50 | private ConfigurationOptionResult resultFunction; | 55 | private ConfigurationOptionResult resultFunction; |
51 | 56 | ||
52 | private IGenericConfig configurationPlugin = null; | 57 | private IGenericConfig configurationPlugin = null; |
53 | |||
54 | /// <summary> | 58 | /// <summary> |
55 | /// This is the default configuration DLL loaded | 59 | /// This is the default configuration DLL loaded |
56 | /// </summary> | 60 | /// </summary> |
57 | private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; | 61 | private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; |
58 | 62 | public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) | |
59 | public ConfigurationMember(string configuration_filename, string configuration_description, | ||
60 | ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) | ||
61 | { | 63 | { |
62 | configurationFilename = configuration_filename; | 64 | this.configurationFilename = configuration_filename; |
63 | configurationDescription = configuration_description; | 65 | this.configurationDescription = configuration_description; |
64 | loadFunction = load_function; | 66 | this.loadFunction = load_function; |
65 | resultFunction = result_function; | 67 | this.resultFunction = result_function; |
68 | } | ||
69 | public ConfigurationMember(XmlNode configuration_xml, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) | ||
70 | { | ||
71 | this.configurationFilename = ""; | ||
72 | this.configurationFromXMLNode = configuration_xml; | ||
73 | this.configurationDescription = configuration_description; | ||
74 | this.loadFunction = load_function; | ||
75 | this.resultFunction = result_function; | ||
66 | } | 76 | } |
67 | |||
68 | public void setConfigurationFilename(string filename) | 77 | public void setConfigurationFilename(string filename) |
69 | { | 78 | { |
70 | configurationFilename = filename; | 79 | configurationFilename = filename; |
71 | } | 80 | } |
72 | |||
73 | public void setConfigurationDescription(string desc) | 81 | public void setConfigurationDescription(string desc) |
74 | { | 82 | { |
75 | configurationDescription = desc; | 83 | configurationDescription = desc; |
@@ -84,11 +92,7 @@ namespace OpenSim.Framework | |||
84 | { | 92 | { |
85 | configurationPluginFilename = dll_filename; | 93 | configurationPluginFilename = dll_filename; |
86 | } | 94 | } |
87 | 95 | public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt) | |
88 | public void addConfigurationOption(string configuration_key, | ||
89 | ConfigurationOption.ConfigurationTypes configuration_type, | ||
90 | string configuration_question, string configuration_default, | ||
91 | bool use_default_no_prompt) | ||
92 | { | 96 | { |
93 | ConfigurationOption configOption = new ConfigurationOption(); | 97 | ConfigurationOption configOption = new ConfigurationOption(); |
94 | configOption.configurationKey = configuration_key; | 98 | configOption.configurationKey = configuration_key; |
@@ -97,8 +101,7 @@ namespace OpenSim.Framework | |||
97 | configOption.configurationType = configuration_type; | 101 | configOption.configurationType = configuration_type; |
98 | configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; | 102 | configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; |
99 | 103 | ||
100 | if ((configuration_key != "" && configuration_question != "") || | 104 | if ((configuration_key != "" && configuration_question != "") || (configuration_key != "" && use_default_no_prompt)) |
101 | (configuration_key != "" && use_default_no_prompt)) | ||
102 | { | 105 | { |
103 | if (!configurationOptions.Contains(configOption)) | 106 | if (!configurationOptions.Contains(configOption)) |
104 | { | 107 | { |
@@ -107,37 +110,32 @@ namespace OpenSim.Framework | |||
107 | } | 110 | } |
108 | else | 111 | else |
109 | { | 112 | { |
110 | MainLog.Instance.Notice( | 113 | MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + configuration_key + ")"); |
111 | "Required fields for adding a configuration option is invalid. Will not add this option (" + | ||
112 | configuration_key + ")"); | ||
113 | } | 114 | } |
114 | } | 115 | } |
115 | 116 | ||
116 | public void performConfigurationRetrieve() | 117 | public void performConfigurationRetrieve() |
117 | { | 118 | { |
118 | configurationPlugin = LoadConfigDll(configurationPluginFilename); | 119 | configurationPlugin = this.LoadConfigDll(configurationPluginFilename); |
119 | configurationOptions.Clear(); | 120 | configurationOptions.Clear(); |
120 | if (loadFunction == null) | 121 | if(loadFunction == null) |
121 | { | 122 | { |
122 | MainLog.Instance.Error("Load Function for '" + configurationDescription + | 123 | MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); |
123 | "' is null. Refusing to run configuration."); | ||
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | 126 | ||
127 | if (resultFunction == null) | 127 | if(resultFunction == null) |
128 | { | 128 | { |
129 | MainLog.Instance.Error("Result Function for '" + configurationDescription + | 129 | MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); |
130 | "' is null. Refusing to run configuration."); | ||
131 | return; | 130 | return; |
132 | } | 131 | } |
133 | 132 | ||
134 | MainLog.Instance.Verbose("Calling Configuration Load Function..."); | 133 | MainLog.Instance.Verbose("Calling Configuration Load Function..."); |
135 | loadFunction(); | 134 | this.loadFunction(); |
136 | 135 | ||
137 | if (configurationOptions.Count <= 0) | 136 | if(configurationOptions.Count <= 0) |
138 | { | 137 | { |
139 | MainLog.Instance.Error("No configuration options were specified for '" + configurationOptions + | 138 | MainLog.Instance.Error("No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration."); |
140 | "'. Refusing to continue configuration."); | ||
141 | return; | 139 | return; |
142 | } | 140 | } |
143 | 141 | ||
@@ -156,6 +154,12 @@ namespace OpenSim.Framework | |||
156 | } | 154 | } |
157 | else | 155 | else |
158 | { | 156 | { |
157 | if (this.configurationFromXMLNode != null) | ||
158 | { | ||
159 | MainLog.Instance.Notice("Loading from XML Node, will not save to the file"); | ||
160 | configurationPlugin.LoadDataFromString(configurationFromXMLNode.OuterXml); | ||
161 | } | ||
162 | |||
159 | MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); | 163 | MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); |
160 | useFile = false; | 164 | useFile = false; |
161 | } | 165 | } |
@@ -168,9 +172,10 @@ namespace OpenSim.Framework | |||
168 | bool ignoreNextFromConfig = false; | 172 | bool ignoreNextFromConfig = false; |
169 | while (convertSuccess == false) | 173 | while (convertSuccess == false) |
170 | { | 174 | { |
175 | |||
171 | string console_result = ""; | 176 | string console_result = ""; |
172 | string attribute = null; | 177 | string attribute = null; |
173 | if (useFile) | 178 | if (useFile || (!useFile && configurationFromXMLNode != null)) |
174 | { | 179 | { |
175 | if (!ignoreNextFromConfig) | 180 | if (!ignoreNextFromConfig) |
176 | { | 181 | { |
@@ -190,20 +195,16 @@ namespace OpenSim.Framework | |||
190 | } | 195 | } |
191 | else | 196 | else |
192 | { | 197 | { |
198 | |||
193 | if (configurationDescription.Trim() != "") | 199 | if (configurationDescription.Trim() != "") |
194 | { | 200 | { |
195 | console_result = | 201 | console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault); |
196 | MainLog.Instance.CmdPrompt( | ||
197 | configurationDescription + ": " + configOption.configurationQuestion, | ||
198 | configOption.configurationDefault); | ||
199 | } | 202 | } |
200 | else | 203 | else |
201 | { | 204 | { |
202 | console_result = | 205 | console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault); |
203 | MainLog.Instance.CmdPrompt(configOption.configurationQuestion, | ||
204 | configOption.configurationDefault); | ||
205 | } | 206 | } |
206 | } | 207 | } |
207 | } | 208 | } |
208 | else | 209 | else |
209 | { | 210 | { |
@@ -266,6 +267,7 @@ namespace OpenSim.Framework | |||
266 | { | 267 | { |
267 | convertSuccess = true; | 268 | convertSuccess = true; |
268 | return_result = intResult; | 269 | return_result = intResult; |
270 | |||
269 | } | 271 | } |
270 | errorMessage = "a signed 32 bit integer (int)"; | 272 | errorMessage = "a signed 32 bit integer (int)"; |
271 | break; | 273 | break; |
@@ -320,6 +322,7 @@ namespace OpenSim.Framework | |||
320 | { | 322 | { |
321 | convertSuccess = true; | 323 | convertSuccess = true; |
322 | return_result = uintResult; | 324 | return_result = uintResult; |
325 | |||
323 | } | 326 | } |
324 | errorMessage = "an unsigned 32 bit integer (uint)"; | 327 | errorMessage = "an unsigned 32 bit integer (uint)"; |
325 | break; | 328 | break; |
@@ -334,9 +337,7 @@ namespace OpenSim.Framework | |||
334 | break; | 337 | break; |
335 | case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: | 338 | case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: |
336 | float floatResult; | 339 | float floatResult; |
337 | if ( | 340 | if (float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out floatResult)) |
338 | float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, | ||
339 | out floatResult)) | ||
340 | { | 341 | { |
341 | convertSuccess = true; | 342 | convertSuccess = true; |
342 | return_result = floatResult; | 343 | return_result = floatResult; |
@@ -345,9 +346,7 @@ namespace OpenSim.Framework | |||
345 | break; | 346 | break; |
346 | case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: | 347 | case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: |
347 | double doubleResult; | 348 | double doubleResult; |
348 | if ( | 349 | if (Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out doubleResult)) |
349 | Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, | ||
350 | out doubleResult)) | ||
351 | { | 350 | { |
352 | convertSuccess = true; | 351 | convertSuccess = true; |
353 | return_result = doubleResult; | 352 | return_result = doubleResult; |
@@ -364,10 +363,9 @@ namespace OpenSim.Framework | |||
364 | } | 363 | } |
365 | 364 | ||
366 | 365 | ||
367 | if (!resultFunction(configOption.configurationKey, return_result)) | 366 | if (!this.resultFunction(configOption.configurationKey, return_result)) |
368 | { | 367 | { |
369 | MainLog.Instance.Notice( | 368 | Console.MainLog.Instance.Notice("The handler for the last configuration option denied that input, please try again."); |
370 | "The handler for the last configuration option denied that input, please try again."); | ||
371 | convertSuccess = false; | 369 | convertSuccess = false; |
372 | ignoreNextFromConfig = true; | 370 | ignoreNextFromConfig = true; |
373 | } | 371 | } |
@@ -376,27 +374,19 @@ namespace OpenSim.Framework | |||
376 | { | 374 | { |
377 | if (configOption.configurationUseDefaultNoPrompt) | 375 | if (configOption.configurationUseDefaultNoPrompt) |
378 | { | 376 | { |
379 | MainLog.Instance.Error("CONFIG", | 377 | MainLog.Instance.Error("CONFIG", string.Format("[{3}]:[{1}] is not valid default for parameter [{0}].\nThe configuration result must be parsable to {2}.\n", configOption.configurationKey, console_result, errorMessage, configurationFilename)); |
380 | string.Format( | ||
381 | "[{3}]:[{1}] is not valid default for parameter [{0}].\nThe configuration result must be parsable to {2}.\n", | ||
382 | configOption.configurationKey, console_result, errorMessage, | ||
383 | configurationFilename)); | ||
384 | convertSuccess = true; | 378 | convertSuccess = true; |
385 | } | 379 | } |
386 | else | 380 | else |
387 | { | 381 | { |
388 | MainLog.Instance.Warn("CONFIG", | 382 | MainLog.Instance.Warn("CONFIG", string.Format("[{3}]:[{1}] is not a valid value [{0}].\nThe configuration result must be parsable to {2}.\n", configOption.configurationKey, console_result, errorMessage, configurationFilename)); |
389 | string.Format( | ||
390 | "[{3}]:[{1}] is not a valid value [{0}].\nThe configuration result must be parsable to {2}.\n", | ||
391 | configOption.configurationKey, console_result, errorMessage, | ||
392 | configurationFilename)); | ||
393 | ignoreNextFromConfig = true; | 383 | ignoreNextFromConfig = true; |
394 | } | 384 | } |
395 | } | 385 | } |
396 | } | 386 | } |
397 | } | 387 | } |
398 | 388 | ||
399 | if (useFile) | 389 | if(useFile) |
400 | { | 390 | { |
401 | configurationPlugin.Commit(); | 391 | configurationPlugin.Commit(); |
402 | configurationPlugin.Close(); | 392 | configurationPlugin.Close(); |
@@ -418,8 +408,7 @@ namespace OpenSim.Framework | |||
418 | 408 | ||
419 | if (typeInterface != null) | 409 | if (typeInterface != null) |
420 | { | 410 | { |
421 | plug = | 411 | plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); |
422 | (IGenericConfig) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
423 | } | 412 | } |
424 | } | 413 | } |
425 | } | 414 | } |
@@ -431,10 +420,10 @@ namespace OpenSim.Framework | |||
431 | 420 | ||
432 | public void forceSetConfigurationOption(string configuration_key, string configuration_value) | 421 | public void forceSetConfigurationOption(string configuration_key, string configuration_value) |
433 | { | 422 | { |
434 | configurationPlugin.LoadData(); | 423 | this.configurationPlugin.LoadData(); |
435 | configurationPlugin.SetAttribute(configuration_key, configuration_value); | 424 | this.configurationPlugin.SetAttribute(configuration_key, configuration_value); |
436 | configurationPlugin.Commit(); | 425 | this.configurationPlugin.Commit(); |
437 | configurationPlugin.Close(); | 426 | this.configurationPlugin.Close(); |
438 | } | 427 | } |
439 | } | 428 | } |
440 | } \ No newline at end of file | 429 | } |