markus / ConvertService / ServiceBase / ServiceTestApp / MainWindow.xaml.cs @ a0341bef
이력 | 보기 | 이력해설 | 다운로드 (31.5 KB)
1 |
using Markus.EntityModel; |
---|---|
2 |
using Markus.Service; |
3 |
using Markus.Service.Extensions; |
4 |
using Markus.Service.Helper; |
5 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
6 |
using Microsoft.Win32; |
7 |
using Newtonsoft.Json; |
8 |
using Newtonsoft.Json.Linq; |
9 |
using System; |
10 |
using System.Collections.Generic; |
11 |
using System.Diagnostics; |
12 |
using System.IO; |
13 |
using System.Linq; |
14 |
using System.Net.Http; |
15 |
using System.ServiceModel; |
16 |
using System.Text; |
17 |
using System.Threading.Tasks; |
18 |
using System.Web; |
19 |
using System.Web.Script.Serialization; |
20 |
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 |
var config = Markus.Service.Helper.ConfigHelper.AppConfig("ServiceStation.ini"); |
37 |
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 |
//timer.Start(); |
44 |
} |
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 |
PrivateObject stationObj; |
172 |
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 |
private static readonly HttpClient _Client = new HttpClient(); |
433 |
private static JavaScriptSerializer _Serializer = new JavaScriptSerializer(); |
434 |
|
435 |
private async void WebServiceTest_click(object sender, RoutedEventArgs e) |
436 |
{ |
437 |
//string cookie = ""; |
438 |
|
439 |
//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 |
|
448 |
////POST 전송일 경우 |
449 |
|
450 |
//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 |
|
461 |
//Console.WriteLine(responseText); |
462 |
|
463 |
|
464 |
//using (var client = new System.Net.Http.HttpClient()) |
465 |
//{ |
466 |
// var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); |
467 |
|
468 |
// var data2 = new SEND |
469 |
// { |
470 |
// ProjectNo = "111111", |
471 |
// DocumentID = "453" |
472 |
// }; |
473 |
|
474 |
// var jsonRequest2 = JsonConvert.SerializeObject(data2); |
475 |
// var stringContent = new System.Net.Http.StringContent(jsonRequest2, Encoding.UTF8, "application/json"); |
476 |
// var response = await client.PostAsync(uri2, stringContent); |
477 |
|
478 |
// if (response.IsSuccessStatusCode) |
479 |
// { |
480 |
// System.Diagnostics.Debug.WriteLine(response.Content.Headers.First()); |
481 |
// System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
482 |
// } |
483 |
//} |
484 |
|
485 |
using (var client = new System.Net.Http.HttpClient()) |
486 |
{ |
487 |
var uri2 = new Uri("http://localhost:13009/MarkusService.svc/Rest/GetCommantList"); |
488 |
|
489 |
var data2 = new SEND |
490 |
{ |
491 |
ProjectNo = "111111", |
492 |
DocumentID = "453" |
493 |
}; |
494 |
|
495 |
var jsonRequest2 = JsonConvert.SerializeObject(data2); |
496 |
var stringContent = new System.Net.Http.StringContent(jsonRequest2, Encoding.UTF8, "application/json"); |
497 |
var response = await client.PostAsync(uri2, stringContent); |
498 |
|
499 |
if (response.IsSuccessStatusCode) |
500 |
{ |
501 |
System.Diagnostics.Debug.WriteLine(response.Content.Headers.First()); |
502 |
System.Diagnostics.Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
503 |
} |
504 |
} |
505 |
|
506 |
//var client2 = new System.Net.WebClient(); |
507 |
//client2.Proxy = new System.Net.WebProxy("127.0.0.1", 8888); |
508 |
//var result = await client2.DownloadStringTaskAsync("http://localhost:9101/StationService/Rest/GetConvertItem?ProjectNo=111111&DocumentID=453"); |
509 |
//System.Diagnostics.Debug.WriteLine(result); |
510 |
} |
511 |
|
512 |
static async Task<System.Net.Http.HttpResponseMessage> Request(HttpMethod pMethod, string pUrl, string pJsonContent, Dictionary<string, string> pHeaders) |
513 |
{ |
514 |
var httpRequestMessage = new HttpRequestMessage(); |
515 |
httpRequestMessage.Method = pMethod; |
516 |
httpRequestMessage.RequestUri = new Uri(pUrl); |
517 |
foreach (var head in pHeaders) |
518 |
{ |
519 |
httpRequestMessage.Headers.Add(head.Key, head.Value); |
520 |
} |
521 |
switch (pMethod.Method) |
522 |
{ |
523 |
case "POST": |
524 |
HttpContent httpContent = new StringContent(pJsonContent, Encoding.UTF8, "application/json"); |
525 |
httpRequestMessage.Content = httpContent; |
526 |
break; |
527 |
|
528 |
} |
529 |
|
530 |
return await new HttpClient().SendAsync(httpRequestMessage); |
531 |
} |
532 |
|
533 |
private async void ConvertWebServiceTest_click(object sender, RoutedEventArgs e) |
534 |
{ |
535 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
536 |
{ |
537 |
|
538 |
var items = database.GetConvertItems(Markus.Message.StatusCodeType.Completed).Take(100).ToList(); |
539 |
|
540 |
var service = new ConvertWebService.ConversionSoapClient(); |
541 |
|
542 |
int count = 0; |
543 |
|
544 |
foreach (var item in items) |
545 |
{ |
546 |
count++; |
547 |
byte[] bytes = Encoding.UTF8.GetBytes(item.OriginfilePath); |
548 |
var url = Convert.ToBase64String(bytes); |
549 |
var result = await service.ConvertRunAsync(count.ToString(), item.UniqueKey, item.UniqueKey + count.ToString(), count.ToString(), "111111", item.UniqueKey, url); |
550 |
|
551 |
System.Diagnostics.Debug.WriteLine(item.ConvertID + " " + result.ToString()); |
552 |
} |
553 |
} |
554 |
} |
555 |
|
556 |
private async void DownLoadTest_click(object sender, RoutedEventArgs e) |
557 |
{ |
558 |
await DownloadFileAsync("http://172.20.110.75:8880/ifweb/external/DLMFileDownload.jsp?objectId=33808.61925.45058.48300&format=Original PDF&fileName=MARKUS_20190731_0001_A.pdf"); |
559 |
} |
560 |
|
561 |
private async Task<bool> DownloadFileAsync(string FileaPath) |
562 |
{ |
563 |
bool result = false; |
564 |
|
565 |
try |
566 |
{ |
567 |
Uri pdfFileUri = null; |
568 |
|
569 |
//if (saveItem.PdfFilePath.Contains("VPCS_DOCLIB")) |
570 |
//{ |
571 |
// FileName = DocUri.Remove(0, DocUri.LastIndexOf("/") + 1); |
572 |
// ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더 |
573 |
// ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString(); |
574 |
// ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID; |
575 |
// DownloadFilePath = ItemPath + "\\" + FileName; |
576 |
//} |
577 |
//else |
578 |
//{ |
579 |
// ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더 |
580 |
// ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString(); |
581 |
// ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID; |
582 |
// FileName = HttpUtility.ParseQueryString(new Uri(DocUri).Query).Get("fileName"); |
583 |
// DownloadFilePath = string.IsNullOrWhiteSpace(FileName) ? ItemPath + "\\" + FileName : ItemPath + "\\" + FileName; |
584 |
|
585 |
//} |
586 |
|
587 |
FileaPath = HttpUtility.UrlDecode(FileaPath); //PDF 전체 경로 |
588 |
string FileName = DownloadUri.GetFileName(FileaPath); |
589 |
|
590 |
string downloadFilePath = System.IO.Path.Combine(@"c:\temp", FileName); |
591 |
|
592 |
// 드라이브 경로가 포함되었는지 판단. |
593 |
if (Path.IsPathRooted(FileaPath)) |
594 |
{ |
595 |
if (File.Exists(FileaPath)) |
596 |
{ |
597 |
File.Copy(FileaPath, downloadFilePath, true); |
598 |
} |
599 |
else |
600 |
{ |
601 |
throw new Exception("File Not Found. Please, check the file path."); |
602 |
} |
603 |
} |
604 |
else if (Uri.TryCreate(FileaPath, UriKind.RelativeOrAbsolute, out pdfFileUri)) |
605 |
{ |
606 |
try |
607 |
{ |
608 |
using (System.Net.WebClient webClient = new System.Net.WebClient()) |
609 |
{ |
610 |
webClient.UseDefaultCredentials = true;//.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증 |
611 |
|
612 |
//if (!System.IO.Directory.Exists(ConvertProcessContext.TempDirectory)) |
613 |
//{ |
614 |
// System.IO.Directory.CreateDirectory(ConvertProcessContext.TempDirectory); |
615 |
//} |
616 |
|
617 |
await webClient.DownloadFileTaskAsync(pdfFileUri, downloadFilePath); |
618 |
} |
619 |
} |
620 |
catch (Exception) |
621 |
{ |
622 |
throw new Exception("File Download Error. Please, check the file path."); |
623 |
} |
624 |
} |
625 |
else |
626 |
{ |
627 |
throw new Exception("Please, check the file path."); |
628 |
} |
629 |
|
630 |
if (File.Exists(downloadFilePath)) |
631 |
{ |
632 |
var file = File.Open(downloadFilePath, FileMode.Open); |
633 |
|
634 |
if (file.Length == 0) |
635 |
{ |
636 |
throw new Exception("File Size 0. Please, check the file path."); |
637 |
} |
638 |
|
639 |
file.Close(); |
640 |
file.Dispose(); |
641 |
|
642 |
FileaPath = downloadFilePath; |
643 |
result = true; |
644 |
|
645 |
} |
646 |
} |
647 |
catch (Exception EX) |
648 |
{ |
649 |
System.Diagnostics.Debug.WriteLine(EX.ToString()); |
650 |
result = false; |
651 |
} |
652 |
|
653 |
return result; |
654 |
} |
655 |
|
656 |
private void ServiceCallTest_click(object sender, RoutedEventArgs e) |
657 |
{ |
658 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
659 |
{ |
660 |
|
661 |
var items = database.GetConvertItems(Markus.Message.StatusCodeType.Completed).Take(100).ToList(); |
662 |
|
663 |
int count = 0; |
664 |
|
665 |
foreach (var item in items) |
666 |
{ |
667 |
database.SetCleanUpItem(item.ConvertID, 0); |
668 |
|
669 |
System.Net.WebClient client = new System.Net.WebClient(); |
670 |
var convertResult = client.DownloadString($"http://192.168.0.129:9101/StationService/Rest/ConvertAdd?ProjectNo={item.ProjectNumber}&DocumentID={item.ConvertID}"); |
671 |
|
672 |
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
673 |
var result = jObject["ConvertAddResult"].ToString(); |
674 |
System.Diagnostics.Debug.WriteLine(item.ConvertID + " " + result.ToString()); |
675 |
} |
676 |
} |
677 |
} |
678 |
|
679 |
private void ConfingSectionTest_click(object sender, RoutedEventArgs e) |
680 |
{ |
681 |
var config = Markus.Service.Helper.ConfigHelper.AppConfig("Plugin.ini"); |
682 |
|
683 |
Dictionary<string, object> parameters = new Dictionary<string, object>(); |
684 |
|
685 |
var sections = config.Sections.Where(x => x.SectionName == "PemssDocumentInfo").FirstOrDefault(); |
686 |
|
687 |
foreach (var item in sections.Keys) |
688 |
{ |
689 |
parameters.Add(item.Name,item.Content); |
690 |
} |
691 |
} |
692 |
|
693 |
private void PemssPluginTest_click(object sender, RoutedEventArgs e) |
694 |
{ |
695 |
|
696 |
} |
697 |
} |
698 |
|
699 |
class IntegratedServiceInstaller |
700 |
{ |
701 |
public void Install(String ServiceName, String DisplayName, String Description, |
702 |
System.ServiceProcess.ServiceAccount Account, |
703 |
System.ServiceProcess.ServiceStartMode StartMode) |
704 |
{ |
705 |
System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); |
706 |
ProcessInstaller.Account = Account; |
707 |
|
708 |
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
709 |
|
710 |
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext(); |
711 |
string processPath = Process.GetCurrentProcess().MainModule.FileName; |
712 |
if (processPath != null && processPath.Length > 0) |
713 |
{ |
714 |
System.IO.FileInfo fi = new System.IO.FileInfo(processPath); |
715 |
//Context = new System.Configuration.Install.InstallContext(); |
716 |
//Context.Parameters.Add("assemblyPath", fi.FullName); |
717 |
//Context.Parameters.Add("startParameters", "Test"); |
718 |
|
719 |
String path = String.Format("/assemblypath={0}", fi.FullName); |
720 |
String[] cmdline = { path }; |
721 |
Context = new System.Configuration.Install.InstallContext("", cmdline); |
722 |
} |
723 |
|
724 |
SINST.Context = Context; |
725 |
SINST.DisplayName = DisplayName; |
726 |
SINST.Description = Description; |
727 |
SINST.ServiceName = ServiceName; |
728 |
SINST.StartType = StartMode; |
729 |
SINST.Parent = ProcessInstaller; |
730 |
|
731 |
// http://bytes.com/forum/thread527221.html |
732 |
// SINST.ServicesDependedOn = new String[] {}; |
733 |
|
734 |
System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary(); |
735 |
SINST.Install(state); |
736 |
|
737 |
// http://www.dotnet247.com/247reference/msgs/43/219565.aspx |
738 |
using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true)) |
739 |
{ |
740 |
try |
741 |
{ |
742 |
Object sValue = oKey.GetValue("ImagePath"); |
743 |
oKey.SetValue("ImagePath", sValue); |
744 |
} |
745 |
catch (Exception Ex) |
746 |
{ |
747 |
// System.Console.WriteLine(Ex.Message); |
748 |
} |
749 |
} |
750 |
|
751 |
} |
752 |
public void Uninstall(String ServiceName) |
753 |
{ |
754 |
System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller(); |
755 |
|
756 |
System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null); |
757 |
SINST.Context = Context; |
758 |
SINST.ServiceName = ServiceName; |
759 |
SINST.Uninstall(null); |
760 |
} |
761 |
} |
762 |
|
763 |
public class SEND |
764 |
{ |
765 |
public string ProjectNo { get; set; } |
766 |
public string DocumentID{ get; set; } |
767 |
} |
768 |
} |