* 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,35 +3,31 @@ using System.Xml;
namespace TechBot.Library
{
public class WmCommand : BaseCommand, ICommand
public class WMCommand : XmlCommand
{
private IServiceOutput serviceOutput;
private string wmXml;
private XmlDocument wmXmlDocument;
public WmCommand(IServiceOutput serviceOutput,
string wmXml)
public WMCommand(TechBotService techBot)
: base(techBot)
{
this.serviceOutput = serviceOutput;
this.wmXml = wmXml;
wmXmlDocument = new XmlDocument();
wmXmlDocument.Load(wmXml);
}
public override string XmlFile
{
get { return Settings.Default.WMXml; }
}
public bool CanHandle(string commandName)
{
return CanHandle(commandName,
new string[] { "wm" });
}
public override string[] AvailableCommands
{
get { return new string[] { "wm" }; }
}
public void Handle(MessageContext context,
public override void Handle(MessageContext context,
string commandName,
string parameters)
{
string wmText = parameters;
if (wmText.Equals(String.Empty))
{
serviceOutput.WriteLine(context,
TechBot.ServiceOutput.WriteLine(context,
"Please provide a valid window message value or name.");
return;
}
@@ -51,27 +47,27 @@ namespace TechBot.Library
if (output != null)
{
serviceOutput.WriteLine(context,
TechBot.ServiceOutput.WriteLine(context,
String.Format("{0} is {1}.",
wmText,
output));
}
else
{
serviceOutput.WriteLine(context,
TechBot.ServiceOutput.WriteLine(context,
String.Format("I don't know about window message {0}.",
wmText));
}
}
public string Help()
public override string Help()
{
return "!wm <value> or !wm <name>";
}
private string GetWmDescription(long wm)
{
XmlElement root = wmXmlDocument.DocumentElement;
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
wm));
if (node != null)
@@ -87,7 +83,7 @@ namespace TechBot.Library
private string GetWmNumber(string wmName)
{
XmlElement root = wmXmlDocument.DocumentElement;
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
wmName));
if (node != null)