markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / MainViewModel.cs @ 82fd7a58
이력 | 보기 | 이력해설 | 다운로드 (3.6 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 | using Markus.Service.Helper; |
||
8 | using Markus.Service.StationController.StationService; |
||
9 | ed79bff0 | taeseongkim | using MaterialDesignExtensions.Model; |
10 | 53c9637d | taeseongkim | |
11 | namespace Markus.Service.StationController.ViewModel |
||
12 | { |
||
13 | public class MainViewModel : Base.ViewModelBase |
||
14 | { |
||
15 | StationService.StationServiceClient client; |
||
16 | |||
17 | public MainViewModel() |
||
18 | { |
||
19 | a537d79a | taeseongkim | ServiceConnection(); |
20 | 53c9637d | taeseongkim | |
21 | System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); |
||
22 | timer.Interval = new TimeSpan(0, 0, 1); |
||
23 | timer.Tick += Timer_Tick; |
||
24 | timer.Start(); |
||
25 | ed79bff0 | taeseongkim | |
26 | NavigationItems = new List<INavigationItem> |
||
27 | { |
||
28 | 566f0526 | taeseongkim | new SubheaderNavigationItem(){ Subheader = "Service Settings",IsSelected = true }, |
29 | ed79bff0 | taeseongkim | new FirstLevelNavigationItem(){Label = "Service1"}, |
30 | new DividerNavigationItem(), |
||
31 | new FirstLevelNavigationItem(){Label = "Service2"}, |
||
32 | }; |
||
33 | |||
34 | 566f0526 | taeseongkim | SelectNavigationItem = NavigationItems.First(); |
35 | 53c9637d | taeseongkim | } |
36 | |||
37 | a537d79a | taeseongkim | private void ServiceConnection() |
38 | { |
||
39 | try |
||
40 | { |
||
41 | if(client != null) |
||
42 | { |
||
43 | client.Abort(); |
||
44 | client.AliveConvertListCompleted -= Client_AliveConvertListCompleted; |
||
45 | client = null; |
||
46 | } |
||
47 | |||
48 | var configFileName = $"StationController.ini"; |
||
49 | |||
50 | var config = ConfigHelper.AppConfig(configFileName); |
||
51 | |||
52 | 566f0526 | taeseongkim | var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://172.20.101.119:9101/StationService"); |
53 | a537d79a | taeseongkim | |
54 | BasicHttpBinding myBinding = new BasicHttpBinding(); |
||
55 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(serviceUri)); |
||
56 | client = new StationService.StationServiceClient(myBinding, myEndpoint); |
||
57 | client.AliveConvertListCompleted += Client_AliveConvertListCompleted; |
||
58 | } |
||
59 | catch (Exception) |
||
60 | { |
||
61 | } |
||
62 | |||
63 | } |
||
64 | |||
65 | 53c9637d | taeseongkim | private void Timer_Tick(object sender, EventArgs e) |
66 | { |
||
67 | a537d79a | taeseongkim | try |
68 | { |
||
69 | client.AliveConvertListAsync(); |
||
70 | } |
||
71 | catch (Exception ex) |
||
72 | { |
||
73 | ServiceConnection(); |
||
74 | } |
||
75 | 53c9637d | taeseongkim | } |
76 | |||
77 | private void Client_AliveConvertListCompleted(object sender, AliveConvertListCompletedEventArgs e) |
||
78 | { |
||
79 | AliveItems = e.Result; |
||
80 | } |
||
81 | |||
82 | private string id; |
||
83 | |||
84 | public string Id |
||
85 | { |
||
86 | get => id; set |
||
87 | { |
||
88 | id = value; |
||
89 | OnPropertyChanged(() => Id); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | ed79bff0 | taeseongkim | private List<StationService.ConvertItem> aliveItems; |
94 | |||
95 | 53c9637d | taeseongkim | public List<ConvertItem> AliveItems |
96 | { |
||
97 | get => aliveItems; set |
||
98 | { |
||
99 | aliveItems = value; |
||
100 | OnPropertyChanged(() => AliveItems); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | ed79bff0 | taeseongkim | private List<INavigationItem> navigationItems; |
105 | |||
106 | 566f0526 | taeseongkim | public List<INavigationItem> NavigationItems |
107 | { |
||
108 | ed79bff0 | taeseongkim | get => navigationItems; set |
109 | { |
||
110 | navigationItems = value; |
||
111 | OnPropertyChanged(() => navigationItems); |
||
112 | } |
||
113 | } |
||
114 | 566f0526 | taeseongkim | |
115 | private INavigationItem selectNavigationItem; |
||
116 | |||
117 | public INavigationItem SelectNavigationItem |
||
118 | { |
||
119 | get => selectNavigationItem; set |
||
120 | { |
||
121 | selectNavigationItem = value; |
||
122 | OnPropertyChanged(() => SelectNavigationItem); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | |||
127 | 53c9637d | taeseongkim | } |
128 | } |