프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / ServiceTestApp / MainWindow.xaml.cs @ f87dfb18

이력 | 보기 | 이력해설 | 다운로드 (35.1 KB)

1
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
using Newtonsoft.Json.Linq;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.IO;
12
using System.Linq;
13
using System.Net;
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
        private Object 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
            using (var client = new System.Net.Http.HttpClient())
464
            {
465

    
466
                var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem");
467
                var data2 = new SEND
468
                {
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

    
484
            //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
            //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
            //System.Diagnostics.Debug.WriteLine(result);
509
        }
510

    
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

    
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

    
555
        private async void DownLoadTest_click(object sender, RoutedEventArgs e)
556
        {
557
            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");
558
        }
559

    
560
        private async Task<bool> DownloadFileAsync(string FileaPath)
561
        {
562
            bool result = false;
563

    
564
            try
565
            {
566
                Uri pdfFileUri = null;
567

    
568
                //if (saveItem.PdfFilePath.Contains("VPCS_DOCLIB"))
569
                //{
570
                //    FileName = DocUri.Remove(0, DocUri.LastIndexOf("/") + 1);
571
                //    ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더
572
                //    ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString();
573
                //    ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID;
574
                //    DownloadFilePath = ItemPath + "\\" + FileName;
575
                //}
576
                //else
577
                //{
578
                //    ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.PROJECT_NO + "_Tile"; //프로젝트 폴더
579
                //    ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.DOCUMENT_ID) / 100).ToString();
580
                //    ItemPath = ItemListPath + "\\" + ConverterItem.DOCUMENT_ID;
581
                //    FileName = HttpUtility.ParseQueryString(new Uri(DocUri).Query).Get("fileName");
582
                //    DownloadFilePath = string.IsNullOrWhiteSpace(FileName) ? ItemPath + "\\" + FileName : ItemPath + "\\" + FileName;
583

    
584
                //}
585

    
586
                FileaPath = HttpUtility.UrlDecode(FileaPath); //PDF 전체 경로
587
                string FileName = DownloadUri.GetFileName(FileaPath);
588

    
589
                string downloadFilePath = System.IO.Path.Combine(@"c:\temp", FileName);
590

    
591
                // 드라이브 경로가 포함되었는지 판단.
592
                if (Path.IsPathRooted(FileaPath))
593
                {
594
                    if (File.Exists(FileaPath))
595
                    {
596
                        File.Copy(FileaPath, downloadFilePath, true);
597
                    }
598
                    else
599
                    {
600
                        throw new Exception("File Not Found. Please, check the file path.");
601
                    }
602
                }
603
                else if (Uri.TryCreate(FileaPath, UriKind.RelativeOrAbsolute, out pdfFileUri))
604
                {
605
                    try
606
                    {
607
                        using (System.Net.WebClient webClient = new System.Net.WebClient())
608
                        {
609
                            webClient.UseDefaultCredentials = true;//.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증
610

    
611
                            //if (!System.IO.Directory.Exists(ConvertProcessContext.TempDirectory))
612
                            //{
613
                            //    System.IO.Directory.CreateDirectory(ConvertProcessContext.TempDirectory);
614
                            //}
615

    
616
                            await webClient.DownloadFileTaskAsync(pdfFileUri, downloadFilePath);
617
                        }
618
                    }
619
                    catch (Exception)
620
                    {
621
                        throw new Exception("File Download Error. Please, check the file path.");
622
                    }
623
                }
624
                else
625
                {
626
                    throw new Exception("Please, check the file path.");
627
                }
628

    
629
                if (File.Exists(downloadFilePath))
630
                {
631
                    var file = File.Open(downloadFilePath, FileMode.Open);
632

    
633
                    if (file.Length == 0)
634
                    {
635
                        throw new Exception("File Size 0. Please, check the file path.");
636
                    }
637

    
638
                    file.Close();
639
                    file.Dispose();
640

    
641
                    FileaPath = downloadFilePath;
642
                    result = true;
643

    
644
                }
645
            }
646
            catch (Exception EX)
647
            {
648
                System.Diagnostics.Debug.WriteLine(EX.ToString());
649
                result = false;
650
            }
651

    
652
            return result;
653
        }
654

    
655
        private void ServiceCallTest_click(object sender, RoutedEventArgs e)
656
        {
657
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
658
            {
659

    
660
                var items = database.GetConvertItems(Markus.Message.StatusCodeType.Completed).Take(100).ToList();
661

    
662
                int count = 0;
663

    
664
                foreach (var item in items)
665
                {
666
                    database.SetCleanUpItem(item.ConvertID, 0);
667

    
668
                    System.Net.WebClient client = new System.Net.WebClient();
669
                    var convertResult = client.DownloadString($"http://192.168.0.129:9101/StationService/Rest/ConvertAdd?ProjectNo={item.ProjectNumber}&DocumentID={item.ConvertID}");
670

    
671
                    JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
672
                    var result = jObject["ConvertAddResult"].ToString();
673
                    System.Diagnostics.Debug.WriteLine(item.ConvertID + " " + result.ToString());
674
                }
675
            }
676
        }
677

    
678
        private void ConfingSectionTest_click(object sender, RoutedEventArgs e)
679
        {
680
            var config = Markus.Service.Helper.ConfigHelper.AppConfig("Plugin.ini");
681

    
682
            Dictionary<string, object> parameters = new Dictionary<string, object>();
683

    
684
            var sections = config.Sections.Where(x => x.SectionName == "PemssDocumentInfo").FirstOrDefault();
685

    
686
            foreach (var item in sections.Keys)
687
            {
688
                parameters.Add(item.Name,item.Content);
689
            }
690
        }
691

    
692
        private void PemssPluginTest_click(object sender, RoutedEventArgs e)
693
        {
694

    
695
        }
696

    
697
        private void MonitorTest_Click(object sender, RoutedEventArgs e)
698
        {
699
            Markus.Service.MonitorService.ServiceMonitor service = new Markus.Service.MonitorService.ServiceMonitor();
700
            service.Start(null);
701
        }
702

    
703
        private async void FileDownloadTest_Click(object sender, RoutedEventArgs e)
704
        {
705
            try
706
            {
707
                if (!string.IsNullOrWhiteSpace(txtEncodeDownloadFile.Text))
708
                {
709
                    txtDecodeDownloadFile.Text = HttpUtility.UrlDecode(txtEncodeDownloadFile.Text,Encoding.UTF8);
710
                }
711

    
712
                if(!string.IsNullOrWhiteSpace(txtDecodeDownloadFile.Text))
713
                {
714
                    txtEncodeDownloadFile.Text = HttpUtility.UrlEncode(txtDecodeDownloadFile.Text,Encoding.UTF8);
715
                }
716

    
717
                string File = txtDecodeDownloadFile.Text;
718

    
719
                DownloadCurrent(File);
720

    
721
                string Savepath = txtSavePath.Text;
722

    
723
                //if (!System.IO.Directory.Exists(Savepath))
724
                //{
725
                //    System.IO.Directory.CreateDirectory(Savepath);
726
                //}
727

    
728
                //Markus.Service.Convert.ConvertService convertService = new Markus.Service.Convert.ConvertService();
729

    
730
                //var result = await convertService.DownloadFileAsync(new Markus.Message.SaveItem { PdfFilePath = File, SavePath = Savepath });
731

    
732
               // System.Windows.MessageBox.Show(result.ToString());
733
            }
734
            catch (Exception ex)
735
            {
736
                System.Windows.MessageBox.Show(ex.ToString());
737
            }
738
        }
739

    
740
        private  void DownloadCurrent(string fileUri)
741
        {
742
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(fileUri);
743
            webRequest.Method = "GET";
744
            webRequest.Timeout = 3000;
745
            webRequest.Credentials = CredentialCache.DefaultCredentials;
746
            webRequest.BeginGetResponse(new AsyncCallback(PlayResponeAsync), webRequest);
747
        }
748

    
749
        private void PlayResponeAsync(IAsyncResult asyncResult)
750
        {
751
            long total = 0;
752
            long received = 0;
753
            HttpWebRequest webRequest = (HttpWebRequest)asyncResult.AsyncState;
754

    
755
            try
756
            {
757
                using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asyncResult))
758
                {
759
                    byte[] buffer = new byte[1024];
760

    
761
                    FileStream fileStream = File.OpenWrite(@"D:\Case\test.pdf");
762
                    using (Stream input = webResponse.GetResponseStream())
763
                    {
764
                        total = input.Length;
765

    
766
                        int size = input.Read(buffer, 0, buffer.Length);
767
                        while (size > 0)
768
                        {
769
                            fileStream.Write(buffer, 0, size);
770
                            received += size;
771

    
772
                            size = input.Read(buffer, 0, buffer.Length);
773
                        }
774
                    }
775

    
776
                    fileStream.Flush();
777
                    fileStream.Close();
778
                }
779
            }
780
            catch (Exception ex)
781
            {
782
            }
783
        }
784

    
785
        private  string ToHexString(char chr)
786
        {
787
            UTF8Encoding utf8 = new UTF8Encoding();
788
            byte[] encodedBytes = utf8.GetBytes(chr.ToString());
789
            StringBuilder builder = new StringBuilder();
790
            for (int index = 0; index < encodedBytes.Length; index++)
791
            {
792
                builder.AppendFormat("%{0}", Convert.ToString(encodedBytes[index], 16));
793
            }
794

    
795
            return builder.ToString();
796
        }
797
    }
798

    
799

    
800
    class IntegratedServiceInstaller
801
    {
802
        public void Install(String ServiceName, String DisplayName, String Description,
803
            System.ServiceProcess.ServiceAccount Account,
804
            System.ServiceProcess.ServiceStartMode StartMode)
805
        {
806
            System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
807
            ProcessInstaller.Account = Account;
808

    
809
            System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
810

    
811
            System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
812
            string processPath = Process.GetCurrentProcess().MainModule.FileName;
813
            if (processPath != null && processPath.Length > 0)
814
            {
815
                System.IO.FileInfo fi = new System.IO.FileInfo(processPath);
816
                //Context = new System.Configuration.Install.InstallContext();
817
                //Context.Parameters.Add("assemblyPath", fi.FullName);
818
                //Context.Parameters.Add("startParameters", "Test");
819

    
820
                String path = String.Format("/assemblypath={0}", fi.FullName);
821
                String[] cmdline = { path };
822
                Context = new System.Configuration.Install.InstallContext("", cmdline);
823
            }
824

    
825
            SINST.Context = Context;
826
            SINST.DisplayName = DisplayName;
827
            SINST.Description = Description;
828
            SINST.ServiceName = ServiceName;
829
            SINST.StartType = StartMode;
830
            SINST.Parent = ProcessInstaller;
831

    
832
            // http://bytes.com/forum/thread527221.html
833
            //            SINST.ServicesDependedOn = new String[] {};
834

    
835
            System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
836
            SINST.Install(state);
837

    
838
            // http://www.dotnet247.com/247reference/msgs/43/219565.aspx
839
            using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true))
840
            {
841
                try
842
                {
843
                    Object sValue = oKey.GetValue("ImagePath");
844
                    oKey.SetValue("ImagePath", sValue);
845
                }
846
                catch (Exception Ex)
847
                {
848
                    //                    System.Console.WriteLine(Ex.Message);
849
                }
850
            }
851

    
852
        }
853
        public void Uninstall(String ServiceName)
854
        {
855
            System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
856

    
857
            System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null);
858
            SINST.Context = Context;
859
            SINST.ServiceName = ServiceName;
860
            SINST.Uninstall(null);
861
        }
862
    }
863

    
864
    public class SEND
865
    {
866
        public string ProjectNo { get; set; }
867
        public string DocumentID{ get; set; }
868
}
869
}
클립보드 이미지 추가 (최대 크기: 500 MB)