- Add support for "!wm <value>" and "!wm <name>" commands.
[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 void RunIrcService()
162 {
163 IrcService ircService = new IrcService(IRCServerHostName,
164 IRCServerHostPort,
165 IRCChannelNames,
166 IRCBotName,
167 ChmPath,
168 MainChm,
169 NtstatusXml,
170 WinerrorXml,
171 HresultXml,
172 WmXml,
173 SvnCommand);
174 ircService.Run();
175 }
176
177 public static void Main(string[] args)
178 {
179 if (args.Length > 0 && args[0].ToLower().Equals("irc"))
180 {
181 RunIrcService();
182 return;
183 }
184
185 System.Console.WriteLine("TechBot running console service...");
186 TechBotService service = new TechBotService(new ConsoleServiceOutput(),
187 ChmPath,
188 MainChm,
189 NtstatusXml,
190 WinerrorXml,
191 HresultXml,
192 WmXml,
193 SvnCommand);
194 service.Run();
195 while (true)
196 {
197 string s = System.Console.ReadLine();
198 service.InjectMessage(null,
199 s);
200 }
201 }
202 }
203 }