4 namespace TechBot.Library
6 public class WinerrorCommand : BaseCommand, ICommand
8 private IServiceOutput serviceOutput;
9 private string winerrorXml;
10 private XmlDocument winerrorXmlDocument;
12 public WinerrorCommand(IServiceOutput serviceOutput,
15 this.serviceOutput = serviceOutput;
16 this.winerrorXml = winerrorXml;
17 winerrorXmlDocument = new XmlDocument();
18 winerrorXmlDocument.Load(winerrorXml);
21 public bool CanHandle(string commandName)
23 return CanHandle(commandName,
24 new string[] { "winerror" });
27 public void Handle(MessageContext context,
31 string winerrorText = parameters;
32 if (winerrorText.Equals(String.Empty))
34 serviceOutput.WriteLine(context,
35 "Please provide a valid System Error Code value.");
39 NumberParser np = new NumberParser();
40 long winerror = np.Parse(winerrorText);
43 serviceOutput.WriteLine(context,
44 String.Format("{0} is not a valid System Error Code value.",
49 string description = GetWinerrorDescription(winerror);
50 if (description != null)
52 serviceOutput.WriteLine(context,
53 String.Format("{0} is {1}.",
59 serviceOutput.WriteLine(context,
60 String.Format("I don't know about System Error Code {0}.",
67 return "!winerror <value>";
70 private string GetWinerrorDescription(long winerror)
72 XmlElement root = winerrorXmlDocument.DocumentElement;
73 XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
77 XmlAttribute text = node.Attributes["text"];
79 throw new Exception("Node has no text attribute.");