markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / MainViewModel.cs @ 45f9a2ad
이력 | 보기 | 이력해설 | 다운로드 (4.41 KB)
1 | 53c9637d | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.ServiceModel; |
||
5 | using System.Text; |
||
6 | using System.Threading.Tasks; |
||
7 | 45f9a2ad | taeseongkim | using System.Windows.Input; |
8 | using Markus.Mvvm.ToolKit; |
||
9 | 53c9637d | taeseongkim | using Markus.Service.Helper; |
10 | using Markus.Service.StationController.StationService; |
||
11 | ed79bff0 | taeseongkim | using MaterialDesignExtensions.Model; |
12 | 53c9637d | taeseongkim | |
13 | namespace Markus.Service.StationController.ViewModel |
||
14 | { |
||
15 | 45f9a2ad | taeseongkim | public class MainViewModel : ViewModelBase |
16 | 53c9637d | taeseongkim | { |
17 | StationService.StationServiceClient client; |
||
18 | 45f9a2ad | taeseongkim | System.Windows.Threading.DispatcherTimer timer; |
19 | bool IsTimer; |
||
20 | 53c9637d | taeseongkim | |
21 | 45f9a2ad | taeseongkim | #region Command |
22 | |||
23 | private ICommand _ClosingCommand; |
||
24 | public ICommand ClosingCommand |
||
25 | { |
||
26 | get => _ClosingCommand ?? (_ClosingCommand = new RelayCommand(param => this.Closing())); |
||
27 | } |
||
28 | |||
29 | private ICommand _LoadedCommand; |
||
30 | public ICommand LoadedCommand |
||
31 | { |
||
32 | get => _LoadedCommand ?? (_LoadedCommand = new RelayCommand(param => this.Loaded())); |
||
33 | } |
||
34 | |||
35 | #endregion Command |
||
36 | |||
37 | #region 프로퍼티 |
||
38 | |||
39 | private string id; |
||
40 | |||
41 | public string Id |
||
42 | { |
||
43 | get => id; set |
||
44 | { |
||
45 | id = value; |
||
46 | OnPropertyChanged(() => Id); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | private List<StationService.ConvertItem> aliveItems; |
||
51 | |||
52 | public List<ConvertItem> AliveItems |
||
53 | { |
||
54 | get => aliveItems; set |
||
55 | { |
||
56 | aliveItems = value; |
||
57 | OnPropertyChanged(() => AliveItems); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | private List<INavigationItem> navigationItems; |
||
62 | |||
63 | public List<INavigationItem> NavigationItems |
||
64 | { |
||
65 | get => navigationItems; set |
||
66 | { |
||
67 | navigationItems = value; |
||
68 | OnPropertyChanged(() => navigationItems); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | private INavigationItem selectNavigationItem; |
||
73 | |||
74 | public INavigationItem SelectNavigationItem |
||
75 | { |
||
76 | get => selectNavigationItem; set |
||
77 | { |
||
78 | selectNavigationItem = value; |
||
79 | OnPropertyChanged(() => SelectNavigationItem); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | #endregion 프로퍼티 |
||
84 | |||
85 | private void Loaded() |
||
86 | 53c9637d | taeseongkim | { |
87 | 45f9a2ad | taeseongkim | IsTimer = true; |
88 | |||
89 | a537d79a | taeseongkim | ServiceConnection(); |
90 | 53c9637d | taeseongkim | |
91 | 45f9a2ad | taeseongkim | timer = new System.Windows.Threading.DispatcherTimer(); |
92 | 53c9637d | taeseongkim | timer.Interval = new TimeSpan(0, 0, 1); |
93 | timer.Tick += Timer_Tick; |
||
94 | timer.Start(); |
||
95 | ed79bff0 | taeseongkim | |
96 | NavigationItems = new List<INavigationItem> |
||
97 | { |
||
98 | 566f0526 | taeseongkim | new SubheaderNavigationItem(){ Subheader = "Service Settings",IsSelected = true }, |
99 | ed79bff0 | taeseongkim | new FirstLevelNavigationItem(){Label = "Service1"}, |
100 | new DividerNavigationItem(), |
||
101 | new FirstLevelNavigationItem(){Label = "Service2"}, |
||
102 | }; |
||
103 | |||
104 | 566f0526 | taeseongkim | SelectNavigationItem = NavigationItems.First(); |
105 | 53c9637d | taeseongkim | } |
106 | |||
107 | 45f9a2ad | taeseongkim | private void Closing() |
108 | { |
||
109 | IsTimer = false; |
||
110 | } |
||
111 | |||
112 | a537d79a | taeseongkim | private void ServiceConnection() |
113 | { |
||
114 | try |
||
115 | { |
||
116 | if(client != null) |
||
117 | { |
||
118 | client.Abort(); |
||
119 | client.AliveConvertListCompleted -= Client_AliveConvertListCompleted; |
||
120 | client = null; |
||
121 | } |
||
122 | |||
123 | var configFileName = $"StationController.ini"; |
||
124 | |||
125 | var config = ConfigHelper.AppConfig(configFileName); |
||
126 | |||
127 | 566f0526 | taeseongkim | var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://172.20.101.119:9101/StationService"); |
128 | a537d79a | taeseongkim | |
129 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
130 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(serviceUri)); |
||
131 | client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
132 | client.AliveConvertListCompleted += Client_AliveConvertListCompleted; |
||
133 | } |
||
134 | catch (Exception) |
||
135 | { |
||
136 | } |
||
137 | |||
138 | } |
||
139 | |||
140 | 53c9637d | taeseongkim | private void Timer_Tick(object sender, EventArgs e) |
141 | { |
||
142 | a537d79a | taeseongkim | try |
143 | { |
||
144 | 45f9a2ad | taeseongkim | if (!IsTimer) |
145 | { |
||
146 | timer.Stop(); |
||
147 | } |
||
148 | |||
149 | a537d79a | taeseongkim | client.AliveConvertListAsync(); |
150 | } |
||
151 | catch (Exception ex) |
||
152 | { |
||
153 | ServiceConnection(); |
||
154 | } |
||
155 | 53c9637d | taeseongkim | } |
156 | |||
157 | private void Client_AliveConvertListCompleted(object sender, AliveConvertListCompletedEventArgs e) |
||
158 | { |
||
159 | AliveItems = e.Result; |
||
160 | } |
||
161 | |||
162 | 566f0526 | taeseongkim | |
163 | |||
164 | 53c9637d | taeseongkim | } |
165 | } |