프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / AliveViewModel.cs @ e19522be

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

1
using Markus.Service.StationController.StationService;
2
using System;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8
using Markus.Service.Extensions;
9

    
10

    
11
namespace Markus.Service.StationController.ViewModel
12
{
13
    public class AliveViewModel :Mvvm.ToolKit.ViewModelBase
14
    {
15
        BackgroundWorker backgroundWorker;
16

    
17
        private List<StationService.ConvertItem> aliveItems;
18
        private bool isLoading;
19

    
20
        public List<ConvertItem> AliveItems
21
        {
22
            get => aliveItems; set
23
            {
24
                aliveItems = value;
25
                OnPropertyChanged(() => AliveItems);
26
            }
27
        }
28

    
29
        public bool IsLoading
30
        {
31
            get => isLoading; set
32
            {
33
                if (isLoading != value)
34
                {
35
                    isLoading = value;
36
                    OnPropertyChanged(() => IsLoading);
37
                }
38
            }
39
        }
40

    
41
        public AliveViewModel()
42
        {
43
        }
44

    
45
        // 진행률에 변화가 있을때 이벤트가 발생
46
        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
47
        {
48
        }
49

    
50
        // 일이 모두 마쳤을때 수행되어야할 코드
51
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
52
        {
53
        }
54

    
55
        // BackgroundWorker에서 수행할 일을 정의.
56
        private async void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
57
        {
58
            while (IsAcitve)
59
            {
60
                System.Threading.Thread.Sleep(1000);
61

    
62
                try
63
                {
64
                    IsLoading = true;
65

    
66
                    List<ConvertItem> newitems = new List<ConvertItem>();
67

    
68
                    foreach (var client in App.StationClientList)
69
                    {
70
                        newitems.AddRange(await client.AliveConvertListAsync());
71
                    }
72

    
73
                  newitems.Update(AliveItems);
74

    
75
                    AliveItems = newitems;
76

    
77
                }
78
                catch (Exception ex)
79
                {
80
                }
81
            }
82
            
83
        }
84

    
85
        public override void Loaded()
86
        {
87
            base.Loaded();
88

    
89
            backgroundWorker = new BackgroundWorker();
90
            backgroundWorker.DoWork += backgroundWorker_DoWork;
91
            backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
92
            backgroundWorker.WorkerReportsProgress = false;
93
            backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
94

    
95
            backgroundWorker.RunWorkerAsync();
96
        }
97

    
98
        public override void Closed()
99
        {
100
            backgroundWorker.DoWork -= backgroundWorker_DoWork;
101
            backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted;
102
            backgroundWorker.WorkerReportsProgress = false;
103
            backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
104

    
105
            backgroundWorker.Dispose();
106

    
107
            base.Closed();
108
        }
109
    }
110
}
클립보드 이미지 추가 (최대 크기: 500 MB)