4 namespace TechBot.Library
6 public class HResultCommand : XmlCommand
8 public HResultCommand(TechBotService techBot)
13 public override string XmlFile
15 get { return Settings.Default.HResultXml; }
18 public override string[] AvailableCommands
20 get { return new string[] { "hresult" }; }
24 public bool CanHandle(string commandName)
26 return CanHandle(commandName,
27 new string[] { "hresult" });
31 public override void Handle(MessageContext context,
35 string hresultText = parameters;
36 if (hresultText.Equals(String.Empty))
38 TechBot.ServiceOutput.WriteLine(context,
39 "Please provide a valid HRESULT value.");
43 NumberParser np = new NumberParser();
44 long hresult = np.Parse(hresultText);
47 TechBot.ServiceOutput.WriteLine(context,
48 String.Format("{0} is not a valid HRESULT value.",
53 string description = GetHresultDescription(hresult);
54 if (description != null)
56 TechBot.ServiceOutput.WriteLine(context,
57 String.Format("{0} is {1}.",
63 TechBot.ServiceOutput.WriteLine(context,
64 String.Format("I don't know about HRESULT {0}.",
69 public override string Help()
71 return "!hresult <value>";
74 public string GetHresultDescription(long hresult)
76 XmlElement root = base.m_XmlDocument.DocumentElement;
77 XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
78 hresult.ToString("X8")));
81 XmlAttribute text = node.Attributes["text"];
83 throw new Exception("Node has no text attribute.");