9705e67892547c9f10bf8287e1d0ed170b3bb1fd
[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(string message)
10 {
11 System.Console.WriteLine(message);
12 }
13 }
14
15
16 class MainClass
17 {
18 private static void VerifyRequiredOption(string optionName,
19 string optionValue)
20 {
21 if (optionValue == null)
22 {
23 throw new Exception(String.Format("Option '{0}' not set.",
24 optionName));
25 }
26 }
27
28 private static string IRCServerHostName
29 {
30 get
31 {
32 string optionName = "IRCServerHostName";
33 string s = ConfigurationSettings.AppSettings[optionName];
34 VerifyRequiredOption(optionName,
35 s);
36 return s;
37 }
38 }
39
40 private static int IRCServerHostPort
41 {
42 get
43 {
44 string optionName = "IRCServerHostPort";
45 string s = ConfigurationSettings.AppSettings[optionName];
46 VerifyRequiredOption(optionName,
47 s);
48 return Int32.Parse(s);
49 }
50 }
51
52 private static string IRCChannelName
53 {
54 get
55 {
56 string optionName = "IRCChannelName";
57 string s = ConfigurationSettings.AppSettings[optionName];
58 VerifyRequiredOption(optionName,
59 s);
60 return s;
61 }
62 }
63
64 private static string IRCBotName
65 {
66 get
67 {
68 string optionName = "IRCBotName";
69 string s = ConfigurationSettings.AppSettings[optionName];
70 VerifyRequiredOption(optionName,
71 s);
72 return s;
73 }
74 }
75
76 private static string ChmPath
77 {
78 get
79 {
80 string optionName = "ChmPath";
81 string s = ConfigurationSettings.AppSettings[optionName];
82 VerifyRequiredOption(optionName,
83 s);
84 return s;
85 }
86 }
87
88 private static string MainChm
89 {
90 get
91 {
92 string optionName = "MainChm";
93 string s = ConfigurationSettings.AppSettings[optionName];
94 VerifyRequiredOption(optionName,
95 s);
96 return s;
97 }
98 }
99
100 private static string NtstatusXml
101 {
102 get
103 {
104 string optionName = "NtstatusXml";
105 string s = ConfigurationSettings.AppSettings[optionName];
106 VerifyRequiredOption(optionName,
107 s);
108 return s;
109 }
110 }
111
112 private static string WinerrorXml
113 {
114 get
115 {
116 string optionName = "WinerrorXml";
117 string s = ConfigurationSettings.AppSettings[optionName];
118 VerifyRequiredOption(optionName,
119 s);
120 return s;
121 }
122 }
123
124 private static string HresultXml
125 {
126 get
127 {
128 string optionName = "HresultXml";
129 string s = ConfigurationSettings.AppSettings[optionName];
130 VerifyRequiredOption(optionName,
131 s);
132 return s;
133 }
134 }
135
136 private static string SvnCommand
137 {
138 get
139 {
140 string optionName = "SvnCommand";
141 string s = ConfigurationSettings.AppSettings[optionName];
142 VerifyRequiredOption(optionName,
143 s);
144 return s;
145 }
146 }
147
148 private static void RunIrcService()
149 {
150 IrcService ircService = new IrcService(IRCServerHostName,
151 IRCServerHostPort,
152 IRCChannelName,
153 IRCBotName,
154 ChmPath,
155 MainChm,
156 NtstatusXml,
157 WinerrorXml,
158 HresultXml,
159 SvnCommand);
160 ircService.Run();
161 }
162
163 public static void Main(string[] args)
164 {
165 if (args.Length > 0 && args[0].ToLower().Equals("irc"))
166 {
167 RunIrcService();
168 return;
169 }
170
171 System.Console.WriteLine("TechBot running console service...");
172 TechBotService service = new TechBotService(new ConsoleServiceOutput(),
173 ChmPath,
174 MainChm,
175 NtstatusXml,
176 WinerrorXml,
177 HresultXml,
178 SvnCommand);
179 service.Run();
180 while (true)
181 {
182 string s = System.Console.ReadLine();
183 service.InjectMessage(s);
184 }
185 }
186 }
187 }