Implement "!bug <number>" command.
[reactos.git] / irc / TechBot / TechBot.Console / Main.cs
1 using System;
2 using System.Configuration;
3 using TechBot.Library;
4
5 namespace TechBot.Console
6 {
7 public class ConsoleServiceOutput : IServiceOutput
8 {
9 public void WriteLine(MessageContext context,
10 string message)
11 {
12 System.Console.WriteLine(message);
13 }
14 }
15
16
17 class MainClass
18 {
19 private static void VerifyRequiredOption(string optionName,
20 string optionValue)
21 {
22 if (optionValue == null)
23 {
24 throw new Exception(String.Format("Option '{0}' not set.",
25 optionName));
26 }
27 }
28
29 private static string IRCServerHostName
30 {
31 get
32 {
33 string optionName = "IRCServerHostName";
34 string s = ConfigurationSettings.AppSettings[optionName];
35 VerifyRequiredOption(optionName,
36 s);
37 return s;
38 }
39 }
40
41 private static int IRCServerHostPort
42 {
43 get
44 {
45 string optionName = "IRCServerHostPort";
46 string s = ConfigurationSettings.AppSettings[optionName];
47 VerifyRequiredOption(optionName,
48 s);
49 return Int32.Parse(s);
50 }
51 }
52
53 private static string IRCChannelNames
54 {
55 get
56 {
57 string optionName = "IRCChannelNames";
58 string s = ConfigurationSettings.AppSettings[optionName];
59 VerifyRequiredOption(optionName,
60 s);
61 return s;
62 }
63 }
64
65 private static string IRCBotName
66 {
67 get
68 {
69 string optionName = "IRCBotName";
70 string s = ConfigurationSettings.AppSettings[optionName];
71 VerifyRequiredOption(optionName,
72 s);
73 return s;
74 }
75 }
76
77 private static string ChmPath
78 {
79 get
80 {
81 string optionName = "ChmPath";
82 string s = ConfigurationSettings.AppSettings[optionName];
83 VerifyRequiredOption(optionName,
84 s);
85 return s;
86 }
87 }
88
89 private static string MainChm
90 {
91 get
92 {
93 string optionName = "MainChm";
94 string s = ConfigurationSettings.AppSettings[optionName];
95 VerifyRequiredOption(optionName,
96 s);
97 return s;
98 }
99 }
100
101 private static string NtstatusXml
102 {
103 get
104 {
105 string optionName = "NtstatusXml";
106 string s = ConfigurationSettings.AppSettings[optionName];
107 VerifyRequiredOption(optionName,
108 s);
109 return s;
110 }
111 }
112
113 private static string WinerrorXml
114 {
115 get
116 {
117 string optionName = "WinerrorXml";
118 string s = ConfigurationSettings.AppSettings[optionName];
119 VerifyRequiredOption(optionName,
120 s);
121 return s;
122 }
123 }
124
125 private static string HresultXml
126 {
127 get
128 {
129 string optionName = "HresultXml";
130 string s = ConfigurationSettings.AppSettings[optionName];
131 VerifyRequiredOption(optionName,
132 s);
133 return s;
134 }
135 }
136
137 private static string WmXml
138 {
139 get
140 {
141 string optionName = "WmXml";
142 string s = ConfigurationSettings.AppSettings[optionName];
143 VerifyRequiredOption(optionName,
144 s);
145 return s;
146 }
147 }
148
149 private static string SvnCommand
150 {
151 get
152 {
153 string optionName = "SvnCommand";
154 string s = ConfigurationSettings.AppSettings[optionName];
155 VerifyRequiredOption(optionName,
156 s);
157 return s;
158 }
159 }
160
161 private static string BugUrl
162 {
163 get
164 {
165 string optionName = "BugUrl";
166 string s = ConfigurationSettings.AppSettings[optionName];
167 VerifyRequiredOption(optionName,
168 s);
169 return s;
170 }
171 }
172
173 private static void RunIrcService()
174 {
175 IrcService ircService = new IrcService(IRCServerHostName,
176 IRCServerHostPort,
177 IRCChannelNames,
178 IRCBotName,
179 ChmPath,
180 MainChm,
181 NtstatusXml,
182 WinerrorXml,
183 HresultXml,
184 WmXml,
185 SvnCommand,
186 BugUrl);
187 ircService.Run();
188 }
189
190 public static void Main(string[] args)
191 {
192 if (args.Length > 0 && args[0].ToLower().Equals("irc"))
193 {
194 RunIrcService();
195 return;
196 }
197
198 System.Console.WriteLine("TechBot running console service...");
199 TechBotService service = new TechBotService(new ConsoleServiceOutput(),
200 ChmPath,
201 MainChm,
202 NtstatusXml,
203 WinerrorXml,
204 HresultXml,
205 WmXml,
206 SvnCommand,
207 BugUrl);
208 service.Run();
209 while (true)
210 {
211 string s = System.Console.ReadLine();
212 service.InjectMessage(null,
213 s);
214 }
215 }
216 }
217 }