4 namespace TechBot.Library
6 [Command("hresult", Help = "!hresult <value>")]
7 public class HResultCommand : XmlLookupCommand
9 public HResultCommand()
13 public override string XmlFile
15 get { return Settings.Default.HResultXml; }
18 public override void ExecuteCommand()
20 if (Text.Equals(String.Empty))
22 TechBot.ServiceOutput.WriteLine(Context,
23 "Please provide a valid HRESULT value.");
27 NumberParser np = new NumberParser();
28 long hresult = np.Parse(Text);
31 TechBot.ServiceOutput.WriteLine(Context,
32 String.Format("{0} is not a valid HRESULT value.",
37 string description = GetHresultDescription(hresult);
38 if (description != null)
40 TechBot.ServiceOutput.WriteLine(Context,
41 String.Format("{0} is {1}.",
47 TechBot.ServiceOutput.WriteLine(Context,
48 String.Format("I don't know about HRESULT {0}.",
53 public string GetHresultDescription(long hresult)
55 XmlElement root = base.m_XmlDocument.DocumentElement;
56 XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
57 hresult.ToString("X8")));
60 XmlAttribute text = node.Attributes["text"];
62 throw new Exception("Node has no text attribute.");