aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/ConfigurationMember.cs
diff options
context:
space:
mode:
authorlbsa712007-12-27 21:41:48 +0000
committerlbsa712007-12-27 21:41:48 +0000
commitefd90b56b761219af6425b1c7a2cdd3b6ffb4de2 (patch)
treebf5b897e1e3c13211e3e2fc61d30508b94c928c0 /OpenSim/Framework/ConfigurationMember.cs
parent* removed always true if (diff)
downloadopensim-SC_OLD-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.zip
opensim-SC_OLD-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.gz
opensim-SC_OLD-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.bz2
opensim-SC_OLD-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.xz
* Optimized usings
* shortened references * Removed redundant 'this' * Normalized EOF
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/ConfigurationMember.cs135
1 files changed, 87 insertions, 48 deletions
diff --git a/OpenSim/Framework/ConfigurationMember.cs b/OpenSim/Framework/ConfigurationMember.cs
index 271c02c..a5ab613 100644
--- a/OpenSim/Framework/ConfigurationMember.cs
+++ b/OpenSim/Framework/ConfigurationMember.cs
@@ -27,24 +27,20 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Reflection;
31using System.Collections;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Text; 31using System.Globalization;
34using System.Net; 32using System.Net;
33using System.Reflection;
35using System.Xml; 34using System.Xml;
36
37using libsecondlife; 35using libsecondlife;
38
39using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
40using OpenSim.Framework;
41using System.Globalization;
42 37
43namespace OpenSim.Framework 38namespace OpenSim.Framework
44{ 39{
45 public class ConfigurationMember 40 public class ConfigurationMember
46 { 41 {
47 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); 42 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result);
43
48 public delegate void ConfigurationOptionsLoad(); 44 public delegate void ConfigurationOptionsLoad();
49 45
50 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); 46 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>();
@@ -55,29 +51,36 @@ namespace OpenSim.Framework
55 private ConfigurationOptionResult resultFunction; 51 private ConfigurationOptionResult resultFunction;
56 52
57 private IGenericConfig configurationPlugin = null; 53 private IGenericConfig configurationPlugin = null;
54
58 /// <summary> 55 /// <summary>
59 /// This is the default configuration DLL loaded 56 /// This is the default configuration DLL loaded
60 /// </summary> 57 /// </summary>
61 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; 58 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll";
62 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) 59
60 public ConfigurationMember(string configuration_filename, string configuration_description,
61 ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function)
63 { 62 {
64 this.configurationFilename = configuration_filename; 63 configurationFilename = configuration_filename;
65 this.configurationDescription = configuration_description; 64 configurationDescription = configuration_description;
66 this.loadFunction = load_function; 65 loadFunction = load_function;
67 this.resultFunction = result_function; 66 resultFunction = result_function;
68 } 67 }
69 public ConfigurationMember(XmlNode configuration_xml, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) 68
69 public ConfigurationMember(XmlNode configuration_xml, string configuration_description,
70 ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function)
70 { 71 {
71 this.configurationFilename = ""; 72 configurationFilename = "";
72 this.configurationFromXMLNode = configuration_xml; 73 configurationFromXMLNode = configuration_xml;
73 this.configurationDescription = configuration_description; 74 configurationDescription = configuration_description;
74 this.loadFunction = load_function; 75 loadFunction = load_function;
75 this.resultFunction = result_function; 76 resultFunction = result_function;
76 } 77 }
78
77 public void setConfigurationFilename(string filename) 79 public void setConfigurationFilename(string filename)
78 { 80 {
79 configurationFilename = filename; 81 configurationFilename = filename;
80 } 82 }
83
81 public void setConfigurationDescription(string desc) 84 public void setConfigurationDescription(string desc)
82 { 85 {
83 configurationDescription = desc; 86 configurationDescription = desc;
@@ -92,9 +95,11 @@ namespace OpenSim.Framework
92 { 95 {
93 configurationPluginFilename = dll_filename; 96 configurationPluginFilename = dll_filename;
94 } 97 }
98
95 private void checkAndAddConfigOption(ConfigurationOption option) 99 private void checkAndAddConfigOption(ConfigurationOption option)
96 { 100 {
97 if ((option.configurationKey != "" && option.configurationQuestion != "") || (option.configurationKey != "" && option.configurationUseDefaultNoPrompt)) 101 if ((option.configurationKey != "" && option.configurationQuestion != "") ||
102 (option.configurationKey != "" && option.configurationUseDefaultNoPrompt))
98 { 103 {
99 if (!configurationOptions.Contains(option)) 104 if (!configurationOptions.Contains(option))
100 { 105 {
@@ -103,11 +108,16 @@ namespace OpenSim.Framework
103 } 108 }
104 else 109 else
105 { 110 {
106 MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + option.configurationKey + ")"); 111 MainLog.Instance.Notice(
112 "Required fields for adding a configuration option is invalid. Will not add this option (" +
113 option.configurationKey + ")");
107 } 114 }
108 } 115 }
109 116
110 public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt) 117 public void addConfigurationOption(string configuration_key,
118 ConfigurationOption.ConfigurationTypes configuration_type,
119 string configuration_question, string configuration_default,
120 bool use_default_no_prompt)
111 { 121 {
112 ConfigurationOption configOption = new ConfigurationOption(); 122 ConfigurationOption configOption = new ConfigurationOption();
113 configOption.configurationKey = configuration_key; 123 configOption.configurationKey = configuration_key;
@@ -119,7 +129,11 @@ namespace OpenSim.Framework
119 checkAndAddConfigOption(configOption); 129 checkAndAddConfigOption(configOption);
120 } 130 }
121 131
122 public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt, ConfigurationOption.ConfigurationOptionShouldBeAsked shouldIBeAskedDelegate) 132 public void addConfigurationOption(string configuration_key,
133 ConfigurationOption.ConfigurationTypes configuration_type,
134 string configuration_question, string configuration_default,
135 bool use_default_no_prompt,
136 ConfigurationOption.ConfigurationOptionShouldBeAsked shouldIBeAskedDelegate)
123 { 137 {
124 ConfigurationOption configOption = new ConfigurationOption(); 138 ConfigurationOption configOption = new ConfigurationOption();
125 configOption.configurationKey = configuration_key; 139 configOption.configurationKey = configuration_key;
@@ -133,26 +147,30 @@ namespace OpenSim.Framework
133 147
134 public void performConfigurationRetrieve() 148 public void performConfigurationRetrieve()
135 { 149 {
136 configurationPlugin = this.LoadConfigDll(configurationPluginFilename); 150 configurationPlugin = LoadConfigDll(configurationPluginFilename);
137 configurationOptions.Clear(); 151 configurationOptions.Clear();
138 if(loadFunction == null) 152 if (loadFunction == null)
139 { 153 {
140 MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 154 MainLog.Instance.Error("Load Function for '" + configurationDescription +
155 "' is null. Refusing to run configuration.");
141 return; 156 return;
142 } 157 }
143 158
144 if(resultFunction == null) 159 if (resultFunction == null)
145 { 160 {
146 MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 161 MainLog.Instance.Error("Result Function for '" + configurationDescription +
162 "' is null. Refusing to run configuration.");
147 return; 163 return;
148 } 164 }
149 165
150 MainLog.Instance.Verbose("CONFIG", "Calling Configuration Load Function..."); 166 MainLog.Instance.Verbose("CONFIG", "Calling Configuration Load Function...");
151 this.loadFunction(); 167 loadFunction();
152 168
153 if(configurationOptions.Count <= 0) 169 if (configurationOptions.Count <= 0)
154 { 170 {
155 MainLog.Instance.Error("CONFIG", "No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration."); 171 MainLog.Instance.Error("CONFIG",
172 "No configuration options were specified for '" + configurationOptions +
173 "'. Refusing to continue configuration.");
156 return; 174 return;
157 } 175 }
158 176
@@ -179,7 +197,7 @@ namespace OpenSim.Framework
179 } 197 }
180 else 198 else
181 { 199 {
182 if (this.configurationFromXMLNode != null) 200 if (configurationFromXMLNode != null)
183 { 201 {
184 MainLog.Instance.Notice("Loading from XML Node, will not save to the file"); 202 MainLog.Instance.Notice("Loading from XML Node, will not save to the file");
185 configurationPlugin.LoadDataFromString(configurationFromXMLNode.OuterXml); 203 configurationPlugin.LoadDataFromString(configurationFromXMLNode.OuterXml);
@@ -219,15 +237,22 @@ namespace OpenSim.Framework
219 } 237 }
220 else 238 else
221 { 239 {
222 if ((configOption.shouldIBeAsked != null && configOption.shouldIBeAsked(configOption.configurationKey)) || configOption.shouldIBeAsked == null) 240 if ((configOption.shouldIBeAsked != null &&
241 configOption.shouldIBeAsked(configOption.configurationKey)) ||
242 configOption.shouldIBeAsked == null)
223 { 243 {
224 if (configurationDescription.Trim() != "") 244 if (configurationDescription.Trim() != "")
225 { 245 {
226 console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault); 246 console_result =
247 MainLog.Instance.CmdPrompt(
248 configurationDescription + ": " + configOption.configurationQuestion,
249 configOption.configurationDefault);
227 } 250 }
228 else 251 else
229 { 252 {
230 console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault); 253 console_result =
254 MainLog.Instance.CmdPrompt(configOption.configurationQuestion,
255 configOption.configurationDefault);
231 } 256 }
232 } 257 }
233 else 258 else
@@ -235,7 +260,7 @@ namespace OpenSim.Framework
235 //Dont Ask! Just use default 260 //Dont Ask! Just use default
236 console_result = configOption.configurationDefault; 261 console_result = configOption.configurationDefault;
237 } 262 }
238 } 263 }
239 } 264 }
240 else 265 else
241 { 266 {
@@ -366,7 +391,9 @@ namespace OpenSim.Framework
366 break; 391 break;
367 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: 392 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT:
368 float floatResult; 393 float floatResult;
369 if (float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out floatResult)) 394 if (
395 float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
396 out floatResult))
370 { 397 {
371 convertSuccess = true; 398 convertSuccess = true;
372 return_result = floatResult; 399 return_result = floatResult;
@@ -375,7 +402,9 @@ namespace OpenSim.Framework
375 break; 402 break;
376 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: 403 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE:
377 double doubleResult; 404 double doubleResult;
378 if (Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out doubleResult)) 405 if (
406 Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
407 out doubleResult))
379 { 408 {
380 convertSuccess = true; 409 convertSuccess = true;
381 return_result = doubleResult; 410 return_result = doubleResult;
@@ -391,9 +420,10 @@ namespace OpenSim.Framework
391 configurationPlugin.SetAttribute(configOption.configurationKey, console_result); 420 configurationPlugin.SetAttribute(configOption.configurationKey, console_result);
392 } 421 }
393 422
394 if (!this.resultFunction(configOption.configurationKey, return_result)) 423 if (!resultFunction(configOption.configurationKey, return_result))
395 { 424 {
396 Console.MainLog.Instance.Notice("The handler for the last configuration option denied that input, please try again."); 425 MainLog.Instance.Notice(
426 "The handler for the last configuration option denied that input, please try again.");
397 convertSuccess = false; 427 convertSuccess = false;
398 ignoreNextFromConfig = true; 428 ignoreNextFromConfig = true;
399 } 429 }
@@ -402,19 +432,27 @@ namespace OpenSim.Framework
402 { 432 {
403 if (configOption.configurationUseDefaultNoPrompt) 433 if (configOption.configurationUseDefaultNoPrompt)
404 { 434 {
405 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)); 435 MainLog.Instance.Error("CONFIG",
436 string.Format(
437 "[{3}]:[{1}] is not valid default for parameter [{0}].\nThe configuration result must be parsable to {2}.\n",
438 configOption.configurationKey, console_result, errorMessage,
439 configurationFilename));
406 convertSuccess = true; 440 convertSuccess = true;
407 } 441 }
408 else 442 else
409 { 443 {
410 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)); 444 MainLog.Instance.Warn("CONFIG",
445 string.Format(
446 "[{3}]:[{1}] is not a valid value [{0}].\nThe configuration result must be parsable to {2}.\n",
447 configOption.configurationKey, console_result, errorMessage,
448 configurationFilename));
411 ignoreNextFromConfig = true; 449 ignoreNextFromConfig = true;
412 } 450 }
413 } 451 }
414 } 452 }
415 } 453 }
416 454
417 if(useFile) 455 if (useFile)
418 { 456 {
419 configurationPlugin.Commit(); 457 configurationPlugin.Commit();
420 configurationPlugin.Close(); 458 configurationPlugin.Close();
@@ -436,7 +474,8 @@ namespace OpenSim.Framework
436 474
437 if (typeInterface != null) 475 if (typeInterface != null)
438 { 476 {
439 plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 477 plug =
478 (IGenericConfig) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
440 } 479 }
441 } 480 }
442 } 481 }
@@ -448,10 +487,10 @@ namespace OpenSim.Framework
448 487
449 public void forceSetConfigurationOption(string configuration_key, string configuration_value) 488 public void forceSetConfigurationOption(string configuration_key, string configuration_value)
450 { 489 {
451 this.configurationPlugin.LoadData(); 490 configurationPlugin.LoadData();
452 this.configurationPlugin.SetAttribute(configuration_key, configuration_value); 491 configurationPlugin.SetAttribute(configuration_key, configuration_value);
453 this.configurationPlugin.Commit(); 492 configurationPlugin.Commit();
454 this.configurationPlugin.Close(); 493 configurationPlugin.Close();
455 } 494 }
456 } 495 }
457} 496} \ No newline at end of file