markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseByStatusViewModel.cs @ 06f13e11
이력 | 보기 | 이력해설 | 다운로드 (3.43 KB)
1 |
|
---|---|
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 |
using Markus.Message; |
10 |
using Markus.Service.WcfClient.StationServiceTask; |
11 |
|
12 |
namespace Markus.Service.StationController.ViewModel |
13 |
{ |
14 |
public class DataBaseByStatusViewModel : Mvvm.ToolKit.ViewModelBase |
15 |
{ |
16 |
BackgroundWorker backgroundWorker; |
17 |
|
18 |
private List<ConvertItem> items; |
19 |
private StatusCodeType statusType; |
20 |
private bool isLoading; |
21 |
|
22 |
public List<ConvertItem> Items |
23 |
{ |
24 |
get => items; set |
25 |
{ |
26 |
items = value; |
27 |
OnPropertyChanged(() => Items); |
28 |
} |
29 |
} |
30 |
|
31 |
|
32 |
public StatusCodeType StatusType |
33 |
{ |
34 |
get => statusType; set |
35 |
{ |
36 |
statusType = value; |
37 |
OnPropertyChanged(() => StatusType); |
38 |
} |
39 |
} |
40 |
|
41 |
public bool IsLoading |
42 |
{ |
43 |
get => isLoading; set |
44 |
{ |
45 |
if (isLoading != value) |
46 |
{ |
47 |
isLoading = value; |
48 |
OnPropertyChanged(() => IsLoading); |
49 |
} |
50 |
} |
51 |
} |
52 |
|
53 |
public DataBaseByStatusViewModel() |
54 |
{ |
55 |
} |
56 |
|
57 |
// 진행률에 변화가 있을때 이벤트가 발생 |
58 |
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
59 |
{ |
60 |
} |
61 |
|
62 |
// 일이 모두 마쳤을때 수행되어야할 코드 |
63 |
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
64 |
{ |
65 |
} |
66 |
|
67 |
// BackgroundWorker에서 수행할 일을 정의. |
68 |
private async void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
69 |
{ |
70 |
while (IsAcitve) |
71 |
{ |
72 |
System.Threading.Thread.Sleep(1000); |
73 |
|
74 |
try |
75 |
{ |
76 |
IsLoading = true; |
77 |
|
78 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
79 |
|
80 |
foreach (var client in App.StationClientList) |
81 |
{ |
82 |
var items = await client.AliveConvertListAsync(); |
83 |
|
84 |
newitems.AddRange(items); |
85 |
} |
86 |
|
87 |
newitems.Update(Items); |
88 |
|
89 |
Items = newitems; |
90 |
|
91 |
} |
92 |
catch (Exception ex) |
93 |
{ |
94 |
} |
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
public override void Loaded() |
100 |
{ |
101 |
base.Loaded(); |
102 |
|
103 |
backgroundWorker = new BackgroundWorker(); |
104 |
backgroundWorker.DoWork += backgroundWorker_DoWork; |
105 |
backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
106 |
backgroundWorker.WorkerReportsProgress = false; |
107 |
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
108 |
|
109 |
backgroundWorker.RunWorkerAsync(); |
110 |
} |
111 |
|
112 |
public override void Closed() |
113 |
{ |
114 |
backgroundWorker.DoWork -= backgroundWorker_DoWork; |
115 |
backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
116 |
backgroundWorker.WorkerReportsProgress = false; |
117 |
backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
118 |
|
119 |
backgroundWorker.Dispose(); |
120 |
|
121 |
base.Closed(); |
122 |
} |
123 |
} |
124 |
} |