2005-01-15 19:27:25 +00:00
|
|
|
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" });
|
|
|
|
}
|
|
|
|
|
2005-02-16 21:07:55 +00:00
|
|
|
public void Handle(MessageContext context,
|
|
|
|
string commandName,
|
2005-01-15 19:27:25 +00:00
|
|
|
string parameters)
|
|
|
|
{
|
|
|
|
string winerrorText = parameters;
|
|
|
|
if (winerrorText.Equals(String.Empty))
|
|
|
|
{
|
2005-02-16 21:07:55 +00:00
|
|
|
serviceOutput.WriteLine(context,
|
|
|
|
"Please provide a valid System Error Code value.");
|
2005-01-15 19:27:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberParser np = new NumberParser();
|
|
|
|
long winerror = np.Parse(winerrorText);
|
|
|
|
if (np.Error)
|
|
|
|
{
|
2005-02-16 21:07:55 +00:00
|
|
|
serviceOutput.WriteLine(context,
|
|
|
|
String.Format("{0} is not a valid System Error Code value.",
|
2005-01-15 19:27:25 +00:00
|
|
|
winerrorText));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string description = GetWinerrorDescription(winerror);
|
|
|
|
if (description != null)
|
|
|
|
{
|
2005-02-16 21:07:55 +00:00
|
|
|
serviceOutput.WriteLine(context,
|
|
|
|
String.Format("{0} is {1}.",
|
2005-01-15 19:27:25 +00:00
|
|
|
winerrorText,
|
|
|
|
description));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-16 21:07:55 +00:00
|
|
|
serviceOutput.WriteLine(context,
|
|
|
|
String.Format("I don't know about System Error Code {0}.",
|
2005-01-15 19:27:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|