프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / MainViewModel.cs @ a537d79a

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

1
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
using MaterialDesignExtensions.Model;
10

    
11
namespace Markus.Service.StationController.ViewModel
12
{
13
    public class MainViewModel : Base.ViewModelBase
14
    {
15
        StationService.StationServiceClient client;
16

    
17
        public MainViewModel()
18
        {
19
            ServiceConnection();
20

    
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

    
26
            NavigationItems = new List<INavigationItem>
27
            {
28
                new SubheaderNavigationItem(){ Subheader = "Service Settings" },
29
                new FirstLevelNavigationItem(){Label = "Service1"},
30
                new DividerNavigationItem(),
31
                new FirstLevelNavigationItem(){Label = "Service2"},
32
            };
33

    
34
            NavigationItems.First().IsSelected = true;
35
        }
36

    
37
        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
                var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://LOCALHOST:9101/StationService");
53

    
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
        private void Timer_Tick(object sender, EventArgs e)
66
        {
67
            try
68
            {
69
                client.AliveConvertListAsync();
70
            }
71
            catch (Exception ex)
72
            {
73
                ServiceConnection();
74
            }
75
        }
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
        private List<StationService.ConvertItem> aliveItems;
94

    
95
        public List<ConvertItem> AliveItems
96
        {
97
            get => aliveItems; set
98
            {
99
                aliveItems = value;
100
                OnPropertyChanged(() => AliveItems);
101
            }
102
        }
103

    
104
        private List<INavigationItem> navigationItems;
105

    
106
        public List<INavigationItem> NavigationItems {
107
            get => navigationItems; set
108
            {
109
                navigationItems = value;
110
                OnPropertyChanged(() => navigationItems);
111
            }
112
        }
113
    }
114
}
클립보드 이미지 추가 (최대 크기: 500 MB)