- Assign first the partitions to drive letters, which have a registry entry in Mounte...
[reactos.git] / irc / TechBot / TechBot.Library / HresultCommand.cs
1 using System;
2 using System.Xml;
3
4 namespace TechBot.Library
5 {
6 public class HresultCommand : BaseCommand, ICommand
7 {
8 private IServiceOutput serviceOutput;
9 private string hresultXml;
10 private XmlDocument hresultXmlDocument;
11
12 public HresultCommand(IServiceOutput serviceOutput,
13 string hresultXml)
14 {
15 this.serviceOutput = serviceOutput;
16 this.hresultXml = hresultXml;
17 hresultXmlDocument = new XmlDocument();
18 hresultXmlDocument.Load(hresultXml);
19 }
20
21 public bool CanHandle(string commandName)
22 {
23 return CanHandle(commandName,
24 new string[] { "hresult" });
25 }
26
27 public void Handle(MessageContext context,
28 string commandName,
29 string parameters)
30 {
31 string hresultText = parameters;
32 if (hresultText.Equals(String.Empty))
33 {
34 serviceOutput.WriteLine(context,
35 "Please provide a valid HRESULT value.");
36 return;
37 }
38
39 NumberParser np = new NumberParser();
40 long hresult = np.Parse(hresultText);
41 if (np.Error)
42 {
43 serviceOutput.WriteLine(context,
44 String.Format("{0} is not a valid HRESULT value.",
45 hresultText));
46 return;
47 }
48
49 string description = GetHresultDescription(hresult);
50 if (description != null)
51 {
52 serviceOutput.WriteLine(context,
53 String.Format("{0} is {1}.",
54 hresultText,
55 description));
56 }
57 else
58 {
59 serviceOutput.WriteLine(context,
60 String.Format("I don't know about HRESULT {0}.",
61 hresultText));
62 }
63 }
64
65 public string Help()
66 {
67 return "!hresult <value>";
68 }
69
70 private string GetHresultDescription(long hresult)
71 {
72 XmlElement root = hresultXmlDocument.DocumentElement;
73 XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
74 hresult.ToString("X8")));
75 if (node != null)
76 {
77 XmlAttribute text = node.Attributes["text"];
78 if (text == null)
79 throw new Exception("Node has no text attribute.");
80 return text.Value;
81 }
82 else
83 return null;
84 }
85 }
86 }