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(string commandName,
30 string winerrorText = parameters;
31 if (winerrorText.Equals(String.Empty))
33 serviceOutput.WriteLine("Please provide a valid System Error Code value.");
37 NumberParser np = new NumberParser();
38 long winerror = np.Parse(winerrorText);
41 serviceOutput.WriteLine(String.Format("{0} is not a valid System Error Code value.",
46 string description = GetWinerrorDescription(winerror);
47 if (description != null)
49 serviceOutput.WriteLine(String.Format("{0} is {1}.",
55 serviceOutput.WriteLine(String.Format("I don't know about System Error Code {0}.",
62 return "!winerror <value>";
65 private string GetWinerrorDescription(long winerror)
67 XmlElement root = winerrorXmlDocument.DocumentElement;
68 XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
72 XmlAttribute text = node.Attributes["text"];
74 throw new Exception("Node has no text attribute.");