markus / ConvertService / ServiceBase / ServiceTestApp / MainWindow.xaml.cs @ c5519c44
이력 | 보기 | 이력해설 | 다운로드 (36.3 KB)
1 | ff4b1e6e | taeseongkim | using Markus.EntityModel; |
---|---|---|---|
2 | using Markus.Service; |
||
3 | using Markus.Service.Extensions; |
||
4 | using Markus.Service.Helper; |
||
5 | using Microsoft.Win32; |
||
6 | using Newtonsoft.Json; |
||
7 | 65fbe3cb | taeseongkim | using Newtonsoft.Json.Linq; |
8 | 53c9637d | taeseongkim | using System; |
9 | using System.Collections.Generic; |
||
10 | ff4b1e6e | taeseongkim | using System.Diagnostics; |
11 | 53c9637d | taeseongkim | using System.IO; |
12 | using System.Linq; |
||
13 | 150747cb | taeseongkim | using System.Net; |
14 | ff4b1e6e | taeseongkim | using System.Net.Http; |
15 | 53c9637d | taeseongkim | using System.ServiceModel; |
16 | using System.Text; |
||
17 | using System.Threading.Tasks; |
||
18 | 60723dc9 | taeseongkim | using System.Web; |
19 | ff4b1e6e | taeseongkim | using System.Web.Script.Serialization; |
20 | 53c9637d | taeseongkim | using System.Windows; |
21 | using System.Windows.Data; |
||
22 | using System.Windows.Forms; |
||
23 | using static Markus.Service.Extensions.Encrypt; |
||
24 | |||
25 | namespace ServiceTestApp |
||
26 | { |
||
27 | /// <summary> |
||
28 | /// MainWindow.xaml에 대한 상호 작용 논리 |
||
29 | /// </summary> |
||
30 | public partial class MainWindow : Window |
||
31 | { |
||
32 | public MainWindow() |
||
33 | { |
||
34 | InitializeComponent(); |
||
35 | |||
36 | a537d79a | taeseongkim | var config = Markus.Service.Helper.ConfigHelper.AppConfig("ServiceStation.ini"); |
37 | 53c9637d | taeseongkim | MarkusDBConnectionString = AESEncrypter.Decrypt(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MARKUS_CONNECTION_STRING)); |
38 | |||
39 | datagrid.ItemsSource = convertItems; |
||
40 | |||
41 | timer.Interval = new TimeSpan(0, 0, 0, 0, 700); |
||
42 | timer.Tick += Timer_Tick; |
||
43 | 06f13e11 | taeseongkim | //timer.Start(); |
44 | 53c9637d | taeseongkim | } |
45 | System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); |
||
46 | private string MarkusDBConnectionString; |
||
47 | |||
48 | private void Timer_0_Tick(object sender, EventArgs e) |
||
49 | { |
||
50 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
51 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
52 | |||
53 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
54 | |||
55 | var result = client.AliveConvertList(); |
||
56 | |||
57 | datagrid.ItemsSource = result; |
||
58 | |||
59 | if(result.Count() < 2) |
||
60 | { |
||
61 | foreach (var filename in Directory.EnumerateFiles("D:\\Case")) |
||
62 | { |
||
63 | var additem = client.ConvertMenualAdd("111111", filename, "test"); |
||
64 | |||
65 | if (!string.IsNullOrWhiteSpace(additem)) |
||
66 | { |
||
67 | Log.Text += $"Wcf Station Service call{filename} {result}\n"; |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | Log.Text += $"Call Error {filename} {result}\n"; |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | private void Timer_Tick(object sender, EventArgs e) |
||
78 | { |
||
79 | timer.Stop(); |
||
80 | |||
81 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
82 | { |
||
83 | var data = database.GetConvertItems(Markus.Message.StatusCodeType.Saving); |
||
84 | |||
85 | foreach (var item in data) |
||
86 | { |
||
87 | var getitem = convertItems.Where(f => f.ConvertID == item.ConvertID); |
||
88 | |||
89 | if (getitem.Count() == 0) |
||
90 | { |
||
91 | convertItems.Add(item); |
||
92 | } |
||
93 | else |
||
94 | { |
||
95 | var binditem = getitem.First(); |
||
96 | |||
97 | binditem.ConvertState = item.ConvertState; |
||
98 | binditem.CurrentPageNo = item.CurrentPageNo; |
||
99 | binditem.TotalPage = item.TotalPage; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | var _removeitems = convertItems.Select(f => f.ConvertID).Except(data.Select(x => x.ConvertID)).ToList(); |
||
104 | |||
105 | foreach (var item in _removeitems) |
||
106 | { |
||
107 | var items = convertItems.Where(x => x.ConvertID == item); |
||
108 | |||
109 | if (items.Count() > 0) |
||
110 | { |
||
111 | Markus.Service.Interface.ConvertItem convertItem = items.First(); |
||
112 | convertItems.Remove(convertItem); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | var process = Process.GetProcessesByName("Markus.Service.ConvertProcess"); |
||
118 | |||
119 | this.Dispatcher.Invoke(() => |
||
120 | { |
||
121 | CollectionViewSource.GetDefaultView(datagrid.ItemsSource).Refresh(); |
||
122 | |||
123 | if (process.Count() > 0) |
||
124 | { |
||
125 | if (Log.Text.Length > int.MaxValue) |
||
126 | { |
||
127 | Log.Text = ""; |
||
128 | } |
||
129 | |||
130 | Log.Text += "-------------------------------------\n"; |
||
131 | |||
132 | Log.Text += $" Physical memory usage : {process.Sum(f => f.WorkingSet64)}" + "\n"; |
||
133 | Log.Text += $" Base priority : {process.Sum(f => f.BasePriority)}" + "\n"; |
||
134 | //Log.Text += $" Priority class : {process[0].PriorityClass}" + "\n"; |
||
135 | //Log.Text += $" User processor time : {process[0].UserProcessorTime}" + "\n"; |
||
136 | //Log.Text += $" Privileged processor time : {process[0].PrivilegedProcessorTime}" + "\n"; |
||
137 | //Log.Text += $" Total processor time : {process[0].TotalProcessorTime}" + "\n"; |
||
138 | Log.Text += $" Paged system memory size : {process.Sum(f => f.PagedSystemMemorySize64)}" + "\n"; |
||
139 | Log.Text += $" Paged memory size : {process.Sum(f => f.PagedMemorySize64)}" + "\n"; |
||
140 | } |
||
141 | }); |
||
142 | |||
143 | //if (process.Count() < 3) |
||
144 | //{ |
||
145 | // BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
146 | // EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
147 | // StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
148 | // foreach (var filename in Directory.EnumerateFiles("D:\\Case")) |
||
149 | // { |
||
150 | // var _id = new Guid().CreateUniqueGuid().ToString(); |
||
151 | |||
152 | // var result = client.ConvertMenualAdd("111111", _id, filename, "test"); |
||
153 | |||
154 | // if (result) |
||
155 | // { |
||
156 | // Log.Text += $"Wcf Station Service call{filename} {result}\n"; |
||
157 | // } |
||
158 | // else |
||
159 | // { |
||
160 | // Log.Text += $"Call Error {filename} {result}\n"; |
||
161 | // } |
||
162 | // } |
||
163 | //} |
||
164 | |||
165 | timer.Start(); |
||
166 | |||
167 | } |
||
168 | |||
169 | private System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem> convertItems = new System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem>(); |
||
170 | |||
171 | 6b6e937c | taeseongkim | private Object stationObj; |
172 | 53c9637d | taeseongkim | Markus.Service.ServiceStation station = new Markus.Service.ServiceStation(); |
173 | |||
174 | private void Button_Click(object sender, RoutedEventArgs e) |
||
175 | { |
||
176 | station.StartService(); |
||
177 | |||
178 | // if (station == null) |
||
179 | // { |
||
180 | // station = new PrivateObject(typeof(Markus.Service.StationService.ServiceStation)); |
||
181 | // } |
||
182 | |||
183 | |||
184 | |||
185 | Log.Text += "Wcf Service start\n"; |
||
186 | } |
||
187 | |||
188 | private async void ServiceCall_Click(object sender, RoutedEventArgs e) |
||
189 | { |
||
190 | ConvertService.ConvertServiceClient client = new ConvertService.ConvertServiceClient(); |
||
191 | var result = await client.ConvertAddAsync(1); |
||
192 | |||
193 | Log.Text += $"Wcf Convert Service call{result}\n"; |
||
194 | } |
||
195 | |||
196 | private async void StationServiceCall_Click(object sender, RoutedEventArgs e) |
||
197 | { |
||
198 | StationService.StationServiceClient client = new StationService.StationServiceClient(); |
||
199 | var result = await client.ConvertAddAsync("test", "11"); |
||
200 | |||
201 | Log.Text += $"Wcf Station Service call{result}\n"; |
||
202 | } |
||
203 | |||
204 | private async void ItemAdd_Click(object sender, RoutedEventArgs e) |
||
205 | { |
||
206 | string ProjectNo = "111111"; |
||
207 | |||
208 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
209 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
210 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
211 | foreach (var filename in GetFileList()) |
||
212 | { |
||
213 | var result = await client.ConvertMenualAddAsync("111111", filename, "test"); |
||
214 | |||
215 | if (!string.IsNullOrWhiteSpace(result)) |
||
216 | { |
||
217 | Log.Text += $"Wcf Station Service call{filename} convert ID : {result}\n"; |
||
218 | } |
||
219 | else |
||
220 | { |
||
221 | Log.Text += $"Call Error {filename}\n"; |
||
222 | } |
||
223 | } |
||
224 | |||
225 | #region 데이터베이스 테스트 |
||
226 | /* |
||
227 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(ProjectNo)) |
||
228 | { |
||
229 | foreach (var filename in GetFileList()) |
||
230 | { |
||
231 | var _id = new Guid().CreateUniqueGuid().ToString(); |
||
232 | |||
233 | if (!database.SetConvertDoc(ProjectNo, _id, filename,_id)) |
||
234 | { |
||
235 | System.Windows.MessageBox.Show("저장에 실패!"); |
||
236 | break; |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | */ |
||
241 | #endregion |
||
242 | } |
||
243 | |||
244 | private IEnumerable<string> GetFileList() |
||
245 | { |
||
246 | IEnumerable<string> result = new string[] { }; |
||
247 | |||
248 | using (FolderBrowserDialog dialog = new FolderBrowserDialog()) |
||
249 | { |
||
250 | dialog.Description = "PDF가 있는 폴더를 선택하세요."; |
||
251 | dialog.ShowNewFolderButton = false; |
||
252 | dialog.RootFolder = Environment.SpecialFolder.MyComputer; |
||
253 | |||
254 | if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
||
255 | { |
||
256 | result = Directory.EnumerateFiles(dialog.SelectedPath, "*.pdf", SearchOption.AllDirectories); |
||
257 | } |
||
258 | } |
||
259 | |||
260 | return result; |
||
261 | } |
||
262 | |||
263 | private void ServiceInstall_Click(object sender, RoutedEventArgs e) |
||
264 | { |
||
265 | //Markus.Service.ProjectInstaller projectInstaller = new Markus.Service.ProjectInstaller(); |
||
266 | //Hashtable savedState = new Hashtable(); |
||
267 | //projectInstaller.serviceProcessInstaller.Install(savedState); |
||
268 | |||
269 | //projectInstaller.serviceProcessInstaller.Uninstall(savedState); |
||
270 | |||
271 | |||
272 | IntegratedServiceInstaller integrated = new IntegratedServiceInstaller(); |
||
273 | integrated.Install("ServiceStation", "ServiceStation", "test", System.ServiceProcess.ServiceAccount.LocalService, System.ServiceProcess.ServiceStartMode.Automatic); |
||
274 | |||
275 | } |
||
276 | |||
277 | private void LibInstall_Click(object sender, RoutedEventArgs e) |
||
278 | { |
||
279 | Markus.Library.Installer.Install(); |
||
280 | } |
||
281 | |||
282 | private async void ItemAddFile_Click(object sender, RoutedEventArgs e) |
||
283 | { |
||
284 | System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); |
||
285 | |||
286 | if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
||
287 | { |
||
288 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
289 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
290 | |||
291 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
292 | |||
293 | var result = await client.ConvertMenualAddAsync("111111", dialog.FileName, "test"); |
||
294 | |||
295 | Log.Text += $"Wcf Station Service call{dialog.FileName} {result}\n"; |
||
296 | } |
||
297 | } |
||
298 | |||
299 | private async void AliveList_Click(object sender, RoutedEventArgs e) |
||
300 | { |
||
301 | await AliveItemAsync(); |
||
302 | } |
||
303 | private async Task AliveItemAsync() |
||
304 | { |
||
305 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
306 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
307 | |||
308 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
309 | var _id = new Guid().CreateUniqueGuid().ToString(); |
||
310 | |||
311 | var result = await client.AliveConvertListAsync(); |
||
312 | |||
313 | datagrid.ItemsSource = result; |
||
314 | } |
||
315 | |||
316 | private async void WaitList_Click(object sender, RoutedEventArgs e) |
||
317 | { |
||
318 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
319 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
320 | |||
321 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
322 | var _id = new Guid().CreateUniqueGuid().ToString(); |
||
323 | |||
324 | var result = await client.WaitConvertListAsync(); |
||
325 | |||
326 | datagrid.ItemsSource = result; |
||
327 | } |
||
328 | |||
329 | private void ProcessKill_Click(object sender, RoutedEventArgs e) |
||
330 | { |
||
331 | station.Stopprocess(); |
||
332 | } |
||
333 | |||
334 | private void DeadLockProcessList_Click(object sender, RoutedEventArgs e) |
||
335 | { |
||
336 | station.DeadLockProcessKill(); |
||
337 | } |
||
338 | |||
339 | private async void Button_Click_1(object sender, RoutedEventArgs e) |
||
340 | { |
||
341 | int count = 0; |
||
342 | |||
343 | |||
344 | if(int.TryParse(txtProcessCount.Text,out count)) |
||
345 | { |
||
346 | |||
347 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
348 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
349 | |||
350 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
351 | |||
352 | var result = await client.SettingMultiProcessAsync(count); |
||
353 | |||
354 | } |
||
355 | } |
||
356 | |||
357 | private async void RemoteFileList_Click(object sender, RoutedEventArgs e) |
||
358 | { |
||
359 | var uriList = new[] |
||
360 | { |
||
361 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000053/250page.pdf", |
||
362 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000038/250page.pdf", |
||
363 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000027/BigSize.pdf", |
||
364 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000032/BigSize.pdf", |
||
365 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000087/1-5110-ZJ-492-005_C.pdf", |
||
366 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000070/VP-TEST-MARKUS-040.pdf", |
||
367 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000051/250page.pdf", |
||
368 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000039/250page.pdf", |
||
369 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000022/BigSize.pdf", |
||
370 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000023/BigSize.pdf", |
||
371 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000049/250page.pdf", |
||
372 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000050/250page.pdf", |
||
373 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000050/250page.pdf", |
||
374 | "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000036/250page.pdf" |
||
375 | |||
376 | }; |
||
377 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
378 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService")); |
||
379 | |||
380 | StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
381 | |||
382 | foreach (var item in uriList) |
||
383 | { |
||
384 | var result = await client.ConvertMenualAddAsync("111111", item, "test"); |
||
385 | Log.Text += $"Wcf Station Service call{item} {result}\n"; |
||
386 | } |
||
387 | |||
388 | } |
||
389 | |||
390 | private void Button_Click_2(object sender, RoutedEventArgs e) |
||
391 | { |
||
392 | var pageinfoList = new Markus.Message.PageInfo[] |
||
393 | { |
||
394 | new Markus.Message.PageInfo |
||
395 | { |
||
396 | Width = 111, |
||
397 | Height = 111, |
||
398 | PageNo = 1, |
||
399 | |||
400 | }, |
||
401 | new Markus.Message.PageInfo |
||
402 | { |
||
403 | Width = 111, |
||
404 | Height = 111, |
||
405 | PageNo = 2, |
||
406 | } |
||
407 | |||
408 | }; |
||
409 | |||
410 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
411 | { |
||
412 | |||
413 | List<DOCPAGE> docPageList = new List<DOCPAGE>(); |
||
414 | |||
415 | docPageList = pageinfoList.Select(f => new DOCPAGE |
||
416 | { |
||
417 | ID = GuidExtension.shortGuid(), |
||
418 | PAGE_WIDTH = f.Width.ToString(), |
||
419 | PAGE_HEIGHT = f.Height.ToString(), |
||
420 | PAGE_NUMBER = f.PageNo |
||
421 | }).ToList(); |
||
422 | |||
423 | database.SetDocumentInfo("1df16d9a-1ea9-9a32-8a61-aad6ce4a2a49", 2, docPageList); |
||
424 | } |
||
425 | } |
||
426 | |||
427 | private void wcfTest_Click(object sender, RoutedEventArgs e) |
||
428 | { |
||
429 | station.GetApplicationConfig(); |
||
430 | station.StartWcfService(); |
||
431 | } |
||
432 | c433ebde | taeseongkim | private static readonly HttpClient _Client = new HttpClient(); |
433 | private static JavaScriptSerializer _Serializer = new JavaScriptSerializer(); |
||
434 | 53c9637d | taeseongkim | |
435 | private async void WebServiceTest_click(object sender, RoutedEventArgs e) |
||
436 | { |
||
437 | b92f142f | taeseongkim | //string cookie = ""; |
438 | 53c9637d | taeseongkim | |
439 | b92f142f | taeseongkim | //var uri = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); // string 을 Uri 로 형변환 |
440 | //var wReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환 |
||
441 | //wReq.Method = "POST"; // 전송 방법 "GET" or "POST" |
||
442 | //wReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; |
||
443 | //wReq.Proxy = new System.Net.WebProxy("127.0.0.1", 8888); |
||
444 | ////wReq.ServicePoint.Expect100Continue = false; |
||
445 | ////wReq.CookieContainer = new System.Net.CookieContainer(); |
||
446 | ////wReq.CookieContainer.SetCookies(uri, cookie); // 넘겨줄 쿠키가 있을때 CookiContainer 에 저장 |
||
447 | 53c9637d | taeseongkim | |
448 | b92f142f | taeseongkim | ////POST 전송일 경우 |
449 | c433ebde | taeseongkim | |
450 | b92f142f | taeseongkim | //string url = "http://localhost:9101/StationService/Rest/GetConvertItem"; |
451 | //var data = new SEND |
||
452 | //{ |
||
453 | // ProjectNo = "111111", |
||
454 | // DocumentID = "453" |
||
455 | //}; |
||
456 | |||
457 | //var json = _Serializer.Serialize(data); |
||
458 | //var response2 = await Request(HttpMethod.Post, url, json, new Dictionary<string, string>()); |
||
459 | //string responseText = await response2.Content.ReadAsStringAsync(); |
||
460 | 53c9637d | taeseongkim | |
461 | b92f142f | taeseongkim | //Console.WriteLine(responseText); |
462 | |||
463 | 53c9637d | taeseongkim | using (var client = new System.Net.Http.HttpClient()) |
464 | { |
||
465 | b92f142f | taeseongkim | |
466 | 150747cb | taeseongkim | var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); |
467 | c433ebde | taeseongkim | var data2 = new SEND |
468 | 53c9637d | taeseongkim | { |
469 | ProjectNo = "111111", |
||
470 | DocumentID = "453" |
||
471 | }; |
||
472 | |||
473 | var jsonRequest2 = JsonConvert.SerializeObject(data2); |
||
474 | var stringContent = new System.Net.Http.StringContent(jsonRequest2, Encoding.UTF8, "application/json"); |
||
475 | var response = await client.PostAsync(uri2, stringContent); |
||
476 | |||
477 | if (response.IsSuccessStatusCode) |
||
478 | { |
||
479 | System.Diagnostics.Debug.WriteLine(response.Content.Headers.First()); |
||
480 | System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
||
481 | } |
||
482 | } |
||
483 | c433ebde | taeseongkim | |
484 | 150747cb | taeseongkim | //using (var client = new System.Net.Http.HttpClient()) |
485 | //{ |
||
486 | // var uri2 = new Uri("http://localhost:13009/MarkusService.svc/Rest/GetCommantList"); |
||
487 | |||
488 | // var data2 = new SEND |
||
489 | // { |
||
490 | // ProjectNo = "111111", |
||
491 | // DocumentID = "453" |
||
492 | // }; |
||
493 | |||
494 | // var jsonRequest2 = JsonConvert.SerializeObject(data2); |
||
495 | // var stringContent = new System.Net.Http.StringContent(jsonRequest2, Encoding.UTF8, "application/json"); |
||
496 | // var response = await client.PostAsync(uri2, stringContent); |
||
497 | |||
498 | // if (response.IsSuccessStatusCode) |
||
499 | // { |
||
500 | // System.Diagnostics.Debug.WriteLine(response.Content.Headers.First()); |
||
501 | // System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
||
502 | // } |
||
503 | //} |
||
504 | |||
505 | c433ebde | taeseongkim | //var client2 = new System.Net.WebClient(); |
506 | //client2.Proxy = new System.Net.WebProxy("127.0.0.1", 8888); |
||
507 | //var result = await client2.DownloadStringTaskAsync("http://localhost:9101/StationService/Rest/GetConvertItem?ProjectNo=111111&DocumentID=453"); |
||
508 | 53c9637d | taeseongkim | //System.Diagnostics.Debug.WriteLine(result); |
509 | } |
||
510 | c433ebde | taeseongkim | |
511 | static async Task<System.Net.Http.HttpResponseMessage> Request(HttpMethod pMethod, string pUrl, string pJsonContent, Dictionary<string, string> pHeaders) |
||
512 | { |
||
513 | var httpRequestMessage = new HttpRequestMessage(); |
||
514 | httpRequestMessage.Method = pMethod; |
||
515 | httpRequestMessage.RequestUri = new Uri(pUrl); |
||
516 | foreach (var head in pHeaders) |
||
517 | { |
||
518 | httpRequestMessage.Headers.Add(head.Key, head.Value); |
||
519 | } |
||
520 | switch (pMethod.Method) |
||
521 | { |
||
522 | case "POST": |
||
523 | HttpContent httpContent = new StringContent(pJsonContent, Encoding.UTF8, "application/json"); |
||
524 | httpRequestMessage.Content = httpContent; |
||
525 | break; |
||
526 | |||
527 | } |
||
528 | |||
529 | return await new HttpClient().SendAsync(httpRequestMessage); |
||
530 | } |
||
531 | 06f13e11 | taeseongkim | |
532 | private async void ConvertWebServiceTest_click(object sender, RoutedEventArgs e) |
||
533 | { |
||
534 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
535 | { |
||
536 | |||
537 | var items = database.GetConvertItems(Markus.Message.StatusCodeType.Completed).Take(100).ToList(); |
||
538 | |||
539 | var service = new ConvertWebService.ConversionSoapClient(); |
||
540 | |||
541 | int count = 0; |
||
542 | |||
543 | foreach (var item in items) |
||
544 | { |
||
545 | count++; |
||
546 | byte[] bytes = Encoding.UTF8.GetBytes(item.OriginfilePath); |
||
547 | var url = Convert.ToBase64String(bytes); |
||
548 | var result = await service.ConvertRunAsync(count.ToString(), item.UniqueKey, item.UniqueKey + count.ToString(), count.ToString(), "111111", item.UniqueKey, url); |
||
549 | |||
550 | System.Diagnostics.Debug.WriteLine(item.ConvertID + " " + result.ToString()); |
||
551 | } |
||
552 | } |
||
553 | } |
||
554 | 60723dc9 | taeseongkim | |
555 | private async void DownLoadTest_click(object sender, RoutedEventArgs e) |
||
556 | { |
||
557 | a2a64028 | taeseongkim | for (int i = 0; i < 100; i++) |
558 | { |
||
559 | await DownloadFileAsync("http://cloud.devdoftech.co.kr:5977/PDF/000000_app/VPCS_DOCLIB/110001/11000102/ToVendor/VP-DRAWINGS-SAMPLE-002.pdf"); |
||
560 | |||
561 | await Task.Delay(new TimeSpan(0,0,0,1)); |
||
562 | } |
||
563 | |||
564 | 60723dc9 | taeseongkim | } |
565 | |||
566 | private async Task<bool> DownloadFileAsync(string FileaPath) |
||
567 | { |
||
568 | a2a64028 | taeseongkim | System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); |
569 | stopwatch.Start(); |
||
570 | |||
571 | 60723dc9 | taeseongkim | bool result = false; |
572 | |||
573 | try |
||
574 | { |
||
575 | Uri pdfFileUri = null; |
||
576 | |||
577 | //if (saveItem.PdfFilePath.Contains("VPCS_DOCLIB")) |
||
578 | //{ |
||
579 | // FileName = DocUri.Remove(0, DocUri.LastIndexOf("/") + 1); |
||
580 | // ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더 |
||
581 | // ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString(); |
||
582 | // ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID; |
||
583 | // DownloadFilePath = ItemPath + "\\" + FileName; |
||
584 | //} |
||
585 | //else |
||
586 | //{ |
||
587 | // ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더 |
||
588 | // ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString(); |
||
589 | // ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID; |
||
590 | // FileName = HttpUtility.ParseQueryString(new Uri(DocUri).Query).Get("fileName"); |
||
591 | // DownloadFilePath = string.IsNullOrWhiteSpace(FileName) ? ItemPath + "\\" + FileName : ItemPath + "\\" + FileName; |
||
592 | |||
593 | //} |
||
594 | |||
595 | FileaPath = HttpUtility.UrlDecode(FileaPath); //PDF 전체 경로 |
||
596 | a2a64028 | taeseongkim | string FileName = System.IO.Path.GetRandomFileName();// DownloadUri.GetFileName(FileaPath); |
597 | |||
598 | 60723dc9 | taeseongkim | |
599 | string downloadFilePath = System.IO.Path.Combine(@"c:\temp", FileName); |
||
600 | |||
601 | // 드라이브 경로가 포함되었는지 판단. |
||
602 | if (Path.IsPathRooted(FileaPath)) |
||
603 | { |
||
604 | if (File.Exists(FileaPath)) |
||
605 | { |
||
606 | File.Copy(FileaPath, downloadFilePath, true); |
||
607 | } |
||
608 | else |
||
609 | { |
||
610 | throw new Exception("File Not Found. Please, check the file path."); |
||
611 | } |
||
612 | } |
||
613 | else if (Uri.TryCreate(FileaPath, UriKind.RelativeOrAbsolute, out pdfFileUri)) |
||
614 | { |
||
615 | try |
||
616 | { |
||
617 | using (System.Net.WebClient webClient = new System.Net.WebClient()) |
||
618 | { |
||
619 | webClient.UseDefaultCredentials = true;//.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증 |
||
620 | |||
621 | a2a64028 | taeseongkim | webClient.Proxy = null; |
622 | //System.Net.IWebProxy webProxy = webClient.Proxy; |
||
623 | |||
624 | //if (webProxy != null) |
||
625 | //{ |
||
626 | // // Use the default credentials of the logged on user. |
||
627 | // webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; |
||
628 | //} |
||
629 | 60723dc9 | taeseongkim | //if (!System.IO.Directory.Exists(ConvertProcessContext.TempDirectory)) |
630 | //{ |
||
631 | // System.IO.Directory.CreateDirectory(ConvertProcessContext.TempDirectory); |
||
632 | //} |
||
633 | |||
634 | a2a64028 | taeseongkim | System.Diagnostics.Debug.WriteLine("file download Test"); |
635 | 60723dc9 | taeseongkim | await webClient.DownloadFileTaskAsync(pdfFileUri, downloadFilePath); |
636 | a2a64028 | taeseongkim | System.Diagnostics.Debug.WriteLine("file download Test : " + new TimeSpan(stopwatch.ElapsedTicks)); |
637 | webClient.Dispose(); |
||
638 | 60723dc9 | taeseongkim | } |
639 | } |
||
640 | a2a64028 | taeseongkim | catch (Exception ex) |
641 | 60723dc9 | taeseongkim | { |
642 | throw new Exception("File Download Error. Please, check the file path."); |
||
643 | } |
||
644 | } |
||
645 | else |
||
646 | { |
||
647 | throw new Exception("Please, check the file path."); |
||
648 | } |
||
649 | |||
650 | a2a64028 | taeseongkim | System.Diagnostics.Debug.WriteLine("file download Test File.Exists : " + new TimeSpan(stopwatch.ElapsedTicks)); |
651 | |||
652 | 60723dc9 | taeseongkim | if (File.Exists(downloadFilePath)) |
653 | { |
||
654 | var file = File.Open(downloadFilePath, FileMode.Open); |
||
655 | |||
656 | if (file.Length == 0) |
||
657 | { |
||
658 | throw new Exception("File Size 0. Please, check the file path."); |
||
659 | } |
||
660 | |||
661 | file.Close(); |
||
662 | file.Dispose(); |
||
663 | |||
664 | FileaPath = downloadFilePath; |
||
665 | result = true; |
||
666 | |||
667 | } |
||
668 | } |
||
669 | catch (Exception EX) |
||
670 | { |
||
671 | System.Diagnostics.Debug.WriteLine(EX.ToString()); |
||
672 | result = false; |
||
673 | } |
||
674 | |||
675 | return result; |
||
676 | } |
||
677 | |||
678 | 65fbe3cb | taeseongkim | private void ServiceCallTest_click(object sender, RoutedEventArgs e) |
679 | { |
||
680 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
681 | { |
||
682 | |||
683 | var items = database.GetConvertItems(Markus.Message.StatusCodeType.Completed).Take(100).ToList(); |
||
684 | |||
685 | int count = 0; |
||
686 | |||
687 | foreach (var item in items) |
||
688 | { |
||
689 | database.SetCleanUpItem(item.ConvertID, 0); |
||
690 | |||
691 | System.Net.WebClient client = new System.Net.WebClient(); |
||
692 | var convertResult = client.DownloadString($"http://192.168.0.129:9101/StationService/Rest/ConvertAdd?ProjectNo={item.ProjectNumber}&DocumentID={item.ConvertID}"); |
||
693 | |||
694 | JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
||
695 | var result = jObject["ConvertAddResult"].ToString(); |
||
696 | System.Diagnostics.Debug.WriteLine(item.ConvertID + " " + result.ToString()); |
||
697 | } |
||
698 | } |
||
699 | } |
||
700 | f363a40e | taeseongkim | |
701 | private void ConfingSectionTest_click(object sender, RoutedEventArgs e) |
||
702 | { |
||
703 | var config = Markus.Service.Helper.ConfigHelper.AppConfig("Plugin.ini"); |
||
704 | |||
705 | Dictionary<string, object> parameters = new Dictionary<string, object>(); |
||
706 | |||
707 | var sections = config.Sections.Where(x => x.SectionName == "PemssDocumentInfo").FirstOrDefault(); |
||
708 | |||
709 | foreach (var item in sections.Keys) |
||
710 | { |
||
711 | parameters.Add(item.Name,item.Content); |
||
712 | } |
||
713 | } |
||
714 | |||
715 | private void PemssPluginTest_click(object sender, RoutedEventArgs e) |
||
716 | { |
||
717 | |||
718 | } |
||
719 | f22054ff | taeseongkim | |
720 | private void MonitorTest_Click(object sender, RoutedEventArgs e) |
||
721 | { |
||
722 | Markus.Service.MonitorService.ServiceMonitor service = new Markus.Service.MonitorService.ServiceMonitor(); |
||
723 | service.Start(null); |
||
724 | } |
||
725 | |||
726 | private async void FileDownloadTest_Click(object sender, RoutedEventArgs e) |
||
727 | { |
||
728 | try |
||
729 | { |
||
730 | if (!string.IsNullOrWhiteSpace(txtEncodeDownloadFile.Text)) |
||
731 | { |
||
732 | f87dfb18 | taeseongkim | txtDecodeDownloadFile.Text = HttpUtility.UrlDecode(txtEncodeDownloadFile.Text,Encoding.UTF8); |
733 | f22054ff | taeseongkim | } |
734 | |||
735 | if(!string.IsNullOrWhiteSpace(txtDecodeDownloadFile.Text)) |
||
736 | { |
||
737 | f87dfb18 | taeseongkim | txtEncodeDownloadFile.Text = HttpUtility.UrlEncode(txtDecodeDownloadFile.Text,Encoding.UTF8); |
738 | f22054ff | taeseongkim | } |
739 | |||
740 | f87dfb18 | taeseongkim | string File = txtDecodeDownloadFile.Text; |
741 | |||
742 | DownloadCurrent(File); |
||
743 | |||
744 | f22054ff | taeseongkim | string Savepath = txtSavePath.Text; |
745 | |||
746 | f87dfb18 | taeseongkim | //if (!System.IO.Directory.Exists(Savepath)) |
747 | //{ |
||
748 | // System.IO.Directory.CreateDirectory(Savepath); |
||
749 | //} |
||
750 | f22054ff | taeseongkim | |
751 | f87dfb18 | taeseongkim | //Markus.Service.Convert.ConvertService convertService = new Markus.Service.Convert.ConvertService(); |
752 | f22054ff | taeseongkim | |
753 | f87dfb18 | taeseongkim | //var result = await convertService.DownloadFileAsync(new Markus.Message.SaveItem { PdfFilePath = File, SavePath = Savepath }); |
754 | f22054ff | taeseongkim | |
755 | f87dfb18 | taeseongkim | // System.Windows.MessageBox.Show(result.ToString()); |
756 | f22054ff | taeseongkim | } |
757 | catch (Exception ex) |
||
758 | { |
||
759 | System.Windows.MessageBox.Show(ex.ToString()); |
||
760 | } |
||
761 | } |
||
762 | f87dfb18 | taeseongkim | |
763 | private void DownloadCurrent(string fileUri) |
||
764 | { |
||
765 | HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(fileUri); |
||
766 | webRequest.Method = "GET"; |
||
767 | webRequest.Timeout = 3000; |
||
768 | webRequest.Credentials = CredentialCache.DefaultCredentials; |
||
769 | webRequest.BeginGetResponse(new AsyncCallback(PlayResponeAsync), webRequest); |
||
770 | } |
||
771 | |||
772 | private void PlayResponeAsync(IAsyncResult asyncResult) |
||
773 | { |
||
774 | long total = 0; |
||
775 | long received = 0; |
||
776 | HttpWebRequest webRequest = (HttpWebRequest)asyncResult.AsyncState; |
||
777 | |||
778 | try |
||
779 | { |
||
780 | using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asyncResult)) |
||
781 | { |
||
782 | byte[] buffer = new byte[1024]; |
||
783 | |||
784 | FileStream fileStream = File.OpenWrite(@"D:\Case\test.pdf"); |
||
785 | using (Stream input = webResponse.GetResponseStream()) |
||
786 | { |
||
787 | total = input.Length; |
||
788 | |||
789 | int size = input.Read(buffer, 0, buffer.Length); |
||
790 | while (size > 0) |
||
791 | { |
||
792 | fileStream.Write(buffer, 0, size); |
||
793 | received += size; |
||
794 | |||
795 | size = input.Read(buffer, 0, buffer.Length); |
||
796 | } |
||
797 | } |
||
798 | |||
799 | fileStream.Flush(); |
||
800 | fileStream.Close(); |
||
801 | } |
||
802 | } |
||
803 | catch (Exception ex) |
||
804 | { |
||
805 | } |
||
806 | } |
||
807 | |||
808 | private string ToHexString(char chr) |
||
809 | { |
||
810 | UTF8Encoding utf8 = new UTF8Encoding(); |
||
811 | byte[] encodedBytes = utf8.GetBytes(chr.ToString()); |
||
812 | StringBuilder builder = new StringBuilder(); |
||
813 | for (int index = 0; index < encodedBytes.Length; index++) |
||
814 | { |
||
815 | builder.AppendFormat("%{0}", Convert.ToString(encodedBytes[index], 16)); |
||
816 | } |
||
817 | |||
818 | return builder.ToString(); |
||
819 | } |
||
820 | c5519c44 | taeseongkim | |
821 | private void GetStackTest_Click(object sender, RoutedEventArgs e) |
||
822 | { |
||
823 | System.Windows.MessageBox.Show(LogHelper.GetStack()); |
||
824 | } |
||
825 | 53c9637d | taeseongkim | } |
826 | |||
827 | f87dfb18 | taeseongkim | |
828 | 53c9637d | taeseongkim | class IntegratedServiceInstaller |
829 | { |
||
830 | public void Install(String ServiceName, String DisplayName, String Description, |
||
831 | System.ServiceProcess.ServiceAccount Account, |
||
832 | System.ServiceProcess.ServiceStartMode StartMode) |
||
833 | { |
||
834 | System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); |
||
835 | ProcessInstaller.Account = Account; |
||
836 | |||
837 | System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
||
838 | |||
839 | System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext(); |
||
840 | string processPath = Process.GetCurrentProcess().MainModule.FileName; |
||
841 | if (processPath != null && processPath.Length > 0) |
||
842 | { |
||
843 | System.IO.FileInfo fi = new System.IO.FileInfo(processPath); |
||
844 | //Context = new System.Configuration.Install.InstallContext(); |
||
845 | //Context.Parameters.Add("assemblyPath", fi.FullName); |
||
846 | //Context.Parameters.Add("startParameters", "Test"); |
||
847 | |||
848 | String path = String.Format("/assemblypath={0}", fi.FullName); |
||
849 | String[] cmdline = { path }; |
||
850 | Context = new System.Configuration.Install.InstallContext("", cmdline); |
||
851 | } |
||
852 | |||
853 | SINST.Context = Context; |
||
854 | SINST.DisplayName = DisplayName; |
||
855 | SINST.Description = Description; |
||
856 | SINST.ServiceName = ServiceName; |
||
857 | SINST.StartType = StartMode; |
||
858 | SINST.Parent = ProcessInstaller; |
||
859 | |||
860 | // http://bytes.com/forum/thread527221.html |
||
861 | // SINST.ServicesDependedOn = new String[] {}; |
||
862 | |||
863 | System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary(); |
||
864 | SINST.Install(state); |
||
865 | |||
866 | // http://www.dotnet247.com/247reference/msgs/43/219565.aspx |
||
867 | using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true)) |
||
868 | { |
||
869 | try |
||
870 | { |
||
871 | Object sValue = oKey.GetValue("ImagePath"); |
||
872 | oKey.SetValue("ImagePath", sValue); |
||
873 | } |
||
874 | catch (Exception Ex) |
||
875 | { |
||
876 | // System.Console.WriteLine(Ex.Message); |
||
877 | } |
||
878 | } |
||
879 | |||
880 | } |
||
881 | public void Uninstall(String ServiceName) |
||
882 | { |
||
883 | System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
||
884 | |||
885 | System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null); |
||
886 | SINST.Context = Context; |
||
887 | SINST.ServiceName = ServiceName; |
||
888 | SINST.Uninstall(null); |
||
889 | } |
||
890 | } |
||
891 | c433ebde | taeseongkim | |
892 | public class SEND |
||
893 | { |
||
894 | public string ProjectNo { get; set; } |
||
895 | public string DocumentID{ get; set; } |
||
896 | } |
||
897 | 53c9637d | taeseongkim | } |