2005-01-15 19:27:25 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Data;
|
|
|
|
using System.Threading;
|
|
|
|
using TechBot.IRCLibrary;
|
|
|
|
|
|
|
|
namespace TechBot.Library
|
|
|
|
{
|
|
|
|
public class TechBotService
|
|
|
|
{
|
|
|
|
private IServiceOutput serviceOutput;
|
|
|
|
private string chmPath;
|
|
|
|
private string mainChm;
|
|
|
|
private string ntstatusXml;
|
|
|
|
private string winerrorXml;
|
|
|
|
private string hresultXml;
|
2005-12-14 17:34:00 +00:00
|
|
|
private string wmXml;
|
2005-01-15 19:27:25 +00:00
|
|
|
private string svnCommand;
|
2006-01-05 21:46:24 +00:00
|
|
|
private string bugUrl, WineBugUrl, SambaBugUrl;
|
2005-01-15 19:27:25 +00:00
|
|
|
private ArrayList commands = new ArrayList();
|
|
|
|
|
|
|
|
public TechBotService(IServiceOutput serviceOutput,
|
|
|
|
string chmPath,
|
2005-12-14 17:34:00 +00:00
|
|
|
string mainChm,
|
|
|
|
string ntstatusXml,
|
|
|
|
string winerrorXml,
|
|
|
|
string hresultXml,
|
|
|
|
string wmXml,
|
2005-12-14 18:13:05 +00:00
|
|
|
string svnCommand,
|
2006-01-05 21:46:24 +00:00
|
|
|
string bugUrl,
|
|
|
|
string WineBugUrl,
|
|
|
|
string SambaBugUrl)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
this.serviceOutput = serviceOutput;
|
|
|
|
this.chmPath = chmPath;
|
|
|
|
this.mainChm = mainChm;
|
|
|
|
this.ntstatusXml = ntstatusXml;
|
|
|
|
this.winerrorXml = winerrorXml;
|
|
|
|
this.hresultXml = hresultXml;
|
2005-12-14 17:34:00 +00:00
|
|
|
this.wmXml = wmXml;
|
2005-01-15 19:27:25 +00:00
|
|
|
this.svnCommand = svnCommand;
|
2005-12-14 18:13:05 +00:00
|
|
|
this.bugUrl = bugUrl;
|
2006-01-05 21:46:24 +00:00
|
|
|
this.WineBugUrl = WineBugUrl;
|
|
|
|
this.SambaBugUrl = SambaBugUrl;
|
2005-01-15 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
{
|
|
|
|
commands.Add(new HelpCommand(serviceOutput,
|
|
|
|
commands));
|
2006-09-09 10:53:28 +00:00
|
|
|
/*commands.Add(new ApiCommand(serviceOutput,
|
2005-01-15 19:27:25 +00:00
|
|
|
chmPath,
|
2006-09-09 10:53:28 +00:00
|
|
|
mainChm));*/
|
2005-01-15 19:27:25 +00:00
|
|
|
commands.Add(new NtStatusCommand(serviceOutput,
|
|
|
|
ntstatusXml));
|
|
|
|
commands.Add(new WinerrorCommand(serviceOutput,
|
|
|
|
winerrorXml));
|
|
|
|
commands.Add(new HresultCommand(serviceOutput,
|
|
|
|
hresultXml));
|
2006-01-05 17:52:39 +00:00
|
|
|
commands.Add(new ErrorCommand(serviceOutput,
|
|
|
|
ntstatusXml,
|
|
|
|
winerrorXml,
|
|
|
|
hresultXml));
|
2005-12-14 17:34:00 +00:00
|
|
|
commands.Add(new WmCommand(serviceOutput,
|
|
|
|
wmXml));
|
2005-01-15 19:27:25 +00:00
|
|
|
commands.Add(new SvnCommand(serviceOutput,
|
|
|
|
svnCommand));
|
2005-12-14 18:13:05 +00:00
|
|
|
commands.Add(new BugCommand(serviceOutput,
|
2006-01-05 21:46:24 +00:00
|
|
|
bugUrl,
|
|
|
|
WineBugUrl,
|
|
|
|
SambaBugUrl));
|
2005-01-15 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 21:07:55 +00:00
|
|
|
public void InjectMessage(MessageContext context,
|
|
|
|
string message)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
if (message.StartsWith("!"))
|
2005-02-16 21:07:55 +00:00
|
|
|
ParseCommandMessage(context,
|
|
|
|
message);
|
2005-01-15 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool IsCommandMessage(string message)
|
|
|
|
{
|
|
|
|
return message.StartsWith("!");
|
|
|
|
}
|
|
|
|
|
2005-02-16 21:07:55 +00:00
|
|
|
public void ParseCommandMessage(MessageContext context,
|
|
|
|
string message)
|
2005-01-15 19:27:25 +00:00
|
|
|
{
|
|
|
|
if (!IsCommandMessage(message))
|
|
|
|
return;
|
|
|
|
|
|
|
|
message = message.Substring(1).Trim();
|
|
|
|
int index = message.IndexOf(' ');
|
|
|
|
string commandName;
|
|
|
|
string parameters = "";
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
commandName = message.Substring(0, index).Trim();
|
|
|
|
parameters = message.Substring(index).Trim();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
commandName = message.Trim();
|
|
|
|
|
|
|
|
foreach (ICommand command in commands)
|
|
|
|
{
|
|
|
|
if (command.CanHandle(commandName))
|
|
|
|
{
|
2005-02-16 21:07:55 +00:00
|
|
|
command.Handle(context,
|
|
|
|
commandName, parameters);
|
2005-01-15 19:27:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|