4 namespace TechBot.Library
6 public class WMCommand : XmlCommand
8 public WMCommand(TechBotService techBot)
13 public override string XmlFile
15 get { return Settings.Default.WMXml; }
18 public override string[] AvailableCommands
20 get { return new string[] { "wm" }; }
23 public override void Handle(MessageContext context,
27 string wmText = parameters;
28 if (wmText.Equals(String.Empty))
30 TechBot.ServiceOutput.WriteLine(context,
31 "Please provide a valid window message value or name.");
35 NumberParser np = new NumberParser();
36 long wm = np.Parse(wmText);
40 // Assume "!wm <name>" form.
41 output = GetWmNumber(wmText);
45 output = GetWmDescription(wm);
50 TechBot.ServiceOutput.WriteLine(context,
51 String.Format("{0} is {1}.",
57 TechBot.ServiceOutput.WriteLine(context,
58 String.Format("I don't know about window message {0}.",
63 public override string Help()
65 return "!wm <value> or !wm <name>";
68 private string GetWmDescription(long wm)
70 XmlElement root = base.m_XmlDocument.DocumentElement;
71 XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
75 XmlAttribute text = node.Attributes["text"];
77 throw new Exception("Node has no text attribute.");
84 private string GetWmNumber(string wmName)
86 XmlElement root = base.m_XmlDocument.DocumentElement;
87 XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
91 XmlAttribute value = node.Attributes["value"];
93 throw new Exception("Node has no value attribute.");