diff --git a/irc/TechBot/Resources/wm.xml b/irc/TechBot/Resources/wm.xml
new file mode 100644
index 00000000000..86994eae728
--- /dev/null
+++ b/irc/TechBot/Resources/wm.xml
@@ -0,0 +1,321 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/irc/TechBot/TechBot.Console/App.config b/irc/TechBot/TechBot.Console/App.config
index f7fa9ac9905..03b57ba4892 100644
--- a/irc/TechBot/TechBot.Console/App.config
+++ b/irc/TechBot/TechBot.Console/App.config
@@ -10,6 +10,7 @@
+
diff --git a/irc/TechBot/TechBot.Console/Main.cs b/irc/TechBot/TechBot.Console/Main.cs
index f658ec38cde..d6e60452401 100644
--- a/irc/TechBot/TechBot.Console/Main.cs
+++ b/irc/TechBot/TechBot.Console/Main.cs
@@ -134,6 +134,18 @@ namespace TechBot.Console
}
}
+ private static string WmXml
+ {
+ get
+ {
+ string optionName = "WmXml";
+ string s = ConfigurationSettings.AppSettings[optionName];
+ VerifyRequiredOption(optionName,
+ s);
+ return s;
+ }
+ }
+
private static string SvnCommand
{
get
@@ -157,6 +169,7 @@ namespace TechBot.Console
NtstatusXml,
WinerrorXml,
HresultXml,
+ WmXml,
SvnCommand);
ircService.Run();
}
@@ -176,6 +189,7 @@ namespace TechBot.Console
NtstatusXml,
WinerrorXml,
HresultXml,
+ WmXml,
SvnCommand);
service.Run();
while (true)
diff --git a/irc/TechBot/TechBot.Library/IrcService.cs b/irc/TechBot/TechBot.Library/IrcService.cs
index 374c4754ff0..587bd9ba959 100644
--- a/irc/TechBot/TechBot.Library/IrcService.cs
+++ b/irc/TechBot/TechBot.Library/IrcService.cs
@@ -16,6 +16,7 @@ namespace TechBot.Library
private string ntstatusXml;
private string winerrorXml;
private string hresultXml;
+ private string wmXml;
private string svnCommand;
private IrcClient client;
private ArrayList channels = new ArrayList(); /* IrcChannel */
@@ -31,18 +32,20 @@ namespace TechBot.Library
string ntstatusXml,
string winerrorXml,
string hresultXml,
+ string wmXml,
string svnCommand)
{
this.hostname = hostname;
this.port = port;
this.channelnames = channelnames;
- this.botname = botname;
- this.chmPath = chmPath;
- this.mainChm = mainChm;
- this.ntstatusXml = ntstatusXml;
- this.winerrorXml = winerrorXml;
- this.hresultXml = hresultXml;
- this.svnCommand = svnCommand;
+ this.botname = botname;
+ this.chmPath = chmPath;
+ this.mainChm = mainChm;
+ this.ntstatusXml = ntstatusXml;
+ this.winerrorXml = winerrorXml;
+ this.hresultXml = hresultXml;
+ this.wmXml = wmXml;
+ this.svnCommand = svnCommand;
}
public void Run()
@@ -53,6 +56,7 @@ namespace TechBot.Library
ntstatusXml,
winerrorXml,
hresultXml,
+ wmXml,
svnCommand);
service.Run();
diff --git a/irc/TechBot/TechBot.Library/TechBot.Library.prjx b/irc/TechBot/TechBot.Library/TechBot.Library.prjx
index 1f6fd18d368..cce5c674a77 100644
--- a/irc/TechBot/TechBot.Library/TechBot.Library.prjx
+++ b/irc/TechBot/TechBot.Library/TechBot.Library.prjx
@@ -13,6 +13,8 @@
+
+
diff --git a/irc/TechBot/TechBot.Library/TechBotService.cs b/irc/TechBot/TechBot.Library/TechBotService.cs
index aede24db4fe..1236998d343 100644
--- a/irc/TechBot/TechBot.Library/TechBotService.cs
+++ b/irc/TechBot/TechBot.Library/TechBotService.cs
@@ -15,16 +15,18 @@ namespace TechBot.Library
private string ntstatusXml;
private string winerrorXml;
private string hresultXml;
+ private string wmXml;
private string svnCommand;
private ArrayList commands = new ArrayList();
public TechBotService(IServiceOutput serviceOutput,
string chmPath,
- string mainChm,
- string ntstatusXml,
- string winerrorXml,
- string hresultXml,
- string svnCommand)
+ string mainChm,
+ string ntstatusXml,
+ string winerrorXml,
+ string hresultXml,
+ string wmXml,
+ string svnCommand)
{
this.serviceOutput = serviceOutput;
this.chmPath = chmPath;
@@ -32,6 +34,7 @@ namespace TechBot.Library
this.ntstatusXml = ntstatusXml;
this.winerrorXml = winerrorXml;
this.hresultXml = hresultXml;
+ this.wmXml = wmXml;
this.svnCommand = svnCommand;
}
@@ -48,6 +51,8 @@ namespace TechBot.Library
winerrorXml));
commands.Add(new HresultCommand(serviceOutput,
hresultXml));
+ commands.Add(new WmCommand(serviceOutput,
+ wmXml));
commands.Add(new SvnCommand(serviceOutput,
svnCommand));
}
diff --git a/irc/TechBot/TechBot.Library/WmCommand.cs b/irc/TechBot/TechBot.Library/WmCommand.cs
new file mode 100644
index 00000000000..0809c3e81fe
--- /dev/null
+++ b/irc/TechBot/TechBot.Library/WmCommand.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Xml;
+
+namespace TechBot.Library
+{
+ public class WmCommand : BaseCommand, ICommand
+ {
+ private IServiceOutput serviceOutput;
+ private string wmXml;
+ private XmlDocument wmXmlDocument;
+
+ public WmCommand(IServiceOutput serviceOutput,
+ string wmXml)
+ {
+ this.serviceOutput = serviceOutput;
+ this.wmXml = wmXml;
+ wmXmlDocument = new XmlDocument();
+ wmXmlDocument.Load(wmXml);
+ }
+
+ public bool CanHandle(string commandName)
+ {
+ return CanHandle(commandName,
+ new string[] { "wm" });
+ }
+
+ public void Handle(MessageContext context,
+ string commandName,
+ string parameters)
+ {
+ string wmText = parameters;
+ if (wmText.Equals(String.Empty))
+ {
+ serviceOutput.WriteLine(context,
+ "Please provide a valid window message value or name.");
+ return;
+ }
+
+ NumberParser np = new NumberParser();
+ long wm = np.Parse(wmText);
+ string output;
+ if (np.Error)
+ {
+ // Assume "!wm " form.
+ output = GetWmNumber(wmText);
+ }
+ else
+ {
+ output = GetWmDescription(wm);
+ }
+
+ if (output != null)
+ {
+ serviceOutput.WriteLine(context,
+ String.Format("{0} is {1}.",
+ wmText,
+ output));
+ }
+ else
+ {
+ serviceOutput.WriteLine(context,
+ String.Format("I don't know about window message {0}.",
+ wmText));
+ }
+ }
+
+ public string Help()
+ {
+ return "!wm or !wm ";
+ }
+
+ private string GetWmDescription(long wm)
+ {
+ XmlElement root = wmXmlDocument.DocumentElement;
+ XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
+ wm));
+ 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;
+ }
+
+ private string GetWmNumber(string wmName)
+ {
+ XmlElement root = wmXmlDocument.DocumentElement;
+ XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
+ wmName));
+ if (node != null)
+ {
+ XmlAttribute value = node.Attributes["value"];
+ if (value == null)
+ throw new Exception("Node has no value attribute.");
+ return value.Value;
+ }
+ else
+ return null;
+ }
+ }
+}
diff --git a/irc/TechBot/TechBot/App.config b/irc/TechBot/TechBot/App.config
index f7fa9ac9905..03b57ba4892 100644
--- a/irc/TechBot/TechBot/App.config
+++ b/irc/TechBot/TechBot/App.config
@@ -10,6 +10,7 @@
+
diff --git a/irc/TechBot/TechBot/ServiceThread.cs b/irc/TechBot/TechBot/ServiceThread.cs
index 728eb959688..5a612194dc9 100644
--- a/irc/TechBot/TechBot/ServiceThread.cs
+++ b/irc/TechBot/TechBot/ServiceThread.cs
@@ -15,6 +15,7 @@ namespace TechBot
private string MainChm;
private string NtstatusXml;
private string HresultXml;
+ private string WmXml;
private string WinerrorXml;
private string SvnCommand;
private EventLog eventLog;
@@ -34,6 +35,7 @@ namespace TechBot
MainChm = ConfigurationSettings.AppSettings["MainChm"];
NtstatusXml = ConfigurationSettings.AppSettings["NtstatusXml"];
HresultXml = ConfigurationSettings.AppSettings["HresultXml"];
+ WmXml = ConfigurationSettings.AppSettings["WmXml"];
WinerrorXml = ConfigurationSettings.AppSettings["WinerrorXml"];
SvnCommand = ConfigurationSettings.AppSettings["SvnCommand"];
}
@@ -52,6 +54,7 @@ namespace TechBot
NtstatusXml,
WinerrorXml,
HresultXml,
+ WmXml,
SvnCommand);
ircService.Run();
}