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