프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / ServiceTestApp / MainWindow.xaml.cs @ 1c7f408a

이력 | 보기 | 이력해설 | 다운로드 (29.8 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 System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.IO;
12
using System.Linq;
13
using System.Net.Http;
14
using System.ServiceModel;
15
using System.Text;
16
using System.Threading.Tasks;
17
using System.Web;
18
using System.Web.Script.Serialization;
19
using System.Windows;
20
using System.Windows.Data;
21
using System.Windows.Forms;
22
using static Markus.Service.Extensions.Encrypt;
23

    
24
namespace ServiceTestApp
25
{
26
    /// <summary>
27
    /// MainWindow.xaml에 대한 상호 작용 논리
28
    /// </summary>
29
    public partial class MainWindow : Window
30
    {
31
        public MainWindow()
32
        {
33
            InitializeComponent();
34

    
35
            var config = Markus.Service.Helper.ConfigHelper.AppConfig("ServiceStation.ini");
36
            MarkusDBConnectionString = AESEncrypter.Decrypt(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MARKUS_CONNECTION_STRING));
37

    
38
            datagrid.ItemsSource = convertItems;
39
          
40
            timer.Interval = new TimeSpan(0, 0, 0, 0, 700);
41
            timer.Tick += Timer_Tick;
42
            //timer.Start();
43
        }
44
        System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
45
        private string MarkusDBConnectionString;
46

    
47
        private void Timer_0_Tick(object sender, EventArgs e)
48
        {
49
            BasicHttpBinding myBinding = new BasicHttpBinding();
50
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
51

    
52
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
53
 
54
            var result =  client.AliveConvertList();
55

    
56
            datagrid.ItemsSource = result;
57

    
58
            if(result.Count() < 2)
59
            {
60
                foreach (var filename in Directory.EnumerateFiles("D:\\Case"))
61
                {
62
                    var additem = client.ConvertMenualAdd("111111",  filename, "test");
63

    
64
                    if (!string.IsNullOrWhiteSpace(additem))
65
                    {
66
                        Log.Text += $"Wcf Station Service call{filename} {result}\n";
67
                    }
68
                    else
69
                    {
70
                        Log.Text += $"Call Error {filename} {result}\n";
71
                    }
72
                }
73
            }
74
        }
75

    
76
        private void Timer_Tick(object sender, EventArgs e)
77
        {
78
            timer.Stop();
79

    
80
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
81
            {
82
                var data = database.GetConvertItems(Markus.Message.StatusCodeType.Saving);
83

    
84
                foreach (var item in data)
85
                {
86
                    var getitem = convertItems.Where(f => f.ConvertID == item.ConvertID);
87

    
88
                    if (getitem.Count() == 0)
89
                    {
90
                        convertItems.Add(item);
91
                    }
92
                    else
93
                    {
94
                        var binditem = getitem.First();
95

    
96
                        binditem.ConvertState = item.ConvertState;
97
                        binditem.CurrentPageNo = item.CurrentPageNo;
98
                        binditem.TotalPage = item.TotalPage;
99
                    }
100
                }
101

    
102
                var _removeitems = convertItems.Select(f => f.ConvertID).Except(data.Select(x => x.ConvertID)).ToList();
103

    
104
                foreach (var item in _removeitems)
105
                {
106
                    var items = convertItems.Where(x => x.ConvertID == item);
107

    
108
                    if (items.Count() > 0)
109
                    {
110
                        Markus.Service.Interface.ConvertItem convertItem = items.First();
111
                        convertItems.Remove(convertItem);
112
                    }
113
                }
114
            }
115

    
116
            var process = Process.GetProcessesByName("Markus.Service.ConvertProcess");
117

    
118
            this.Dispatcher.Invoke(() =>
119
            {
120
                CollectionViewSource.GetDefaultView(datagrid.ItemsSource).Refresh();
121

    
122
                if (process.Count() > 0)
123
                {
124
                    if (Log.Text.Length > int.MaxValue)
125
                    {
126
                        Log.Text = "";
127
                    }
128

    
129
                    Log.Text += "-------------------------------------\n";
130

    
131
                    Log.Text += $"  Physical memory usage     : {process.Sum(f => f.WorkingSet64)}" + "\n";
132
                    Log.Text += $"  Base priority             : {process.Sum(f => f.BasePriority)}" + "\n";
133
                    //Log.Text += $"  Priority class            : {process[0].PriorityClass}" + "\n";
134
                    //Log.Text += $"  User processor time       : {process[0].UserProcessorTime}" + "\n";
135
                    //Log.Text += $"  Privileged processor time : {process[0].PrivilegedProcessorTime}" + "\n";
136
                    //Log.Text += $"  Total processor time      : {process[0].TotalProcessorTime}" + "\n";
137
                    Log.Text += $"  Paged system memory size  : {process.Sum(f => f.PagedSystemMemorySize64)}" + "\n";
138
                    Log.Text += $"  Paged memory size         : {process.Sum(f => f.PagedMemorySize64)}" + "\n";
139
                }
140
            });
141

    
142
            //if (process.Count() < 3)
143
            //{
144
            //    BasicHttpBinding myBinding = new BasicHttpBinding();
145
            //    EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
146
            //    StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
147
            //    foreach (var filename in Directory.EnumerateFiles("D:\\Case"))
148
            //    {
149
            //        var _id = new Guid().CreateUniqueGuid().ToString();
150

    
151
            //        var result = client.ConvertMenualAdd("111111", _id, filename, "test");
152

    
153
            //        if (result)
154
            //        {
155
            //            Log.Text += $"Wcf Station Service call{filename} {result}\n";
156
            //        }
157
            //        else
158
            //        {
159
            //            Log.Text += $"Call Error {filename} {result}\n";
160
            //        }
161
            //    }
162
            //}
163

    
164
            timer.Start();
165

    
166
        }
167

    
168
        private System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem> convertItems = new System.Collections.ObjectModel.ObservableCollection<Markus.Service.Interface.ConvertItem>();
169

    
170
        PrivateObject stationObj;
171
        Markus.Service.ServiceStation station = new Markus.Service.ServiceStation();
172

    
173
        private void Button_Click(object sender, RoutedEventArgs e)
174
        {
175
            station.StartService();
176

    
177
            // if (station == null)
178
            // {
179
            //     station = new PrivateObject(typeof(Markus.Service.StationService.ServiceStation));
180
            // }
181

    
182

    
183

    
184
            Log.Text += "Wcf Service start\n";
185
        }
186

    
187
        private async void ServiceCall_Click(object sender, RoutedEventArgs e)
188
        {
189
            ConvertService.ConvertServiceClient client = new ConvertService.ConvertServiceClient();
190
            var result = await client.ConvertAddAsync(1);
191

    
192
            Log.Text += $"Wcf Convert Service call{result}\n";
193
        }
194

    
195
        private async void StationServiceCall_Click(object sender, RoutedEventArgs e)
196
        {
197
            StationService.StationServiceClient client = new StationService.StationServiceClient();
198
            var result = await client.ConvertAddAsync("test", "11");
199

    
200
            Log.Text += $"Wcf Station Service call{result}\n";
201
        }
202

    
203
        private async void ItemAdd_Click(object sender, RoutedEventArgs e)
204
        {
205
            string ProjectNo = "111111";
206

    
207
            BasicHttpBinding myBinding = new BasicHttpBinding();
208
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
209
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
210
            foreach (var filename in GetFileList())
211
            {
212
                var result = await client.ConvertMenualAddAsync("111111", filename, "test");
213

    
214
                if (!string.IsNullOrWhiteSpace(result))
215
                {
216
                    Log.Text += $"Wcf Station Service call{filename} convert ID : {result}\n";
217
                }
218
                else
219
                {
220
                    Log.Text += $"Call Error {filename}\n";
221
                }
222
            }
223

    
224
            #region 데이터베이스 테스트 
225
            /*
226
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(ProjectNo))
227
            {
228
                foreach (var filename in GetFileList())
229
                {
230
                    var _id = new Guid().CreateUniqueGuid().ToString();
231

    
232
                    if (!database.SetConvertDoc(ProjectNo, _id, filename,_id))
233
                    {
234
                        System.Windows.MessageBox.Show("저장에 실패!");
235
                        break;
236
                    }
237
                }
238
            }
239
            */
240
            #endregion
241
        }
242

    
243
        private IEnumerable<string> GetFileList()
244
        {
245
            IEnumerable<string> result = new string[] { };
246

    
247
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
248
            {
249
                dialog.Description = "PDF가 있는 폴더를 선택하세요.";
250
                dialog.ShowNewFolderButton = false;
251
                dialog.RootFolder = Environment.SpecialFolder.MyComputer;
252

    
253
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
254
                {
255
                    result = Directory.EnumerateFiles(dialog.SelectedPath, "*.pdf", SearchOption.AllDirectories);
256
                }
257
            }
258

    
259
            return result;
260
        }
261

    
262
        private void ServiceInstall_Click(object sender, RoutedEventArgs e)
263
        {
264
            //Markus.Service.ProjectInstaller projectInstaller = new Markus.Service.ProjectInstaller();
265
            //Hashtable savedState = new Hashtable();
266
            //projectInstaller.serviceProcessInstaller.Install(savedState);
267

    
268
            //projectInstaller.serviceProcessInstaller.Uninstall(savedState);
269

    
270

    
271
            IntegratedServiceInstaller integrated = new IntegratedServiceInstaller();
272
            integrated.Install("ServiceStation", "ServiceStation", "test", System.ServiceProcess.ServiceAccount.LocalService, System.ServiceProcess.ServiceStartMode.Automatic);
273

    
274
        }
275

    
276
        private void LibInstall_Click(object sender, RoutedEventArgs e)
277
        {
278
            Markus.Library.Installer.Install();
279
        }
280

    
281
        private async void ItemAddFile_Click(object sender, RoutedEventArgs e)
282
        {
283
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
284

    
285
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
286
            {
287
                BasicHttpBinding myBinding = new BasicHttpBinding();
288
                EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
289

    
290
                StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
291

    
292
                var result = await client.ConvertMenualAddAsync("111111", dialog.FileName, "test");
293

    
294
                Log.Text += $"Wcf Station Service call{dialog.FileName} {result}\n";
295
            }
296
        }
297

    
298
        private async void AliveList_Click(object sender, RoutedEventArgs e)
299
        {
300
            await AliveItemAsync();
301
        }
302
        private async Task AliveItemAsync()
303
        {
304
            BasicHttpBinding myBinding = new BasicHttpBinding();
305
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
306

    
307
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
308
            var _id = new Guid().CreateUniqueGuid().ToString();
309

    
310
            var result = await client.AliveConvertListAsync();
311

    
312
            datagrid.ItemsSource = result;
313
        }
314

    
315
        private async void WaitList_Click(object sender, RoutedEventArgs e)
316
        {
317
            BasicHttpBinding myBinding = new BasicHttpBinding();
318
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
319

    
320
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
321
            var _id = new Guid().CreateUniqueGuid().ToString();
322

    
323
            var result = await client.WaitConvertListAsync();
324

    
325
            datagrid.ItemsSource = result;
326
        }
327

    
328
        private void ProcessKill_Click(object sender, RoutedEventArgs e)
329
        {
330
            station.Stopprocess();
331
        }
332

    
333
        private void DeadLockProcessList_Click(object sender, RoutedEventArgs e)
334
        {
335
            station.DeadLockProcessKill();
336
        }
337

    
338
        private async void Button_Click_1(object sender, RoutedEventArgs e)
339
        {
340
            int count = 0;
341

    
342

    
343
            if(int.TryParse(txtProcessCount.Text,out count))
344
            {
345

    
346
            BasicHttpBinding myBinding = new BasicHttpBinding();
347
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
348

    
349
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
350

    
351
            var result = await client.SettingMultiProcessAsync(count);
352

    
353
            }
354
        }
355

    
356
        private async void RemoteFileList_Click(object sender, RoutedEventArgs e)
357
        {
358
            var uriList = new[]
359
            {
360
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000053/250page.pdf",
361
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000038/250page.pdf",
362
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000027/BigSize.pdf",
363
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000032/BigSize.pdf",
364
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000087/1-5110-ZJ-492-005_C.pdf",
365
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000070/VP-TEST-MARKUS-040.pdf",
366
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000051/250page.pdf",
367
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000039/250page.pdf",
368
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000022/BigSize.pdf",
369
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000023/BigSize.pdf",
370
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000049/250page.pdf",
371
                "http://www.devdoftech.co.kr:5100/Doc_Manager/000000_app/VPCS_DOCLIB/40000050/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/40000036/250page.pdf"
374

    
375
            };
376
            BasicHttpBinding myBinding = new BasicHttpBinding();
377
            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate("http://localhost:9101/StationService"));
378

    
379
            StationService.StationServiceClient client = new StationService.StationServiceClient(myBinding, myEndpoint);
380

    
381
            foreach (var item in uriList)
382
            {
383
                var result = await client.ConvertMenualAddAsync("111111", item, "test");
384
                Log.Text += $"Wcf Station Service call{item} {result}\n";
385
            }
386

    
387
        }
388

    
389
        private void Button_Click_2(object sender, RoutedEventArgs e)
390
        {
391
            var pageinfoList = new Markus.Message.PageInfo[]
392
            {
393
                new Markus.Message.PageInfo
394
                {
395
                    Width = 111,
396
                    Height = 111,
397
                    PageNo = 1,
398

    
399
                },
400
                new Markus.Message.PageInfo
401
                {
402
                    Width = 111,
403
                    Height = 111,
404
                    PageNo = 2,
405
                }
406

    
407
            };
408

    
409
            using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString))
410
            {
411

    
412
                List<DOCPAGE> docPageList = new List<DOCPAGE>();
413

    
414
                docPageList = pageinfoList.Select(f => new DOCPAGE
415
                {
416
                    ID = GuidExtension.shortGuid(),
417
                    PAGE_WIDTH = f.Width.ToString(),
418
                    PAGE_HEIGHT = f.Height.ToString(),
419
                    PAGE_NUMBER = f.PageNo
420
                }).ToList();
421

    
422
                database.SetDocumentInfo("1df16d9a-1ea9-9a32-8a61-aad6ce4a2a49", 2, docPageList);
423
            }
424
        }
425

    
426
        private void wcfTest_Click(object sender, RoutedEventArgs e)
427
        {
428
            station.GetApplicationConfig();
429
            station.StartWcfService();
430
        }
431
        private static readonly HttpClient _Client = new HttpClient();
432
        private static JavaScriptSerializer _Serializer = new JavaScriptSerializer();
433

    
434
        private async void WebServiceTest_click(object sender, RoutedEventArgs e)
435
        {
436
            //string cookie = "";
437

    
438
            //var  uri = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem"); // string 을 Uri 로 형변환
439
            //var wReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환
440
            //wReq.Method = "POST"; // 전송 방법 "GET" or "POST"
441
            //wReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
442
            //wReq.Proxy = new System.Net.WebProxy("127.0.0.1", 8888);
443
            ////wReq.ServicePoint.Expect100Continue = false;
444
            ////wReq.CookieContainer = new System.Net.CookieContainer();
445
            ////wReq.CookieContainer.SetCookies(uri, cookie); // 넘겨줄 쿠키가 있을때 CookiContainer 에 저장
446

    
447
            ////POST 전송일 경우
448

    
449
            //string url = "http://localhost:9101/StationService/Rest/GetConvertItem";
450
            //var data = new SEND
451
            //{
452
            //    ProjectNo = "111111",
453
            //    DocumentID = "453"
454
            //};
455

    
456
            //var json = _Serializer.Serialize(data);
457
            //var response2 = await Request(HttpMethod.Post, url, json, new Dictionary<string, string>());
458
            //string responseText = await response2.Content.ReadAsStringAsync();
459

    
460
            //Console.WriteLine(responseText);
461

    
462

    
463
            //using (var client = new System.Net.Http.HttpClient())
464
            //{
465
            //    var uri2 = new Uri("http://localhost:9101/StationService/Rest/GetConvertItem");
466
 
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
    }
656

    
657
    class IntegratedServiceInstaller
658
    {
659
        public void Install(String ServiceName, String DisplayName, String Description,
660
            System.ServiceProcess.ServiceAccount Account,
661
            System.ServiceProcess.ServiceStartMode StartMode)
662
        {
663
            System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
664
            ProcessInstaller.Account = Account;
665

    
666
            System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
667

    
668
            System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
669
            string processPath = Process.GetCurrentProcess().MainModule.FileName;
670
            if (processPath != null && processPath.Length > 0)
671
            {
672
                System.IO.FileInfo fi = new System.IO.FileInfo(processPath);
673
                //Context = new System.Configuration.Install.InstallContext();
674
                //Context.Parameters.Add("assemblyPath", fi.FullName);
675
                //Context.Parameters.Add("startParameters", "Test");
676

    
677
                String path = String.Format("/assemblypath={0}", fi.FullName);
678
                String[] cmdline = { path };
679
                Context = new System.Configuration.Install.InstallContext("", cmdline);
680
            }
681

    
682
            SINST.Context = Context;
683
            SINST.DisplayName = DisplayName;
684
            SINST.Description = Description;
685
            SINST.ServiceName = ServiceName;
686
            SINST.StartType = StartMode;
687
            SINST.Parent = ProcessInstaller;
688

    
689
            // http://bytes.com/forum/thread527221.html
690
            //            SINST.ServicesDependedOn = new String[] {};
691

    
692
            System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
693
            SINST.Install(state);
694

    
695
            // http://www.dotnet247.com/247reference/msgs/43/219565.aspx
696
            using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true))
697
            {
698
                try
699
                {
700
                    Object sValue = oKey.GetValue("ImagePath");
701
                    oKey.SetValue("ImagePath", sValue);
702
                }
703
                catch (Exception Ex)
704
                {
705
                    //                    System.Console.WriteLine(Ex.Message);
706
                }
707
            }
708

    
709
        }
710
        public void Uninstall(String ServiceName)
711
        {
712
            System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();
713

    
714
            System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext("c:\\install.log", null);
715
            SINST.Context = Context;
716
            SINST.ServiceName = ServiceName;
717
            SINST.Uninstall(null);
718
        }
719
    }
720

    
721
    public class SEND
722
    {
723
        public string ProjectNo { get; set; }
724
        public string DocumentID{ get; set; }
725
}
726
}
클립보드 이미지 추가 (최대 크기: 500 MB)