mirror of
https://github.com/reactos/reactos.git
synced 2025-06-13 07:18:30 +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/WinerrorCommand.cs
Normal file
81
irc/TechBot/TechBot.Library/WinerrorCommand.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class WinerrorCommand : BaseCommand, ICommand
|
||||
{
|
||||
private IServiceOutput serviceOutput;
|
||||
private string winerrorXml;
|
||||
private XmlDocument winerrorXmlDocument;
|
||||
|
||||
public WinerrorCommand(IServiceOutput serviceOutput,
|
||||
string winerrorXml)
|
||||
{
|
||||
this.serviceOutput = serviceOutput;
|
||||
this.winerrorXml = winerrorXml;
|
||||
winerrorXmlDocument = new XmlDocument();
|
||||
winerrorXmlDocument.Load(winerrorXml);
|
||||
}
|
||||
|
||||
public bool CanHandle(string commandName)
|
||||
{
|
||||
return CanHandle(commandName,
|
||||
new string[] { "winerror" });
|
||||
}
|
||||
|
||||
public void Handle(string commandName,
|
||||
string parameters)
|
||||
{
|
||||
string winerrorText = parameters;
|
||||
if (winerrorText.Equals(String.Empty))
|
||||
{
|
||||
serviceOutput.WriteLine("Please provide a valid System Error Code value.");
|
||||
return;
|
||||
}
|
||||
|
||||
NumberParser np = new NumberParser();
|
||||
long winerror = np.Parse(winerrorText);
|
||||
if (np.Error)
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("{0} is not a valid System Error Code value.",
|
||||
winerrorText));
|
||||
return;
|
||||
}
|
||||
|
||||
string description = GetWinerrorDescription(winerror);
|
||||
if (description != null)
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("{0} is {1}.",
|
||||
winerrorText,
|
||||
description));
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceOutput.WriteLine(String.Format("I don't know about System Error Code {0}.",
|
||||
winerrorText));
|
||||
}
|
||||
}
|
||||
|
||||
public string Help()
|
||||
{
|
||||
return "!winerror <value>";
|
||||
}
|
||||
|
||||
private string GetWinerrorDescription(long winerror)
|
||||
{
|
||||
XmlElement root = winerrorXmlDocument.DocumentElement;
|
||||
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
|
||||
winerror));
|
||||
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