mirror of
https://github.com/reactos/reactos.git
synced 2025-06-20 07:36:05 +00:00
- code refactoring
- made more and more easily extensible: * commands automatically loaded from plugins dlls * declarative and automatic command parameter parsing * common code moved to base classes - other fixes svn path=/trunk/; revision=33344
This commit is contained in:
parent
e3407fdd9c
commit
d7b2077ed8
42 changed files with 2263 additions and 1689 deletions
69
irc/TechBot/TechBot.Library/Commands/NtStatusCommand.cs
Normal file
69
irc/TechBot/TechBot.Library/Commands/NtStatusCommand.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
[Command("ntstatus", Help = "!ntstatus <value>")]
|
||||
public class NtStatusCommand : XmlLookupCommand
|
||||
{
|
||||
public NtStatusCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public override string XmlFile
|
||||
{
|
||||
get { return Settings.Default.NtStatusXml; }
|
||||
}
|
||||
|
||||
public override void ExecuteCommand()
|
||||
{
|
||||
if (Text.Equals(String.Empty))
|
||||
{
|
||||
TechBot.ServiceOutput.WriteLine(Context,
|
||||
"Please provide a valid NTSTATUS value.");
|
||||
return;
|
||||
}
|
||||
|
||||
NumberParser np = new NumberParser();
|
||||
long ntstatus = np.Parse(Text);
|
||||
if (np.Error)
|
||||
{
|
||||
TechBot.ServiceOutput.WriteLine(Context,
|
||||
String.Format("{0} is not a valid NTSTATUS value.",
|
||||
Text));
|
||||
return;
|
||||
}
|
||||
|
||||
string description = GetNtstatusDescription(ntstatus);
|
||||
if (description != null)
|
||||
{
|
||||
TechBot.ServiceOutput.WriteLine(Context,
|
||||
String.Format("{0} is {1}.",
|
||||
Text,
|
||||
description));
|
||||
}
|
||||
else
|
||||
{
|
||||
TechBot.ServiceOutput.WriteLine(Context,
|
||||
String.Format("I don't know about NTSTATUS {0}.",
|
||||
Text));
|
||||
}
|
||||
}
|
||||
|
||||
public string GetNtstatusDescription(long ntstatus)
|
||||
{
|
||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue