From 002940dd5dc8a4b5fa23ea6d5183e00431dd48df Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 17 Aug 2009 05:00:30 +0100 Subject: Filling in the blanks: The "meat" of the REST console --- OpenSim/Framework/Console/CommandConsole.cs | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'OpenSim/Framework/Console/CommandConsole.cs') diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index 8b63d01..7af8204 100644 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs @@ -26,6 +26,7 @@ */ using System; +using System.Xml; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; @@ -369,6 +370,65 @@ namespace OpenSim.Framework.Console return new string[0]; } + + public XmlElement GetXml(XmlDocument doc) + { + XmlElement root = doc.CreateElement("", "HelpTree", ""); + + ProcessTreeLevel(tree, root, doc); + + return root; + } + + private void ProcessTreeLevel(Dictionary level, XmlElement xml, XmlDocument doc) + { + foreach (KeyValuePair kvp in level) + { + if (kvp.Value is Dictionary) + { + XmlElement next = doc.CreateElement("", "Level", ""); + next.SetAttribute("Name", kvp.Key); + + xml.AppendChild(next); + + ProcessTreeLevel((Dictionary)kvp.Value, next, doc); + } + else + { + CommandInfo c = (CommandInfo)kvp.Value; + + XmlElement cmd = doc.CreateElement("", "Command", ""); + + XmlElement e; + + e = doc.CreateElement("", "Module", ""); + cmd.AppendChild(e); + e.AppendChild(doc.CreateTextNode(c.module)); + + e = doc.CreateElement("", "Shared", ""); + cmd.AppendChild(e); + e.AppendChild(doc.CreateTextNode(c.shared.ToString())); + + e = doc.CreateElement("", "HelpText", ""); + cmd.AppendChild(e); + e.AppendChild(doc.CreateTextNode(c.help_text)); + + e = doc.CreateElement("", "LongHelp", ""); + cmd.AppendChild(e); + e.AppendChild(doc.CreateTextNode(c.long_help)); + + e = doc.CreateElement("", "Description", ""); + cmd.AppendChild(e); + e.AppendChild(doc.CreateTextNode(c.descriptive_help)); + + xml.AppendChild(cmd); + } + } + } + + public void FromXml(XmlElement root) + { + } } public class Parser -- cgit v1.1 From cef16bec6dabc90fdccf82f755d24683d834208b Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 17 Aug 2009 08:45:20 +0100 Subject: Add the OpenSim.ConsoleClient app. Usage: OpenSim.ConsoleClient -h -p -u -P host defaults to localhost, port defaults to 8003. --- OpenSim/Framework/Console/CommandConsole.cs | 92 ++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Console/CommandConsole.cs') diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index 7af8204..3387013 100644 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs @@ -373,10 +373,28 @@ namespace OpenSim.Framework.Console public XmlElement GetXml(XmlDocument doc) { + CommandInfo help = (CommandInfo)((Dictionary)tree["help"])[String.Empty]; + ((Dictionary)tree["help"]).Remove(string.Empty); + if (((Dictionary)tree["help"]).Count == 0) + tree.Remove("help"); + + CommandInfo quit = (CommandInfo)((Dictionary)tree["quit"])[String.Empty]; + ((Dictionary)tree["quit"]).Remove(string.Empty); + if (((Dictionary)tree["quit"]).Count == 0) + tree.Remove("quit"); + XmlElement root = doc.CreateElement("", "HelpTree", ""); ProcessTreeLevel(tree, root, doc); + if (!tree.ContainsKey("help")) + tree["help"] = (object) new Dictionary(); + ((Dictionary)tree["help"])[String.Empty] = help; + + if (!tree.ContainsKey("quit")) + tree["quit"] = (object) new Dictionary(); + ((Dictionary)tree["quit"])[String.Empty] = quit; + return root; } @@ -426,8 +444,80 @@ namespace OpenSim.Framework.Console } } - public void FromXml(XmlElement root) + public void FromXml(XmlElement root, CommandDelegate fn) + { + CommandInfo help = (CommandInfo)((Dictionary)tree["help"])[String.Empty]; + ((Dictionary)tree["help"]).Remove(string.Empty); + if (((Dictionary)tree["help"]).Count == 0) + tree.Remove("help"); + + CommandInfo quit = (CommandInfo)((Dictionary)tree["quit"])[String.Empty]; + ((Dictionary)tree["quit"]).Remove(string.Empty); + if (((Dictionary)tree["quit"]).Count == 0) + tree.Remove("quit"); + + tree.Clear(); + + ReadTreeLevel(tree, root, fn); + + if (!tree.ContainsKey("help")) + tree["help"] = (object) new Dictionary(); + ((Dictionary)tree["help"])[String.Empty] = help; + + if (!tree.ContainsKey("quit")) + tree["quit"] = (object) new Dictionary(); + ((Dictionary)tree["quit"])[String.Empty] = quit; + } + + private void ReadTreeLevel(Dictionary level, XmlNode node, CommandDelegate fn) { + Dictionary next; + string name; + + XmlNodeList nodeL = node.ChildNodes; + XmlNodeList cmdL; + CommandInfo c; + + foreach (XmlNode part in nodeL) + { + switch (part.Name) + { + case "Level": + name = ((XmlElement)part).GetAttribute("Name"); + next = new Dictionary(); + level[name] = next; + ReadTreeLevel(next, part, fn); + break; + case "Command": + cmdL = part.ChildNodes; + c = new CommandInfo(); + foreach (XmlNode cmdPart in cmdL) + { + switch (cmdPart.Name) + { + case "Module": + c.module = cmdPart.InnerText; + break; + case "Shared": + c.shared = Convert.ToBoolean(cmdPart.InnerText); + break; + case "HelpText": + c.help_text = cmdPart.InnerText; + break; + case "LongHelp": + c.long_help = cmdPart.InnerText; + break; + case "Description": + c.descriptive_help = cmdPart.InnerText; + break; + } + } + c.fn = new List(); + c.fn.Add(fn); + level[String.Empty] = c; + break; + } + } } } -- cgit v1.1