From b74c052b43d7c4a830386940a036eb7c2ec9abc2 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期二, 14 一月 2020 13:37:26 +0800
Subject: [PATCH] 2020-1-14-01
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 324 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 203 insertions(+), 121 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index 168cc2b..ea5c735 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -117,10 +117,20 @@
{
return;
}
+
+ List<string> listBackupGwId = new List<string>();
+ var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
+ if (fileData != null)
+ {
+ //鏂板锛氳櫧鐒舵鐜囦綆锛屼絾鏄‘瀹炲彂鐢熶簡銆傚鏋滄湁缃戠粶鏃讹紝App閲嶆柊缁戝畾璁板綍鐨勭綉鍏冲け璐ョ殑璇�
+ //涓嶅簲璇ュ垹闄ゅ畠
+ listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
+ }
+
List<string> listDelete = new List<string>();
foreach (var gatewayId in this.dicGateway.Keys)
{
- if (result.ContainsKey(gatewayId) == false)
+ if (result.ContainsKey(gatewayId) == false && listBackupGwId.Contains(gatewayId) == false)
{
//鏈湴瀛樺湪浜戠涓嶅瓨鍦ㄧ殑缃戝叧锛屽垯鍒犻櫎
listDelete.Add(gatewayId);
@@ -707,7 +717,7 @@
//绉婚櫎
ZbGateway.GateWayList.RemoveAll((obj) => this.GetGatewayId(obj) == zbGatewayID);
//鏂紑mqtt杩炴帴
- realWay.DisConnect("GD");
+ realWay.DisConnectLocalMqttClient("GD");
return true;
}
@@ -1043,14 +1053,14 @@
this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
return -1;
}
- ChannelIdInfo data = null;
+ int data = -1;
Action<string, string> action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon")
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- data = Newtonsoft.Json.JsonConvert.DeserializeObject<ChannelIdInfo>(jobject["Data"].ToString());
+ data = Convert.ToInt32(jobject["Data"]["Channel"].ToString());
}
};
realWay.Actions += action;
@@ -1059,34 +1069,22 @@
realWay.Send("ZbGw/GetChannel", jObject.ToString());
int TimeOut = 0;
- while (data == null && TimeOut < 30)
+ while (data == -1 && TimeOut < 30)
{
System.Threading.Thread.Sleep(100);
TimeOut++;
}
realWay.Actions -= action;
- if (data == null)
+ if (data == -1)
{
//鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐�
string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
this.ShowTipMsg(msg);
- return -1;
}
- return data.Channel;
- }
-
- /// <summary>
- /// 缃戝叧淇¢亾淇℃伅
- /// </summary>
- private class ChannelIdInfo
- {
- /// <summary>
- /// 缃戝叧淇¢亾
- /// </summary>
- public int Channel = -1;
+ return data;
}
#endregion
@@ -1107,14 +1105,14 @@
this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
return null;
}
- CoordinatorMacInfo data = null;
+ string data = null;
Action<string, string> action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon")
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- data = Newtonsoft.Json.JsonConvert.DeserializeObject<CoordinatorMacInfo>(jobject["Data"].ToString());
+ data = jobject["Data"]["MacAddr"].ToString();
}
};
realWay.Actions += action;
@@ -1136,21 +1134,9 @@
string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
this.ShowTipMsg(msg);
- return null;
}
- return data.MacAddr;
- }
-
- /// <summary>
- /// 缃戝叧鍗忚皟鍣∕ac淇℃伅
- /// </summary>
- private class CoordinatorMacInfo
- {
- /// <summary>
- /// 璋冨櫒Mac
- /// </summary>
- public string MacAddr = string.Empty;
+ return data;
}
#endregion
@@ -1171,14 +1157,14 @@
this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
return -1;
}
- PanIdInfo data = null;
+ int panId = -1;
Action<string, string> action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
if (topic == gatewayID + "/" + "ZbGw/GetPanId_Respon")
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- data = Newtonsoft.Json.JsonConvert.DeserializeObject<PanIdInfo>(jobject["Data"].ToString());
+ panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString());
}
};
realWay.Actions += action;
@@ -1187,34 +1173,128 @@
realWay.Send("ZbGw/GetPanId", jObject.ToString());
int TimeOut = 0;
- while (data == null && TimeOut < 30)
+ while (panId == -1 && TimeOut < 30)
{
System.Threading.Thread.Sleep(100);
TimeOut++;
}
realWay.Actions -= action;
- if (data == null)
+ if (panId == -1)
{
//鑾峰彇鍗忚皟鍣≒anID澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
this.ShowTipMsg(msg);
- return -1;
}
- return data.PANID;
+ return panId;
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧鑷姩澶囦唤璁剧疆___________________
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧鑷姩澶囦唤璁剧疆(-1:寮傚父 0:鍏抽棴 1:鎵撳紑)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public int GetGatewayAutoBackupStatu(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return -1;
+ }
+ int statu = -1;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/GatewayAutoBackup_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ statu = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", 1 } };
+ jObject.Add("Data", data);
+ realWay.Send("GatewayAutoBackup", jObject.ToString());
+
+ int TimeOut = 0;
+ while (statu == -1 && TimeOut < 60)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (statu == -1)
+ {
+ //鑾峰彇缃戝叧鑷姩澶囦唤璁剧疆澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayAutoBackupStatuFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ }
+
+ return statu;
}
/// <summary>
- /// 缃戝叧PanId淇℃伅
+ /// 璁剧疆缃戝叧鑷姩澶囦唤璁剧疆
/// </summary>
- private class PanIdInfo
+ /// <param name="zbGateway"></param>
+ /// <param name="statu"></param>
+ /// <returns></returns>
+ public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu)
{
- /// <summary>
- /// PanId
- /// </summary>
- public int PANID = -1;
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return false;
+ }
+ int result = -1;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/GatewayAutoBackup_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ result = Convert.ToInt32(jobject["Data"]["AutoBackupStatus"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6205 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "AutoBackup", statu == true ? 2 : 3 } };
+ jObject.Add("Data", data);
+ realWay.Send("GatewayAutoBackup", jObject.ToString());
+
+ int TimeOut = 0;
+ while (result == -1 && TimeOut < 60)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (result == -1)
+ {
+ //璁剧疆缃戝叧鑷姩澶囦唤澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewayAutoBackupStatuFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ return false;
+ }
+
+ return true;
}
#endregion
@@ -1486,7 +1566,7 @@
//鏈�鍚庡啀鏂紑mqtt杩炴帴
for (int i = 0; i < list.Count; i++)
{
- list[i].DisConnect("G");
+ list[i].DisConnectLocalMqttClient("G");
}
list.Clear();
}
@@ -1763,50 +1843,6 @@
realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
}
- #endregion
-
- #region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <summary>
- /// 寮瑰嚭缃戝叧涓嶅湪绾跨殑
- /// </summary>
- private void ShowGatewayNotOnlineMsg()
- {
- Application.RunOnMainThread(() =>
- {
- //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁�
- string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork);
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
- });
- }
-
- /// <summary>
- /// 鏄剧ず閿欒淇℃伅绐楀彛
- /// </summary>
- /// <param name="msg"></param>
- private void ShowErrorMsg(string msg)
- {
- Application.RunOnMainThread(() =>
- {
- var contr = new ShowMsgControl(ShowMsgType.Error, msg);
- contr.Show();
- });
- }
-
- /// <summary>
- /// 鏄剧ずTip淇℃伅绐楀彛
- /// </summary>
- /// <param name="msg"></param>
- private void ShowTipMsg(string msg)
- {
- Application.RunOnMainThread(() =>
- {
- var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
- contr.Show();
- });
- }
-
#endregion
#region 鈻� 缃戝叧鐩戣___________________________
@@ -2010,17 +2046,19 @@
{
return;
}
- //鑾峰彇褰撳墠鎺ュ彈鍦ㄧ嚎鐘舵�佹帹閫佺殑鐣岄潰
- var listForm = new List<CommonFormBase>();
- listForm.AddRange(UserCenterResourse.listGatewayOnlinePushForm);
- if (listForm.Count > 0)
+ //淇濆瓨褰撳墠婵�娲荤殑鐣岄潰ID
+ var listId = new List<string>();
+ listId.AddRange(UserCenterResourse.listActionFormId);
+ for (int i = 0; i < listId.Count; i++)
{
- for (int i = 0; i < listChange.Count; i++)
+ if (UserCenterResourse.DicActionForm.ContainsKey(listId[i]) == false)
{
- foreach (var form in listForm)
- {
- form?.GatewayOnlinePush(listChange[i], listChangeStatu[i]);
- }
+ continue;
+ }
+ //缃戝叧鍦ㄧ嚎鎺ㄩ��
+ for (int j = 0; j < listChange.Count; j++)
+ {
+ UserCenterResourse.DicActionForm[listId[i]]?.GatewayOnlinePush(listChange[j], listChangeStatu[j]);
}
}
}
@@ -2317,27 +2355,27 @@
/// <returns></returns>
public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData)
{
- ZbGateway realWay = null;
- if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
- {
- //娌℃湁鎵惧埌鐪熷疄鐗╃悊缃戝叧
- return false;
- }
- string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
- //鍒涘缓鏂囦欢瀵硅薄
- var result = await realWay.CreateFileAsync(fileName);
- if (result == null || result.Result != 0)
- {
- return false;
- }
- //鍙戦�佹暟鎹祦
- var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
- var byteData = System.Text.Encoding.UTF8.GetBytes(data);
- var result2 = await realWay.SendFileAsync(byteData);
- if (result2 == null || result2.Result != 0)
- {
- return false;
- }
+ //ZbGateway realWay = null;
+ //if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
+ //{
+ // //娌℃湁鎵惧埌鐪熷疄鐗╃悊缃戝叧
+ // return false;
+ //}
+ //string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
+ ////鍒涘缓鏂囦欢瀵硅薄
+ //var result = await realWay.CreateFileAsync(fileName);
+ //if (result == null || result.Result != 0)
+ //{
+ // return false;
+ //}
+ ////鍙戦�佹暟鎹祦
+ //var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
+ //var byteData = System.Text.Encoding.UTF8.GetBytes(data);
+ //var result2 = await realWay.SendFileAsync(byteData);
+ //if (result2 == null || result2.Result != 0)
+ //{
+ // return false;
+ //}
return true;
}
@@ -2574,5 +2612,49 @@
}
#endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 寮瑰嚭缃戝叧涓嶅湪绾跨殑
+ /// </summary>
+ private void ShowGatewayNotOnlineMsg()
+ {
+ Application.RunOnMainThread(() =>
+ {
+ //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁�
+ string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork);
+ var control = new ShowMsgControl(ShowMsgType.Tip, msg);
+ control.Show();
+ });
+ }
+
+ /// <summary>
+ /// 鏄剧ず閿欒淇℃伅绐楀彛
+ /// </summary>
+ /// <param name="msg"></param>
+ private void ShowErrorMsg(string msg)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+ contr.Show();
+ });
+ }
+
+ /// <summary>
+ /// 鏄剧ずTip淇℃伅绐楀彛
+ /// </summary>
+ /// <param name="msg"></param>
+ private void ShowTipMsg(string msg)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+ contr.Show();
+ });
+ }
+
+ #endregion
}
}
--
Gitblit v1.8.0