프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 5a954acc

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

1
using Markus.Message;
2
using Markus.Service.DataBase;
3
using Markus.Service.Extensions;
4
using Markus.Service.StationController.Data;
5
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
using System.Threading.Tasks;
13
using System.Web;
14
using System.Windows;
15
using Telerik.Windows.Controls;
16
using Telerik.Windows.Data;
17
using ConvertItem = Markus.Service.Interface.ConvertItem;
18
using System.Net;
19
using System.Windows.Threading;
20
using System.Diagnostics;
21
using System.Windows.Input;
22
using Markus.Mvvm.ToolKit;
23
using System.Windows.Data;
24

    
25
namespace Markus.Service.StationController.ViewModel
26
{
27
    //세미
28
    public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase
29
    {
30
        #region Constructor
31

    
32
        /// <summary>
33
        /// 실행하면 처음 들어가는 부분
34
        /// </summary>
35
        public DataBaseItemsModel()
36
        {
37
            DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData);
38
            ConvertCommand = new DelegateCommand(DataConvert);
39
            DeleteCommand = new DelegateCommand(DataDelete);
40
            ValidateCommand = new DelegateCommand(DataValidate);
41
            MarkusLinkCommand = new DelegateCommand(MarkusLink);
42
            RemoveCreateTimeFilterCommand = new DelegateCommand(RemoveCreateTimeFilter);
43
            FilterConvertSourceView.Filter = new Predicate<object>(o => DetailFilter(o as ConvertItem));
44
        }
45

    
46
        #endregion
47

    
48
        #region Properties
49

    
50
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems;
51
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems
52
        {
53
            get => _AliveItems;
54
            set
55
            {
56
                _AliveItems = value;
57
                OnPropertyChanged(() => AliveItems);
58
            }
59
        }
60

    
61
        public ICollectionView FilterConvertSourceView
62
        {
63
            get { return CollectionViewSource.GetDefaultView(FilterConvertSource); }
64
        }
65

    
66
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource;
67
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource
68
        {
69
            //get => _FilterConvertSource;
70
            get
71
            {
72
                if (_FilterConvertSource == null)
73
                {
74
                    _FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
75
                }
76
                //if (_FilterConvertSource != null)
77
                //{
78
                //    var view = CollectionViewSource.GetDefaultView(FilterConvertSource);
79
                //    if (view.CanFilter)
80
                //    {
81
                //        view.Filter = DetailFilter;
82
                //    }
83
                //}
84
                return _FilterConvertSource;
85
            }
86
            set
87
            {
88
                _FilterConvertSource = value;
89
                OnPropertyChanged(() => FilterConvertSource);
90
            }
91
        }
92

    
93

    
94
        private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource;
95
        public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource
96
        {
97
            get => _RealConvertSource;
98
            set
99
            {
100
                _RealConvertSource = value;
101
                OnPropertyChanged(() => RealConvertSource);
102
            }
103
        }
104

    
105

    
106
        private System.Windows.Documents.FlowDocument connectionLog;
107
        public System.Windows.Documents.FlowDocument ConnectionLog
108
        {
109
            get => connectionLog;
110
            set
111
            {
112
                if (connectionLog != value)
113
                {
114
                    connectionLog = value;
115
                    OnPropertyChanged(() => ConnectionLog);
116
                }
117
            }
118
        }
119

    
120

    
121
        private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus;
122
        public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus
123
        {
124
            get => _SelectedStatus;
125
            set
126
            {
127
                _SelectedStatus = value;
128
                OnPropertyChanged(() => SelectedStatus);
129
            }
130
        }
131

    
132

    
133
        private SelectedCountItem _SelectedCount;
134
        public SelectedCountItem SelectedCount
135
        {
136
            get => _SelectedCount;
137
            set
138
            {
139
                _SelectedCount = value;
140
                OnPropertyChanged(() => SelectedCount);
141
            }
142
        }
143

    
144
        List<SelectedCountItem> _SelectedCountList;
145
        public List<SelectedCountItem> SelectedCountList
146
        {
147
            get
148
            {
149
                if (_SelectedCountList == null)
150
                {
151
                    _SelectedCountList = new List<SelectedCountItem>
152
                    {
153
                        new SelectedCountItem{DisplayMember = "50",ValueMember = 50},
154
                        new SelectedCountItem{DisplayMember = "100",ValueMember = 100},
155
                        new SelectedCountItem{DisplayMember = "150",ValueMember = 150},
156
                        new SelectedCountItem{DisplayMember = "200",ValueMember = 200}
157
                    };
158
                }
159

    
160
                return _SelectedCountList;
161
            }
162
        }
163

    
164
        private ConvertItem _SelectFilterConvert;
165
        public ConvertItem SelectFilterConvert
166
        {
167
            get => _SelectFilterConvert;
168
            set
169
            {
170
                _SelectFilterConvert = value;
171
                OnPropertyChanged(() => SelectFilterConvert);
172
            }
173
        }
174

    
175
        private ConvertItem _SelectRealConvert;
176
        public ConvertItem SelectRealConvert
177
        {
178
            get => _SelectRealConvert;
179
            set
180
            {
181
                _SelectRealConvert = value;
182
                OnPropertyChanged(() => SelectRealConvert);
183
            }
184
        }
185

    
186

    
187
        private StatusTypeList _StatusType;
188
        public StatusTypeList StatusType
189
        {
190
            get => _StatusType;
191
            set
192
            {
193
                _StatusType = value;
194
                OnPropertyChanged(() => StatusType);
195
            }
196
        }
197

    
198
        private bool _IsLoading;
199
        public bool IsLoading
200
        {
201
            get => _IsLoading;
202
            set
203
            {
204
                if (_IsLoading != value)
205
                {
206
                    _IsLoading = value;
207
                    OnPropertyChanged(() => IsLoading);
208
                }
209
            }
210
        }
211

    
212
        IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList;
213
        public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList
214
        {
215
            get
216
            {
217
                if (_StatusCodeList == null)
218
                {
219
                    _StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>();
220
                }
221

    
222
                return _StatusCodeList;
223
            }
224
        }
225

    
226
        public bool _ConvertShow;
227
        public bool ConvertShow
228
        {
229
            get => _ConvertShow;
230
            set
231
            {
232
                if(_ConvertShow =! value)
233
                {
234
                    _ConvertShow = false;
235
                }
236
                _ConvertShow = value;
237
                OnPropertyChanged(() => ConvertShow);
238
            }
239
        }
240

    
241
        public string _ProjectNumberFilter;
242
        public string ProjectNumberFilter
243
        {
244
            get { return _ProjectNumberFilter; }
245
            set
246
            {
247
                if (_ProjectNumberFilter != value)
248
                {
249
                    _ProjectNumberFilter = value;
250
                    OnPropertyChanged(() => ProjectNumberFilter);
251
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
252
                    FilterConvertSourceView.Refresh();
253
                }
254
            }
255
        }
256

    
257
        public string _UniqueKeyFilter;
258
        public string UniqueKeyFilter
259
        {
260
            get { return _UniqueKeyFilter; }
261
            set
262
            {
263
                if (_UniqueKeyFilter != value)
264
                {
265
                    _UniqueKeyFilter = value;
266
                    OnPropertyChanged(() => UniqueKeyFilter);
267
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
268
                    FilterConvertSourceView.Refresh();
269
                }
270
            }
271
        }
272

    
273
        public StatusCodeType _ConvertStateFilter;
274
        public StatusCodeType ConvertStateFilter
275
        {
276
            get { return _ConvertStateFilter; }
277
            set
278
            {
279
                if (_ConvertStateFilter != value)
280
                {
281
                    _ConvertStateFilter = value;
282
                    OnPropertyChanged(() => ConvertStateFilter);
283
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
284
                    FilterConvertSourceView.Refresh();
285
                }
286
            }
287
        }
288

    
289
        public string _Docuemnt_NOFilter;
290
        public string Docuemnt_NOFilter
291
        {
292
            get { return _Docuemnt_NOFilter; }
293
            set
294
            {
295
                if (_Docuemnt_NOFilter != value)
296
                {
297
                    _Docuemnt_NOFilter = value;
298
                    OnPropertyChanged(() => Docuemnt_NOFilter);
299
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
300
                    FilterConvertSourceView.Refresh();
301
                }
302
            }
303
        }
304

    
305
        public string _Docuemnt_NameFilter;
306
        public string Docuemnt_NameFilter
307
        {
308
            get { return _Docuemnt_NameFilter; }
309
            set
310
            {
311
                if (_Docuemnt_NameFilter != value)
312
                {
313
                    _Docuemnt_NameFilter = value;
314
                    OnPropertyChanged(() => Docuemnt_NameFilter);
315
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
316
                    FilterConvertSourceView.Refresh();
317
                }
318
            }
319
        }
320

    
321
        public int? _ReconverterFilter;
322
        public int? ReconverterFilter
323
        {
324
            get { return _ReconverterFilter; }
325
            set
326
            {
327
                if (_ReconverterFilter != value)
328
                {
329
                    _ReconverterFilter = value;
330
                    OnPropertyChanged(() => ReconverterFilter);
331
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
332
                    FilterConvertSourceView.Refresh();
333

    
334
                }
335
            }
336
        }
337

    
338
        public string _Service_IDFilter;
339
        public string Service_IDFilter
340
        {
341
            get { return _Service_IDFilter; }
342
            set
343
            {
344
                if (_Service_IDFilter != value)
345
                {
346
                    _Service_IDFilter = value;
347
                    OnPropertyChanged(() => Service_IDFilter);
348
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
349
                    FilterConvertSourceView.Refresh();
350
                }
351
            }
352
        }
353

    
354
        public string _RevisionFilter;
355
        public string RevisionFilter
356
        {
357
            get { return _RevisionFilter; }
358
            set
359
            {
360
                if (_RevisionFilter != value)
361
                {
362
                    _RevisionFilter = value;
363
                    OnPropertyChanged(() => RevisionFilter);
364
                    //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
365
                    FilterConvertSourceView.Refresh();
366
                }
367
            }
368
        }
369

    
370
        private DateTime _SelectedCreateTimeBegin = DateTime.Now;
371
        public DateTime SelectedCreateTimeBegin
372
        {
373

    
374
            get { return _SelectedCreateTimeBegin; }
375
            set
376
            {
377
                if (_SelectedCreateTimeBegin == value)
378
                    return;
379
                _SelectedCreateTimeBegin = value;
380
                OnPropertyChanged(() => SelectedCreateTimeBegin);
381
                //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
382
                FilterConvertSourceView.Refresh();
383
                //AddGeneratorBeginFilter();
384

    
385
            }
386
        }
387

    
388
        private DateTime _SelectedCreateTimeEnd = DateTime.Now;
389
        public DateTime SelectedCreateTimeEnd
390
        {
391

    
392
            get { return _SelectedCreateTimeEnd; }
393
            set
394
            {
395
                if (_SelectedCreateTimeEnd == value)
396
                    return;
397
                _SelectedCreateTimeEnd = value;
398
                OnPropertyChanged(() => SelectedCreateTimeEnd);
399
                //CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh();
400
                FilterConvertSourceView.Refresh();
401
                //AddGeneratorBeginFilter();
402

    
403
            }
404
        }
405

    
406
        #endregion
407

    
408
        #region Command
409

    
410
        public DelegateCommand ConvertCommand { get; private set; }
411
        public DelegateCommand DeleteCommand { get; private set; }
412
        public DelegateCommand ValidateCommand { get; private set; }
413
        public DelegateCommand DataSaveFileGemBoxCommand { get; private set; }
414
        public DelegateCommand MarkusLinkCommand { get; private set; }
415
        public DelegateCommand RemoveCreateTimeFilterCommand { get; private set;}
416

    
417
        #endregion
418

    
419
        #region Main Logic
420

    
421
        /// <summary>
422
        /// 각각의 Grid row 객체들 업데이트
423
        /// </summary>
424

    
425
        private DispatcherTimer dispatcherTimer;
426
        public override void Loaded()
427
        {
428
            base.Loaded();
429

    
430
            if (!App.IsDesignMode)
431
            {
432
                dispatcherTimer = new DispatcherTimer();
433
                dispatcherTimer.Tick += new EventHandler(Timer_Tick);
434
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
435
                dispatcherTimer.Start();
436
            }
437
        }
438

    
439
        private async void Timer_Tick(object sender, EventArgs e)
440
        {
441
            dispatcherTimer.Stop();
442

    
443
            if (IsAcitve)
444
            {
445
                await App.Current.Dispatcher.InvokeAsync(() =>
446
                {
447
                    DataSelect();
448

    
449
                    AliveDataSelect();
450
                });
451
            }
452

    
453
            await Task.Delay(5000);
454

    
455
            //System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100));
456

    
457
            dispatcherTimer.Start();
458
        }
459

    
460
        public override void Closed()
461
        {
462
            if (dispatcherTimer != null)
463
            {
464
                dispatcherTimer.Stop();
465
            }
466

    
467
            base.Closed();
468
        }
469

    
470

    
471
        #endregion
472

    
473
        #region Function
474

    
475
        #region Data Select
476

    
477
        /// <summary>
478
        /// 상단 그리드 중앙 그리드 출력 데이터
479
        /// </summary>
480
        private void DataSelect()
481
        {
482

    
483
            if (FilterConvertSource == null)
484
            {
485
                FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
486
            }
487

    
488
            if (RealConvertSource == null)
489
            {
490
                RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
491
            }
492

    
493
            /// combobox 에서 선택된 items
494
            if (SelectedStatus != null)
495
            {
496
                DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource);
497
            }
498

    
499
            /// 컨버터중인 items
500
            RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource);
501

    
502
        }
503

    
504
        private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
505
        {
506
            try
507
            {
508
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
509
                {
510
                    var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
511
                                          .Take(SelectedCount.ValueMember).ToList();//
512

    
513
                    items.ForEach(newitem =>
514
                    {
515
                        collection.UpdateWhere(changeitem =>
516
                        ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber);
517
                    });
518
                }
519
            }
520
            catch (Exception ex)
521
            {
522
                MessageBox.Show(ex.ToString());
523
            }
524
        }
525

    
526
        private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection)
527
        {
528
            try
529
            {
530
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
531
                {
532

    
533
                    int _status = 0;
534
                    if (SelectedStatus != null)
535
                    {
536
                        _status = (int)SelectedStatus.Value;
537
                    }
538

    
539
                    //var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값  Count()안에 predicator 조건 만족하면 count개수안에 넣음
540
                    //                      .Take(SelectedCount.ValueMember).ToList();
541
                    var items = database.GetConvertProjects(_status).ToList();
542
                    if (ProjectNumberFilter != null)
543
                    {
544
                        items.Where(x => x.ProjectNumber.Contains("/" + ProjectNumberFilter + "/"));
545
                    }
546
                    if (Docuemnt_NameFilter != null)
547
                    {
548
                        items.Where(x => x.DocumnetName.Contains("/" + Docuemnt_NameFilter + "/"));
549
                    }
550
                    if (Service_IDFilter != null)
551
                    {
552
                        items.Where(x => x.ServiceID.Contains("/" + Service_IDFilter + "/"));
553
                    }
554
                    if (UniqueKeyFilter != null)
555
                    {
556
                        items.Where(x => x.UniqueKey.Contains("/" + UniqueKeyFilter + "/"));
557
                    }
558
                    if (Docuemnt_NOFilter != null)
559
                    {
560
                        items.Where(x => x.DocumnetNo.Contains("/" + Docuemnt_NOFilter + "/"));
561
                    }
562
                    if (ReconverterFilter.HasValue)
563
                    {
564
                        items.Where(x => x.ReConverter == ReconverterFilter.Value);
565
                    }
566
                    if (RevisionFilter != null)
567
                    {
568
                        items.Where(x => x.Revision.Contains("/" + RevisionFilter + "/"));
569
                    }
570
                    items = items.Take(SelectedCount.ValueMember).ToList();
571

    
572
                    if (collection.Count() == 0)
573
                    {
574
                        if (statusCodeTypeList.Count() == 1)
575
                        {
576
                            items.ForEach(x => collection.Add(x));
577
                        }
578
                    }
579
                    else
580
                    {
581

    
582
                        ////세미 업데이트
583
                        items.ForEach(newitem =>
584
                        {
585
                            collection.UpdateWhere(changeitem =>
586
                            ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
587
                        });
588

    
589

    
590
                        if (statusCodeTypeList.Count() == 1)
591
                        {
592
                            //삭제
593
                            for (int i = collection.Count() - 1; i >= 0; --i)
594
                            {
595
                                var item = collection[i];
596

    
597
                                if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교
598
                                {//참=> 0제외한 모든 수
599
                                    collection.RemoveAt(i);
600
                                }
601
                            }
602
                        }
603

    
604
                        if (statusCodeTypeList.Count() == 1)
605
                        {
606
                            //추가 convert 후 추가됨
607
                            foreach (var item in items)
608
                            {
609
                                if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감
610
                                {
611
                                    /*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/
612
                                    for (int i = 0; i < 200; i++)
613
                                    {
614
                                        if (i < collection.Count() - 1)
615
                                        {
616
                                            if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0)
617
                                            {
618
                                                collection.Insert(i, item);
619
                                                break;
620
                                            }
621
                                        }
622
                                        else
623
                                        {
624
                                            collection.Add(item);
625
                                            break;
626
                                        }
627
                                    }
628

    
629
                                }
630

    
631
                            }
632
                        }
633

    
634
                    }
635
                }
636

    
637
            }
638
            catch (Exception ex)
639
            {
640
                MessageBox.Show(ex.ToString());
641
            }
642
        }
643

    
644
        /// <summary>
645
        /// 서비스의 실시간 컨버터 Item
646
        /// </summary>
647
        private async void AliveDataSelect()
648
        {
649
            try
650
            {
651
                List<ConvertItem> newitems = new List<ConvertItem>();
652

    
653
                foreach (var client in App.StationClientList)
654
                {
655
                    if (await SimplePingAsync(client.Endpoint.Address.ToString()))
656
                    {
657
                        try
658
                        {
659
                            List<ConvertItem> itemsToList = new List<ConvertItem>();
660
                            var items = await client.AliveConvertListAsync();
661
                            foreach (var item in items)
662
                            {
663
                                ConvertItem itemsToEach = new ConvertItem();
664
                                itemsToEach.ServiceID = item.ServiceID;
665
                                itemsToEach.ConvertID = item.ConvertID;
666
                                itemsToEach.ProjectNumber = item.ProjectNumber;
667

    
668
                                if (item.ConvertState != null)
669
                                {
670
                                    itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState);
671
                                }
672

    
673
                                itemsToEach.CurrentPageNo = item.CurrentPageNo;
674
                                itemsToEach.TotalPage = item.TotalPage;
675
                                itemsToEach.OriginfilePath = item.OriginfilePath;
676
                                itemsToEach.ConvertPath = item.ConvertPath;
677
                                itemsToEach.MarkusLink = item.MarkusLink;
678
                                itemsToEach.UniqueKey = item.UniqueKey;
679
                                itemsToEach.FileName = item.FileName;
680
                                itemsToEach.ConvertPath = item.ConvertPath;
681
                                itemsToEach.CreateTime = item.CreateTime;
682
                                itemsToEach.Exception = item.Exception;
683
                                itemsToEach.ProcessorAffinity = item.ProcessorAffinity;
684
                                itemsToEach.ReConverter = item.ReConverter;
685
                                itemsToEach.DocumentID = item.DocumentID;
686
                                itemsToEach.DocumnetName = item.DocumnetName;
687
                                itemsToEach.GroupNo = item.GroupNo;
688
                                itemsToEach.Revision = item.Revision;
689
                                itemsToEach.StartTime = item.StartTime;
690
                                itemsToEach.EndTime = item.EndTime;
691

    
692

    
693
                                itemsToList.Add(itemsToEach);
694
                            }
695
                            newitems.AddRange(itemsToList);
696
                            System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping");
697

    
698
                            if (items.Count() == 0)
699
                            {
700
                                System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero.");
701
                            }
702
                        }
703
                        catch (Exception ex)
704
                        {
705
                            System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}");
706
                        }
707
                    }
708
                    else
709
                    {
710
                        System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error");
711
                    }
712
                }
713

    
714
                ItemsUpdate(newitems);
715
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems));
716
            }
717
            catch (Exception ex)
718
            {
719
                System.Diagnostics.Debug.WriteLine(ex.ToString());
720
            }
721
        }
722

    
723
        /// <summary>
724
        /// AliveDataSelect의 Data Update
725
        /// </summary>
726
        /// <param name="newitems"></param>
727
        private void ItemsUpdate(List<ConvertItem> newitems)
728
        {
729

    
730
            foreach (var item in newitems)
731
            {
732
                item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath);
733
            }
734

    
735
            if (AliveItems == null)
736
            {
737
                AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>();
738

    
739
                foreach (var item in newitems)
740
                {
741
                    AliveItems.Add(item);
742
                }
743
            }
744
            else
745
            {
746
                /// 데이터 업데이트
747
                newitems.ForEach(newitem =>
748
                {
749
                    AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID);
750
                });
751

    
752
                // 추가
753
                foreach (var item in newitems)
754
                {
755
                    if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
756
                    {
757
                        AliveItems.Add(item);
758
                    }
759
                }
760

    
761
                /// 삭제
762

    
763
                for (int i = AliveItems.Count() - 1; i > -1; --i)
764
                {
765
                    var item = AliveItems[i];
766

    
767
                    if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
768
                    {
769
                        try
770
                        {
771
                            AliveItems.RemoveAt(i);
772
                        }
773
                        catch (Exception ex)
774
                        {
775
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
776
                        }
777
                    }
778
                }
779
            }
780
        }
781

    
782

    
783
        public static async Task<bool> SimplePingAsync(string uri)
784
        {
785
            bool result = false;
786

    
787
            try
788
            {
789
                using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient())
790
                {
791
                    Client.Timeout = new TimeSpan(0, 0, 60);
792

    
793
                    var message = await Client.GetAsync(uri);
794

    
795
                    System.Net.HttpStatusCode StatusCode = message.StatusCode;
796

    
797
                    switch (StatusCode)
798
                    {
799

    
800
                        case System.Net.HttpStatusCode.Accepted:
801
                        case System.Net.HttpStatusCode.OK:
802
                            result = true;
803
                            break;
804
                    }
805
                }
806
            }
807
            catch (Exception ex)
808
            {
809
                result = false;
810
                System.Diagnostics.Debug.WriteLine(ex.ToString());
811
            }
812

    
813
            return result;
814
        }
815

    
816
        #endregion
817

    
818
        #region Data Convert
819

    
820
        private void DataConvert(object obj)
821
        {
822
            if (SelectFilterConvert == null && SelectRealConvert == null)
823
            {
824
                MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!");
825
            }
826
            else
827
            {
828
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
829
                var resultRealConvert = 0;
830
                var resultFiltertConvert = 0;
831

    
832
                if (SelectRealConvert != null)
833
                {
834
                    resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert);
835
                }
836
                else if (SelectFilterConvert != null)
837
                {
838
                    resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert);
839
                }
840
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
841

    
842
                using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString))
843
                {
844
                    var items = database.GetConvertProjects(SelectFilterConvert);
845

    
846
                    foreach (var item in items)
847
                    {
848
                        RealConvertSource.Add(item);
849
                    }
850
                    if (RealConvertSource.Count() == 1)
851
                    {
852
                        ConvertShow = true;
853
                    }
854
                }
855
            }
856
        }
857

    
858
        #endregion
859

    
860
        #region Validation
861

    
862
        private void DataValidate(object obj)
863
        {
864

    
865
            bool result = false;
866

    
867
            WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath);
868
            webRequest.Timeout = 1200; // miliseconds
869
            webRequest.Method = "HEAD";
870

    
871
            HttpWebResponse response = null;
872

    
873
            try
874
            {
875
                response = (HttpWebResponse)webRequest.GetResponse();
876
                result = true;
877
            }
878
            catch (WebException webException)
879
            {
880
                MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message);
881
                result = true;
882
            }
883
            finally
884
            {
885
                if (response != null)
886
                {
887
                    response.Close();
888
                }
889
            }
890
            if (result == true)
891
            {
892
                MessageBox.Show("File exists");
893
            }
894
        }
895

    
896
        #endregion
897

    
898
        #region MarkusLink
899

    
900
        private void MarkusLink(object obj)///여기서 부터 
901
        {
902
            if (obj is ConvertItem)
903
            {
904
                if (obj != null)
905
                {
906
                    var convertitem = obj as ConvertItem;
907

    
908
                    SelectFilterConvert = convertitem;
909

    
910
                    SelectRealConvert = convertitem;
911

    
912
                    ProcessStartInfo startInfo = null;
913

    
914
                    startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink);
915

    
916
                    Process.Start(startInfo);
917
                }
918
            }
919
        }
920

    
921
        #endregion
922

    
923
        #region Data Delete
924

    
925
        private void DataDelete(object obj)
926
        {
927
            RadWindow.Alert("do you want to delete it??", this.OnClosed);
928
        }
929

    
930
        private void OnClosed(object sender, WindowClosedEventArgs e)
931
        {
932
            var result = e.DialogResult;
933
            if (result == true)
934
            {
935
                ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString);
936
                var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID);
937
                var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID);
938
                System.Diagnostics.Debug.WriteLine(resultRealConvert + "  " + resultFiltertConvert);
939
            }
940
        }
941

    
942

    
943
        #endregion
944

    
945
        #region Data Export
946

    
947

    
948
        /// <summary>
949
        /// 필터된 상단 그리드 엑셀로 출력
950
        /// </summary>
951

    
952
        public void DataExportData(object obj)
953
        {
954
            SaveFileDialog saveFileDialog = new SaveFileDialog();
955

    
956
            saveFileDialog.FileName = "Document"; // Default file name
957
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
958
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
959

    
960

    
961
            if (saveFileDialog.ShowDialog() == true)
962
            {
963

    
964

    
965
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
966
                {
967

    
968
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
969

    
970
                    if (extension == ".xlsx" || extension == ".csv")
971
                    {
972

    
973
                        var headers = new List<HeaderMember>
974
                        {
975
                            new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" },
976
                            new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" },
977
                            new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" },
978
                            new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" },
979
                            new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" },
980
                            new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" },
981
                            new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" },
982
                            new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" },
983
                            new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" },
984
                            new HeaderMember{HeaderName = "Exception", Property = "Exception" },
985
                            new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" },
986
                            new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" },
987
                            new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" }
988
                        };
989

    
990

    
991
                        DataExport dataExport = new DataExport();
992
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers);
993
                        //_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(),  Projectsource, headers);
994
                        //GemBoxFileSave(obj);
995
                    }
996
                }
997
            }
998
        }
999

    
1000
        #endregion
1001

    
1002
        #region DetailFilter
1003

    
1004

    
1005
        /// <summary>
1006
        /// Grid Filter
1007
        /// </summary>
1008

    
1009
        private bool DetailFilter(object item)
1010
        {
1011
            var Item = item as ConvertItem;
1012
            if (ProjectNumberFilter == null) return true;
1013
            if (ProjectNumberFilter == Item.ProjectNumber) return true;
1014
            //if (ConvertStateFilter == null) return true;
1015
            //if (ConvertStateFilter == (StatusCodeType)Item.ConvertState) return true;
1016
            if (Docuemnt_NameFilter == null) return true;
1017
            if (Docuemnt_NameFilter == Item.DocumnetName) return true;
1018
            if (Service_IDFilter == null) return true;
1019
            if (Service_IDFilter == Item.ServiceID) return true;
1020
            if (UniqueKeyFilter == null) return true;
1021
            if (UniqueKeyFilter == Item.UniqueKey) return true;
1022
            if (Docuemnt_NOFilter == null) return true;
1023
            if (Docuemnt_NOFilter == Item.DocumnetNo) return true;
1024
            if (ReconverterFilter == null) return true;
1025
            if (ReconverterFilter == Item.ReConverter) return true;
1026
            if (RevisionFilter == null) return true;
1027
            if (RevisionFilter == Item.Revision) return true;
1028

    
1029
            return false;
1030
        }
1031

    
1032
        public void RemoveCreateTimeFilter(object obj)//미완성
1033
        {
1034
            SelectedCreateTimeBegin = DateTime.Now;
1035
            SelectedCreateTimeEnd = DateTime.Now;
1036
        }
1037

    
1038
        #endregion
1039

    
1040
        #endregion
1041
    }
1042
}
1043

    
클립보드 이미지 추가 (최대 크기: 500 MB)