aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/ConfigurationMember.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Framework/General/ConfigurationMember.cs
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/General/ConfigurationMember.cs110
1 files changed, 68 insertions, 42 deletions
diff --git a/OpenSim/Framework/General/ConfigurationMember.cs b/OpenSim/Framework/General/ConfigurationMember.cs
index c71982a..5883d73 100644
--- a/OpenSim/Framework/General/ConfigurationMember.cs
+++ b/OpenSim/Framework/General/ConfigurationMember.cs
@@ -27,22 +27,19 @@
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;
35 33using System.Reflection;
36using libsecondlife; 34using libsecondlife;
37
38using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
39using System.Globalization;
40 36
41namespace OpenSim.Framework 37namespace OpenSim.Framework
42{ 38{
43 public class ConfigurationMember 39 public class ConfigurationMember
44 { 40 {
45 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); 41 public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result);
42
46 public delegate void ConfigurationOptionsLoad(); 43 public delegate void ConfigurationOptionsLoad();
47 44
48 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); 45 private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>();
@@ -53,22 +50,26 @@ namespace OpenSim.Framework
53 private ConfigurationOptionResult resultFunction; 50 private ConfigurationOptionResult resultFunction;
54 51
55 private IGenericConfig configurationPlugin = null; 52 private IGenericConfig configurationPlugin = null;
53
56 /// <summary> 54 /// <summary>
57 /// This is the default configuration DLL loaded 55 /// This is the default configuration DLL loaded
58 /// </summary> 56 /// </summary>
59 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; 57 private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll";
60 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) 58
59 public ConfigurationMember(string configuration_filename, string configuration_description,
60 ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function)
61 { 61 {
62 this.configurationFilename = configuration_filename; 62 configurationFilename = configuration_filename;
63 this.configurationDescription = configuration_description; 63 configurationDescription = configuration_description;
64 this.loadFunction = load_function; 64 loadFunction = load_function;
65 this.resultFunction = result_function; 65 resultFunction = result_function;
66 } 66 }
67 67
68 public void setConfigurationFilename(string filename) 68 public void setConfigurationFilename(string filename)
69 { 69 {
70 configurationFilename = filename; 70 configurationFilename = filename;
71 } 71 }
72
72 public void setConfigurationDescription(string desc) 73 public void setConfigurationDescription(string desc)
73 { 74 {
74 configurationDescription = desc; 75 configurationDescription = desc;
@@ -83,7 +84,11 @@ namespace OpenSim.Framework
83 { 84 {
84 configurationPluginFilename = dll_filename; 85 configurationPluginFilename = dll_filename;
85 } 86 }
86 public void addConfigurationOption(string configuration_key, ConfigurationOption.ConfigurationTypes configuration_type, string configuration_question, string configuration_default, bool use_default_no_prompt) 87
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)
87 { 92 {
88 ConfigurationOption configOption = new ConfigurationOption(); 93 ConfigurationOption configOption = new ConfigurationOption();
89 configOption.configurationKey = configuration_key; 94 configOption.configurationKey = configuration_key;
@@ -92,7 +97,8 @@ namespace OpenSim.Framework
92 configOption.configurationType = configuration_type; 97 configOption.configurationType = configuration_type;
93 configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; 98 configOption.configurationUseDefaultNoPrompt = use_default_no_prompt;
94 99
95 if ((configuration_key != "" && configuration_question != "") || (configuration_key != "" && use_default_no_prompt)) 100 if ((configuration_key != "" && configuration_question != "") ||
101 (configuration_key != "" && use_default_no_prompt))
96 { 102 {
97 if (!configurationOptions.Contains(configOption)) 103 if (!configurationOptions.Contains(configOption))
98 { 104 {
@@ -101,32 +107,37 @@ namespace OpenSim.Framework
101 } 107 }
102 else 108 else
103 { 109 {
104 MainLog.Instance.Notice("Required fields for adding a configuration option is invalid. Will not add this option (" + configuration_key + ")"); 110 MainLog.Instance.Notice(
111 "Required fields for adding a configuration option is invalid. Will not add this option (" +
112 configuration_key + ")");
105 } 113 }
106 } 114 }
107 115
108 public void performConfigurationRetrieve() 116 public void performConfigurationRetrieve()
109 { 117 {
110 configurationPlugin = this.LoadConfigDll(configurationPluginFilename); 118 configurationPlugin = LoadConfigDll(configurationPluginFilename);
111 configurationOptions.Clear(); 119 configurationOptions.Clear();
112 if(loadFunction == null) 120 if (loadFunction == null)
113 { 121 {
114 MainLog.Instance.Error("Load Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 122 MainLog.Instance.Error("Load Function for '" + configurationDescription +
123 "' is null. Refusing to run configuration.");
115 return; 124 return;
116 } 125 }
117 126
118 if(resultFunction == null) 127 if (resultFunction == null)
119 { 128 {
120 MainLog.Instance.Error("Result Function for '" + this.configurationDescription + "' is null. Refusing to run configuration."); 129 MainLog.Instance.Error("Result Function for '" + configurationDescription +
130 "' is null. Refusing to run configuration.");
121 return; 131 return;
122 } 132 }
123 133
124 MainLog.Instance.Verbose("Calling Configuration Load Function..."); 134 MainLog.Instance.Verbose("Calling Configuration Load Function...");
125 this.loadFunction(); 135 loadFunction();
126 136
127 if(configurationOptions.Count <= 0) 137 if (configurationOptions.Count <= 0)
128 { 138 {
129 MainLog.Instance.Error("No configuration options were specified for '" + this.configurationOptions + "'. Refusing to continue configuration."); 139 MainLog.Instance.Error("No configuration options were specified for '" + configurationOptions +
140 "'. Refusing to continue configuration.");
130 return; 141 return;
131 } 142 }
132 143
@@ -157,7 +168,6 @@ namespace OpenSim.Framework
157 bool ignoreNextFromConfig = false; 168 bool ignoreNextFromConfig = false;
158 while (convertSuccess == false) 169 while (convertSuccess == false)
159 { 170 {
160
161 string console_result = ""; 171 string console_result = "";
162 string attribute = null; 172 string attribute = null;
163 if (useFile) 173 if (useFile)
@@ -180,16 +190,20 @@ namespace OpenSim.Framework
180 } 190 }
181 else 191 else
182 { 192 {
183
184 if (configurationDescription.Trim() != "") 193 if (configurationDescription.Trim() != "")
185 { 194 {
186 console_result = MainLog.Instance.CmdPrompt(configurationDescription + ": " + configOption.configurationQuestion, configOption.configurationDefault); 195 console_result =
196 MainLog.Instance.CmdPrompt(
197 configurationDescription + ": " + configOption.configurationQuestion,
198 configOption.configurationDefault);
187 } 199 }
188 else 200 else
189 { 201 {
190 console_result = MainLog.Instance.CmdPrompt(configOption.configurationQuestion, configOption.configurationDefault); 202 console_result =
203 MainLog.Instance.CmdPrompt(configOption.configurationQuestion,
204 configOption.configurationDefault);
191 } 205 }
192 } 206 }
193 } 207 }
194 else 208 else
195 { 209 {
@@ -252,7 +266,6 @@ namespace OpenSim.Framework
252 { 266 {
253 convertSuccess = true; 267 convertSuccess = true;
254 return_result = intResult; 268 return_result = intResult;
255
256 } 269 }
257 errorMessage = "a signed 32 bit integer (int)"; 270 errorMessage = "a signed 32 bit integer (int)";
258 break; 271 break;
@@ -307,7 +320,6 @@ namespace OpenSim.Framework
307 { 320 {
308 convertSuccess = true; 321 convertSuccess = true;
309 return_result = uintResult; 322 return_result = uintResult;
310
311 } 323 }
312 errorMessage = "an unsigned 32 bit integer (uint)"; 324 errorMessage = "an unsigned 32 bit integer (uint)";
313 break; 325 break;
@@ -322,7 +334,9 @@ namespace OpenSim.Framework
322 break; 334 break;
323 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: 335 case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT:
324 float floatResult; 336 float floatResult;
325 if (float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out floatResult)) 337 if (
338 float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
339 out floatResult))
326 { 340 {
327 convertSuccess = true; 341 convertSuccess = true;
328 return_result = floatResult; 342 return_result = floatResult;
@@ -331,7 +345,9 @@ namespace OpenSim.Framework
331 break; 345 break;
332 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: 346 case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE:
333 double doubleResult; 347 double doubleResult;
334 if (Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out doubleResult)) 348 if (
349 Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
350 out doubleResult))
335 { 351 {
336 convertSuccess = true; 352 convertSuccess = true;
337 return_result = doubleResult; 353 return_result = doubleResult;
@@ -348,9 +364,10 @@ namespace OpenSim.Framework
348 } 364 }
349 365
350 366
351 if (!this.resultFunction(configOption.configurationKey, return_result)) 367 if (!resultFunction(configOption.configurationKey, return_result))
352 { 368 {
353 Console.MainLog.Instance.Notice("The handler for the last configuration option denied that input, please try again."); 369 MainLog.Instance.Notice(
370 "The handler for the last configuration option denied that input, please try again.");
354 convertSuccess = false; 371 convertSuccess = false;
355 ignoreNextFromConfig = true; 372 ignoreNextFromConfig = true;
356 } 373 }
@@ -359,19 +376,27 @@ namespace OpenSim.Framework
359 { 376 {
360 if (configOption.configurationUseDefaultNoPrompt) 377 if (configOption.configurationUseDefaultNoPrompt)
361 { 378 {
362 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)); 379 MainLog.Instance.Error("CONFIG",
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));
363 convertSuccess = true; 384 convertSuccess = true;
364 } 385 }
365 else 386 else
366 { 387 {
367 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)); 388 MainLog.Instance.Warn("CONFIG",
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));
368 ignoreNextFromConfig = true; 393 ignoreNextFromConfig = true;
369 } 394 }
370 } 395 }
371 } 396 }
372 } 397 }
373 398
374 if(useFile) 399 if (useFile)
375 { 400 {
376 configurationPlugin.Commit(); 401 configurationPlugin.Commit();
377 configurationPlugin.Close(); 402 configurationPlugin.Close();
@@ -393,7 +418,8 @@ namespace OpenSim.Framework
393 418
394 if (typeInterface != null) 419 if (typeInterface != null)
395 { 420 {
396 plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 421 plug =
422 (IGenericConfig) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
397 } 423 }
398 } 424 }
399 } 425 }
@@ -405,10 +431,10 @@ namespace OpenSim.Framework
405 431
406 public void forceSetConfigurationOption(string configuration_key, string configuration_value) 432 public void forceSetConfigurationOption(string configuration_key, string configuration_value)
407 { 433 {
408 this.configurationPlugin.LoadData(); 434 configurationPlugin.LoadData();
409 this.configurationPlugin.SetAttribute(configuration_key, configuration_value); 435 configurationPlugin.SetAttribute(configuration_key, configuration_value);
410 this.configurationPlugin.Commit(); 436 configurationPlugin.Commit();
411 this.configurationPlugin.Close(); 437 configurationPlugin.Close();
412 } 438 }
413 } 439 }
414} 440} \ No newline at end of file