4 namespace TechBot.Library
6 public class NtStatusCommand : BaseCommand, ICommand
8 private IServiceOutput serviceOutput;
9 private string ntstatusXml;
10 private XmlDocument ntstatusXmlDocument;
12 public NtStatusCommand(IServiceOutput serviceOutput,
15 this.serviceOutput = serviceOutput;
16 this.ntstatusXml = ntstatusXml;
17 ntstatusXmlDocument = new XmlDocument();
18 ntstatusXmlDocument.Load(ntstatusXml);
21 public bool CanHandle(string commandName)
23 return CanHandle(commandName,
24 new string[] { "ntstatus" });
27 public void Handle(string commandName,
30 string ntstatusText = parameters;
31 if (ntstatusText.Equals(String.Empty))
33 serviceOutput.WriteLine("Please provide a valid NTSTATUS value.");
37 NumberParser np = new NumberParser();
38 long ntstatus = np.Parse(ntstatusText);
41 serviceOutput.WriteLine(String.Format("{0} is not a valid NTSTATUS value.",
46 string description = GetNtstatusDescription(ntstatus);
47 if (description != null)
49 serviceOutput.WriteLine(String.Format("{0} is {1}.",
55 serviceOutput.WriteLine(String.Format("I don't know about NTSTATUS {0}.",
62 return "!ntstatus <value>";
65 private string GetNtstatusDescription(long ntstatus)
67 XmlElement root = ntstatusXmlDocument.DocumentElement;
68 XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
69 ntstatus.ToString("X8")));
72 XmlAttribute text = node.Attributes["text"];
74 throw new Exception("Node has no text attribute.");