markus / ConvertService / ServiceBase / ServiceTestApp / MainWindow.xaml.cs @ 53c9637d
이력 | 보기 | 이력해설 | 다운로드 (22.8 KB)
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.ServiceModel; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows; |
10 |
using System.Windows.Controls; |
11 |
using System.Windows.Data; |
12 |
using System.Windows.Documents; |
13 |
using System.Windows.Forms; |
14 |
using System.Windows.Input; |
15 |
using System.Windows.Media; |
16 |
using System.Windows.Media.Imaging; |
17 |
using System.Windows.Navigation; |
18 |
using System.Windows.Shapes; |
19 |
using Markus.Service.Extensions; |
20 |
using System.Diagnostics; |
21 |
using System.Collections; |
22 |
using Microsoft.Win32; |
23 |
using Markus.Service.IWcfService; |
24 |
using Markus.Service; |
25 |
using static Markus.Service.Extensions.Encrypt; |
26 |
using Markus.Service.Helper; |
27 |
using Markus.Service.DataBase; |
28 |
using Newtonsoft.Json; |
29 |
|
30 |
namespace ServiceTestApp |
31 |
{ |
32 |
/// <summary> |
33 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
34 |
/// </summary> |
35 |
public partial class MainWindow : Window |
36 |
{ |
37 |
public MainWindow() |
38 |
{ |
39 |
InitializeComponent(); |
40 |
|
41 |
var config = Markus.Service.ConfigHelper.AppConfig("ServiceStation.ini"); |
42 |
MarkusDBConnectionString = AESEncrypter.Decrypt(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MARKUS_CONNECTION_STRING)); |
43 |
|
44 |
datagrid.ItemsSource = convertItems; |
45 |
|
46 |
timer.Interval = new TimeSpan(0, 0, 0, 0, 700); |
47 |
timer.Tick += Timer_Tick; |
48 |
timer.Start(); |
49 |
} |
50 |
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); |
51 |
private string MarkusDBConnectionString; |
52 |
|
53 |
private void Timer_0_Tick(object sender, EventArgs e) |
54 |
{ |
55 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
56 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
57 |
|
58 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
59 |
|
60 |
var result = client.AliveConvertList(); |
61 |
|
62 |
datagrid.ItemsSource = result; |
63 |
|
64 |
if(result.Count() < 2) |
65 |
{ |
66 |
foreach (var filename in Directory.EnumerateFiles("D:\\Case")) |
67 |
{ |
68 |
var additem = client.ConvertMenualAdd("111111", filename, "test"); |
69 |
|
70 |
if (!string.IsNullOrWhiteSpace(additem)) |
71 |
{ |
72 |
Log.Text += $"Wcf Station Service call{filename} {result}\n"; |
73 |
} |
74 |
else |
75 |
{ |
76 |
Log.Text += $"Call Error {filename} {result}\n"; |
77 |
} |
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
private void Timer_Tick(object sender, EventArgs e) |
83 |
{ |
84 |
timer.Stop(); |
85 |
|
86 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
87 |
{ |
88 |
var data = database.GetConvertItems(Markus.Message.StatusCodeType.Saving); |
89 |
|
90 |
foreach (var item in data) |
91 |
{ |
92 |
var getitem = convertItems.Where(f => f.ConvertID == item.ConvertID); |
93 |
|
94 |
if (getitem.Count() == 0) |
95 |
{ |
96 |
convertItems.Add(item); |
97 |
} |
98 |
else |
99 |
{ |
100 |
var binditem = getitem.First(); |
101 |
|
102 |
binditem.ConvertState = item.ConvertState; |
103 |
binditem.CurrentPageNo = item.CurrentPageNo; |
104 |
binditem.TotalPage = item.TotalPage; |
105 |
} |
106 |
} |
107 |
|
108 |
var _removeitems = convertItems.Select(f => f.ConvertID).Except(data.Select(x => x.ConvertID)).ToList(); |
109 |
|
110 |
foreach (var item in _removeitems) |
111 |
{ |
112 |
var items = convertItems.Where(x => x.ConvertID == item); |
113 |
|
114 |
if (items.Count() > 0) |
115 |
{ |
116 |
Markus.Service.Interface.ConvertItem convertItem = items.First(); |
117 |
convertItems.Remove(convertItem); |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
var process = Process.GetProcessesByName("Markus.Service.ConvertProcess"); |
123 |
|
124 |
this.Dispatcher.Invoke(() => |
125 |
{ |
126 |
CollectionViewSource.GetDefaultView(datagrid.ItemsSource).Refresh(); |
127 |
|
128 |
if (process.Count() > 0) |
129 |
{ |
130 |
if (Log.Text.Length > int.MaxValue) |
131 |
{ |
132 |
Log.Text = ""; |
133 |
} |
134 |
|
135 |
Log.Text += "-------------------------------------\n"; |
136 |
|
137 |
Log.Text += $" Physical memory usage : {process.Sum(f => f.WorkingSet64)}" + "\n"; |
138 |
Log.Text += $" Base priority : {process.Sum(f => f.BasePriority)}" + "\n"; |
139 |
//Log.Text += $" Priority class : {process[0].PriorityClass}" + "\n"; |
140 |
//Log.Text += $" User processor time : {process[0].UserProcessorTime}" + "\n"; |
141 |
//Log.Text += $" Privileged processor time : {process[0].PrivilegedProcessorTime}" + "\n"; |
142 |
//Log.Text += $" Total processor time : {process[0].TotalProcessorTime}" + "\n"; |
143 |
Log.Text += $" Paged system memory size : {process.Sum(f => f.PagedSystemMemorySize64)}" + "\n"; |
144 |
Log.Text += $" Paged memory size : {process.Sum(f => f.PagedMemorySize64)}" + "\n"; |
145 |
} |
146 |
}); |
147 |
|
148 |
//if (process.Count() < 3) |
149 |
//{ |
150 |
// BasicHttpBinding myBinding = new BasicHttpBinding(); |
151 |
// EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
152 |
// StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
153 |
// foreach (var filename in Directory.EnumerateFiles("D:\\Case")) |
154 |
// { |
155 |
// var _id = new Guid().CreateUniqueGuid().ToString(); |
156 |
|
157 |
// var result = client.ConvertMenualAdd("111111", _id, filename, "test"); |
158 |
|
159 |
// if (result) |
160 |
// { |
161 |
// Log.Text += $"Wcf Station Service call{filename} {result}\n"; |
162 |
// } |
163 |
// else |
164 |
// { |
165 |
// Log.Text += $"Call Error {filename} {result}\n"; |
166 |
// } |
167 |
// } |
168 |
//} |
169 |
|
170 |
timer.Start(); |
171 |
|
172 |
} |
173 |
|
174 |
private System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem> convertItems = new System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem>(); |
175 |
|
176 |
PrivateObject stationObj; |
177 |
Markus.Service.ServiceStation station = new Markus.Service.ServiceStation(); |
178 |
|
179 |
private void Button_Click(object sender, RoutedEventArgs e) |
180 |
{ |
181 |
station.StartService(); |
182 |
|
183 |
// if (station == null) |
184 |
// { |
185 |
// station = new PrivateObject(typeof(Markus.Service.StationService.ServiceStation)); |
186 |
// } |
187 |
|
188 |
|
189 |
|
190 |
Log.Text += "Wcf Service start\n"; |
191 |
} |
192 |
|
193 |
private async void ServiceCall_Click(object sender, RoutedEventArgs e) |
194 |
{ |
195 |
ConvertService.ConvertServiceClient client = new ConvertService.ConvertServiceClient(); |
196 |
var result = await client.ConvertAddAsync(1); |
197 |
|
198 |
Log.Text += $"Wcf Convert Service call{result}\n"; |
199 |
} |
200 |
|
201 |
private async void StationServiceCall_Click(object sender, RoutedEventArgs e) |
202 |
{ |
203 |
StationService.StationServiceClient client = new StationService.StationServiceClient(); |
204 |
var result = await client.ConvertAddAsync("test", "11"); |
205 |
|
206 |
Log.Text += $"Wcf Station Service call{result}\n"; |
207 |
} |
208 |
|
209 |
private async void ItemAdd_Click(object sender, RoutedEventArgs e) |
210 |
{ |
211 |
string ProjectNo = "111111"; |
212 |
|
213 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
214 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
215 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
216 |
foreach (var filename in GetFileList()) |
217 |
{ |
218 |
var result = await client.ConvertMenualAddAsync("111111", filename, "test"); |
219 |
|
220 |
if (!string.IsNullOrWhiteSpace(result)) |
221 |
{ |
222 |
Log.Text += $"Wcf Station Service call{filename} convert ID : {result}\n"; |
223 |
} |
224 |
else |
225 |
{ |
226 |
Log.Text += $"Call Error {filename}\n"; |
227 |
} |
228 |
} |
229 |
|
230 |
#region 데이터베이스 테스트 |
231 |
/* |
232 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(ProjectNo)) |
233 |
{ |
234 |
foreach (var filename in GetFileList()) |
235 |
{ |
236 |
var _id = new Guid().CreateUniqueGuid().ToString(); |
237 |
|
238 |
if (!database.SetConvertDoc(ProjectNo, _id, filename,_id)) |
239 |
{ |
240 |
System.Windows.MessageBox.Show("저장에 실패!"); |
241 |
break; |
242 |
} |
243 |
} |
244 |
} |
245 |
*/ |
246 |
#endregion |
247 |
} |
248 |
|
249 |
private IEnumerable<string> GetFileList() |
250 |
{ |
251 |
IEnumerable<string> result = new string[] { }; |
252 |
|
253 |
using (FolderBrowserDialog dialog = new FolderBrowserDialog()) |
254 |
{ |
255 |
dialog.Description = "PDF가 있는 폴더를 선택하세요."; |
256 |
dialog.ShowNewFolderButton = false; |
257 |
dialog.RootFolder = Environment.SpecialFolder.MyComputer; |
258 |
|
259 |
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
260 |
{ |
261 |
result = Directory.EnumerateFiles(dialog.SelectedPath, "*.pdf", SearchOption.AllDirectories); |
262 |
} |
263 |
} |
264 |
|
265 |
return result; |
266 |
} |
267 |
|
268 |
private void ServiceInstall_Click(object sender, RoutedEventArgs e) |
269 |
{ |
270 |
//Markus.Service.ProjectInstaller projectInstaller = new Markus.Service.ProjectInstaller(); |
271 |
//Hashtable savedState = new Hashtable(); |
272 |
//projectInstaller.serviceProcessInstaller.Install(savedState); |
273 |
|
274 |
//projectInstaller.serviceProcessInstaller.Uninstall(savedState); |
275 |
|
276 |
|
277 |
IntegratedServiceInstaller integrated = new IntegratedServiceInstaller(); |
278 |
integrated.Install("ServiceStation", "ServiceStation", "test", System.ServiceProcess.ServiceAccount.LocalService, System.ServiceProcess.ServiceStartMode.Automatic); |
279 |
|
280 |
} |
281 |
|
282 |
private void LibInstall_Click(object sender, RoutedEventArgs e) |
283 |
{ |
284 |
Markus.Library.Installer.Install(); |
285 |
} |
286 |
|
287 |
private async void ItemAddFile_Click(object sender, RoutedEventArgs e) |
288 |
{ |
289 |
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); |
290 |
|
291 |
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
292 |
{ |
293 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
294 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
295 |
|
296 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
297 |
|
298 |
var result = await client.ConvertMenualAddAsync("111111", dialog.FileName, "test"); |
299 |
|
300 |
Log.Text += $"Wcf Station Service call{dialog.FileName} {result}\n"; |
301 |
} |
302 |
} |
303 |
|
304 |
private async void AliveList_Click(object sender, RoutedEventArgs e) |
305 |
{ |
306 |
await AliveItemAsync(); |
307 |
} |
308 |
private async Task AliveItemAsync() |
309 |
{ |
310 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
311 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
312 |
|
313 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
314 |
var _id = new Guid().CreateUniqueGuid().ToString(); |
315 |
|
316 |
var result = await client.AliveConvertListAsync(); |
317 |
|
318 |
datagrid.ItemsSource = result; |
319 |
} |
320 |
|
321 |
private async void WaitList_Click(object sender, RoutedEventArgs e) |
322 |
{ |
323 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
324 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
325 |
|
326 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
327 |
var _id = new Guid().CreateUniqueGuid().ToString(); |
328 |
|
329 |
var result = await client.WaitConvertListAsync(); |
330 |
|
331 |
datagrid.ItemsSource = result; |
332 |
} |
333 |
|
334 |
private void ProcessKill_Click(object sender, RoutedEventArgs e) |
335 |
{ |
336 |
station.Stopprocess(); |
337 |
} |
338 |
|
339 |
private void DeadLockProcessList_Click(object sender, RoutedEventArgs e) |
340 |
{ |
341 |
station.DeadLockProcessKill(); |
342 |
} |
343 |
|
344 |
private async void Button_Click_1(object sender, RoutedEventArgs e) |
345 |
{ |
346 |
int count = 0; |
347 |
|
348 |
|
349 |
if(int.TryParse(txtProcessCount.Text,out count)) |
350 |
{ |
351 |
|
352 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
353 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
354 |
|
355 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
356 |
|
357 |
var result = await client.SettingMultiProcessAsync(count); |
358 |
|
359 |
} |
360 |
} |
361 |
|
362 |
private async void RemoteFileList_Click(object sender, RoutedEventArgs e) |
363 |
{ |
364 |
var uriList = new[] |
365 |
{ |
366 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000053/250page.pdf", |
367 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000038/250page.pdf", |
368 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000027/BigSize.pdf", |
369 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000032/BigSize.pdf", |
370 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000087/1-5110-ZJ-492-005_C.pdf", |
371 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000070/VP-TEST-MARKUS-040.pdf", |
372 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000051/250page.pdf", |
373 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000039/250page.pdf", |
374 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000022/BigSize.pdf", |
375 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000023/BigSize.pdf", |
376 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000049/250page.pdf", |
377 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000050/250page.pdf", |
378 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000050/250page.pdf", |
379 |
"http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000036/250page.pdf" |
380 |
|
381 |
}; |
382 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
383 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
384 |
|
385 |
StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
386 |
|
387 |
foreach (var item in uriList) |
388 |
{ |
389 |
var result = await client.ConvertMenualAddAsync("111111", item, "test"); |
390 |
Log.Text += $"Wcf Station Service call{item} {result}\n"; |
391 |
} |
392 |
|
393 |
} |
394 |
|
395 |
private void Button_Click_2(object sender, RoutedEventArgs e) |
396 |
{ |
397 |
var pageinfoList = new Markus.Message.PageInfo[] |
398 |
{ |
399 |
new Markus.Message.PageInfo |
400 |
{ |
401 |
Width = 111, |
402 |
Height = 111, |
403 |
PageNo = 1, |
404 |
|
405 |
}, |
406 |
new Markus.Message.PageInfo |
407 |
{ |
408 |
Width = 111, |
409 |
Height = 111, |
410 |
PageNo = 2, |
411 |
} |
412 |
|
413 |
}; |
414 |
|
415 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
416 |
{ |
417 |
|
418 |
List<DOCPAGE> docPageList = new List<DOCPAGE>(); |
419 |
|
420 |
docPageList = pageinfoList.Select(f => new DOCPAGE |
421 |
{ |
422 |
ID = GuidExtension.shortGuid(), |
423 |
PAGE_WIDTH = f.Width.ToString(), |
424 |
PAGE_HEIGHT = f.Height.ToString(), |
425 |
PAGE_NUMBER = f.PageNo |
426 |
}).ToList(); |
427 |
|
428 |
database.SetDocumentInfo("1df16d9a-1ea9-9a32-8a61-aad6ce4a2a49", 2, docPageList); |
429 |
} |
430 |
} |
431 |
|
432 |
private void wcfTest_Click(object sender, RoutedEventArgs e) |
433 |
{ |
434 |
station.GetApplicationConfig(); |
435 |
station.StartWcfService(); |
436 |
} |
437 |
|
438 |
private async void WebServiceTest_click(object sender, RoutedEventArgs e) |
439 |
{ |
440 |
string cookie = ""; |
441 |
|
442 |
var uri = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); // string 을 Uri 로 형변환 |
443 |
var wReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환 |
444 |
wReq.Method = "GET"; // 전송 방법 "GET" or "POST" |
445 |
wReq.ServicePoint.Expect100Continue = false; |
446 |
wReq.CookieContainer = new System.Net.CookieContainer(); |
447 |
wReq.CookieContainer.SetCookies(uri, cookie); // 넘겨줄 쿠키가 있을때 CookiContainer 에 저장 |
448 |
|
449 |
//POST 전송일 경우 |
450 |
var data = new |
451 |
{ |
452 |
ProjectNo = "111111", |
453 |
DocumentID = "453" |
454 |
}; |
455 |
var jsonRequest = JsonConvert.SerializeObject(data); |
456 |
|
457 |
byte[] byteArray = Encoding.UTF8.GetBytes(jsonRequest); |
458 |
|
459 |
Stream dataStream = wReq.GetRequestStream(); |
460 |
dataStream.Write(byteArray, 0, byteArray.Length); |
461 |
dataStream.Close(); |
462 |
|
463 |
|
464 |
using (var wRes = (System.Net.HttpWebResponse)wReq.GetResponse()) |
465 |
{ |
466 |
Stream respPostStream = wRes.GetResponseStream(); |
467 |
StreamReader readerPost = new StreamReader(respPostStream, Encoding.GetEncoding("EUC-KR"), true); |
468 |
|
469 |
var resResult = readerPost.ReadToEnd(); |
470 |
System.Diagnostics.Debug.WriteLine( resResult); |
471 |
} |
472 |
|
473 |
|
474 |
using (var client = new System.Net.Http.HttpClient()) |
475 |
{ |
476 |
var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); |
477 |
var data2 = new |
478 |
{ |
479 |
ProjectNo = "111111", |
480 |
DocumentID = "453" |
481 |
}; |
482 |
|
483 |
var jsonRequest2 = JsonConvert.SerializeObject(data2); |
484 |
var stringContent = new System.Net.Http.StringContent(jsonRequest2, Encoding.UTF8, "application/json"); |
485 |
var response = await client.PostAsync(uri2, stringContent); |
486 |
|
487 |
if (response.IsSuccessStatusCode) |
488 |
{ |
489 |
System.Diagnostics.Debug.WriteLine(response.Content.Headers.First()); |
490 |
System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
491 |
} |
492 |
} |
493 |
//var client = new System.Net.WebClient(); |
494 |
//var result = await client.DownloadStringTaskAsync("http://localhost:9101/StationService/Rest/GetConvertItem?ProjectNo=111111&DocumentID=453"); |
495 |
//System.Diagnostics.Debug.WriteLine(result); |
496 |
} |
497 |
} |
498 |
|
499 |
class IntegratedServiceInstaller |
500 |
{ |
501 |
public void Install(String ServiceName, String DisplayName, String Description, |
502 |
System.ServiceProcess.ServiceAccount Account, |
503 |
System.ServiceProcess.ServiceStartMode StartMode) |
504 |
{ |
505 |
System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); |
506 |
ProcessInstaller.Account = Account; |
507 |
|
508 |
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
509 |
|
510 |
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext(); |
511 |
string processPath = Process.GetCurrentProcess().MainModule.FileName; |
512 |
if (processPath != null && processPath.Length > 0) |
513 |
{ |
514 |
System.IO.FileInfo fi = new System.IO.FileInfo(processPath); |
515 |
//Context = new System.Configuration.Install.InstallContext(); |
516 |
//Context.Parameters.Add("assemblyPath", fi.FullName); |
517 |
//Context.Parameters.Add("startParameters", "Test"); |
518 |
|
519 |
String path = String.Format("/assemblypath={0}", fi.FullName); |
520 |
String[] cmdline = { path }; |
521 |
Context = new System.Configuration.Install.InstallContext("", cmdline); |
522 |
} |
523 |
|
524 |
SINST.Context = Context; |
525 |
SINST.DisplayName = DisplayName; |
526 |
SINST.Description = Description; |
527 |
SINST.ServiceName = ServiceName; |
528 |
SINST.StartType = StartMode; |
529 |
SINST.Parent = ProcessInstaller; |
530 |
|
531 |
// http://bytes.com/forum/thread527221.html |
532 |
// SINST.ServicesDependedOn = new String[] {}; |
533 |
|
534 |
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary(); |
535 |
SINST.Install(state); |
536 |
|
537 |
// http://www.dotnet247.com/247reference/msgs/43/219565.aspx |
538 |
using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true)) |
539 |
{ |
540 |
try |
541 |
{ |
542 |
Object sValue = oKey.GetValue("ImagePath"); |
543 |
oKey.SetValue("ImagePath", sValue); |
544 |
} |
545 |
catch (Exception Ex) |
546 |
{ |
547 |
// System.Console.WriteLine(Ex.Message); |
548 |
} |
549 |
} |
550 |
|
551 |
} |
552 |
public void Uninstall(String ServiceName) |
553 |
{ |
554 |
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
555 |
|
556 |
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null); |
557 |
SINST.Context = Context; |
558 |
SINST.ServiceName = ServiceName; |
559 |
SINST.Uninstall(null); |
560 |
} |
561 |
} |
562 |
} |