2005-01-15 19:27:25 +00:00
|
|
|
using System;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
namespace TechBot.Library
|
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
public class NtStatusCommand : XmlCommand
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
public NtStatusCommand(TechBotService techBot)
|
|
|
|
: base(techBot)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
}
|
2007-12-10 19:08:13 +00:00
|
|
|
|
|
|
|
public override string XmlFile
|
|
|
|
{
|
|
|
|
get { return Settings.Default.NtStatusXml; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string[] AvailableCommands
|
|
|
|
{
|
|
|
|
get { return new string[] { "ntstatus" }; }
|
|
|
|
}
|
|
|
|
/*
|
2005-01-15 19:27:25 +00:00
|
|
|
public bool CanHandle(string commandName)
|
|
|
|
{
|
|
|
|
return CanHandle(commandName,
|
|
|
|
new string[] { "ntstatus" });
|
|
|
|
}
|
2007-12-10 19:08:13 +00:00
|
|
|
*/
|
|
|
|
public override void Handle(MessageContext context,
|
2005-02-16 21:07:55 +00:00
|
|
|
string commandName,
|
2005-01-15 19:27:25 +00:00
|
|
|
string parameters)
|
|
|
|
{
|
|
|
|
string ntstatusText = parameters;
|
|
|
|
if (ntstatusText.Equals(String.Empty))
|
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
TechBot.ServiceOutput.WriteLine(context,
|
2005-02-16 21:07:55 +00:00
|
|
|
"Please provide a valid NTSTATUS value.");
|
2005-01-15 19:27:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberParser np = new NumberParser();
|
|
|
|
long ntstatus = np.Parse(ntstatusText);
|
|
|
|
if (np.Error)
|
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
TechBot.ServiceOutput.WriteLine(context,
|
2005-02-16 21:07:55 +00:00
|
|
|
String.Format("{0} is not a valid NTSTATUS value.",
|
2005-01-15 19:27:25 +00:00
|
|
|
ntstatusText));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string description = GetNtstatusDescription(ntstatus);
|
|
|
|
if (description != null)
|
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
TechBot.ServiceOutput.WriteLine(context,
|
2005-02-16 21:07:55 +00:00
|
|
|
String.Format("{0} is {1}.",
|
2005-01-15 19:27:25 +00:00
|
|
|
ntstatusText,
|
|
|
|
description));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
TechBot.ServiceOutput.WriteLine(context,
|
2005-02-16 21:07:55 +00:00
|
|
|
String.Format("I don't know about NTSTATUS {0}.",
|
2005-01-15 19:27:25 +00:00
|
|
|
ntstatusText));
|
|
|
|
}
|
|
|
|
}
|
2007-12-10 19:08:13 +00:00
|
|
|
|
|
|
|
public override string Help()
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
return "!ntstatus <value>";
|
|
|
|
}
|
|
|
|
|
2006-01-05 17:52:39 +00:00
|
|
|
public string GetNtstatusDescription(long ntstatus)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
2007-12-10 19:08:13 +00:00
|
|
|
XmlElement root = base.m_XmlDocument.DocumentElement;
|
2005-01-15 19:27:25 +00:00
|
|
|
XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
|
|
|
|
ntstatus.ToString("X8")));
|
|
|
|
if (node != null)
|
|
|
|
{
|
|
|
|
XmlAttribute text = node.Attributes["text"];
|
|
|
|
if (text == null)
|
|
|
|
throw new Exception("Node has no text attribute.");
|
|
|
|
return text.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|