aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/CommandConsole.cs
diff options
context:
space:
mode:
authorAdam Frisby2009-08-18 00:23:27 +1000
committerAdam Frisby2009-08-18 00:23:27 +1000
commit58d9d6026eb36d530c7cec753279b7aeaa6b43eb (patch)
tree86a09687ef01b308ac2ae8e1023ec9ddb943c54f /OpenSim/Framework/Console/CommandConsole.cs
parent* Implementing a bunch of Unimplemented MRM stubs. (diff)
parentAdd System.Xml reference to the console project (diff)
downloadopensim-SC_OLD-58d9d6026eb36d530c7cec753279b7aeaa6b43eb.zip
opensim-SC_OLD-58d9d6026eb36d530c7cec753279b7aeaa6b43eb.tar.gz
opensim-SC_OLD-58d9d6026eb36d530c7cec753279b7aeaa6b43eb.tar.bz2
opensim-SC_OLD-58d9d6026eb36d530c7cec753279b7aeaa6b43eb.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Framework/Console/CommandConsole.cs')
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs150
1 files changed, 150 insertions, 0 deletions
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index 8b63d01..3387013 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Xml;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Diagnostics; 31using System.Diagnostics;
31using System.Reflection; 32using System.Reflection;
@@ -369,6 +370,155 @@ namespace OpenSim.Framework.Console
369 370
370 return new string[0]; 371 return new string[0];
371 } 372 }
373
374 public XmlElement GetXml(XmlDocument doc)
375 {
376 CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
377 ((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
378 if (((Dictionary<string, object>)tree["help"]).Count == 0)
379 tree.Remove("help");
380
381 CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
382 ((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
383 if (((Dictionary<string, object>)tree["quit"]).Count == 0)
384 tree.Remove("quit");
385
386 XmlElement root = doc.CreateElement("", "HelpTree", "");
387
388 ProcessTreeLevel(tree, root, doc);
389
390 if (!tree.ContainsKey("help"))
391 tree["help"] = (object) new Dictionary<string, object>();
392 ((Dictionary<string, object>)tree["help"])[String.Empty] = help;
393
394 if (!tree.ContainsKey("quit"))
395 tree["quit"] = (object) new Dictionary<string, object>();
396 ((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
397
398 return root;
399 }
400
401 private void ProcessTreeLevel(Dictionary<string, object> level, XmlElement xml, XmlDocument doc)
402 {
403 foreach (KeyValuePair<string, object> kvp in level)
404 {
405 if (kvp.Value is Dictionary<string, Object>)
406 {
407 XmlElement next = doc.CreateElement("", "Level", "");
408 next.SetAttribute("Name", kvp.Key);
409
410 xml.AppendChild(next);
411
412 ProcessTreeLevel((Dictionary<string, object>)kvp.Value, next, doc);
413 }
414 else
415 {
416 CommandInfo c = (CommandInfo)kvp.Value;
417
418 XmlElement cmd = doc.CreateElement("", "Command", "");
419
420 XmlElement e;
421
422 e = doc.CreateElement("", "Module", "");
423 cmd.AppendChild(e);
424 e.AppendChild(doc.CreateTextNode(c.module));
425
426 e = doc.CreateElement("", "Shared", "");
427 cmd.AppendChild(e);
428 e.AppendChild(doc.CreateTextNode(c.shared.ToString()));
429
430 e = doc.CreateElement("", "HelpText", "");
431 cmd.AppendChild(e);
432 e.AppendChild(doc.CreateTextNode(c.help_text));
433
434 e = doc.CreateElement("", "LongHelp", "");
435 cmd.AppendChild(e);
436 e.AppendChild(doc.CreateTextNode(c.long_help));
437
438 e = doc.CreateElement("", "Description", "");
439 cmd.AppendChild(e);
440 e.AppendChild(doc.CreateTextNode(c.descriptive_help));
441
442 xml.AppendChild(cmd);
443 }
444 }
445 }
446
447 public void FromXml(XmlElement root, CommandDelegate fn)
448 {
449 CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
450 ((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
451 if (((Dictionary<string, object>)tree["help"]).Count == 0)
452 tree.Remove("help");
453
454 CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
455 ((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
456 if (((Dictionary<string, object>)tree["quit"]).Count == 0)
457 tree.Remove("quit");
458
459 tree.Clear();
460
461 ReadTreeLevel(tree, root, fn);
462
463 if (!tree.ContainsKey("help"))
464 tree["help"] = (object) new Dictionary<string, object>();
465 ((Dictionary<string, object>)tree["help"])[String.Empty] = help;
466
467 if (!tree.ContainsKey("quit"))
468 tree["quit"] = (object) new Dictionary<string, object>();
469 ((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
470 }
471
472 private void ReadTreeLevel(Dictionary<string, object> level, XmlNode node, CommandDelegate fn)
473 {
474 Dictionary<string, object> next;
475 string name;
476
477 XmlNodeList nodeL = node.ChildNodes;
478 XmlNodeList cmdL;
479 CommandInfo c;
480
481 foreach (XmlNode part in nodeL)
482 {
483 switch (part.Name)
484 {
485 case "Level":
486 name = ((XmlElement)part).GetAttribute("Name");
487 next = new Dictionary<string, object>();
488 level[name] = next;
489 ReadTreeLevel(next, part, fn);
490 break;
491 case "Command":
492 cmdL = part.ChildNodes;
493 c = new CommandInfo();
494 foreach (XmlNode cmdPart in cmdL)
495 {
496 switch (cmdPart.Name)
497 {
498 case "Module":
499 c.module = cmdPart.InnerText;
500 break;
501 case "Shared":
502 c.shared = Convert.ToBoolean(cmdPart.InnerText);
503 break;
504 case "HelpText":
505 c.help_text = cmdPart.InnerText;
506 break;
507 case "LongHelp":
508 c.long_help = cmdPart.InnerText;
509 break;
510 case "Description":
511 c.descriptive_help = cmdPart.InnerText;
512 break;
513 }
514 }
515 c.fn = new List<CommandDelegate>();
516 c.fn.Add(fn);
517 level[String.Empty] = c;
518 break;
519 }
520 }
521 }
372 } 522 }
373 523
374 public class Parser 524 public class Parser