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;
|
|
|
|
private string svnCommand;
|
|
|
|
private ArrayList commands = new ArrayList();
|
|
|
|
|
|
|
|
public TechBotService(IServiceOutput serviceOutput,
|
|
|
|
string chmPath,
|
|
|
|
string mainChm,
|
|
|
|
string ntstatusXml,
|
|
|
|
string winerrorXml,
|
|
|
|
string hresultXml,
|
|
|
|
string svnCommand)
|
|
|
|
{
|
|
|
|
this.serviceOutput = serviceOutput;
|
|
|
|
this.chmPath = chmPath;
|
|
|
|
this.mainChm = mainChm;
|
|
|
|
this.ntstatusXml = ntstatusXml;
|
|
|
|
this.winerrorXml = winerrorXml;
|
|
|
|
this.hresultXml = hresultXml;
|
|
|
|
this.svnCommand = svnCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
{
|
|
|
|
commands.Add(new HelpCommand(serviceOutput,
|
|
|
|
commands));
|
|
|
|
commands.Add(new ApiCommand(serviceOutput,
|
|
|
|
chmPath,
|
|
|
|
mainChm));
|
|
|
|
commands.Add(new NtStatusCommand(serviceOutput,
|
|
|
|
ntstatusXml));
|
|
|
|
commands.Add(new WinerrorCommand(serviceOutput,
|
|
|
|
winerrorXml));
|
|
|
|
commands.Add(new HresultCommand(serviceOutput,
|
|
|
|
hresultXml));
|
|
|
|
commands.Add(new SvnCommand(serviceOutput,
|
|
|
|
svnCommand));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|