* 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:
Marc Piulachs
2007-12-10 19:08:13 +00:00
parent 588f8770cd
commit 82b5e2eb8b
31 changed files with 687 additions and 491 deletions

View File

@@ -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)