merge 37282 from amd64-branch:
[reactos.git] / irc / TechBot / TechBot.Commands.Common / WinerrorCommand.cs
1 using System;
2 using System.Xml;
3
4 using TechBot.Library;
5
6 namespace TechBot.Commands.Common
7 {
8 [Command("winerror", Help = "!winerror <value>")]
9 public class WinErrorCommand : XmlLookupCommand
10 {
11 public WinErrorCommand()
12 {
13 }
14
15 public override string XmlFile
16 {
17 get { return Settings.Default.WinErrorXml; }
18 }
19
20 public override void ExecuteCommand()
21 {
22 if (string.IsNullOrEmpty(Text))
23 {
24 Say("Please provide a valid System Error Code value.");
25 }
26 else
27 {
28 NumberParser np = new NumberParser();
29 long winerror = np.Parse(Text);
30 if (np.Error)
31 {
32 Say("{0} is not a valid System Error Code value.", Text);
33 return;
34 }
35
36 string description = GetWinerrorDescription(winerror);
37 if (description != null)
38 {
39 Say("{0} is {1}.",
40 Text,
41 description);
42 }
43 else
44 {
45 Say("I don't know about System Error Code {0}.", Text);
46 }
47 }
48 }
49
50 public string GetWinerrorDescription(long winerror)
51 {
52 XmlElement root = base.m_XmlDocument.DocumentElement;
53 XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
54 winerror.ToString()));
55 if (node != null)
56 {
57 XmlAttribute text = node.Attributes["text"];
58 if (text == null)
59 throw new Exception("Node has no text attribute.");
60 return text.Value;
61 }
62 else
63 return null;
64 }
65 }
66 }