mirror of
https://github.com/reactos/reactos.git
synced 2025-06-12 00:18:31 +00:00
Import TechBot
svn path=/trunk/; revision=13064
This commit is contained in:
parent
568b27baeb
commit
9dab4509fa
94 changed files with 24386 additions and 0 deletions
81
irc/TechBot/TechBot.Library/HresultCommand.cs
Normal file
81
irc/TechBot/TechBot.Library/HresultCommand.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class HresultCommand : BaseCommand, ICommand
|
||||
{
|
||||
private IServiceOutput serviceOutput;
|
||||
private string hresultXml;
|
||||
private XmlDocument hresultXmlDocument;
|
||||
|
||||
public HresultCommand(IServiceOutput serviceOutput,
|
||||
string hresultXml)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
this.hresultXml = hresultXml;
|
||||
hresultXmlDocument = new XmlDocument();
|
||||
hresultXmlDocument.Load(hresultXml);
|
||||
}
|
||||
|
||||
public bool CanHandle(string commandName)
|
||||
{
|
||||
return CanHandle(commandName,
|
||||
new string[] { "hresult" });
|
||||
}
|
||||
|
||||
public void Handle(string commandName,
|
||||
string parameters)
|
||||
{
|
||||
string hresultText = parameters;
|
||||
if (hresultText.Equals(String.Empty))
|
||||
{
|
||||
serviceOutput.WriteLine("Please provide a valid HRESULT value.");
|
||||
return;
|
||||
}
|
||||
|
||||
NumberParser np = new NumberParser();
|
||||
long hresult = np.Parse(hresultText);
|
||||
if (np.Error)
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("{0} is not a valid HRESULT value.",
|
||||
hresultText));
|
||||
return;
|
||||
}
|
||||
|
||||
string description = GetHresultDescription(hresult);
|
||||
if (description != null)
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("{0} is {1}.",
|
||||
hresultText,
|
||||
description));
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("I don't know about HRESULT {0}.",
|
||||
hresultText));
|
||||
}
|
||||
}
|
||||
|
||||
public string Help()
|
||||
{
|
||||
return "!hresult <value>";
|
||||
}
|
||||
|
||||
private string GetHresultDescription(long hresult)
|
||||
{
|
||||
XmlElement root = hresultXmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
|
||||
hresult.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