adding missing dx headers
[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 SvnCommand
138 {
139 get
140 {
141 string optionName = "SvnCommand";
142 string s = ConfigurationSettings.AppSettings[optionName];
143 VerifyRequiredOption(optionName,
144 s);
145 return s;
146 }
147 }
148
149 private static void RunIrcService()
150 {
151 IrcService ircService = new IrcService(IRCServerHostName,
152 IRCServerHostPort,
153 IRCChannelNames,
154 IRCBotName,
155 ChmPath,
156 MainChm,
157 NtstatusXml,
158 WinerrorXml,
159 HresultXml,
160 SvnCommand);
161 ircService.Run();
162 }
163
164 public static void Main(string[] args)
165 {
166 if (args.Length > 0 && args[0].ToLower().Equals("irc"))
167 {
168 RunIrcService();
169 return;
170 }
171
172 System.Console.WriteLine("TechBot running console service...");
173 TechBotService service = new TechBotService(new ConsoleServiceOutput(),
174 ChmPath,
175 MainChm,
176 NtstatusXml,
177 WinerrorXml,
178 HresultXml,
179 SvnCommand);
180 service.Run();
181 while (true)
182 {
183 string s = System.Console.ReadLine();
184 service.InjectMessage(null,
185 s);
186 }
187 }
188 }
189 }