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 RowNewVersionTipView();
|
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 = (RowNewVersionTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
|
btnNew.Visible = true;
|
}
|
});
|
}
|
}
|
}
|
|
#endregion
|
}
|
}
|