HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.HdlBackup
{
    /// <summary>
    /// 网关列表的备份界面
    /// </summary>
    public class HdlGatewayListBackUpForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listview = null;
        /// <summary>
        /// 生成的网关状态控件暂时存入内存中
        /// </summary>
        private Dictionary<string, GatewayRowControl> dicRowContr = new Dictionary<string, GatewayRowControl>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uGatewayBackup));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            listview = new VerticalScrolViewLayout();
            listview.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listview);
 
            //设定中部信息
            this.SetMiddleFrameInfo();
        }
 
        /// <summary>
        /// 设定中部信息
        /// </summary>
        private void SetMiddleFrameInfo()
        {
            //设置接受在线状态推送
            this.AddGatewayOnlinePush();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                List<ZbGateway> listway = HdlGatewayLogic.Current.GetAllLocalGateway();
                if (listway.Count == 0)
                {
                    return;
                }
                //开启进度条
                this.ShowProgressBar();
 
                Application.RunOnMainThread(() =>
                {
                    for (int i = 0; i < listway.Count; i++)
                    {
                        //添加行
                        this.AddRowLayout(HdlGatewayLogic.Current.GetGatewayId(listway[i]));
                    }
                    this.CloseProgressBar();
                    //开启网关在线监测的线程
                    this.StartGatewayOnlieCheckThread(listway);
                });
            });
        }
 
        #endregion
 
        #region ■ 添加网关行_________________________
 
        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="strWayId">String way.</param>
        public void AddRowLayout(string strWayId)
        {
            //网关控件
            var Gateway = HdlGatewayLogic.Current.GetLocalGateway(strWayId);
            var gatewayRow = new GatewayRowControl(Gateway);
            listview.AddChidren(gatewayRow);
            //向右图标
            gatewayRow.frameTable.AddRightArrow();
 
            //提示有新版本
            var btnNew = new InformationTipView(gatewayRow.btnIcon);
            btnNew.Visible = false;
            gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
            gatewayRow.AddTag("btnNew", btnNew);
 
            this.dicRowContr[strWayId] = gatewayRow;
 
            //单击事件
            gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //如果点击的是不在线的网关,则当什么事都没有发生
                if (gatewayRow.IsOnline == false)
                {
                    //指定的网关不在线
                    this.ShowMassage(ShowMsgType.Normal, Language.StringByID(R.MyInternationalizationString.uTheGatewayIsNotOnline));
                    return;
                }
                //如果存在新版本,并且单击他的话
                if (btnNew.Visible == true)
                {
                    if (sender is InformationTipView || sender is IconViewControl)
                    {
                        //打开编辑界面
                        btnNew.Visible = false;
                        var form = new GatewayManage.GatewayInfoEditorForm();
                        form.AddForm(Gateway);
                        return;
                    }
                }
                ZbGateway realWay = null;
                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, strWayId) == false)
                {
                    //错误:网关对象丢失
                    string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
                    this.ShowMassage(ShowMsgType.Tip, msg);
                    return;
                }
                var form2 = new HdlGatewayBackUpForm();
                form2.AddForm(realWay);
            };
        }
 
        #endregion
 
        #region ■ 网关在线检测_______________________
 
        /// <summary>
        /// 开启网关在线监测的线程
        /// </summary>
        /// <param name="listway"></param>
        private void StartGatewayOnlieCheckThread(List<ZbGateway> listway)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(300);
                //刷新网关在线状态
                HdlGatewayLogic.Current.RefreshGatewayOnlineStatu(listway);
                foreach (var way in listway)
                {
                    if (this.Parent == null)
                    {
                        return;
                    }
                    bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way);
                    this.GatewayOnlinePush(way, online);
                }
                //网关新版本检测
                this.CheckGatewayNewVersion(listway);
            });
        }
 
        /// <summary>
        /// 网关在线状态变更
        /// </summary>
        /// <param name="gateWay">网关对象</param>
        /// <param name="online">在线状态变更后的状态</param>
        public override void GatewayOnlinePush(ZbGateway gateWay, bool online)
        {
            Application.RunOnMainThread(() =>
            {
                if (this.Parent == null)
                {
                    return;
                }
                string gwid = HdlGatewayLogic.Current.GetGatewayId(gateWay);
                if (this.dicRowContr.ContainsKey(gwid) == true)
                {
                    this.dicRowContr[gwid].RefreshControl(gateWay);
                }
            });
        }
 
        #endregion
 
        #region ■ 网关新版本检测_____________________
 
        /// <summary>
        /// 网关新版本检测
        /// </summary>
        /// <param name="listWays"></param>
        private async void CheckGatewayNewVersion(List<ZbGateway> listWays)
        {
            foreach (var way in listWays)
            {
                if (this.Parent == null)
                {
                    return;
                }
                if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way) == false)
                {
                    //不在线的不用理它
                    continue;
                }
                //获取最新版本
                var result = await HdlGatewayLogic.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO);
                if (result == null)
                {
                    continue;
                }
                if (result[0] != null || result[1] != null || result[2] != null)
                {
                    //有新版本
                    string gwid = HdlGatewayLogic.Current.GetGatewayId(way);
                    Application.RunOnMainThread(() =>
                    {
                        if (this.dicRowContr.ContainsKey(gwid) == true)
                        {
                            var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
                            btnNew.Visible = true;
                        }
                    });
                }
            }
        }
 
        #endregion
    }
}