mirror of
https://github.com/reactos/reactos.git
synced 2026-06-03 17:59:48 +08:00
* refactor the code to make it more OOP and extensible
* remove old outdated SD project files * make it use some .NET 2.0 features as generic collections and settings svn path=/trunk/; revision=31130
This commit is contained in:
@@ -3,33 +3,39 @@ using System.Xml;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class HresultCommand : BaseCommand, ICommand
|
||||
public class HResultCommand : XmlCommand
|
||||
{
|
||||
private IServiceOutput serviceOutput;
|
||||
private XmlDocument hresultXmlDocument;
|
||||
|
||||
public HresultCommand(IServiceOutput serviceOutput,
|
||||
string hresultXml)
|
||||
public HResultCommand(TechBotService techBot)
|
||||
: base(techBot)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
hresultXmlDocument = new XmlDocument();
|
||||
hresultXmlDocument.Load(hresultXml);
|
||||
}
|
||||
|
||||
|
||||
public override string XmlFile
|
||||
{
|
||||
get { return Settings.Default.HResultXml; }
|
||||
}
|
||||
|
||||
public override string[] AvailableCommands
|
||||
{
|
||||
get { return new string[] { "hresult" }; }
|
||||
}
|
||||
|
||||
/*
|
||||
public bool CanHandle(string commandName)
|
||||
{
|
||||
return CanHandle(commandName,
|
||||
new string[] { "hresult" });
|
||||
}
|
||||
*/
|
||||
|
||||
public void Handle(MessageContext context,
|
||||
public override void Handle(MessageContext context,
|
||||
string commandName,
|
||||
string parameters)
|
||||
{
|
||||
string hresultText = parameters;
|
||||
if (hresultText.Equals(String.Empty))
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
TechBot.ServiceOutput.WriteLine(context,
|
||||
"Please provide a valid HRESULT value.");
|
||||
return;
|
||||
}
|
||||
@@ -38,7 +44,7 @@ namespace TechBot.Library
|
||||
long hresult = np.Parse(hresultText);
|
||||
if (np.Error)
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
TechBot.ServiceOutput.WriteLine(context,
|
||||
String.Format("{0} is not a valid HRESULT value.",
|
||||
hresultText));
|
||||
return;
|
||||
@@ -47,27 +53,27 @@ namespace TechBot.Library
|
||||
string description = GetHresultDescription(hresult);
|
||||
if (description != null)
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
TechBot.ServiceOutput.WriteLine(context,
|
||||
String.Format("{0} is {1}.",
|
||||
hresultText,
|
||||
description));
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceOutput.WriteLine(context,
|
||||
TechBot.ServiceOutput.WriteLine(context,
|
||||
String.Format("I don't know about HRESULT {0}.",
|
||||
hresultText));
|
||||
}
|
||||
}
|
||||
|
||||
public string Help()
|
||||
public override string Help()
|
||||
{
|
||||
return "!hresult <value>";
|
||||
}
|
||||
|
||||
public string GetHresultDescription(long hresult)
|
||||
{
|
||||
XmlElement root = hresultXmlDocument.DocumentElement;
|
||||
XmlElement root = base.m_XmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
|
||||
hresult.ToString("X8")));
|
||||
if (node != null)
|
||||
|
||||
Reference in New Issue
Block a user