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 : UserCenterCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalScrolViewLayout listview = null;
|
/// <summary>
|
/// 生成的网关状态控件暂时存入内存中
|
/// </summary>
|
private Dictionary<string, GatewayViewRow> dicRowContr = new Dictionary<string, GatewayViewRow>();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uGatewayBackup));
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
listview = new VerticalScrolViewLayout();
|
listview.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listview);
|
|
//设定中部信息
|
this.SetMiddleFrameInfo();
|
}
|
|
/// <summary>
|
/// 设定中部信息
|
/// </summary>
|
private void SetMiddleFrameInfo()
|
{
|
//设置接受在线状态推送
|
this.AddGatewayOnlinePush();
|
|
new System.Threading.Thread(() =>
|
{
|
List<ZbGateway> listway = Common.LocalGateway.Current.GetAllLocalGateway();
|
if (listway.Count == 0)
|
{
|
return;
|
}
|
//开启进度条
|
this.ShowProgressBar();
|
|
Application.RunOnMainThread(() =>
|
{
|
for (int i = 0; i < listway.Count; i++)
|
{
|
//添加行
|
this.AddRowLayout(Common.LocalGateway.Current.GetGatewayId(listway[i]));
|
}
|
this.CloseProgressBar();
|
//开启网关在线监测的线程
|
this.StartGatewayOnlieCheckThread(listway);
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
#endregion
|
|
#region ■ 添加网关行_________________________
|
|
/// <summary>
|
/// 添加行
|
/// </summary>
|
/// <param name="strWayId">String way.</param>
|
public void AddRowLayout(string strWayId)
|
{
|
//网关控件
|
var Gateway = LocalGateway.Current.GetLocalGateway(strWayId);
|
var gatewayRow = new GatewayViewRow(listview, Gateway);
|
//向右图标
|
gatewayRow.AddRightIconControl();
|
|
//提示有新版本
|
var btnNew = new InformationTipView(gatewayRow.btnIcon);
|
btnNew.Visible = false;
|
gatewayRow.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
|
gatewayRow.AddTag("btnNew", btnNew);
|
|
this.dicRowContr[strWayId] = gatewayRow;
|
|
//单击事件
|
gatewayRow.MouseUpEvent += (sender, e) =>
|
{
|
//如果点击的是不在线的网关,则当什么事都没有发生
|
if (gatewayRow.IsOnline == false)
|
{
|
//指定的网关不在线
|
this.ShowNormalMsg(Language.StringByID(R.MyInternationalizationString.uTheGatewayIsNotOnline));
|
return;
|
}
|
//如果存在新版本,并且单击他的话
|
if (btnNew.Visible == true)
|
{
|
if (sender is InformationTipView || sender is RowLeftIconView)
|
{
|
//打开编辑界面
|
btnNew.Visible = false;
|
var form = new Gateway.GatewayInfoEditorForm();
|
this.AddForm(form, Gateway);
|
return;
|
}
|
}
|
ZbGateway realWay = null;
|
if (Common.LocalGateway.Current.GetRealGateway(ref realWay, strWayId) == false)
|
{
|
//错误:网关对象丢失
|
string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
this.ShowTip(msg);
|
return;
|
}
|
var form2 = new HdlGatewayBackUpForm();
|
this.AddForm(form2, realWay);
|
};
|
}
|
|
#endregion
|
|
#region ■ 网关在线检测_______________________
|
|
/// <summary>
|
/// 开启网关在线监测的线程
|
/// </summary>
|
/// <param name="listway"></param>
|
private void StartGatewayOnlieCheckThread(List<ZbGateway> listway)
|
{
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(300);
|
//刷新网关在线状态
|
Common.LocalGateway.Current.RefreshGatewayOnlineStatu(listway);
|
foreach (var way in listway)
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
bool online = Common.LocalGateway.Current.CheckGatewayOnlineByFlag(way);
|
this.GatewayOnlinePush(way, online);
|
}
|
//网关新版本检测
|
this.CheckGatewayNewVersion(listway);
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <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 = Common.LocalGateway.Current.GetGatewayId(gateWay);
|
if (this.dicRowContr.ContainsKey(gwid) == true)
|
{
|
this.dicRowContr[gwid].zbGateway = gateWay;
|
this.dicRowContr[gwid].RefreshControl(online);
|
}
|
});
|
}
|
|
#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 (Common.LocalGateway.Current.CheckGatewayOnlineByFlag(way) == false)
|
{
|
//不在线的不用理它
|
continue;
|
}
|
//获取最新版本
|
var result = await Common.LocalGateway.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO);
|
if (result == null)
|
{
|
continue;
|
}
|
if (result[0] != null || result[1] != null || result[2] != null)
|
{
|
//有新版本
|
string gwid = Common.LocalGateway.Current.GetGatewayId(way);
|
Application.RunOnMainThread(() =>
|
{
|
if (this.dicRowContr.ContainsKey(gwid) == true)
|
{
|
var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
|
btnNew.Visible = true;
|
}
|
});
|
}
|
}
|
}
|
|
#endregion
|
}
|
}
|