6 namespace TechBot.Commands.Common
8 [Command("hresult", Help = "!hresult <value>")]
9 public class HResultCommand : XmlLookupCommand
11 public HResultCommand()
15 public override string XmlFile
17 get { return Settings.Default.HResultXml; }
20 public override void ExecuteCommand()
22 if (string.IsNullOrEmpty(Text))
24 Say("Please provide a valid HRESULT value.");
28 NumberParser np = new NumberParser();
29 long hresult = np.Parse(Text);
32 Say("{0} is not a valid HRESULT value.", Text);
36 string description = GetHresultDescription(hresult);
37 if (description != null)
45 Say("I don't know about HRESULT {0}.", Text);
50 public string GetHresultDescription(long hresult)
52 XmlElement root = base.m_XmlDocument.DocumentElement;
53 XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
54 hresult.ToString("X8")));
57 XmlAttribute text = node.Attributes["text"];
59 throw new Exception("Node has no text attribute.");