4 namespace TechBot.Library
6 public class WmCommand : BaseCommand, ICommand
8 private IServiceOutput serviceOutput;
10 private XmlDocument wmXmlDocument;
12 public WmCommand(IServiceOutput serviceOutput,
15 this.serviceOutput = serviceOutput;
17 wmXmlDocument = new XmlDocument();
18 wmXmlDocument.Load(wmXml);
21 public bool CanHandle(string commandName)
23 return CanHandle(commandName,
24 new string[] { "wm" });
27 public void Handle(MessageContext context,
31 string wmText = parameters;
32 if (wmText.Equals(String.Empty))
34 serviceOutput.WriteLine(context,
35 "Please provide a valid window message value or name.");
39 NumberParser np = new NumberParser();
40 long wm = np.Parse(wmText);
44 // Assume "!wm <name>" form.
45 output = GetWmNumber(wmText);
49 output = GetWmDescription(wm);
54 serviceOutput.WriteLine(context,
55 String.Format("{0} is {1}.",
61 serviceOutput.WriteLine(context,
62 String.Format("I don't know about window message {0}.",
69 return "!wm <value> or !wm <name>";
72 private string GetWmDescription(long wm)
74 XmlElement root = wmXmlDocument.DocumentElement;
75 XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
79 XmlAttribute text = node.Attributes["text"];
81 throw new Exception("Node has no text attribute.");
88 private string GetWmNumber(string wmName)
90 XmlElement root = wmXmlDocument.DocumentElement;
91 XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
95 XmlAttribute value = node.Attributes["value"];
97 throw new Exception("Node has no value attribute.");