adding missing dx headers
[reactos.git] / irc / TechBot / TechBot.Library / TechBotService.cs
1 using System;
2 using System.Collections;
3 using System.IO;
4 using System.Data;
5 using System.Threading;
6 using TechBot.IRCLibrary;
7
8 namespace TechBot.Library
9 {
10 public class TechBotService
11 {
12 private IServiceOutput serviceOutput;
13 private string chmPath;
14 private string mainChm;
15 private string ntstatusXml;
16 private string winerrorXml;
17 private string hresultXml;
18 private string svnCommand;
19 private ArrayList commands = new ArrayList();
20
21 public TechBotService(IServiceOutput serviceOutput,
22 string chmPath,
23 string mainChm,
24 string ntstatusXml,
25 string winerrorXml,
26 string hresultXml,
27 string svnCommand)
28 {
29 this.serviceOutput = serviceOutput;
30 this.chmPath = chmPath;
31 this.mainChm = mainChm;
32 this.ntstatusXml = ntstatusXml;
33 this.winerrorXml = winerrorXml;
34 this.hresultXml = hresultXml;
35 this.svnCommand = svnCommand;
36 }
37
38 public void Run()
39 {
40 commands.Add(new HelpCommand(serviceOutput,
41 commands));
42 commands.Add(new ApiCommand(serviceOutput,
43 chmPath,
44 mainChm));
45 commands.Add(new NtStatusCommand(serviceOutput,
46 ntstatusXml));
47 commands.Add(new WinerrorCommand(serviceOutput,
48 winerrorXml));
49 commands.Add(new HresultCommand(serviceOutput,
50 hresultXml));
51 commands.Add(new SvnCommand(serviceOutput,
52 svnCommand));
53 }
54
55 public void InjectMessage(MessageContext context,
56 string message)
57 {
58 if (message.StartsWith("!"))
59 ParseCommandMessage(context,
60 message);
61 }
62
63 private bool IsCommandMessage(string message)
64 {
65 return message.StartsWith("!");
66 }
67
68 public void ParseCommandMessage(MessageContext context,
69 string message)
70 {
71 if (!IsCommandMessage(message))
72 return;
73
74 message = message.Substring(1).Trim();
75 int index = message.IndexOf(' ');
76 string commandName;
77 string parameters = "";
78 if (index != -1)
79 {
80 commandName = message.Substring(0, index).Trim();
81 parameters = message.Substring(index).Trim();
82 }
83 else
84 commandName = message.Trim();
85
86 foreach (ICommand command in commands)
87 {
88 if (command.CanHandle(commandName))
89 {
90 command.Handle(context,
91 commandName, parameters);
92 return;
93 }
94 }
95 }
96 }
97 }