Identify TechBot to allow private messages
[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 IRCBotPassword
78 {
79 get
80 {
81 string optionName = "IRCBotPassword";
82 string s = ConfigurationSettings.AppSettings[optionName];
83 VerifyRequiredOption(optionName,
84 s);
85 return s;
86 }
87 }
88
89 private static string ChmPath
90 {
91 get
92 {
93 string optionName = "ChmPath";
94 string s = ConfigurationSettings.AppSettings[optionName];
95 VerifyRequiredOption(optionName,
96 s);
97 return s;
98 }
99 }
100
101 private static string MainChm
102 {
103 get
104 {
105 string optionName = "MainChm";
106 string s = ConfigurationSettings.AppSettings[optionName];
107 VerifyRequiredOption(optionName,
108 s);
109 return s;
110 }
111 }
112
113 private static string NtstatusXml
114 {
115 get
116 {
117 string optionName = "NtstatusXml";
118 string s = ConfigurationSettings.AppSettings[optionName];
119 VerifyRequiredOption(optionName,
120 s);
121 return s;
122 }
123 }
124
125 private static string WinerrorXml
126 {
127 get
128 {
129 string optionName = "WinerrorXml";
130 string s = ConfigurationSettings.AppSettings[optionName];
131 VerifyRequiredOption(optionName,
132 s);
133 return s;
134 }
135 }
136
137 private static string HresultXml
138 {
139 get
140 {
141 string optionName = "HresultXml";
142 string s = ConfigurationSettings.AppSettings[optionName];
143 VerifyRequiredOption(optionName,
144 s);
145 return s;
146 }
147 }
148
149 private static string WmXml
150 {
151 get
152 {
153 string optionName = "WmXml";
154 string s = ConfigurationSettings.AppSettings[optionName];
155 VerifyRequiredOption(optionName,
156 s);
157 return s;
158 }
159 }
160
161 private static string SvnCommand
162 {
163 get
164 {
165 string optionName = "SvnCommand";
166 string s = ConfigurationSettings.AppSettings[optionName];
167 VerifyRequiredOption(optionName,
168 s);
169 return s;
170 }
171 }
172
173 private static string BugUrl
174 {
175 get
176 {
177 string optionName = "BugUrl";
178 string s = ConfigurationSettings.AppSettings[optionName];
179 VerifyRequiredOption(optionName,
180 s);
181 return s;
182 }
183 }
184
185 private static void RunIrcService()
186 {
187 IrcService ircService = new IrcService(IRCServerHostName,
188 IRCServerHostPort,
189 IRCChannelNames,
190 IRCBotName,
191 IRCBotPassword,
192 ChmPath,
193 MainChm,
194 NtstatusXml,
195 WinerrorXml,
196 HresultXml,
197 WmXml,
198 SvnCommand,
199 BugUrl);
200 ircService.Run();
201 }
202
203 public static void Main(string[] args)
204 {
205 if (args.Length > 0 && args[0].ToLower().Equals("irc"))
206 {
207 RunIrcService();
208 return;
209 }
210
211 System.Console.WriteLine("TechBot running console service...");
212 TechBotService service = new TechBotService(new ConsoleServiceOutput(),
213 ChmPath,
214 MainChm,
215 NtstatusXml,
216 WinerrorXml,
217 HresultXml,
218 WmXml,
219 SvnCommand,
220 BugUrl);
221 service.Run();
222 while (true)
223 {
224 string s = System.Console.ReadLine();
225 service.InjectMessage(null,
226 s);
227 }
228 }
229 }
230 }