프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 8c7d1ea1

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

1 e6281033 alzkakdixm
using Markus.Message;
2 a6e5055d alzkakdixm
using Markus.Service.DataBase;
3
using Markus.Service.Extensions;
4 e6281033 alzkakdixm
using Markus.Service.StationController.Data;
5 a6e5055d alzkakdixm
using Markus.Service.StationController.Behaviors;
6
using Markus.Service.StationController.Extensions;
7
using Microsoft.Win32;
8
using System;
9
using System.Collections.Generic;
10
using System.ComponentModel;
11
using System.Linq;
12 2decfbdf alzkakdixm
using System.Threading.Tasks;
13
using System.Web;
14 a6e5055d alzkakdixm
using System.Windows;
15
using Telerik.Windows.Controls;
16
using Telerik.Windows.Data;
17
using ConvertItem = Markus.Service.Interface.ConvertItem;
18 e6281033 alzkakdixm
using System.Net;
19
using System.Windows.Threading;
20 e78f0871 alzkakdixm
using System.Diagnostics;
21
using System.Windows.Input;
22
using Markus.Mvvm.ToolKit;
23 a6e5055d alzkakdixm
24
namespace Markus.Service.StationController.ViewModel
25
{
26
    //세미
27 dfc86b71 taeseongkim
    public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase
28 a6e5055d alzkakdixm
    {
29 e6281033 alzkakdixm
        #region Constructor
30
31
        /// <summary>
32
        /// 실행하면 처음 들어가는 부분
33
        /// </summary>
34
        public DataBaseItemsModel()
35
        {
36
            DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData);
37
            ConvertCommand = new DelegateCommand(DataConvert);
38
            DeleteCommand = new DelegateCommand(DataDelete);
39
            ValidateCommand = new DelegateCommand(DataValidate);
40 e78f0871 alzkakdixm
            MarkusLinkCommand = new DelegateCommand(MarkusLink);
41 e6281033 alzkakdixm
        }
42
43
        #endregion
44
45
        #region Properties
46
47 2decfbdf alzkakdixm
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems;
48
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems
49
        {
50 e6281033 alzkakdixm
            get => _AliveItems;
51
            set
52 2decfbdf alzkakdixm
            {
53 0cb12397 alzkakdixm
                _AliveItems = value;
54 2decfbdf alzkakdixm
                OnPropertyChanged(() => AliveItems);
55
            }
56
        }
57
58 dfc86b71 taeseongkim
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource;
59
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource
60
        {
61
            get => _FilterConvertSource;
62
            set
63
            {
64
                _FilterConvertSource = value;
65
                OnPropertyChanged(() => FilterConvertSource);
66
            }
67
        }
68
69
70
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource;
71
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource
72
        {
73
            get => _RealConvertSource;
74
            set
75
            {
76
                _RealConvertSource = value;
77
                OnPropertyChanged(() => RealConvertSource);
78
            }
79
        }
80
81 2decfbdf alzkakdixm
82 0cb12397 alzkakdixm
        private System.Windows.Documents.FlowDocument connectionLog;
83 2decfbdf alzkakdixm
        public System.Windows.Documents.FlowDocument ConnectionLog
84
        {
85
            get => connectionLog;
86
            set
87
            {
88
                if (connectionLog != value)
89
                {
90
                    connectionLog = value;
91
                    OnPropertyChanged(() => ConnectionLog);
92
                }
93
            }
94
        }
95
96 a6e5055d alzkakdixm
97
        private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus;
98
        public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus
99
        {
100
            get => _SelectedStatus;
101
            set
102
            {
103
                _SelectedStatus = value;
104 0cb12397 alzkakdixm
                OnPropertyChanged(() => SelectedStatus);
105 a6e5055d alzkakdixm
            }
106
        }
107
108
109
        private SelectedCountItem _SelectedCount;
110
        public SelectedCountItem SelectedCount
111
        {
112
            get => _SelectedCount;
113
            set
114
            {
115
                _SelectedCount = value;
116 dfc86b71 taeseongkim
                OnPropertyChanged(() => SelectedCount);
117 a6e5055d alzkakdixm
            }
118
        }
119
120 e6281033 alzkakdixm
        List<SelectedCountItem> _SelectedCountList;
121
        public List<SelectedCountItem> SelectedCountList
122 a6e5055d alzkakdixm
        {
123 e6281033 alzkakdixm
            get
124 2decfbdf alzkakdixm
            {
125 e6281033 alzkakdixm
                if (_SelectedCountList == null)
126 2decfbdf alzkakdixm
                {
127 e6281033 alzkakdixm
                    _SelectedCountList = new List<SelectedCountItem>
128 2decfbdf alzkakdixm
                    {
129 e6281033 alzkakdixm
                        new SelectedCountItem{DisplayMember = "50",ValueMember = 50},
130
                        new SelectedCountItem{DisplayMember = "100",ValueMember = 100},
131
                        new SelectedCountItem{DisplayMember = "150",ValueMember = 150},
132
                        new SelectedCountItem{DisplayMember = "200",ValueMember = 200}
133
                    };
134 2decfbdf alzkakdixm
                }
135 a6e5055d alzkakdixm
136 e6281033 alzkakdixm
                return _SelectedCountList;
137 2decfbdf alzkakdixm
            }
138
        }
139 a6e5055d alzkakdixm
140 0cb12397 alzkakdixm
        private ConvertItem _SelectFilterConvert;
141 a6e5055d alzkakdixm
        public ConvertItem SelectFilterConvert
142
        {
143
            get => _SelectFilterConvert;
144
            set
145
            {
146
                _SelectFilterConvert = value;
147 dfc86b71 taeseongkim
                OnPropertyChanged(() => SelectFilterConvert);
148 a6e5055d alzkakdixm
            }
149
        }
150 0cb12397 alzkakdixm
151
        private ConvertItem _SelectRealConvert;
152 a6e5055d alzkakdixm
        public ConvertItem SelectRealConvert
153
        {
154
            get => _SelectRealConvert;
155
            set
156
            {
157
                _SelectRealConvert = value;
158 dfc86b71 taeseongkim
                OnPropertyChanged(() => SelectRealConvert);
159 a6e5055d alzkakdixm
            }
160
        }
161
162 0cb12397 alzkakdixm
163
        private StatusTypeList _StatusType;
164 a6e5055d alzkakdixm
        public StatusTypeList StatusType
165
        {
166
            get => _StatusType;
167
            set
168
            {
169
                _StatusType = value;
170 dfc86b71 taeseongkim
                OnPropertyChanged(() => StatusType);
171 a6e5055d alzkakdixm
            }
172
        }
173
174 0cb12397 alzkakdixm
        private bool _IsLoading;
175 a6e5055d alzkakdixm
        public bool IsLoading
176
        {
177
            get => _IsLoading;
178
            set
179
            {
180
                if (_IsLoading != value)
181
                {
182
                    _IsLoading = value;
183 dfc86b71 taeseongkim
                    OnPropertyChanged(() => IsLoading);
184 a6e5055d alzkakdixm
                }
185
            }
186
        }
187
188 e6281033 alzkakdixm
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
189
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
190 a6e5055d alzkakdixm
        {
191
            get
192
            {
193 e6281033 alzkakdixm
                if (_StatusCodeList == null)
194 a6e5055d alzkakdixm
                {
195 e6281033 alzkakdixm
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>();
196 a6e5055d alzkakdixm
                }
197
198 e6281033 alzkakdixm
                return _StatusCodeList;
199 a6e5055d alzkakdixm
            }
200
        }
201 8c7d1ea1 alzkakdixm
202
        public bool _ConvertShow;
203
        public bool ConvertShow
204
        {
205
            get => _ConvertShow;
206
            set
207
            {
208
                if(_ConvertShow =! value)
209
                {
210
                    _ConvertShow = false;
211
                }
212
                _ConvertShow = value;
213
                OnPropertyChanged(() => ConvertShow);
214
            }
215
        }
216 e6281033 alzkakdixm
        #endregion
217
218
        #region Command
219 a6e5055d alzkakdixm
220 0cb12397 alzkakdixm
        public DelegateCommand ConvertCommand { get; private set; }
221
        public DelegateCommand DeleteCommand { get; private set; }
222
        public DelegateCommand ValidateCommand { get; private set; }
223 e6281033 alzkakdixm
        public DelegateCommand DataSaveFileGemBoxCommand { get; private set; }
224 e78f0871 alzkakdixm
        public DelegateCommand MarkusLinkCommand { get; private set; }
225 e6281033 alzkakdixm
        #endregion
226 a6e5055d alzkakdixm
227 e6281033 alzkakdixm
        #region Main Logic
228 a6e5055d alzkakdixm
229 e6281033 alzkakdixm
        /// <summary>
230
        /// 각각의 Grid row 객체들 업데이트
231
        /// </summary>
232
233
        private DispatcherTimer dispatcherTimer;
234
        public override void Loaded()
235 a6e5055d alzkakdixm
        {
236 e6281033 alzkakdixm
            base.Loaded();
237
238
            if (!App.IsDesignMode)
239
            {
240
                dispatcherTimer = new DispatcherTimer();
241
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
242
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
243
                dispatcherTimer.Start();
244
            }
245 a6e5055d alzkakdixm
        }
246
247 b119eeaa taeseongkim
        private async void Timer_Tick(object sender, EventArgs e)
248 a6e5055d alzkakdixm
        {
249 e6281033 alzkakdixm
            dispatcherTimer.Stop();
250
251
            if (IsAcitve)
252 a6e5055d alzkakdixm
            {
253 b119eeaa taeseongkim
                await App.Current.Dispatcher.InvokeAsync(() =>
254 a6e5055d alzkakdixm
                {
255 e6281033 alzkakdixm
                    DataSelect();
256
257
                    AliveDataSelect();
258
                });
259
            }
260
261 b119eeaa taeseongkim
            await Task.Delay(5000);
262
263
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
264 e6281033 alzkakdixm
265
            dispatcherTimer.Start();
266
        }
267 a6e5055d alzkakdixm
268 e6281033 alzkakdixm
        public override void Closed()
269
        {
270
            if (dispatcherTimer != null)
271
            {
272
                dispatcherTimer.Stop();
273 a6e5055d alzkakdixm
            }
274 e6281033 alzkakdixm
275
            base.Closed();
276 a6e5055d alzkakdixm
        }
277 0cb12397 alzkakdixm
278 2decfbdf alzkakdixm
279 e6281033 alzkakdixm
        #endregion
280 a6e5055d alzkakdixm
281 e6281033 alzkakdixm
        #region Function
282 a6e5055d alzkakdixm
283 e6281033 alzkakdixm
        #region Data Select
284
285
        /// <summary>
286
        /// 상단 그리드 중앙 그리드 출력 데이터
287
        /// </summary>
288
        private void DataSelect()
289
        {
290 a6e5055d alzkakdixm
291 e6281033 alzkakdixm
            if (FilterConvertSource == null)
292
            {
293
                FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
294
            }
295
296
            if (RealConvertSource == null)
297
            {
298
                RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
299
            }
300
301
            /// combobox 에서 선택된 items
302
            if (SelectedStatus != null)
303
            {
304
                DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
305 a6e5055d alzkakdixm
            }
306
307 e6281033 alzkakdixm
            /// 컨버터중인 items
308
            RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource);
309 2decfbdf alzkakdixm
310 e6281033 alzkakdixm
        }
311 2decfbdf alzkakdixm
312
        private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
313
        {
314
            try
315
            {
316
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
317
                {
318
                    var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
319
                                          .Take(SelectedCount.ValueMember).ToList();//
320
321
                    items.ForEach(newitem =>
322
                    {
323
                        collection.UpdateWhere(changeitem =>
324
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber);
325
                    });
326
                }
327
            }
328
            catch (Exception ex)
329
            {
330
                MessageBox.Show(ex.ToString());
331
            }
332
        }
333
334 a6e5055d alzkakdixm
        private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
335
        {
336
            try
337
            {
338
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
339
                {
340
341 2decfbdf alzkakdixm
                    int _status = 0;
342
                    if (SelectedStatus != null)
343
                    {
344
                        _status = (int)SelectedStatus.Value;
345
                    }
346
347
                    var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
348 0cb12397 alzkakdixm
                                          .Take(SelectedCount.ValueMember).ToList();
349 2decfbdf alzkakdixm
350 a6e5055d alzkakdixm
                    if (collection.Count() == 0)
351
                    {
352 2decfbdf alzkakdixm
                        if (statusCodeTypeList.Count() == 1)
353
                        {
354
                            items.ForEach(x => collection.Add(x));
355
                        }
356 a6e5055d alzkakdixm
                    }
357
                    else
358
                    {
359 2decfbdf alzkakdixm
360
                        ////세미 업데이트
361
                        items.ForEach(newitem =>
362 a6e5055d alzkakdixm
                        {
363
                            collection.UpdateWhere(changeitem =>
364 2decfbdf alzkakdixm
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
365 a6e5055d alzkakdixm
                        });
366
367 2decfbdf alzkakdixm
368
                        if (statusCodeTypeList.Count() == 1)
369 a6e5055d alzkakdixm
                        {
370 2decfbdf alzkakdixm
                            //삭제
371
                            for (int i = collection.Count() - 1; i >= 0; --i)
372 a6e5055d alzkakdixm
                            {
373 2decfbdf alzkakdixm
                                var item = collection[i];
374 a6e5055d alzkakdixm
375 2decfbdf alzkakdixm
                                if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교
376
                                {//참=> 0제외한 모든 수
377
                                    collection.RemoveAt(i);
378
                                }
379
                            }
380 a6e5055d alzkakdixm
                        }
381
382 2decfbdf alzkakdixm
                        if (statusCodeTypeList.Count() == 1)
383 a6e5055d alzkakdixm
                        {
384 2decfbdf alzkakdixm
                            //추가 convert 후 추가됨
385
                            foreach (var item in items)
386
                            {
387
                                if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감
388
                                {
389
                                    /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/
390
                                    for (int i = 0; i < 200; i++)
391
                                    {
392
                                        if (i < collection.Count() - 1)
393
                                        {
394
                                            if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
395
                                            {
396
                                                collection.Insert(i, item);
397
                                                break;
398
                                            }
399
                                        }
400
                                        else
401
                                        {
402
                                            collection.Add(item);
403
                                            break;
404
                                        }
405
                                    }
406
407
                                }
408 a6e5055d alzkakdixm
409
                            }
410
                        }
411 2decfbdf alzkakdixm
412 a6e5055d alzkakdixm
                    }
413
                }
414 2decfbdf alzkakdixm
415 a6e5055d alzkakdixm
            }
416
            catch (Exception ex)
417
            {
418
                MessageBox.Show(ex.ToString());
419
            }
420
        }
421
422 e6281033 alzkakdixm
        /// <summary>
423
        /// 서비스의 실시간 컨버터 Item
424
        /// </summary>
425
        private async void AliveDataSelect()
426 a6e5055d alzkakdixm
        {
427 e6281033 alzkakdixm
            try
428 a6e5055d alzkakdixm
            {
429 e6281033 alzkakdixm
                List<ConvertItem> newitems = new List<ConvertItem>();
430 a6e5055d alzkakdixm
431 e6281033 alzkakdixm
                foreach (var client in App.StationClientList)
432
                {
433
                    if (await SimplePingAsync(client.Endpoint.Address.ToString()))
434
                    {
435
                        try
436
                        {
437
                            List<ConvertItem> itemsToList = new List<ConvertItem>();
438
                            var items = await client.AliveConvertListAsync();
439
                            foreach (var item in items)
440
                            {
441
                                ConvertItem itemsToEach = new ConvertItem();
442
                                itemsToEach.ServiceID = item.ServiceID;
443
                                itemsToEach.ConvertID = item.ConvertID;
444
                                itemsToEach.ProjectNumber = item.ProjectNumber;
445 29000595 alzkakdixm
446
                                if (item.ConvertState != null)
447 e6281033 alzkakdixm
                                {
448
                                    itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState);
449
                                }
450
451
                                itemsToEach.CurrentPageNo = item.CurrentPageNo;
452
                                itemsToEach.TotalPage = item.TotalPage;
453
                                itemsToEach.OriginfilePath = item.OriginfilePath;
454
                                itemsToEach.ConvertPath = item.ConvertPath;
455 344ac7ed alzkakdixm
                                itemsToEach.MarkusLink = item.MarkusLink;
456
                                itemsToEach.UniqueKey = item.UniqueKey;
457
                                itemsToEach.FileName = item.FileName;
458
                                itemsToEach.ConvertPath = item.ConvertPath;
459
                                itemsToEach.CreateTime = item.CreateTime;
460
                                itemsToEach.Exception = item.Exception;
461
                                itemsToEach.ProcessorAffinity = item.ProcessorAffinity;
462
                                itemsToEach.ReConverter = item.ReConverter;
463
                                itemsToEach.DocumentID = item.DocumentID;
464
                                itemsToEach.DocumnetName = item.DocumnetName;
465
                                itemsToEach.GroupNo = item.GroupNo;
466
                                itemsToEach.Revision = item.Revision;
467
                                itemsToEach.StartTime = item.StartTime;
468
                                itemsToEach.EndTime = item.EndTime;
469
470 e6281033 alzkakdixm
471
                                itemsToList.Add(itemsToEach);
472
                            }
473
                            newitems.AddRange(itemsToList);
474
                            System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping");
475 2decfbdf alzkakdixm
476 e6281033 alzkakdixm
                            if (items.Count() == 0)
477
                            {
478
                                System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero.");
479
                            }
480
                        }
481
                        catch (Exception ex)
482
                        {
483
                            System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}");
484
                        }
485
                    }
486
                    else
487
                    {
488
                        System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error");
489
                    }
490
                }
491 2decfbdf alzkakdixm
492 e6281033 alzkakdixm
                ItemsUpdate(newitems);
493
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems));
494
            }
495
            catch (Exception ex)
496
            {
497
                System.Diagnostics.Debug.WriteLine(ex.ToString());
498 a6e5055d alzkakdixm
            }
499
        }
500
501 e6281033 alzkakdixm
        /// <summary>
502
        /// AliveDataSelect의 Data Update
503
        /// </summary>
504
        /// <param name="newitems"></param>
505
        private void ItemsUpdate(List<ConvertItem> newitems)
506 a6e5055d alzkakdixm
        {
507
508 e6281033 alzkakdixm
            foreach (var item in newitems)
509
            {
510
                item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath);
511
            }
512
513
            if (AliveItems == null)
514
            {
515
                AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
516
517
                foreach (var item in newitems)
518
                {
519
                    AliveItems.Add(item);
520
                }
521
            }
522
            else
523 a6e5055d alzkakdixm
            {
524 e6281033 alzkakdixm
                /// 데이터 업데이트
525
                newitems.ForEach(newitem =>
526
                {
527
                    AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
528
                });
529
530
                // 추가
531
                foreach (var item in newitems)
532
                {
533
                    if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
534
                    {
535
                        AliveItems.Add(item);
536
                    }
537
                }
538 a6e5055d alzkakdixm
539 e6281033 alzkakdixm
                /// 삭제
540 2decfbdf alzkakdixm
541 e6281033 alzkakdixm
                for (int i = AliveItems.Count() - 1; i > -1; --i)
542
                {
543
                    var item = AliveItems[i];
544 a6e5055d alzkakdixm
545 e6281033 alzkakdixm
                    if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
546
                    {
547
                        try
548
                        {
549
                            AliveItems.RemoveAt(i);
550
                        }
551
                        catch (Exception ex)
552
                        {
553
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
554
                        }
555
                    }
556
                }
557 2decfbdf alzkakdixm
            }
558 a6e5055d alzkakdixm
        }
559
560
561 e6281033 alzkakdixm
        public static async Task<bool> SimplePingAsync(string uri)
562 a6e5055d alzkakdixm
        {
563 e6281033 alzkakdixm
            bool result = false;
564
565
            try
566
            {
567
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
568
                {
569
                    Client.Timeout = new TimeSpan(0, 0, 60);
570
571
                    var message = await Client.GetAsync(uri);
572
573
                    System.Net.HttpStatusCode StatusCode = message.StatusCode;
574
575
                    switch (StatusCode)
576
                    {
577
578
                        case System.Net.HttpStatusCode.Accepted:
579
                        case System.Net.HttpStatusCode.OK:
580
                            result = true;
581
                            break;
582
                    }
583
                }
584
            }
585
            catch (Exception ex)
586
            {
587
                result = false;
588
                System.Diagnostics.Debug.WriteLine(ex.ToString());
589
            }
590
591
            return result;
592 a6e5055d alzkakdixm
        }
593
594 e6281033 alzkakdixm
        #endregion
595
596
        #region Data Convert
597 a6e5055d alzkakdixm
598 e6281033 alzkakdixm
        private void DataConvert(object obj)
599
        {
600
            if (SelectFilterConvert == null && SelectRealConvert == null)
601
            {
602
                MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!");
603
            }
604
            else
605 a6e5055d alzkakdixm
            {
606 e6281033 alzkakdixm
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
607
                var resultRealConvert = 0;
608
                var resultFiltertConvert = 0;
609
610
                if (SelectRealConvert != null)
611
                {
612
                    resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert);
613
                }
614
                else if (SelectFilterConvert != null)
615 a6e5055d alzkakdixm
                {
616 e6281033 alzkakdixm
                    resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert);
617
                }
618
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
619
620
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
621
                {
622
                    var items = database.GetConvertProjects(SelectFilterConvert);
623
624
                    foreach (var item in items)
625
                    {
626
                        RealConvertSource.Add(item);
627
                    }
628 8c7d1ea1 alzkakdixm
                    if (RealConvertSource.Count() == 1)
629
                    {
630
                        ConvertShow = true;
631
                    }
632 a6e5055d alzkakdixm
                }
633
            }
634 e6281033 alzkakdixm
        }
635
636
        #endregion
637
638
        #region Validation
639 a6e5055d alzkakdixm
640 e6281033 alzkakdixm
        private void DataValidate(object obj)
641
        {
642
643
            bool result = false;
644 a6e5055d alzkakdixm
645 e6281033 alzkakdixm
            WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath);
646
            webRequest.Timeout = 1200; // miliseconds
647
            webRequest.Method = "HEAD";
648
649
            HttpWebResponse response = null;
650
651
            try
652
            {
653
                response = (HttpWebResponse)webRequest.GetResponse();
654
                result = true;
655
            }
656
            catch (WebException webException)
657
            {
658
                MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message);
659
                result = true;
660
            }
661
            finally
662 a6e5055d alzkakdixm
            {
663 e6281033 alzkakdixm
                if (response != null)
664 a6e5055d alzkakdixm
                {
665 e6281033 alzkakdixm
                    response.Close();
666 a6e5055d alzkakdixm
                }
667 2decfbdf alzkakdixm
            }
668 e6281033 alzkakdixm
            if (result == true)
669
            {
670
                MessageBox.Show("File exists");
671
            }
672
        }
673
674
        #endregion
675
676 e78f0871 alzkakdixm
        #region MarkusLink
677
678
        private void MarkusLink(object obj)///여기서 부터 
679
        {
680
            if (obj is ConvertItem)
681
            {
682
                if (obj != null)
683
                {
684
                    var convertitem = obj as ConvertItem;
685
686
                    SelectFilterConvert = convertitem;
687
688
                    SelectRealConvert = convertitem;
689
690
                    ProcessStartInfo startInfo = null;
691
692
                    startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink);
693
694
                    Process.Start(startInfo);
695
                }
696
            }
697
        }
698
699
        #endregion
700
701 e6281033 alzkakdixm
        #region Data Delete
702
703
        private void DataDelete(object obj)
704
        {
705 8c7d1ea1 alzkakdixm
            RadWindow.Alert("do you want to delete it??", this.OnClosed);
706 e6281033 alzkakdixm
        }
707
708
        private void OnClosed(object sender, WindowClosedEventArgs e)
709
        {
710
            var result = e.DialogResult;
711
            if (result == true)
712
            {
713
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
714
                var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID);
715
                var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID);
716
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
717
            }
718
        }
719
720
721
        #endregion
722
723
        #region Data Export
724
725
726
        /// <summary>
727
        /// 필터된 상단 그리드 엑셀로 출력
728
        /// </summary>
729
730
        public void DataExportData(object obj)
731
        {
732
            SaveFileDialog saveFileDialog = new SaveFileDialog();
733
734
            saveFileDialog.FileName = "Document"; // Default file name
735
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
736
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
737
738
739
            if (saveFileDialog.ShowDialog() == true)
740 2decfbdf alzkakdixm
            {
741 e6281033 alzkakdixm
742
743
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
744 0cb12397 alzkakdixm
                {
745 e6281033 alzkakdixm
746
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
747
748
                    if (extension == ".xlsx" || extension == ".csv")
749
                    {
750
751
                        var headers = new List<HeaderMember>
752
                        {
753
                            new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" },
754
                            new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" },
755
                            new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" },
756
                            new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" },
757
                            new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" },
758
                            new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" },
759
                            new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" },
760
                            new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" },
761
                            new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" },
762
                            new HeaderMember{HeaderName = "Exception", Property = "Exception" },
763
                            new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" },
764
                            new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" },
765
                            new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" }
766
                        };
767
768
769
                        DataExport dataExport = new DataExport();
770
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers);
771
                        //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(),  Projectsource, headers);
772
                        //GemBoxFileSave(obj);
773
                    }
774 0cb12397 alzkakdixm
                }
775 2decfbdf alzkakdixm
            }
776
        }
777 e6281033 alzkakdixm
778
        #endregion
779
780
        #endregion
781 a6e5055d alzkakdixm
    }
782
}
클립보드 이미지 추가 (최대 크기: 500 MB)