From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 4703 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 2,445 insertions(+), 2,258 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
old mode 100755
new mode 100644
index 9631ac2..b261ec2
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -1,194 +1,190 @@
-锘縰sing Newtonsoft.Json;
-using Shared.Common;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
- /// <summary>
- /// 缃戝叧涓氬姟鐨勯�昏緫绫�
- /// </summary>
- public class HdlGatewayLogic
- {
- #region 鈻� 鍙橀噺澹版槑___________________________
-
- /// <summary>
- /// 缃戝叧涓氬姟鐨勯�昏緫绫�
+锘縰sing Newtonsoft.Json;
+using Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+ /// <summary>
+ /// 缃戝叧涓氬姟鐨勯�昏緫绫�
+ /// </summary>
+ public class HdlGatewayLogic
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// 缃戝叧涓氬姟鐨勯�昏緫绫�
/// </summary>
private static HdlGatewayLogic m_Current = null;
- /// <summary>
- /// 缃戝叧涓氬姟鐨勯�昏緫绫�
+ /// <summary>
+ /// 缃戝叧涓氬姟鐨勯�昏緫绫�
/// </summary>
- public static HdlGatewayLogic Current
- {
- get
- {
- if (m_Current == null)
- {
- m_Current = new HdlGatewayLogic();
- }
- return m_Current;
- }
- }
- /// <summary>
- /// 澶囦唤鐢ㄧ殑缃戝叧ID
- /// </summary>
- private List<string> listBackupGwId = new List<string>();
- /// <summary>
- /// 缃戝叧鏂囦欢鐨勫墠缂�鍚嶅瓧
- /// </summary>
+ public static HdlGatewayLogic Current
+ {
+ get
+ {
+ if (m_Current == null)
+ {
+ m_Current = new HdlGatewayLogic();
+ }
+ return m_Current;
+ }
+ }
+ /// <summary>
+ /// 缃戝叧鏂囦欢鐨勫墠缂�鍚嶅瓧
+ /// </summary>
private string gwFirstName = "Gateway_";
/// <summary>
/// 鍏ㄩ儴缃戝叧(杩欓噷淇濆瓨鐨勬槸铏氭嫙缃戝叧,鑰屼笉鏄湡瀹炵墿鐞嗙綉鍏冲璞�)
/// </summary>
- private Dictionary<string, ZbGateway> dicGateway = new Dictionary<string, ZbGateway>();
-
+ private Dictionary<string, ZbGateway> dicGateway = new Dictionary<string, ZbGateway>();
+
#endregion
-
- #region 鈻� 鍒锋柊缃戝叧___________________________
-
- /// <summary>
- /// 鍒锋柊鏈湴缃戝叧淇℃伅
- /// </summary>
- public void ReFreshByLocal()
- {
- lock (dicGateway)
- {
- this.dicGateway.Clear();
-
- List<string> listFile = this.GetAllGatewayFile();
- //鍙嶅簭鍒楀寲娣诲姞鍒扮紦瀛�
- foreach (string file in listFile)
- {
- //浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
- var gateway = this.GetGatewayFromFile(file);
- if (gateway == null)
- {
- continue;
- }
- //娣诲姞缂撳瓨
- dicGateway[gateway.GwId] = gateway;
- }
- }
- }
- /// <summary>
- /// 鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D
+ #region 鈻� 鍒锋柊缃戝叧___________________________
+
+ /// <summary>
+ /// 鍒锋柊鏈湴缃戝叧淇℃伅
/// </summary>
- public void RefreshAppOldSelectGatewayId()
- {
- GatewayResourse.AppOldSelectGatewayId = string.Empty;
-
- //浠庢枃浠朵腑鑾峰彇涓婁竴娆¢�夋嫨鐨勭綉鍏砳d
- byte[] data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.AppOldSelectGatewayFile);
- if (data != null)
- {
- string strvalue = System.Text.Encoding.UTF8.GetString(data);
- GatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue);
- }
- //濡傛灉鏈湴娌℃湁杩欎釜缃戝叧鐨勮瘽
- if (this.IsGatewayExist(GatewayResourse.AppOldSelectGatewayId) == false)
- {
- GatewayResourse.AppOldSelectGatewayId = string.Empty;
- lock (dicGateway)
- {
- //闅忎究閫変竴涓綉鍏�
- foreach (string wayId in this.dicGateway.Keys)
- {
- GatewayResourse.AppOldSelectGatewayId = wayId;
- break;
- }
- }
- }
+ public void ReFreshByLocal()
+ {
+ lock (dicGateway)
+ {
+ this.dicGateway.Clear();
+
+ List<string> listFile = this.GetAllGatewayFile();
+ //鍙嶅簭鍒楀寲娣诲姞鍒扮紦瀛�
+ foreach (string file in listFile)
+ {
+ //浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
+ var gateway = this.GetGatewayFromFile(file);
+ if (gateway == null)
+ {
+ continue;
+ }
+ //娣诲姞缂撳瓨
+ dicGateway[gateway.GwId] = gateway;
+ }
+ }
}
- /// <summary>
- /// 鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�(鍒囨崲浣忓畢鍚庯紝閲嶆柊鍒锋柊缃戝叧鍒楄〃鍜岃澶囦箣鍚庝娇鐢�)
- /// </summary>
+ /// <summary>
+ /// 鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D
+ /// </summary>
+ public void RefreshAppOldSelectGatewayId()
+ {
+ GatewayResourse.AppOldSelectGatewayId = string.Empty;
+
+ //浠庢枃浠朵腑鑾峰彇涓婁竴娆¢�夋嫨鐨勭綉鍏砳d
+ byte[] data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.AppOldSelectGatewayFile);
+ if (data != null)
+ {
+ string strvalue = System.Text.Encoding.UTF8.GetString(data);
+ GatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue);
+ }
+ //濡傛灉鏈湴娌℃湁杩欎釜缃戝叧鐨勮瘽
+ if (this.IsGatewayExist(GatewayResourse.AppOldSelectGatewayId) == false)
+ {
+ GatewayResourse.AppOldSelectGatewayId = string.Empty;
+ lock (dicGateway)
+ {
+ //闅忎究閫変竴涓綉鍏�
+ foreach (string wayId in this.dicGateway.Keys)
+ {
+ GatewayResourse.AppOldSelectGatewayId = wayId;
+ break;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�(鍒囨崲浣忓畢鍚庯紝閲嶆柊鍒锋柊缃戝叧鍒楄〃鍜岃澶囦箣鍚庝娇鐢�)
+ /// </summary>
/// <returns></returns>
- public void SynchronizeDbGateway()
- {
- //浠庝簯绔幏鍙栫綉鍒楄〃ID
- Dictionary<string, GatewayResult> result = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
- if (result == null)
- {
- return;
- }
-
- List<string> listBackupGwId = new List<string>();
- var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
- if (fileData != null)
- {
- //鏂板锛氳櫧鐒舵鐜囦綆锛屼絾鏄‘瀹炲彂鐢熶簡銆傚鏋滄湁缃戠粶鏃讹紝App閲嶆柊缁戝畾璁板綍鐨勭綉鍏冲け璐ョ殑璇�
- //涓嶅簲璇ュ垹闄ゅ畠
- listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
- }
-
+ public void SynchronizeDbGateway()
+ {
+ //浠庝簯绔幏鍙栫綉鍒楄〃ID
+ Dictionary<string, GatewayResult> result = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
+ if (result == null)
+ {
+ return;
+ }
+
+ var listBackupGwId = new List<string>();
+ var fileData = HdlFileLogic.Current.ReadFileByteContent(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 && listBackupGwId.Contains(gatewayId) == false)
- {
- //鏈湴瀛樺湪浜戠涓嶅瓨鍦ㄧ殑缃戝叧锛屽垯鍒犻櫎
- listDelete.Add(gatewayId);
- }
- }
- foreach (var gatewayId in listDelete)
- {
- //鍒犻櫎鏈湴杩欎釜缃戝叧鎵�鏈夌殑璁惧
- List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
- foreach (var device in list)
- {
- //鍒犻櫎涓�鑸澶�
- Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
- //鍒犻櫎Ota璁惧
- Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
- }
- //鍒犻櫎缃戝叧鏂囦欢
- this.DeleteGatewayFile(gatewayId);
- }
- //濡傛灉缃戝叧閮芥病浜嗙殑璇�,鎶婂満鏅叏閮ㄥ垹浜�
- if (listDelete.Count > 0 && this.GetAllLocalGateway().Count == 0)
- {
- HdlSceneLogic.Current.DeleteAllLocalScene();
- }
+ foreach (var gatewayId in this.dicGateway.Keys)
+ {
+ if (result.ContainsKey(gatewayId) == false && listBackupGwId.Contains(gatewayId) == false)
+ {
+ //鏈湴瀛樺湪浜戠涓嶅瓨鍦ㄧ殑缃戝叧锛屽垯鍒犻櫎
+ listDelete.Add(gatewayId);
+ }
+ }
+ foreach (var gatewayId in listDelete)
+ {
+ //鍒犻櫎鏈湴杩欎釜缃戝叧鎵�鏈夌殑璁惧
+ List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
+ foreach (var device in list)
+ {
+ //鍒犻櫎涓�鑸澶�
+ Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+ //鍒犻櫎Ota璁惧
+ Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
+ }
+ //鍒犻櫎缃戝叧鏂囦欢
+ this.DeleteGatewayFile(gatewayId);
+ }
+ //濡傛灉缃戝叧閮芥病浜嗙殑璇�,鎶婂満鏅叏閮ㄥ垹浜�
+ if (listDelete.Count > 0 && this.GetAllLocalGateway().Count == 0)
+ {
+ HdlSceneLogic.Current.DeleteAllLocalScene();
+ }
}
- /// <summary>
- /// 浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
- /// </summary>
- /// <param name="file"></param>
+ /// <summary>
+ /// 浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
+ /// </summary>
+ /// <param name="file"></param>
/// <returns></returns>
- private ZbGateway GetGatewayFromFile(string file)
- {
- try
- {
- byte[] filebyte = Global.ReadFileByHomeId(file);
- string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
- var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue);
- if (gateway.GwId == string.Empty)
- {
- //杩欐槸鏃ф暟鎹�,闇�瑕佺壒娈婂鐞�
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(strvalue);
- string gwInfo = jobject["getGwInfo"].ToString();
-
- var result = JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(gwInfo);
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(gateway, result);
- }
- if (gateway.HomeId == string.Empty)
- {
- gateway.HomeId = Config.Instance.Home.Id;
- }
- return gateway;
- }
- catch (Exception ex)
- {
- HdlLogLogic.Current.WriteLog(ex);
- return null;
- }
+ private ZbGateway GetGatewayFromFile(string file)
+ {
+ try
+ {
+ byte[] filebyte = Global.ReadFileByHomeId(file);
+ string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
+ var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue);
+ if (gateway.GwId == string.Empty)
+ {
+ //杩欐槸鏃ф暟鎹�,闇�瑕佺壒娈婂鐞�
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(strvalue);
+ string gwInfo = jobject["getGwInfo"].ToString();
+
+ var result = JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(gwInfo);
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(gateway, result);
+ }
+ if (gateway.HomeId == string.Empty)
+ {
+ gateway.HomeId = Config.Instance.Home.Id;
+ }
+ return gateway;
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex);
+ return null;
+ }
}
#endregion
@@ -200,497 +196,543 @@
/// </summary>
/// <param name="zbGateway">缃戝叧</param>
/// <param name="mode">鏄惁鏄剧ず閿欒</param>
- public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
- {
- //璁剧疆缃戝叧鐨勭粡绾害
+ /// <param name="logMode">鏄惁鍐橪og</param>
+ public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO)
+ {
+ //璁剧疆缃戝叧鐨勭粡绾害
bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO);
- if (falge == false)
- {
- return falge;
+ if (falge == false)
+ {
+ if (logMode == WriteLogMode.YES)
+ {
+ HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 璁剧疆缁忕含搴﹀け璐�");
+ }
+ return falge;
}
//鎵ц娣诲姞缃戝叧鍒板唴瀛�
- var result = this.DoAddGatewayToMemory(zbGateway, mode);
- //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
- if (result == 0)
- {
- if (mode == ShowErrorMode.YES)
- {
- //缃戝叧缁戝畾鍦ㄥ綋鍓嶈处鍙蜂笅鐨勫叾浠栦綇瀹呴噷\r\n璇疯В闄ょ粦瀹氬悗鍐嶈瘯
- string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
- if (msg.Contains("{0}") == true)
- {
- msg = string.Format(msg, "\r\n");
- }
- this.ShowTipMsg(msg);
- }
- return false;
- }
- if (result == -1)
- {
- return false;
+ var result = this.DoAddGatewayToMemory(zbGateway, mode, logMode);
+ //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
+ if (result == 0)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //缃戝叧缁戝畾鍦ㄥ綋鍓嶈处鍙蜂笅鐨勫叾浠栦綇瀹呴噷\r\n璇疯В闄ょ粦瀹氬悗鍐嶈瘯
+ string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
+ if (msg.Contains("{0}") == true)
+ {
+ msg = string.Format(msg, "\r\n");
+ }
+ this.ShowTipMsg(msg);
+ }
+ if (logMode == WriteLogMode.YES)
+ {
+ HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰,浜戠涓嶇粰缁戝畾");
+ }
+ return false;
+ }
+ if (result == -1)
+ {
+ return false;
}
//娣诲姞缃戝叧鐨勮瘽,寮哄埗涓婚〉鍒锋柊
UserView.UserPage.Instance.RefreshAllForm = true;
+ if (Config.Instance.Home.TemplateMode == 2)
+ {
+ //濡傛灉杩欎釜绫诲瀷鐨勭綉鍏冲彧鏈変竴涓ā鏉�,鍒欒嚜鍔ㄥ尮閰�
+ var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
+ if (dicName.Count == 1)
+ {
+ foreach (var tempId in dicName.Keys)
+ {
+ TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
+ break;
+ }
+ }
+ }
+
return true;
- }
-
- /// <summary>
- /// 鍒涘缓涓�涓櫄鎷熺殑缃戝叧瀵硅薄
- /// </summary>
- /// <param name="gatewayId">缃戝叧ID</param>
- public void AddVirtualGateway(string gatewayId)
- {
- var gateWay = new ZbGateway { IsVirtual = true };
- gateWay.GwId = gatewayId;
- gateWay.HomeId = Shared.Common.Config.Instance.HomeId;
- gateWay.ReSave();
- this.dicGateway[gatewayId] = gateWay;
- }
-
- /// <summary>
- /// 鎵ц娣诲姞缃戝叧鍒板唴瀛�(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <param name="mode">鏄惁鏄剧ず閿欒</param>
- /// <returns></returns>
- private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
- {
- if (zbGateway == null)
- {
- if (mode == ShowErrorMode.YES)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
- }
- return -1;
- }
- //鑾峰彇缃戝叧鐨勪俊鎭�
- var result = this.GetGatewayInfo(zbGateway, true, mode);
- if (result == null)
- {
- if (mode == ShowErrorMode.YES)
- {
- //鑾峰彇缃戝叧淇℃伅澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
- this.ShowTipMsg(msg);
- }
- return -1;
- }
-
- //璁剧疆浣忓畢ID鍒扮綉鍏�
- if (result.HomeId != Common.Config.Instance.HomeId)
- {
- bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
- if (flage2 == false)
- {
- if (mode == ShowErrorMode.YES)
- {
- //鍚戠綉鍏宠缃綇瀹匢D澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
- this.ShowTipMsg(msg);
- }
- return -1;
- }
- }
-
- //鏇存柊浜戠鏁版嵁搴�
- int flage1 = this.SetGatewayIdToDataBase(zbGateway);
- //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
- if (flage1 == 0)
- {
- return flage1;
- }
- if (flage1 == -1)
- {
- //澶囦唤澶辫触鐨勭綉鍏矷D
- this.BackupGatewayIdOnNotNetwork(zbGateway);
- }
-
- //鏄惁宸茬粡瀛樺湪
- string gwID = zbGateway.GwId;
- bool isEsist = this.IsGatewayExist(zbGateway);
- if (isEsist == false)
- {
- //鏂板缓涓�涓櫄鎷熺殑缃戝叧鍑烘潵
- zbGateway.ReSave();
- var way = this.GetGatewayFromFile(zbGateway.FilePath);
- this.dicGateway[gwID] = way;
- }
-
- //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
- this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
- //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
- this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
-
- if (isEsist == false)
- {
- //娣诲姞澶囦唤
- HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
- }
-
- return 1;
- }
-
- /// <summary>
- /// 璁剧疆浣忓畢ID鍒扮綉鍏�(澶辫触鏃�,涓嶅脊鍑轰换浣曢敊璇俊鎭�,缃戝叧鏂綉闄ゅ)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <param name="HomeId"></param>
+ }
+
+ /// <summary>
+ /// 鍒涘缓涓�涓櫄鎷熺殑缃戝叧瀵硅薄
+ /// </summary>
+ /// <param name="gatewayId">缃戝叧ID</param>
+ public void AddVirtualGateway(string gatewayId)
+ {
+ var gateWay = new ZbGateway { IsVirtual = true };
+ gateWay.GwId = gatewayId;
+ gateWay.HomeId = Shared.Common.Config.Instance.HomeId;
+ gateWay.ReSave();
+ this.dicGateway[gatewayId] = gateWay;
+ }
+
+ /// <summary>
+ /// 鎵ц娣诲姞缃戝叧鍒板唴瀛�(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="mode">鏄惁鏄剧ず閿欒</param>
+ /// <param name="logMode">鏄惁鍐橪og</param>
/// <returns></returns>
- public bool SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
- {
- //璐﹀彿ID
- string accountId = string.Empty;
- if (HomeId != string.Empty)
- {
- if (UserCenterResourse.UserInfo.AuthorityNo == 1)
- {
- //涓昏处鍙�
- accountId = Config.Instance.Guid;
- }
- else
- {
- accountId = Config.Instance.Home.MainUserDistributedMark;
- }
- }
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
- var data = new Newtonsoft.Json.Linq.JObject { { "HomeId", HomeId }, { "AccountId", accountId } };
- jObject.Add("Data", data);
- //浣忓畢ID鐨勮缃�,鍥哄畾浣跨敤灞�鍩熺綉,涓嶅瓨鍦ㄨ繙绋嬬殑璇存硶
- var result = this.SendJobjectDataToGateway(zbGateway, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
- if (result.ErrorMsgDiv == -1)
- {
- if (mode == ShowErrorMode.YES)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
- }
- return false;
- }
- if (result.ErrorMsgDiv == 0)
- {
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// 鏇存柊缃戝叧ID鍒颁簯绔暟鎹簱(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO)
+ {
+ if (zbGateway == null)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ }
+ return -1;
+ }
+ //鑾峰彇缃戝叧鐨勪俊鎭�
+ var result = this.GetGatewayInfo(zbGateway, true, mode);
+ if (result == null)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //鑾峰彇缃戝叧淇℃伅澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
+ this.ShowTipMsg(msg);
+ }
+ if (logMode == WriteLogMode.YES)
+ {
+ HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 鑾峰彇缃戝叧淇℃伅澶辫触");
+ }
+ return -1;
+ }
+
+ //璁剧疆浣忓畢ID鍒扮綉鍏�
+ if (result.HomeId != Common.Config.Instance.HomeId)
+ {
+ bool flage2 = this.SetHomeIdToGateway(zbGateway.GwId, Common.Config.Instance.HomeId, mode);
+ if (flage2 == false)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //鍚戠綉鍏宠缃綇瀹匢D澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
+ this.ShowTipMsg(msg);
+ }
+ if (logMode == WriteLogMode.YES)
+ {
+ HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 鍚戠綉鍏宠缃綇瀹匢D澶辫触");
+ }
+ return -1;
+ }
+ }
+
+ //鏇存柊浜戠鏁版嵁搴�
+ int flage1 = this.SetGatewayIdToDataBase(zbGateway);
+ //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
+ if (flage1 == 0)
+ {
+ return flage1;
+ }
+ if (flage1 == -1)
+ {
+ //澶囦唤澶辫触鐨勭綉鍏矷D
+ this.BackupGatewayIdOnNotNetwork(zbGateway);
+ }
+
+ //鏄惁宸茬粡瀛樺湪
+ string gwID = zbGateway.GwId;
+ bool isEsist = this.IsGatewayExist(zbGateway);
+ if (isEsist == false)
+ {
+ //鏂板缓涓�涓櫄鎷熺殑缃戝叧鍑烘潵
+ zbGateway.ReSave();
+ var way = this.GetGatewayFromFile(zbGateway.FilePath);
+ this.dicGateway[gwID] = way;
+ }
+
+ //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
+ this.dicGateway[gwID].OnlineTime = DateTime.Now;
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
+ //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
+ this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
+
+ if (isEsist == false)
+ {
+ //娣诲姞澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+ }
+
+ return 1;
+ }
+
+ /// <summary>
+ /// 璁剧疆浣忓畢ID鍒扮綉鍏�(澶辫触鏃�,涓嶅脊鍑轰换浣曢敊璇俊鎭�,缃戝叧鏂綉闄ゅ)
+ /// </summary>
+ /// <param name="i_gwId"></param>
+ /// <param name="HomeId"></param>
+ /// <returns></returns>
+ public bool SetHomeIdToGateway(string i_gwId, string HomeId, ShowErrorMode mode)
+ {
+ //璐﹀彿ID
+ string accountId = string.Empty;
+ if (HomeId != string.Empty)
+ {
+ if (UserCenterResourse.UserInfo.AuthorityNo == 1)
+ {
+ //涓昏处鍙�
+ accountId = Config.Instance.Guid;
+ }
+ else
+ {
+ accountId = Config.Instance.Home.MainUserDistributedMark;
+ }
+ }
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "HomeId", HomeId }, { "AccountId", accountId } };
+ jObject.Add("Data", data);
+ //浣忓畢ID鐨勮缃�,鍥哄畾浣跨敤灞�鍩熺綉,涓嶅瓨鍦ㄨ繙绋嬬殑璇存硶
+ var result = this.SendJobjectDataToGateway(i_gwId, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
+ if (result.ErrorMsgDiv == -1)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ }
+ return false;
+ }
+ if (result.ErrorMsgDiv == 0)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// 鏇存柊缃戝叧ID鍒颁簯绔暟鎹簱(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
/// <returns></returns>
private int SetGatewayIdToDataBase(ZbGateway zbGateway)
- {
- //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖true寰�涓嬭蛋)
- var bindGateway = new BindGatewayPra();
- bindGateway.BindGateways.Add(zbGateway.GwId);
- //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+ {
+ //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖true寰�涓嬭蛋)
+ var bindGateway = new BindGatewayPra();
+ bindGateway.BindGateways.Add(zbGateway.GwId);
+ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
- if (result == "Error")
- {
- return -1;
+ if (result == "Error")
+ {
+ return -1;
}
- if (result == "BindGatewaysExists")
- {
- return 0;
+ if (result == "BindGatewaysExists")
+ {
+ return 0;
}
return result == "Success" ? 1 : -1;
- }
-
- /// <summary>
- /// 浣忓畢ID鏄惁涓虹┖
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public bool HomeIdIsEmpty(ZbGateway zbGateway)
- {
- return this.HomeIdIsEmpty(zbGateway.HomeId);
}
- /// <summary>
- /// 浣忓畢ID鏄惁涓虹┖
- /// </summary>
- /// <param name="HomeId"></param>
- /// <returns></returns>
- public bool HomeIdIsEmpty(string HomeId)
- {
- if (string.IsNullOrEmpty(HomeId) == true || HomeId[0] == '\0')
- {
- return true;
- }
- return false;
- }
-
+ /// <summary>
+ /// 浣忓畢ID鏄惁涓虹┖
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public bool HomeIdIsEmpty(ZbGateway zbGateway)
+ {
+ return this.HomeIdIsEmpty(zbGateway.HomeId);
+ }
+
+ /// <summary>
+ /// 浣忓畢ID鏄惁涓虹┖
+ /// </summary>
+ /// <param name="HomeId"></param>
+ /// <returns></returns>
+ public bool HomeIdIsEmpty(string HomeId)
+ {
+ if (string.IsNullOrEmpty(HomeId) == true || HomeId[0] == '\0')
+ {
+ return true;
+ }
+ return false;
+ }
+
#endregion
-
+
#region 鈻� 閲嶆柊缁戝畾缃戝叧_______________________
-
+
/// <summary>
/// 閲嶆柊缁戝畾缃戝叧(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
/// </summary>
/// <param name="zbGateway">缃戝叧</param>
/// <param name="btnMsg">娑堟伅鎺т欢</param>
public int ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
- {
- if (zbGateway == null)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
- return -1;
- }
- //璁剧疆缃戝叧鐨勭粡绾害
+ {
+ if (zbGateway == null)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ return -1;
+ }
+ //璁剧疆缃戝叧鐨勭粡绾害
bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES);
- if (falge == false)
- {
- return -1;
- }
-
- //璁剧疆浣忓畢ID鍒扮綉鍏�
- bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
- if (flage2 == false)
- {
- //鍚戠綉鍏宠缃綇瀹匢D澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
- this.ShowTipMsg(msg);
- return -1;
- }
-
- //鏇存柊浜戠鏁版嵁搴�
- int flage1 = this.SetGatewayIdToDataBase(zbGateway);
- //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
- if (flage1 == 0)
- {
- return flage1;
- }
- if (flage1 == -1)
- {
- //澶囦唤澶辫触鐨勭綉鍏矷D
- HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
- }
-
- if (btnMsg == null)
- {
- //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
- ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
- }
- else
- {
- HdlThreadLogic.Current.RunMain(() =>
- {
- //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
- btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
- });
- }
- System.Threading.Thread.Sleep(8000);
-
- //鑾峰彇缃戝叧鐨勪俊鎭�
- ZbGatewayData.GetGwData result = null;
- int count = 5;
- while (count >= 0)
- {
- result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
- if (result != null)
- {
- break;
- }
- count--;
- //鏈�澶氬啀绛�20绉�
- System.Threading.Thread.Sleep(4000);
- }
- if (result == null)
- {
- //鑾峰彇缃戝叧淇℃伅澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
- this.ShowTipMsg(msg);
- return -1;
- }
-
- //鏄惁宸茬粡瀛樺湪
- string gwID = zbGateway.GwId;
+ if (falge == false)
+ {
+ return -1;
+ }
+
+ //璁剧疆浣忓畢ID鍒扮綉鍏�
+ bool flage2 = this.SetHomeIdToGateway(zbGateway.GwId, Common.Config.Instance.HomeId, ShowErrorMode.YES);
+ if (flage2 == false)
+ {
+ //鍚戠綉鍏宠缃綇瀹匢D澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
+ this.ShowTipMsg(msg);
+ return -1;
+ }
+
+ //鏇存柊浜戠鏁版嵁搴�
+ int flage1 = this.SetGatewayIdToDataBase(zbGateway);
+ //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
+ if (flage1 == 0)
+ {
+ return flage1;
+ }
+ if (flage1 == -1)
+ {
+ //澶囦唤澶辫触鐨勭綉鍏矷D
+ HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
+ }
+
+ if (btnMsg == null)
+ {
+ //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
+ ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
+ }
+ else
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚�
+ btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
+ });
+ }
+ System.Threading.Thread.Sleep(8000);
+
+ //鑾峰彇缃戝叧鐨勪俊鎭�
+ ZbGatewayData.GetGwData result = null;
+ int count = 5;
+ while (count >= 0)
+ {
+ result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+ if (result != null)
+ {
+ break;
+ }
+ count--;
+ //鏈�澶氬啀绛�20绉�
+ System.Threading.Thread.Sleep(4000);
+ }
+ if (result == null)
+ {
+ //鑾峰彇缃戝叧淇℃伅澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
+ this.ShowTipMsg(msg);
+ return -1;
+ }
+
+ //鏄惁宸茬粡瀛樺湪
+ string gwID = zbGateway.GwId;
bool isEsist = HdlGatewayLogic.Current.IsGatewayExist(zbGateway);
- if (isEsist == false)
- {
- //鏂板缓涓�涓櫄鎷熺殑缃戝叧鍑烘潵
- zbGateway.ReSave();
- var way = this.GetGatewayFromFile(zbGateway.FilePath);
- this.dicGateway[gwID] = way;
- }
-
- //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
- this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
- //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
- this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
-
- if (isEsist == false)
- {
- //娣诲姞澶囦唤
- HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
- }
-
- //娣诲姞缃戝叧鐨勮瘽,寮哄埗涓婚〉鍒锋柊
- UserView.UserPage.Instance.RefreshAllForm = true;
-
+ if (isEsist == false)
+ {
+ //鏂板缓涓�涓櫄鎷熺殑缃戝叧鍑烘潵
+ zbGateway.ReSave();
+ var way = this.GetGatewayFromFile(zbGateway.FilePath);
+ this.dicGateway[gwID] = way;
+ }
+
+ //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
+ this.dicGateway[gwID].OnlineTime = DateTime.Now;
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
+ //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
+ this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
+
+ if (isEsist == false)
+ {
+ //娣诲姞澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+ }
+
+ //娣诲姞缃戝叧鐨勮瘽,寮哄埗涓婚〉鍒锋柊
+ UserView.UserPage.Instance.RefreshAllForm = true;
+
+ if (Config.Instance.Home.TemplateMode == 2)
+ {
+ //濡傛灉杩欎釜绫诲瀷鐨勭綉鍏冲彧鏈変竴涓ā鏉�,鍒欒嚜鍔ㄥ尮閰�
+ var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
+ if (dicName.Count == 1)
+ {
+ foreach (var tempId in dicName.Keys)
+ {
+ TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
+ break;
+ }
+ }
+ }
+
return 1;
}
#endregion
-
+
#region 鈻� 淇敼缃戝叧___________________________
-
+
/// <summary>
/// 淇敼鏈湴缃戝叧鍚嶅瓧(澶辫触鏃朵細鏄剧ず淇℃伅)
/// </summary>
/// <param name="zbGateway">缃戝叧瀵硅薄</param>
/// <param name="gatewayName">缃戝叧鍚�</param>
public bool ReName(ZbGateway zbGateway, string gatewayName)
- {
- //鍙彇32涓猙yte
- var bytes = new byte[32];
- var reamarkGwBytes = System.Text.Encoding.UTF8.GetBytes(gatewayName);
- System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length);
- gatewayName = System.Text.Encoding.UTF8.GetString(bytes);
-
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 91 } };
- var data = new Newtonsoft.Json.Linq.JObject { { "GwName", gatewayName } };
- jObject.Add("Data", data);
- var result = this.SendJobjectDataToGateway(zbGateway, "GwReName", jObject.ToString(), "GwReName_Respon");
- if (result.ErrorMsg != null)
- {
- this.ShowTipMsg(result.ErrorMsg);
- return false;
- }
- if (result.ErrorMsgDiv == 0)
- {
- //缃戝叧鍚嶇О淇敼澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
+ {
+ //鍙彇32涓猙yte
+ var bytes = new byte[32];
+ var reamarkGwBytes = System.Text.Encoding.UTF8.GetBytes(gatewayName);
+ System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length);
+ gatewayName = System.Text.Encoding.UTF8.GetString(bytes);
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 91 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "GwName", gatewayName } };
+ jObject.Add("Data", data);
+ var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GwReName", jObject.ToString(), "GwReName_Respon");
+ if (result.ErrorMsg != null)
+ {
+ this.ShowTipMsg(result.ErrorMsg);
+ return false;
+ }
+ if (result.ErrorMsgDiv == 0)
+ {
+ //缃戝叧鍚嶇О淇敼澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
//缃戝叧鍥炲瓒呮椂
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
this.ShowTipMsg(msg);
return false;
- }
-
- //淇敼缂撳瓨
+ }
+
+ //淇敼缂撳瓨
string gwID = zbGateway.GwId;
this.dicGateway[gwID].GwName = gatewayName;
- this.dicGateway[gwID].ReSave();
-
- //娣诲姞鑷姩澶囦唤
+ this.dicGateway[gwID].ReSave();
+
+ //娣诲姞鑷姩澶囦唤
HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath);
return true;
- }
-
+ }
+
#endregion
-
- #region 鈻� 缃戝叧鍒囨崲___________________________
-
- /// <summary>
- /// 鎵ц鍒囨崲缃戝叧鎿嶄綔
- /// </summary>
- /// <param name="gatewayId"></param>
- public bool DoSwitchGateway(string gatewayId)
- {
- //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
- var result = this.GetOnlineGatewayInfo(gatewayId);
- if (result == false)
- {
- return false;
- }
-
- //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
- this.SaveGatewayIdToLocation(gatewayId);
- //鍒囨崲缃戝叧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
- UserView.UserPage.Instance.RefreshAllForm = true;
-
- return true;
- }
-
- /// <summary>
- /// 鑾峰彇鍦ㄧ嚎缃戝叧淇℃伅
- /// </summary>
- /// <param name="gatewayId"></param>
- /// <returns></returns>
- private bool GetOnlineGatewayInfo(string gatewayId)
- {
- //鏄剧ず杩涘害鏉�
- ProgressBar.Show();
-
- //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
- ZbGateway realWay = null;
- bool getGatewayInfo = true;
- if (this.GetRealGateway(ref realWay, gatewayId) == true)
- {
- //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
- if (this.HomeIdIsEmpty(realWay.HomeId) == true)
- {
- int result2 = this.ReBindNewGateway(realWay);
- if (result2 == 0)
- {
- //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇�
- this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
- //鍏抽棴杩涘害鏉�
- ProgressBar.Close();
- }
- else if (result2 == -1)
- {
- //鍏抽棴杩涘害鏉�
- ProgressBar.Close();
- return false;
- }
- //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭�
- getGatewayInfo = false;
- }
- }
-
- if (getGatewayInfo == true)
- {
- //鑾峰彇缃戝叧淇℃伅
- var info = this.GetGatewayInfo(realWay, false);
- if (info == null)
- {
- //鍏抽棴杩涘害鏉�
- ProgressBar.Close();
- return false;
- }
- }
- //鍒锋柊鍏ㄩ儴鍦烘櫙
- if (this.IsMainGateway(realWay) == 1)
- {
- HdlSceneLogic.Current.RefreshSceneUIList(false);
- }
-
- //鑾峰彇鍏ㄩ儴璁惧
- int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay, false);
- //鍏抽棴杩涘害鏉�
- ProgressBar.Close();
- if (result == -1)
- {
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// 淇濆瓨閫夋嫨鐨勭綉鍏矷D鍒版湰鍦�
- /// </summary>
- /// <param name="gatewayId"></param>
- public void SaveGatewayIdToLocation(string gatewayId)
- {
- GatewayResourse.AppOldSelectGatewayId = gatewayId;
- HdlFileLogic.Current.SaveFileContent(DirNameResourse.AppOldSelectGatewayFile, GatewayResourse.AppOldSelectGatewayId);
- }
-
+
+ #region 鈻� 缃戝叧鍒囨崲___________________________
+
+ /// <summary>
+ /// 鎵ц鍒囨崲缃戝叧鎿嶄綔
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ public bool DoSwitchGateway(string gatewayId)
+ {
+ //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
+ var result = this.GetOnlineGatewayInfo(gatewayId);
+ if (result == false)
+ {
+ return false;
+ }
+
+ //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
+ this.SaveGatewayIdToLocation(gatewayId);
+ //鍒囨崲缃戝叧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
+ UserView.UserPage.Instance.RefreshAllForm = true;
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍦ㄧ嚎缃戝叧淇℃伅
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ /// <returns></returns>
+ private bool GetOnlineGatewayInfo(string gatewayId)
+ {
+ //鏄剧ず杩涘害鏉�
+ ProgressBar.Show();
+
+ //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
+ ZbGateway realWay = null;
+ bool getGatewayInfo = true;
+ if (this.GetRealGateway(ref realWay, gatewayId) == true)
+ {
+ //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
+ if (this.HomeIdIsEmpty(realWay.HomeId) == true)
+ {
+ int result2 = this.ReBindNewGateway(realWay);
+ if (result2 == 0)
+ {
+ //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇�
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ }
+ else if (result2 == -1)
+ {
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ return false;
+ }
+ //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭�
+ getGatewayInfo = false;
+ }
+ }
+
+ if (getGatewayInfo == true)
+ {
+ //鑾峰彇缃戝叧淇℃伅
+ var info = this.GetGatewayInfo(realWay, false);
+ if (info == null)
+ {
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ return false;
+ }
+ }
+ //鍒锋柊鍏ㄩ儴鍦烘櫙
+ if (this.IsMainGateway(realWay) == 1)
+ {
+ HdlSceneLogic.Current.RefreshSceneUIList(false);
+ }
+
+ //鑾峰彇鍏ㄩ儴璁惧
+ int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false);
+ //鍏抽棴杩涘害鏉�
+ ProgressBar.Close();
+ if (result == -1)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// 淇濆瓨閫夋嫨鐨勭綉鍏矷D鍒版湰鍦�
+ /// </summary>
+ /// <param name="gatewayId"></param>
+ public void SaveGatewayIdToLocation(string gatewayId)
+ {
+ GatewayResourse.AppOldSelectGatewayId = gatewayId;
+ HdlFileLogic.Current.SaveFileContent(DirNameResourse.AppOldSelectGatewayFile, GatewayResourse.AppOldSelectGatewayId);
+ }
+
#endregion
#region 鈻� 鍒犻櫎缃戝叧___________________________
@@ -700,228 +742,246 @@
/// </summary>
/// <param name="zbGatewayID"></param>
public bool DeleteGateway(string zbGatewayID)
- {
- ZbGateway realWay = null;
- this.GetRealGateway(ref realWay, zbGatewayID);
- //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触 涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
- if (realWay != null)
- {
- this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
- }
-
- //鍒犻櫎浜戠鐨勭綉鍏�
- this.DeleteDataBaseGateway(zbGatewayID);
-
+ {
+ ZbGateway realWay = null;
+ this.GetRealGateway(ref realWay, zbGatewayID);
+ //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触 涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
+ if (realWay != null)
+ {
+ this.SetHomeIdToGateway(realWay.GwId, string.Empty, ShowErrorMode.NO);
+ }
+
+ //鍒犻櫎浜戠鐨勭綉鍏�
+ this.DeleteDataBaseGateway(zbGatewayID);
+
//鍒犻櫎缃戝叧鏂囦欢
this.DeleteGatewayFile(zbGatewayID);
//绉婚櫎
ZbGateway.GateWayList.RemoveAll((obj) => obj.GwId == zbGatewayID);
//鏂紑mqtt杩炴帴
- if (realWay != null)
- {
- realWay.DisConnectLocalMqttClient("GD");
+ if (realWay != null)
+ {
+ realWay.CloseLocalConnectionOnForce();
}
return true;
- }
-
- /// <summary>
- /// 鍒犻櫎缃戝叧鏂囦欢
- /// </summary>
- /// <param name="zbGatewayID">缃戝叧id</param>
- public void DeleteGatewayFile(string zbGatewayID)
- {
- if (dicGateway.ContainsKey(zbGatewayID) == false)
- {
- return;
- }
- //鍒犻櫎鏂囦欢
+ }
+
+ /// <summary>
+ /// 鍒犻櫎缃戝叧鏂囦欢
+ /// </summary>
+ /// <param name="zbGatewayID">缃戝叧id</param>
+ public void DeleteGatewayFile(string zbGatewayID)
+ {
+ if (dicGateway.ContainsKey(zbGatewayID) == false)
+ {
+ return;
+ }
+ //鍒犻櫎鏂囦欢
string file = dicGateway[zbGatewayID].FilePath;
if (Global.IsExistsByHomeId(file) == true)
{
Global.DeleteFilebyHomeId(file);
- }
-
- //绉婚櫎缂撳瓨
- dicGateway.Remove(zbGatewayID);
- //鍒犻櫎鑷姩澶囦唤
- HdlAutoBackupLogic.DeleteFile(file);
-
- //鍒犻櫎璁惧鏂囦欢
- List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGatewayID);
- foreach (var device in list)
- {
- //鍒犻櫎璁惧鏂囦欢
- Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
- //鍒犻櫎Ota璁惧
- Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
- }
- //濡傛灉鏄富缃戝叧
- if (this.IsMainGateway(zbGatewayID) == 1)
- {
- var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
- foreach (var room in listAllRoom)
- {
- //鍒犻櫎鍦烘櫙鏂囦欢
- foreach (var sceneId in room.ListSceneId)
- {
- if (Global.IsExistsByHomeId($"Scene_{sceneId}.json") == true)
- {
- Global.DeleteFilebyHomeId($"Scene_{sceneId}.json");
- }
- }
- }
- }
- }
-
+ }
+
+ //绉婚櫎缂撳瓨
+ dicGateway.Remove(zbGatewayID);
+ //鍒犻櫎鑷姩澶囦唤
+ HdlAutoBackupLogic.DeleteFile(file);
+
+ //鍒犻櫎璁惧鏂囦欢
+ List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGatewayID);
+ foreach (var device in list)
+ {
+ //鍒犻櫎璁惧鏂囦欢
+ Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+ //鍒犻櫎Ota璁惧
+ Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
+ }
+ //濡傛灉鏄富缃戝叧
+ if (this.IsMainGateway(zbGatewayID) == 1)
+ {
+ var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
+ foreach (var room in listAllRoom)
+ {
+ //鍒犻櫎鍦烘櫙鏂囦欢
+ foreach (var sceneId in room.ListSceneId)
+ {
+ if (Global.IsExistsByHomeId($"Scene_{sceneId}.json") == true)
+ {
+ Global.DeleteFilebyHomeId($"Scene_{sceneId}.json");
+ }
+ }
+ }
+ }
+ }
+
#endregion
-
+
#region 鈻� 缃戝叧鎺夌嚎___________________________
- /// <summary>
- /// 鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�(娉ㄦ剰,鍒锋柊鐨勬槸缂撳瓨,璇疯皟鐢–heckGatewayOnlineByFlag鏉ュ垽鏂槸鍚﹀湪绾�)
- /// </summary>
- /// <param name="listGateway"></param>
+ /// <summary>
+ /// 鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�(娉ㄦ剰,鍒锋柊鐨勬槸缂撳瓨,璇疯皟鐢–heckGatewayOnlineByFlag鏉ュ垽鏂槸鍚﹀湪绾�)
+ /// </summary>
+ /// <param name="listGateway"></param>
/// <returns></returns>
- public void RefreshGatewayOnlineStatu(List<ZbGateway> listGateway)
- {
- var listRealWay = new List<ZbGateway>();
- for (int i = 0; i < listGateway.Count; i++)
- {
- ZbGateway zbTemp = null;
- if (this.GetRealGateway(ref zbTemp, listGateway[i]) == true)
- {
- //鐪熷疄鐗╃悊缃戝叧
- listRealWay.Add(zbTemp);
- }
- else
- {
- //铏氭嫙鐗╃悊缃戝叧
- listRealWay.Add(listGateway[i]);
- }
- //鏍囪瘑鎸囧畾缃戝叧涓轰笉鍦ㄧ嚎
- listRealWay[i].GatewayOnlineFlage = false;
- }
-
- //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟2绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage)
- System.Threading.Thread.Sleep(2000);
- //妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
- if (this.CheckHadGatewayInWifi(listRealWay) == false)
- {
- //绗簩閬撳潕锛氬湪杩滅▼鐨勬儏鍐典笅鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�
- this.RefreshGatewayOnlineOnRemode(listRealWay);
- }
-
- //鍒锋柊缂撳瓨鐨勫湪绾挎爣璇�
- foreach (var zbway in listRealWay)
- {
- string gwID = zbway.GwId;
- if (this.dicGateway.ContainsKey(gwID) == false)
- {
- continue;
- }
- this.dicGateway[gwID].GatewayOnlineFlage = zbway.GatewayOnlineFlage;
- }
+ public void RefreshGatewayOnlineStatu(List<ZbGateway> listGateway)
+ {
+ var listRealWay = new List<ZbGateway>();
+ for (int i = 0; i < listGateway.Count; i++)
+ {
+ ZbGateway zbTemp = null;
+ if (this.GetRealGateway(ref zbTemp, listGateway[i]) == true)
+ {
+ //鐪熷疄鐗╃悊缃戝叧
+ listRealWay.Add(zbTemp);
+ }
+ else
+ {
+ //铏氭嫙鐗╃悊缃戝叧
+ listRealWay.Add(listGateway[i]);
+ }
+ }
+ //妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
+ if (this.CheckHadGatewayInWifi(listRealWay) == false)
+ {
+ //绗簩閬撳潕锛氬湪杩滅▼鐨勬儏鍐典笅鍒锋柊缃戝叧鐨勫湪绾跨姸鎬�
+ this.RefreshGatewayOnlineOnRemode(listRealWay);
+ }
+ //wifi鎯呭喌涓�,鐢盇pplication鑷繁鍒锋柊鏍囪瘑
}
- /// <summary>
- /// 妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
- /// </summary>
- /// <param name="listGateway"></param>
+ /// <summary>
+ /// 妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓�
+ /// </summary>
+ /// <param name="listGateway"></param>
/// <returns></returns>
- private bool CheckHadGatewayInWifi(List<ZbGateway> listGateway)
- {
- foreach (var zbway in listGateway)
- {
- //鏄惁瀛樺湪缃戝叧瀛樺湪浜嶹IFI涓�
- if (zbway.GatewayOnlineFlage == true)
- {
- return true;
- }
- }
- return false;
- }
-
- /// <summary>
- /// 鍦ㄨ繙绋嬬殑鎯呭喌涓嬪埛鏂扮綉鍏崇殑鍦ㄧ嚎鐘舵��
- /// </summary>
- /// <param name="listGateway"></param>
- /// <returns></returns>
- private void RefreshGatewayOnlineOnRemode(List<ZbGateway> listGateway)
- {
- //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
- Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
- if (dicDbGateway == null)
- {
- return;
- }
- foreach (var way in listGateway)
- {
- if (way == null)
- {
- continue;
- }
- string strId = way.GwId;
- if (dicDbGateway.ContainsKey(strId) == true) //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
- {
- way.GatewayOnlineFlage = dicDbGateway[strId].MqttOnlineStatus;
- }
- }
+ private bool CheckHadGatewayInWifi(List<ZbGateway> listGateway)
+ {
+ foreach (var zbway in listGateway)
+ {
+ //濡傛灉骞挎挱寰楀埌缃戝叧,鍒欎細鍒锋柊OnlineTime,濡傛灉涓庡綋鍓嶆椂闂寸浉宸皯浜庢寚瀹氱鏁�,鍒欏垽鏂负瀛樺湪缃戝叧瀛樺湪浜嶹IFI涓�
+ if ((DateTime.Now - zbway.OnlineTime).TotalSeconds <= ZigBee.Common.Application.SendTime * 2)
+ {
+ return true;
+ }
+ }
+ return false;
}
- /// <summary>
- /// 鏍规嵁鏌愮鏍囪瘑鍒ゆ柇鎸囧畾缃戝叧鏄惁鍦ㄧ嚎
- /// </summary>
- /// <param name="zbGateway"></param>
+ /// <summary>
+ /// 鍦ㄨ繙绋嬬殑鎯呭喌涓嬪埛鏂扮綉鍏崇殑鍦ㄧ嚎鐘舵��
+ /// </summary>
+ /// <param name="listGateway"></param>
/// <returns></returns>
- public bool CheckGatewayOnlineByFlag(ZbGateway zbGateway)
- {
- if (zbGateway == null)
- {
- return false;
- }
- //浣跨敤缂撳瓨鐨勶紝鍥犱负鍒锋柊鍦ㄧ嚎鐘舵�佺殑鏃跺�欙紝鍒锋柊鐨勫氨鏄紦瀛橈紝鑰屼笉鏄湡瀹炵墿鐞嗙綉鍏�
- string gwID = zbGateway.GwId;
- if (this.dicGateway.ContainsKey(gwID) == true)
- {
- return this.dicGateway[gwID].GatewayOnlineFlage;
- }
-
- return zbGateway.GatewayOnlineFlage;
+ private void RefreshGatewayOnlineOnRemode(List<ZbGateway> listGateway)
+ {
+ //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
+ Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
+ if (dicDbGateway == null)
+ {
+ return;
+ }
+ foreach (var way in listGateway)
+ {
+ if (way == null)
+ {
+ continue;
+ }
+ string strId = way.GwId;
+ if (dicDbGateway.ContainsKey(strId) == true
+ && dicDbGateway[strId].MqttOnlineStatus == true) //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
+ {
+ way.OnlineTime = DateTime.Now;
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鏍规嵁鏈湴缂撳瓨鍒ゆ柇鎸囧畾缃戝叧鏄惁鍦ㄧ嚎
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public bool CheckGatewayOnlineByMemory(ZbGateway zbGateway)
+ {
+ if (zbGateway == null)
+ {
+ return false;
+ }
+ //浣跨敤缂撳瓨鐨勶紝鍥犱负鍒锋柊鍦ㄧ嚎鐘舵�佺殑鏃跺�欙紝鍒锋柊鐨勫氨鏄紦瀛橈紝鑰屼笉鏄湡瀹炵墿鐞嗙綉鍏�
+ string gwID = zbGateway.GwId;
+ if (this.dicGateway.ContainsKey(gwID) == true)
+ {
+ return this.CheckGatewayOnlineByFlage(dicGateway[gwID]);
+ }
+
+ return this.CheckGatewayOnlineByFlage(zbGateway);
+ }
+
+ /// <summary>
+ /// 鍒锋柊缃戝叧鐨勫湪绾挎椂闂寸偣
+ /// </summary>
+ /// <param name="i_gatewayId">缃戝叧ID</param>
+ public void RefreshGatewayOnlineTime(string i_gatewayId)
+ {
+ try
+ {
+ if (this.dicGateway.ContainsKey(i_gatewayId) == true)
+ {
+ this.dicGateway[i_gatewayId].OnlineTime = DateTime.Now;
+ }
+ }
+ catch { }
+ }
+
+ /// <summary>
+ /// 鏍规嵁鎸囧畾鏍囪瘑,鍒ゆ柇缃戝叧鏄惁鍦ㄧ嚎
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ private bool CheckGatewayOnlineByFlage(ZbGateway zbGateway)
+ {
+ if (this.nowGwConnectMode == GatewayConnectMode.Remote)
+ {
+ //杩滅▼姣�20绉掓娴嬩竴娆�
+ return (DateTime.Now - zbGateway.OnlineTime).TotalSeconds <= 40;
+ }
+ //濡傛灉骞挎挱寰楀埌缃戝叧,鍒欎細鍒锋柊OnlineTime,濡傛灉涓庡綋鍓嶆椂闂寸浉宸皯浜�10绉�,鍒欏垽鏂负鍦ㄧ嚎
+ return (DateTime.Now - zbGateway.OnlineTime).TotalSeconds <= 15;
}
#endregion
-
+
#region 鈻� 鑾峰彇缃戝叧___________________________
-
- /// <summary>
- /// 浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧(浠ユ湰鍦扮綉鍏充负鏍囧噯)
- /// </summary>
+
+ /// <summary>
+ /// 浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧(浠ユ湰鍦扮綉鍏充负鏍囧噯)
+ /// </summary>
/// <returns></returns>
- public List<ZbGateway> GetAllGatewayFromGateway()
- {
- //涓嶈鍘籉oreach 瀹冪殑鍒楄〃
- List<ZbGateway> list = new List<ZbGateway>();
- list.AddRange(ZbGateway.GateWayList);
-
- List<ZbGateway> newlist = new List<ZbGateway>();
- foreach (var way in list)
- {
- if (Config.Instance.HomeId != way.HomeId)
- {
- //濡傛灉涓嶆槸褰撳墠浣忓畢
- continue;
- }
- string gwID = way.GwId;
- if (this.dicGateway.ContainsKey(gwID) == false)
- {
- //濡傛灉鏈湴骞舵病鏈夎繖涓綉鍏�
- continue;
- }
- newlist.Add(way);
- }
- return newlist;
+ public List<ZbGateway> GetAllGatewayFromGateway()
+ {
+ //涓嶈鍘籉oreach 瀹冪殑鍒楄〃
+ List<ZbGateway> list = new List<ZbGateway>();
+ list.AddRange(ZbGateway.GateWayList);
+
+ List<ZbGateway> newlist = new List<ZbGateway>();
+ foreach (var way in list)
+ {
+ if (Config.Instance.HomeId != way.HomeId)
+ {
+ //濡傛灉涓嶆槸褰撳墠浣忓畢
+ continue;
+ }
+ string gwID = way.GwId;
+ if (this.dicGateway.ContainsKey(gwID) == false)
+ {
+ //濡傛灉鏈湴骞舵病鏈夎繖涓綉鍏�
+ continue;
+ }
+ newlist.Add(way);
+ }
+ return newlist;
}
/// <summary>
@@ -931,1488 +991,1615 @@
public List<ZbGateway> GetAllLocalGateway()
{
List<ZbGateway> listData = new List<ZbGateway>();
- lock (dicGateway)
- {
- foreach (var way in dicGateway.Values)
- {
- listData.Add(way);
- }
+ lock (dicGateway)
+ {
+ foreach (var way in dicGateway.Values)
+ {
+ listData.Add(way);
+ }
}
return listData;
}
- /// <summary>
- /// 鑾峰彇鏈湴鐨勭綉鍏�
- /// </summary>
- /// <param name="gatewayId">缃戝叧ID</param>
+ /// <summary>
+ /// 鑾峰彇鏈湴鐨勭綉鍏�
+ /// </summary>
+ /// <param name="gatewayId">缃戝叧ID</param>
/// <returns></returns>
public ZbGateway GetLocalGateway(string gatewayId)
{
- if (this.dicGateway.ContainsKey(gatewayId) == true)
- {
- return this.dicGateway[gatewayId];
+ if (this.dicGateway.ContainsKey(gatewayId) == true)
+ {
+ return this.dicGateway[gatewayId];
}
return null;
}
- /// <summary>
- /// 鑾峰彇鏈湴鎵�鏈夌殑缃戝叧鏂囦欢
- /// </summary>
+ /// <summary>
+ /// 鑾峰彇鏈湴鎵�鏈夌殑缃戝叧鏂囦欢
+ /// </summary>
/// <returns></returns>
- public List<string> GetAllGatewayFile()
- {
- List<string> list = new List<string>();
- List<string> listFile = HdlFileLogic.Current.GetRootPathListFile();
- foreach (string file in listFile)
- {
- //鍙幏鍙栫綉鍏宠澶�
- if (file.StartsWith(gwFirstName) == false)
- {
- continue;
- }
- list.Add(file);
- }
- return list;
- }
-
- /// <summary>
- /// 鑾峰彇绯荤粺鍐呴儴鐨勭湡瀹炵綉鍏冲璞″彉閲�
- /// </summary>
- /// <param name="zbGateway">鐪熷疄缃戝叧</param>
- /// <param name="tagartWay">鐩爣缃戝叧</param>
- /// <returns></returns>
- public bool GetRealGateway(ref ZbGateway zbGateway, ZbGateway tagartWay)
- {
- if (tagartWay == null)
- {
- return false;
- }
- return this.GetRealGateway(ref zbGateway, tagartWay.GwId);
+ public List<string> GetAllGatewayFile()
+ {
+ List<string> list = new List<string>();
+ List<string> listFile = HdlFileLogic.Current.GetRootPathListFile();
+ foreach (string file in listFile)
+ {
+ //鍙幏鍙栫綉鍏宠澶�
+ if (file.StartsWith(gwFirstName) == false)
+ {
+ continue;
+ }
+ list.Add(file);
+ }
+ return list;
}
- /// <summary>
- /// 鑾峰彇绯荤粺鍐呴儴鐨勭湡瀹炵綉鍏冲璞″彉閲�
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <param name="gwId"></param>
+ /// <summary>
+ /// 鑾峰彇绯荤粺鍐呴儴鐨勭湡瀹炵綉鍏冲璞″彉閲�
+ /// </summary>
+ /// <param name="zbGateway">鐪熷疄缃戝叧</param>
+ /// <param name="tagartWay">鐩爣缃戝叧</param>
/// <returns></returns>
- public bool GetRealGateway(ref ZbGateway zbGateway, string gwId)
- {
- var realWay = ZbGateway.GateWayList.Find((obj) =>
- {
- return obj.GwId == gwId;
- });
- if (realWay == null)
- {
- //濡傛灉缃戝叧瀵硅薄涓㈠け浜�,鍒欏垱寤轰釜鏂扮殑
+ public bool GetRealGateway(ref ZbGateway zbGateway, ZbGateway tagartWay)
+ {
+ if (tagartWay == null)
+ {
+ return false;
+ }
+ return this.GetRealGateway(ref zbGateway, tagartWay.GwId);
+ }
+
+ /// <summary>
+ /// 鑾峰彇绯荤粺鍐呴儴鐨勭湡瀹炵綉鍏冲璞″彉閲�
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <param name="gwId"></param>
+ /// <returns></returns>
+ public bool GetRealGateway(ref ZbGateway zbGateway, string gwId)
+ {
+ var realWay = ZbGateway.GateWayList.Find((obj) =>
+ {
+ return obj.GwId == gwId;
+ });
+ if (realWay == null)
+ {
+ //濡傛灉缃戝叧瀵硅薄涓㈠け浜�,鍒欏垱寤轰釜鏂扮殑
realWay = new ZbGateway { IsVirtual = true, };
realWay.GwId = gwId;
realWay.HomeId = Shared.Common.Config.Instance.HomeId;
ZbGateway.GateWayList.Add(realWay);
- }
- zbGateway = realWay;
- return true;
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬揰________________
-
- /// <summary>
- /// 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬�(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public int GetGatewayChannelId(ZbGateway zbGateway)
- {
- ZbGateway realWay = null;
- if (this.GetRealGateway(ref realWay, zbGateway) == false)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
- return -1;
- }
- 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 = Convert.ToInt32(jobject["Data"]["Channel"].ToString());
- }
- };
- realWay.Actions += action;
-
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 8 } };
- realWay.Send("ZbGw/GetChannel", jObject.ToString());
-
- int TimeOut = 0;
- while (data == -1 && TimeOut < 30)
- {
- System.Threading.Thread.Sleep(100);
- TimeOut++;
- }
-
- realWay.Actions -= action;
- if (data == -1)
- {
- //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐�
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
- this.ShowTipMsg(msg);
- }
-
- return data;
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇鍗忚皟鍣∕AC______________________
-
- /// <summary>
- /// 鑾峰彇鍗忚皟鍣∕AC鍦板潃(浼氭湁绛夊緟寤惰繜,杩斿洖null浠h〃閿欒)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public string GetGatewayCoordinatorMac(ZbGateway zbGateway)
- {
- ZbGateway realWay = null;
- if (this.GetRealGateway(ref realWay, zbGateway) == false)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
- return 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 = jobject["Data"]["MacAddr"].ToString();
- }
- };
- realWay.Actions += action;
-
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 13 } };
- realWay.Send("ZbGw/GetMac", jObject.ToString());
-
- int TimeOut = 0;
- while (data == null && TimeOut < 30)
- {
- System.Threading.Thread.Sleep(100);
- TimeOut++;
- }
-
- realWay.Actions -= action;
- if (data == null)
- {
- //鑾峰彇鍗忚皟鍣∕ac澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
- this.ShowTipMsg(msg);
- }
-
- return data;
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇鍗忚皟鍣≒anID____________________
-
- /// <summary>
- /// 鑾峰彇鍗忚皟鍣≒anID(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public int GetGatewayPanId(ZbGateway zbGateway)
- {
- ZbGateway realWay = null;
- if (this.GetRealGateway(ref realWay, zbGateway) == false)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
- return -1;
- }
- 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);
- panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString());
- }
- };
- realWay.Actions += action;
-
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 12 } };
- realWay.Send("ZbGw/GetPanId", jObject.ToString());
-
- int TimeOut = 0;
- while (panId == -1 && TimeOut < 30)
- {
- System.Threading.Thread.Sleep(100);
- TimeOut++;
- }
-
- realWay.Actions -= action;
- if (panId == -1)
- {
- //鑾峰彇鍗忚皟鍣≒anID澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
- this.ShowTipMsg(msg);
- }
-
- 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>
- /// 璁剧疆缃戝叧鑷姩澶囦唤璁剧疆
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <param name="statu"></param>
- /// <returns></returns>
- public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu)
- {
- 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
-
- #region 鈻� 鑾峰彇鍚嶇О___________________________
-
- /// <summary>
- /// 鑾峰彇缃戝叧鍔犵壒鏁堢殑鍚嶇О
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public string GetGatewayName(ZbGateway zbGateway)
- {
- if (zbGateway == null) { return string.Empty; }
-
- string gwId = zbGateway.GwId;
- if (this.dicGateway.ContainsKey(gwId) == false)
- {
- return zbGateway.GwName;
- }
- var localWay = this.dicGateway[gwId];
-
- string name = this.GetGatewaySimpleName(localWay);
- if (string.IsNullOrEmpty(name) == false)
- {
- return name;
- }
-
- var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
- if (nameContent != null)
- {
- return nameContent.A澶囨敞鍚嶅瓧;
- }
-
- return string.Empty;
- }
-
- /// <summary>
- /// 鍗曠函鑾峰彇缃戝叧鍚嶇О
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <returns></returns>
- private string GetGatewaySimpleName(ZbGateway zbGateway)
- {
- if (zbGateway == null)
- {
- return string.Empty;
- }
- return zbGateway.GwName;
- }
-
- /// <summary>
- /// 璁剧疆缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛�
- /// </summary>
- /// <param name="button"></param>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public void SetGatewayImageText(Button button, ZbGateway zbGateway)
- {
- //鍒濆鍊�:鏃犳硶璇嗗埆鐨勭綉鍏宠澶�
- button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
-
- string gwId = zbGateway.GwId;
- if (this.dicGateway.ContainsKey(gwId) == false)
- {
- //濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇
- if (zbGateway.LinuxImageType != -1)
- {
- var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
- if (nameContent != null)
- {
- button.Text = nameContent.A瀹樻柟鍚嶅瓧;
- }
- }
- else
- {
- //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
- HdlThreadLogic.Current.RunThread(() =>
- {
- var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
- if (result != null)
- {
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
-
- HdlThreadLogic.Current.RunMain(() =>
- {
- var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
- if (nameContent != null)
- {
- button.Text = nameContent.A瀹樻柟鍚嶅瓧;
- }
- });
- }
- });
- }
- }
- else
- {
- var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
- if (nameContent != null)
- {
- button.Text = nameContent.A瀹樻柟鍚嶅瓧;
- }
- }
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇缃戝叧淇℃伅_______________________
-
- /// <summary>
- /// 鑾峰彇缃戝叧淇℃伅(鐗堟湰淇℃伅,闀滃儚绫诲瀷,鍩烘湰淇℃伅绛夈�傚彧鍒锋柊鏈湴缃戝叧鐨勭紦瀛�)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
- /// <param name="mode"></param>
- /// <returns></returns>
- public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
- {
- //鑾峰彇缃戝叧鐗堟湰淇℃伅
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 95 } };
- var result = this.SendJobjectDataToGateway(zbGateway, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
-
- if (result.ErrorMsgDiv != 1)
- {
- if (mode == ShowErrorMode.YES)
- {
- //鑾峰彇缃戝叧淇℃伅澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
- //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
- this.ShowErrorMsg(msg);
- }
- return null;
- }
- var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(result.ReceiptData);
- string gwID = zbGateway.GwId;
- if (this.dicGateway.ContainsKey(gwID) == true)
- {
- //鍒锋柊缂撳瓨
- ZbGateway localWay = this.dicGateway[gwID];
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(localWay, getGwInfo);
- }
- //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
- this.SetGatewayDataToLocalMemmory(zbGateway, getGwInfo, false);
-
- return getGwInfo;
- }
-
- /// <summary>
- /// 灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- /// </summary>
- /// <param name="localWay">鏈湴缃戝叧</param>
- /// <param name="data">缃戝叧鏁版嵁</param>
- /// <param name="saveFile">鏄惁淇濆瓨鏂囦欢</param>
- private void SetGatewayDataToLocalMemmory(ZbGateway localWay, ZbGatewayData.GetGwData data, bool saveFile = true)
- {
- localWay.GwId = data.GwId;
- localWay.GwName = data.GwName;
- localWay.GwSerialNum = data.GWSN;
- localWay.IsMainGateWay = data.IsDominant == 1 ? true : false;
- localWay.GwIP = data.GwIP;
- localWay.LinuxImageType = data.LinuxImageType;
- localWay.LinuxHardVersion = data.LinuxHWVersion;
- localWay.LinuxFirmwareVersion = data.LinuxFWVersion;
- localWay.CoordinatorHardVersion = data.ZbHWVersion;
- localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
- localWay.CoordinatorImageId = data.ZbImageType;
- localWay.DriveCodeList = data.DriveCodeList;
- localWay.GwVersionDate = data.AppVersion;
- if (saveFile == true)
- {
- localWay.ReSave();
- }
- }
-
- #endregion
-
- #region 鈻� 缃戝叧鎴块棿鐩稿叧_______________________
-
- /// <summary>
- /// 鑾峰彇缃戝叧鎵�鍦ㄧ殑鎴块棿
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <returns></returns>
- public Room GetRoomByGateway(ZbGateway zbGateway)
- {
- return this.GetRoomByGateway(zbGateway.GwId);
- }
-
- /// <summary>
- /// 鑾峰彇缃戝叧鎵�鍦ㄧ殑鎴块棿
- /// </summary>
- /// <param name="gatewayId">缃戝叧ID</param>
- /// <returns></returns>
- public Room GetRoomByGateway(string gatewayId)
- {
- var localGateway = this.GetLocalGateway(gatewayId);
- if (localGateway == null)
- {
- return null;
- }
- return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
- }
-
- /// <summary>
- /// 鍙樻洿缃戝叧鎴块棿
- /// </summary>
- /// <param name="gwId">缃戝叧Id</param>
- /// <param name="roomId">鎴块棿ID</param>
- public void ChangedGatewayRoom(string gwId, string roomId)
- {
- var localGateway = this.GetLocalGateway(gwId);
- if (localGateway != null)
- {
- localGateway.RoomId = roomId;
- localGateway.ReSave();
- //娣诲姞澶囦唤
- HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
- }
- }
-
- #endregion
-
- #region 鈻� 娓呯┖鐪熷疄缃戝叧閾炬帴___________________
-
- /// <summary>
- /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏崇殑閾炬帴
- /// </summary>
- /// <param name="roadGateway">鏄惁鍔犺浇鏈湴鐨勭綉鍏冲璞″埌鐪熷疄鍒楄〃涓�</param>
- public void ClearAllRealGatewayConection(bool roadGateway)
- {
- //鏂紑mqtt杩炴帴(鍗充娇淇濆瓨鍦ㄥ唴瀛樺綋涓篃娌¢棶棰�,鍥犱负濡傛灉骞挎挱涓嶅埌,鍒欏畠涓嶄細寤虹珛閾炬帴)
- for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
- {
- ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G");
- }
- //鍔犺浇鏈湴缃戝叧瀵硅薄
- if (roadGateway == true)
- {
- List<string> listFile = this.GetAllGatewayFile();
- //鍙嶅簭鍒楀寲娣诲姞鍒扮紦瀛�
- foreach (string file in listFile)
- {
- //浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
- var gateway = this.GetGatewayFromFile(file);
- if (gateway == null)
- {
- continue;
- }
+ }
+ zbGateway = realWay;
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬揰________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣ㄥ綋鍓嶄俊閬�(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public int GetGatewayChannelId(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return -1;
+ }
+ 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 = Convert.ToInt32(jobject["Data"]["Channel"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 8 } };
+ realWay.Send("ZbGw/GetChannel", jObject.ToString());
+
+ int TimeOut = 0;
+ while (data == -1 && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (data == -1)
+ {
+ //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ }
+
+ return data;
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍗忚皟鍣∕AC______________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣∕AC鍦板潃(浼氭湁绛夊緟寤惰繜,杩斿洖null浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public string GetGatewayCoordinatorMac(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return 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 = jobject["Data"]["MacAddr"].ToString();
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 13 } };
+ realWay.Send("ZbGw/GetMac", jObject.ToString());
+
+ int TimeOut = 0;
+ while (data == null && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (data == null)
+ {
+ //鑾峰彇鍗忚皟鍣∕ac澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ }
+
+ return data;
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍗忚皟鍣≒anID____________________
+
+ /// <summary>
+ /// 鑾峰彇鍗忚皟鍣≒anID(浼氭湁绛夊緟寤惰繜,杩斿洖-1浠h〃閿欒)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public int GetGatewayPanId(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg));
+ return -1;
+ }
+ 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);
+ panId = Convert.ToInt32(jobject["Data"]["PANID"].ToString());
+ }
+ };
+ realWay.Actions += action;
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 64512 }, { "Command", 12 } };
+ realWay.Send("ZbGw/GetPanId", jObject.ToString());
+
+ int TimeOut = 0;
+ while (panId == -1 && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (panId == -1)
+ {
+ //鑾峰彇鍗忚皟鍣≒anID澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowTipMsg(msg);
+ }
+
+ 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>
+ /// 璁剧疆缃戝叧鑷姩澶囦唤璁剧疆
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <param name="statu"></param>
+ /// <returns></returns>
+ public bool SetGatewayAutoBackupStatu(ZbGateway zbGateway, bool statu)
+ {
+ 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
+
+ #region 鈻� 鑾峰彇鍚嶇О___________________________
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧鍔犵壒鏁堢殑鍚嶇О
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public string GetGatewayName(ZbGateway zbGateway)
+ {
+ if (zbGateway == null) { return string.Empty; }
+
+ string gwId = zbGateway.GwId;
+ if (this.dicGateway.ContainsKey(gwId) == false)
+ {
+ return zbGateway.GwName;
+ }
+ var localWay = this.dicGateway[gwId];
+
+ string name = this.GetGatewaySimpleName(localWay);
+ if (string.IsNullOrEmpty(name) == false)
+ {
+ return name;
+ }
+
+ var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
+ if (nameContent != null)
+ {
+ return nameContent.A澶囨敞鍚嶅瓧;
+ }
+
+ return string.Empty;
+ }
+
+ /// <summary>
+ /// 鍗曠函鑾峰彇缃戝叧鍚嶇О
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <returns></returns>
+ private string GetGatewaySimpleName(ZbGateway zbGateway)
+ {
+ if (zbGateway == null)
+ {
+ return string.Empty;
+ }
+ return zbGateway.GwName;
+ }
+
+ /// <summary>
+ /// 璁剧疆缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛�
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public void SetGatewayImageText(Button button, ZbGateway zbGateway)
+ {
+ //鍒濆鍊�:鏃犳硶璇嗗埆鐨勭綉鍏宠澶�
+ button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
+
+ string gwId = zbGateway.GwId;
+ if (this.dicGateway.ContainsKey(gwId) == false)
+ {
+ //濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇
+ if (zbGateway.LinuxImageType != -1)
+ {
+ var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+ if (nameContent != null)
+ {
+ button.Text = nameContent.A瀹樻柟鍚嶅瓧;
+ }
+ }
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
+ if (result != null)
+ {
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
+
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+ if (nameContent != null)
+ {
+ button.Text = nameContent.A瀹樻柟鍚嶅瓧;
+ }
+ });
+ }
+ });
+ }
+ }
+ else
+ {
+ var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+ if (nameContent != null)
+ {
+ button.Text = nameContent.A瀹樻柟鍚嶅瓧;
+ }
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇缃戝叧淇℃伅_______________________
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧淇℃伅(鐗堟湰淇℃伅,闀滃儚绫诲瀷,鍩烘湰淇℃伅绛夈�傚彧鍒锋柊鏈湴缃戝叧鐨勭紦瀛�)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
+ /// <param name="mode"></param>
+ /// <returns></returns>
+ public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
+ {
+ //鑾峰彇缃戝叧鐗堟湰淇℃伅
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 95 } };
+ var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
+
+ if (result.ErrorMsgDiv != 1)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //鑾峰彇缃戝叧淇℃伅澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ this.ShowErrorMsg(msg);
+ }
+ return null;
+ }
+ var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(result.ReceiptData);
+ string gwID = zbGateway.GwId;
+ if (this.dicGateway.ContainsKey(gwID) == true)
+ {
+ //鍒锋柊缂撳瓨
+ ZbGateway localWay = this.dicGateway[gwID];
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(localWay, getGwInfo);
+ }
+ //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
+ this.SetGatewayDataToLocalMemmory(zbGateway, getGwInfo, false);
+
+ return getGwInfo;
+ }
+
+ /// <summary>
+ /// 灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ /// </summary>
+ /// <param name="localWay">鏈湴缃戝叧</param>
+ /// <param name="data">缃戝叧鏁版嵁</param>
+ /// <param name="saveFile">鏄惁淇濆瓨鏂囦欢</param>
+ private void SetGatewayDataToLocalMemmory(ZbGateway localWay, ZbGatewayData.GetGwData data, bool saveFile = true)
+ {
+ if (localWay == null || data == null) { return; }
+
+ localWay.GwId = data.GwId;
+ localWay.GwName = data.GwName;
+ localWay.GwSerialNum = data.GWSN;
+ localWay.IsMainGateWay = data.IsDominant == 1 ? true : false;
+ localWay.GwIP = data.GwIP;
+ localWay.GwMac = data.GwMac;
+ localWay.LinuxImageType = data.LinuxImageType;
+ localWay.LinuxHardVersion = data.LinuxHWVersion;
+ localWay.LinuxFirmwareVersion = data.LinuxFWVersion;
+ localWay.CoordinatorHardVersion = data.ZbHWVersion;
+ localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
+ localWay.CoordinatorImageId = data.ZbImageType;
+ localWay.DriveCodeList = data.DriveCodeList;
+ localWay.GwVersionDate = data.AppVersion;
+ localWay.OnlineTime = DateTime.Now;
+
+ if (saveFile == true)
+ {
+ localWay.ReSave();
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 娓呯┖鐪熷疄缃戝叧閾炬帴___________________
+
+ /// <summary>
+ /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏崇殑閾炬帴
+ /// </summary>
+ /// <param name="roadGateway">鏄惁鍔犺浇鏈湴鐨勭綉鍏冲璞″埌鐪熷疄鍒楄〃涓�</param>
+ public void ClearAllRealGatewayConection(bool roadGateway)
+ {
+ //鏂紑mqtt杩炴帴(鍗充娇淇濆瓨鍦ㄥ唴瀛樺綋涓篃娌¢棶棰�,鍥犱负濡傛灉骞挎挱涓嶅埌,鍒欏畠涓嶄細寤虹珛閾炬帴)
+ for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
+ {
+ ZbGateway.GateWayList[i].CloseLocalConnectionOnForce();
+ }
+ //鍔犺浇鏈湴缃戝叧瀵硅薄
+ if (roadGateway == true)
+ {
+ List<string> listFile = this.GetAllGatewayFile();
+ //鍙嶅簭鍒楀寲娣诲姞鍒扮紦瀛�
+ foreach (string file in listFile)
+ {
+ //浠庢枃浠朵腑鍙嶅簭鍒楀寲鍑虹綉鍏冲璞�
+ var gateway = this.GetGatewayFromFile(file);
+ if (gateway == null)
+ {
+ continue;
+ }
var tempWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == gateway.GwId));
if (tempWay == null)
{
ZbGateway.GateWayList.Add(gateway);
- }
- }
- }
- }
-
- #endregion
-
- #region 鈻� 妫�娴嬪苟鑾峰彇缃戝叧鍚勭鍥轰欢鏂扮増鏈琠______
-
- /// <summary>
- /// 妫�娴嬪苟鑾峰彇缃戝叧鍚勫浐浠剁殑鏂扮増鏈�,娌℃湁鏂扮増鏈�,鍒欏搴斾綅缃瓨鐨勬槸null,鐩存帴杩斿洖null浠h〃澶辫触(0:Linux鏂扮増鏈� 1:鍗忚皟鍣ㄦ柊鐗堟湰 2锝瀀:閮芥槸铏氭嫙椹卞姩鐨�)
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <param name="mode">閿欒鏃讹紝鏄惁鏄剧ず閿欒</param>
- /// <returns></returns>
- public List<FirmwareVersionInfo> GetGatewayAllNewVersion(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
- {
- //濡傛灉鏄睍绀烘ā鏉�,鎴栬�呮槸铏氭嫙浣忓畢鐨勮瘽,娌℃湁浠�涔堟柊鐗堟湰鐨勮娉�
- if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
- {
- return new List<FirmwareVersionInfo> { null, null, null };
- }
- //鑾峰彇缃戝叧鐗堟湰淇℃伅
- var result = this.GetGatewayInfo(zbGateway, false, mode);
- if (result == null)
- {
- return null;
- }
- //浣跨敤鏈湴缂撳瓨瀵硅薄
- var localWay = this.GetLocalGateway(zbGateway.GwId);
- if (localWay == null)
- {
- return null;
+ }
+ }
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 妫�娴嬪苟鑾峰彇缃戝叧鍚勭鍥轰欢鏂扮増鏈琠______
+
+ /// <summary>
+ /// 妫�娴嬪苟鑾峰彇缃戝叧鍚勫浐浠剁殑鏂扮増鏈�,娌℃湁鏂扮増鏈�,鍒欏搴斾綅缃瓨鐨勬槸null,鐩存帴杩斿洖null浠h〃澶辫触(0:Linux鏂扮増鏈� 1:鍗忚皟鍣ㄦ柊鐗堟湰 2锝瀀:閮芥槸铏氭嫙椹卞姩鐨�)
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <param name="mode">閿欒鏃讹紝鏄惁鏄剧ず閿欒</param>
+ /// <returns></returns>
+ public List<FirmwareVersionInfo> GetGatewayAllNewVersion(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
+ {
+ //濡傛灉鏄睍绀烘ā鏉�,鎴栬�呮槸铏氭嫙浣忓畢鐨勮瘽,娌℃湁浠�涔堟柊鐗堟湰鐨勮娉�
+ if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
+ {
+ return new List<FirmwareVersionInfo> { null, null, null };
+ }
+ //鑾峰彇缃戝叧鐗堟湰淇℃伅
+ var result = this.GetGatewayInfo(zbGateway, false, mode);
+ if (result == null)
+ {
+ return null;
+ }
+ //浣跨敤鏈湴缂撳瓨瀵硅薄
+ var localWay = this.GetLocalGateway(zbGateway.GwId);
+ if (localWay == null)
+ {
+ return null;
}
//娣诲姞缃戝叧鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�)
- var flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
- localWay.LinuxHardVersion.ToString(),
- localWay.LinuxImageType.ToString());
-
- //娣诲姞鍗忚皟鍣ㄧ殑鍗囩骇鍥轰欢(鎴愪笉鎴愬姛閮芥棤鎵�璋�) 蹇呴』鑳藉鑱旂綉鎵嶈
- if (flage == 1)
- {
- //娌$綉鐨勬椂鍊欎笉鍐嶅鐞�
- HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
- localWay.CoordinatorHardVersion.ToString(),
- localWay.CoordinatorImageId.ToString());
- }
-
- //缃戝叧鐨勭増鏈�
- var gatewayFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
- localWay.LinuxHardVersion.ToString(),
- localWay.LinuxImageType.ToString(),
- localWay.LinuxFirmwareVersion);
-
- //鍗忚皟鍣ㄧ増鏈�
- var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
- localWay.CoordinatorHardVersion.ToString(),
- localWay.CoordinatorImageId.ToString(),
- localWay.CoordinatorFirmwareVersion);
-
- var list = new List<FirmwareVersionInfo>();
- list.Add(gatewayFirmware);
- list.Add(coordinatorFirmware);
-
- //杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈
- if (localWay.LinuxImageType != 6)
- {
- //铏氭嫙椹卞姩鍙�
- foreach (var data in localWay.DriveCodeList)
- {
- //娣诲姞铏氭嫙椹卞姩鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�) 蹇呴』鑳藉鑱旂綉鎵嶈
- if (flage == 1)
- {
- HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
- data.DriveHwVersion.ToString(),
- data.DriveImageType.ToString());
- }
-
- //铏氭嫙椹卞姩
- var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
- data.DriveHwVersion.ToString(),
- data.DriveImageType.ToString(),
- data.DriveFwVersion);
-
- if (virtualFirmware != null)
- {
- virtualFirmware.VirtualCode = data.DriveCode;
- list.Add(virtualFirmware);
- }
- }
- }
- if (list.Count == 2)
- {
- //铏氭嫙椹卞姩濡傛灉娌℃湁鏂扮増鏈殑璇濓紝鍥哄畾娣诲姞涓�涓┖鐨�
- list.Add(null);
- }
- return list;
- }
-
- /// <summary>
- /// 鑾峰彇缃戝叧鐨勮櫄鎷熼┍鍔ㄥ彿(杩斿洖null鏃朵唬琛ㄨ幏鍙栧け璐�)
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public List<ZbGatewayData.DriveCodeObj> GetListVDDriveCode(ZbGateway zbGateway)
- {
- //濡傛灉鏄睍绀烘ā鏉�,鎴栬�呮槸铏氭嫙浣忓畢鐨勮瘽,鐩存帴鍙栫紦瀛�
- if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
- {
- //鍙栨湰鍦板璞�
- var localgw = this.GetLocalGateway(zbGateway.GwId);
- return localgw != null ? zbGateway.DriveCodeList : zbGateway.DriveCodeList;
- }
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 505 } };
- var result = this.SendJobjectDataToGateway(zbGateway, "VirtualDrive/CatDriveCode", jObject.ToString(), "VirtualDrive/CatDriveCode_Respon");
- if (result.ErrorMsg != null)
- {
- this.ShowTipMsg(result.ErrorMsg);
- }
- if (result.ErrorMsgDiv == 0)
- {
- return null;
- }
- var dataInfo = JsonConvert.DeserializeObject<ZbGatewayData.VDriveDriveCodeResponData>(result.ReceiptData);
- return dataInfo.DriveCodeList;
- }
-
- #endregion
-
- #region 鈻� 涓荤綉鍏冲垽瀹歘________________________
-
- /// <summary>
- /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
- /// </summary>
- /// <param name="zbGateway">缃戝叧瀵硅薄</param>
- /// <returns></returns>
- public int IsMainGateway(ZbGateway zbGateway)
- {
- return this.IsMainGateway(zbGateway.GwId);
- }
-
- /// <summary>
- /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
- /// </summary>
- /// <param name="waiID">缃戝叧id</param>
- /// <returns></returns>
- public int IsMainGateway(string waiID)
- {
- var realWay = ZbGateway.GateWayList.Find((obj) =>
- {
- return obj.GwId == waiID;
- });
- //铏氭嫙缃戝叧涔熻繑鍥� 0
- if (realWay == null || realWay.IsVirtual == true)
- {
- return 0;
- }
- return realWay.IsMainGateWay == true ? 1 : 2;
- }
-
- #endregion
-
- #region 鈻� 璁剧疆缃戝叧鍥剧墖_______________________
-
- /// <summary>
- /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗�
- /// </summary>
- /// <param name="button"></param>
- /// <param name="zbGateway"></param>
- public void SetRealGatewayPictrue(Button button, ZbGateway zbGateway)
- {
- var localWay = this.GetLocalGateway(zbGateway.GwId);
- if (localWay == null)
- {
- if (zbGateway.LinuxImageType != -1)
- {
- button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.LinuxImageType + ".png";
- }
- else
- {
- //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
- HdlThreadLogic.Current.RunThread(() =>
- {
- var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
- if (result != null)
- {
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
- HdlThreadLogic.Current.RunMain(() =>
- {
- button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
- });
- }
- });
- }
- }
- else
- {
- button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.LinuxImageType + ".png";
- }
- }
-
- /// <summary>
- /// 璁剧疆缃戝叧鍥炬爣
- /// </summary>
- /// <param name="button"></param>
- /// <param name="zbGateway"></param>
- public void SetGatewayIcon(Button button, ZbGateway zbGateway)
- {
- var localWay = this.GetLocalGateway(zbGateway.GwId);
- if (localWay == null)
- {
- if (zbGateway.LinuxImageType != -1)
- {
- button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.LinuxImageType + ".png";
- }
- else
- {
- //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
- HdlThreadLogic.Current.RunThread(() =>
- {
- var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
- if (result != null)
- {
- //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
- this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
- HdlThreadLogic.Current.RunMain(() =>
- {
- button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
- });
- }
- });
- }
- }
- else
- {
- button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.LinuxImageType + ".png";
- }
- }
-
- #endregion
-
- #region 鈻� 缃戝叧瀛樺湪妫�娴媉______________________
-
- /// <summary>
- /// 缃戝叧鏄惁宸茬粡瀛樺湪
- /// </summary>
- /// <param name="zbGateway"></param>
- /// <returns></returns>
- public bool IsGatewayExist(ZbGateway zbGateway)
- {
- return this.IsGatewayExist(zbGateway.GwId);
- }
-
- /// <summary>
- /// 缃戝叧鏄惁宸茬粡瀛樺湪
- /// </summary>
- /// <param name="gatewayId">缃戝叧ID</param>
- /// <returns></returns>
- public bool IsGatewayExist(string gatewayId)
- {
- if (gatewayId == null)
- {
- return false;
- }
- return dicGateway.ContainsKey(gatewayId);
- }
-
- #endregion
-
- #region 鈻� 缃戝叧瀹氫綅___________________________
-
- /// <summary>
- /// 鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆)
- /// </summary>
- /// <param name="zbGateway"></param>
- public void SetFixedPositionCommand(ZbGateway zbGateway)
- {
- ZbGateway realWay = null;
- if (this.GetRealGateway(ref realWay, zbGateway) == false)
- {
- return;
- }
+ var flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
+ localWay.LinuxHardVersion.ToString(),
+ localWay.LinuxImageType.ToString());
+
+ //娣诲姞鍗忚皟鍣ㄧ殑鍗囩骇鍥轰欢(鎴愪笉鎴愬姛閮芥棤鎵�璋�) 蹇呴』鑳藉鑱旂綉鎵嶈
+ if (flage == 1)
+ {
+ //娌$綉鐨勬椂鍊欎笉鍐嶅鐞�
+ HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
+ localWay.CoordinatorHardVersion.ToString(),
+ localWay.CoordinatorImageId.ToString());
+ }
+
+ //缃戝叧鐨勭増鏈�
+ var gatewayFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
+ localWay.LinuxHardVersion.ToString(),
+ localWay.LinuxImageType.ToString(),
+ localWay.LinuxFirmwareVersion);
+
+ //鍗忚皟鍣ㄧ増鏈�
+ var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
+ localWay.CoordinatorHardVersion.ToString(),
+ localWay.CoordinatorImageId.ToString(),
+ localWay.CoordinatorFirmwareVersion);
+
+ var list = new List<FirmwareVersionInfo>();
+ list.Add(gatewayFirmware);
+ list.Add(coordinatorFirmware);
+
+ //杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈
+ if (this.CheckGatewayHadDriveCode(localWay) == true)
+ {
+ //铏氭嫙椹卞姩鍙�
+ foreach (var data in localWay.DriveCodeList)
+ {
+ //娣诲姞铏氭嫙椹卞姩鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�) 蹇呴』鑳藉鑱旂綉鎵嶈
+ if (flage == 1)
+ {
+ HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
+ data.DriveHwVersion.ToString(),
+ data.DriveImageType.ToString());
+ }
+
+ //铏氭嫙椹卞姩
+ var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
+ data.DriveHwVersion.ToString(),
+ data.DriveImageType.ToString(),
+ data.DriveFwVersion);
+
+ if (virtualFirmware != null)
+ {
+ virtualFirmware.VirtualCode = data.DriveCode;
+ list.Add(virtualFirmware);
+ }
+ }
+ }
+ if (list.Count == 2)
+ {
+ //铏氭嫙椹卞姩濡傛灉娌℃湁鏂扮増鏈殑璇濓紝鍥哄畾娣诲姞涓�涓┖鐨�
+ list.Add(null);
+ }
+ return list;
+ }
+
+ /// <summary>
+ /// 鑾峰彇缃戝叧鐨勮櫄鎷熼┍鍔ㄥ彿(杩斿洖null鏃朵唬琛ㄨ幏鍙栧け璐�)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public List<ZbGatewayData.DriveCodeObj> GetListVDDriveCode(ZbGateway zbGateway)
+ {
+ //濡傛灉鏄睍绀烘ā鏉�,鎴栬�呮槸铏氭嫙浣忓畢鐨勮瘽,鐩存帴鍙栫紦瀛�
+ if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
+ {
+ //鍙栨湰鍦板璞�
+ var localgw = this.GetLocalGateway(zbGateway.GwId);
+ return localgw != null ? zbGateway.DriveCodeList : zbGateway.DriveCodeList;
+ }
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 505 } };
+ var result = this.SendJobjectDataToGateway(zbGateway.GwId, "VirtualDrive/CatDriveCode", jObject.ToString(), "VirtualDrive/CatDriveCode_Respon");
+ if (result.ErrorMsg != null)
+ {
+ this.ShowTipMsg(result.ErrorMsg);
+ }
+ if (result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var dataInfo = JsonConvert.DeserializeObject<ZbGatewayData.VDriveDriveCodeResponData>(result.ReceiptData);
+ return dataInfo.DriveCodeList;
+ }
+
+ #endregion
+
+ #region 鈻� 涓荤綉鍏冲垽瀹歘________________________
+
+ /// <summary>
+ /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
+ /// </summary>
+ /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+ /// <returns></returns>
+ public int IsMainGateway(ZbGateway zbGateway)
+ {
+ return this.IsMainGateway(zbGateway.GwId);
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�)
+ /// </summary>
+ /// <param name="waiID">缃戝叧id</param>
+ /// <returns></returns>
+ public int IsMainGateway(string waiID)
+ {
+ var realWay = ZbGateway.GateWayList.Find((obj) =>
+ {
+ return obj.GwId == waiID;
+ });
+ //铏氭嫙缃戝叧涔熻繑鍥� 0
+ if (realWay == null || realWay.IsVirtual == true)
+ {
+ return 0;
+ }
+ return realWay.IsMainGateWay == true ? 1 : 2;
+ }
+
+ #endregion
+
+ #region 鈻� 璁剧疆缃戝叧鍥剧墖_______________________
+
+ /// <summary>
+ /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗�(宸插簾寮�)
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="zbGateway"></param>
+ public void SetRealGatewayPictrue(Button button, ZbGateway zbGateway)
+ {
+ var localWay = this.GetLocalGateway(zbGateway.GwId);
+ if (localWay == null)
+ {
+ if (zbGateway.LinuxImageType != -1)
+ {
+ button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.LinuxImageType + ".png";
+ }
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+ if (result != null)
+ {
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
+ });
+ }
+ });
+ }
+ }
+ else
+ {
+ button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.LinuxImageType + ".png";
+ }
+ }
+
+ /// <summary>
+ /// 璁剧疆缃戝叧鍥炬爣
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="zbGateway"></param>
+ public void SetGatewayIcon(Button button, ZbGateway zbGateway)
+ {
+ var localWay = this.GetLocalGateway(zbGateway.GwId);
+ if (localWay == null)
+ {
+ if (zbGateway.LinuxImageType != -1)
+ {
+ this.SetgatewayIcon(button, "Gateway/GatewayIcon" + zbGateway.LinuxImageType + ".png");
+ }
+ else
+ {
+ //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+ if (result != null)
+ {
+ //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
+ this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ this.SetgatewayIcon(button, "Gateway/GatewayIcon" + result.LinuxImageType + ".png");
+ });
+ }
+ });
+ }
+ }
+ else
+ {
+ this.SetgatewayIcon(button, "Gateway/GatewayIcon" + localWay.LinuxImageType + ".png");
+ }
+ }
+
+ /// <summary>
+ /// 璁剧疆缃戝叧鍥炬爣
+ /// </summary>
+ /// <param name="button"></param>
+ /// <param name="i_IconName"></param>
+ public void SetgatewayIcon(Button button, string i_IconName)
+ {
+ //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛�
+ if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(i_IconName)) == true)
+ {
+ //鍒欎娇鐢ㄥ叡閫氬浘鐗�
+ i_IconName = "Gateway/GatewayIcon.png";
+ }
+ button.UnSelectedImagePath = i_IconName;
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧瀛樺湪妫�娴媉______________________
+
+ /// <summary>
+ /// 缃戝叧鏄惁宸茬粡瀛樺湪
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ /// <returns></returns>
+ public bool IsGatewayExist(ZbGateway zbGateway)
+ {
+ return this.IsGatewayExist(zbGateway.GwId);
+ }
+
+ /// <summary>
+ /// 缃戝叧鏄惁宸茬粡瀛樺湪
+ /// </summary>
+ /// <param name="gatewayId">缃戝叧ID</param>
+ /// <returns></returns>
+ public bool IsGatewayExist(string gatewayId)
+ {
+ if (gatewayId == null)
+ {
+ return false;
+ }
+ return dicGateway.ContainsKey(gatewayId);
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧瀹氫綅___________________________
+
+ /// <summary>
+ /// 鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆)
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ public void SetFixedPositionCommand(ZbGateway zbGateway)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, zbGateway) == false)
+ {
+ return;
+ }
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 85 } };
- if (this.IsGatewayExist(zbGateway) == true)
- {
- realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
- }
- else
- {
- //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
- realWay.SendLocation("GwLinuxLocate_Respon", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
- }
- }
-
- #endregion
-
- #region 鈻� 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D___________
-
+ if (this.IsGatewayExist(zbGateway) == true)
+ {
+ realWay.Send("GwLinuxLocate_Respon", jObject.ToString());
+ }
+ else
+ {
+ //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
+ realWay.SendLocation("GwLinuxLocate_Respon", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D___________
+
/// <summary>
/// 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D
/// </summary>
/// <returns>浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D</returns>
public Dictionary<string, GatewayResult> GetGateWayListFromDataBase()
- {
- Dictionary<string, GatewayResult> dicDbGateway = null;
- if (UserCenterResourse.UserInfo.AuthorityNo == 3)
- {
- //鎴愬憳
- return dicDbGateway;
- }
-
- bool canBreak = false;
- HdlThreadLogic.Current.RunThread(() =>
- {
- List<string> list = new List<string>() { "NotCheck" };
-
- //璁剧疆璁块棶鎺ュ彛鐨勫弬鏁�
- var pra = new GetGatewayPra();
- pra.ReqDto.PageSetting.Page = 1;
- pra.ReqDto.PageSetting.PageSize = 999;
- //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
- pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
- var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
- if (string.IsNullOrEmpty(result) == true)
- {
- canBreak = true;
- return;
- }
- var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult>(result);
-
- Dictionary<string, GatewayResult> dic = new Dictionary<string, GatewayResult>();
- foreach (var data in infoResult.PageData)
- {
- dic[data.GatewayUniqueId] = data;
- }
- dicDbGateway = dic;
- canBreak = true;
- });
-
- int count = 0;
- while (canBreak == false)
- {
- System.Threading.Thread.Sleep(200);
- count++;
- if (count == 25)
- {
- //濡傛灉5绉掕繕涓嶈兘鑾峰彇寰楀埌鏁版嵁锛屽垯涓柇姝ゆ鎿嶄綔
- break;
- }
+ {
+ Dictionary<string, GatewayResult> dicDbGateway = null;
+ if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+ {
+ //鎴愬憳
+ return dicDbGateway;
+ }
+
+ bool canBreak = false;
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ List<string> list = new List<string>() { "NotCheck" };
+
+ //璁剧疆璁块棶鎺ュ彛鐨勫弬鏁�
+ var pra = new GetGatewayPra();
+ pra.ReqDto.PageSetting.Page = 1;
+ pra.ReqDto.PageSetting.PageSize = 999;
+ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+ pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+ var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
+ if (string.IsNullOrEmpty(result) == true)
+ {
+ canBreak = true;
+ return;
+ }
+ var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult>(result);
+
+ Dictionary<string, GatewayResult> dic = new Dictionary<string, GatewayResult>();
+ foreach (var data in infoResult.PageData)
+ {
+ dic[data.GatewayUniqueId] = data;
+ }
+ dicDbGateway = dic;
+ canBreak = true;
+ });
+
+ int count = 0;
+ while (canBreak == false)
+ {
+ System.Threading.Thread.Sleep(200);
+ count++;
+ if (count == 25)
+ {
+ //濡傛灉5绉掕繕涓嶈兘鑾峰彇寰楀埌鏁版嵁锛屽垯涓柇姝ゆ鎿嶄綔
+ break;
+ }
}
return dicDbGateway;
- }
-
- #endregion
-
- #region 鈻� 璁剧疆缃戝叧缁忕含搴____________________
-
- /// <summary>
- /// 璁剧疆缃戝叧缁忕含搴�
- /// </summary>
- /// <param name="gateway">缃戝叧瀵硅薄</param>
- /// <param name="Longitude">缁忓害</param>
- /// <param name="Latitude">缁村害</param>
- /// <param name="mode">鏄剧ず閿欒</param>
- /// <returns></returns>
- public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
- {
- ZbGateway realWay = null;
- if (this.GetRealGateway(ref realWay, gateway) == false)
- {
- if (mode == ShowErrorMode.YES)
- {
- //閿欒:缃戝叧瀵硅薄涓㈠け
- string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
- this.ShowTipMsg(msg);
- }
- return false;
- }
- if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
- {
- //娌℃湁閰嶇疆杩囩粡绾害
- return true;
- }
-
- int result = -1;
- Action<string, string> action = (topic, message) =>
- {
- var gatewayID = topic.Split('/')[0];
- if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
- {
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
- }
- };
- realWay.Actions += action;
- //涓や綅灏忔暟
- Longitude = Math.Round(Longitude, 2);
- Latitude = Math.Round(Latitude, 2);
-
- int intLongitude = Convert.ToInt32(Longitude.ToString().Replace(".", string.Empty));
- int intLatitude = Convert.ToInt32(Latitude.ToString().Replace(".", string.Empty));
-
- var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
- var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
- jObject.Add("Data", data);
- if (this.IsGatewayExist(gateway) == true)
- {
- realWay.Send("Logic/SetSite", jObject.ToString());
- }
- else
- {
- //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
- realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
- }
-
- int TimeOut = 0;
- while (result == -1 && TimeOut < 30)
- {
- System.Threading.Thread.Sleep(100);
- TimeOut++;
- }
-
- realWay.Actions -= action;
- if (result != 0)
- {
- if (mode == ShowErrorMode.YES)
- {
- //璁剧疆缃戝叧缁忕含搴﹀け璐�
- string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
- if (result == -1)
- {
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
- }
- this.ShowTipMsg(msg);
- }
- return false;
- }
-
- return true;
- }
-
- #endregion
-
- #region 鈻� 瑙g粦浜戠缃戝叧_______________________
-
- /// <summary>
- /// 瑙g粦浜戠缁戝畾鐨勭綉鍏�
- /// </summary>
+ }
+
+ #endregion
+
+ #region 鈻� 璁剧疆缃戝叧缁忕含搴____________________
+
+ /// <summary>
+ /// 璁剧疆缃戝叧缁忕含搴�
+ /// </summary>
+ /// <param name="gateway">缃戝叧瀵硅薄</param>
+ /// <param name="Longitude">缁忓害</param>
+ /// <param name="Latitude">缁村害</param>
+ /// <param name="mode">鏄剧ず閿欒</param>
+ /// <returns></returns>
+ public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
+ {
+ ZbGateway realWay = null;
+ if (this.GetRealGateway(ref realWay, gateway) == false)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //閿欒:缃戝叧瀵硅薄涓㈠け
+ string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
+ this.ShowTipMsg(msg);
+ }
+ return false;
+ }
+ if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
+ {
+ //娌℃湁閰嶇疆杩囩粡绾害
+ return true;
+ }
+
+ int result = -1;
+ Action<string, string> action = (topic, message) =>
+ {
+ var gatewayID = topic.Split('/')[0];
+ if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+ result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
+ }
+ };
+ realWay.Actions += action;
+ //涓や綅灏忔暟
+ Longitude = Math.Round(Longitude, 2);
+ Latitude = Math.Round(Latitude, 2);
+
+ int intLongitude = Convert.ToInt32(Longitude.ToString().Replace(".", string.Empty));
+ int intLatitude = Convert.ToInt32(Latitude.ToString().Replace(".", string.Empty));
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
+ jObject.Add("Data", data);
+ if (this.IsGatewayExist(gateway) == true)
+ {
+ realWay.Send("Logic/SetSite", jObject.ToString());
+ }
+ else
+ {
+ //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
+ realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
+ }
+
+ int TimeOut = 0;
+ while (result == -1 && TimeOut < 30)
+ {
+ System.Threading.Thread.Sleep(100);
+ TimeOut++;
+ }
+
+ realWay.Actions -= action;
+ if (result != 0)
+ {
+ if (mode == ShowErrorMode.YES)
+ {
+ //璁剧疆缃戝叧缁忕含搴﹀け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
+ if (result == -1)
+ {
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+ }
+ this.ShowTipMsg(msg);
+ }
+ return false;
+ }
+
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 瑙g粦浜戠缃戝叧_______________________
+
+ /// <summary>
+ /// 瑙g粦浜戠缁戝畾鐨勭綉鍏�
+ /// </summary>
/// <param name="strWayId"></param>
- public bool DeleteDataBaseGateway(string strWayId)
- {
- var Pra = new DeleteGatewayPra();
- Pra.BindGateways.Add(strWayId);
- //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
- Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
- List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
-
- bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
- if (result == false)
- {
- return false;
- }
- return true;
- }
-
- #endregion
-
- #region 鈻� 鏂綉澶囦唤鍙婄粦瀹氱綉鍏矷D_______________
-
- /// <summary>
- /// 鍦ㄦ病缃戠殑鎯呭喌涓嬪浠界綉鍏矷D
- /// </summary>
- /// <param name="zbGateway"></param>
- public void BackupGatewayIdOnNotNetwork(ZbGateway zbGateway)
- {
- var strId = zbGateway.GwId;
- if (listBackupGwId.Contains(strId) == false)
- {
- listBackupGwId.Add(strId);
-
- //澶囦唤
- HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
- }
- }
-
- /// <summary>
- /// 閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
- /// </summary>
- public void ResetComandToBindBackupGateway()
- {
- HdlThreadLogic.Current.RunThread(() =>
- {
- var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
- if (fileData == null)
- {
- return;
- }
- this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
- var listTempId = new List<string>();
- listTempId.AddRange(this.listBackupGwId);
-
- //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�
- var bindGateway = new BindGatewayPra();
- //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
- bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
- foreach (var gwId in listTempId)
- {
- bindGateway.BindGateways.Clear();
- bindGateway.BindGateways.Add(gwId);
- var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
- if (result == "Success")
- {
- this.listBackupGwId.Remove(gwId);
- }
- if (result == "Error")
- {
- break;
- }
- }
-
- if (this.listBackupGwId.Count == 0)
- {
- //濡傛灉娌℃湁浜嗗唴瀹�,鍒欏垹闄ゆ枃浠�
- string file = DirNameResourse.BackupGatewayIdFile;
- if (System.IO.File.Exists(file) == true)
- {
- System.IO.File.Delete(file);
- }
- }
- else
- {
- //澶囦唤
- HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
- }
- });
- }
-
- #endregion
-
- #region 鈻� 鍙戦�佺綉鍏冲懡浠ょ粰缃戝叧_________________
-
- /// <summary>
- /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(ReceiptData涓鸿繑鍥炲��)
- /// </summary>
- /// <param name="gateway">缃戝叧瀵硅薄</param>
- /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
- /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param>
- /// <param name="receiptTopic">鎸囧畾鎺ユ敹鍝釜涓婚</param>
- /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
- /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
- /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
- public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5, bool useLocalConnect = false)
- {
- var reResult = new ReceiptGatewayResult();
-
- ZbGateway myGateway = null;
- if (this.GetRealGateway(ref myGateway, gateway) == false)
- {
- //鑾峰彇缃戝叧瀵硅薄澶辫触
- reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
- reResult.ErrorMsgDiv = -1;
- return reResult;
- }
- //缃戝叧ID
- string gatewayID = gateway.GwId;
- //閿欒涓婚
- string errorTopic = gatewayID + "/" + "Error_Respon";
- //妫�娴嬪璞$殑涓婚
- string checkTopic = gatewayID + "/" + receiptTopic;
-
- Action<string, string> receiptAction = (topic, message) =>
- {
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- //缃戝叧鍥炲閿欒
- if (topic == errorTopic)
- {
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
- reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
- }
- //濡傛灉鏄寚瀹氱殑涓婚
- if (topic == checkTopic)
- {
- reResult.ReceiptData = jobject["Data"].ToString();
- }
- };
- myGateway.Actions += receiptAction;
- //鍙戦�佹暟鎹�
- if (useLocalConnect == false)
- {
- myGateway.Send(sendTopic, sendData);
- }
- else
- {
- myGateway.SendLocation(sendTopic, System.Text.Encoding.UTF8.GetBytes(sendData));
- }
-
- //瓒呮椂鏃堕棿
- int TimeOut = 0;
- waitTime = 20 * waitTime;
- while (reResult.ReceiptData == null && TimeOut < waitTime)
- {
- //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
- System.Threading.Thread.Sleep(50);
- TimeOut++;
- }
- myGateway.Actions -= receiptAction;
- receiptAction = null;
- if (reResult.ReceiptData == null)
- {
- reResult.ErrorMsgDiv = 0;
- }
-
- return reResult;
- }
-
- #endregion
-
- #region 鈻� 缃戝叧鐩戣___________________________
-
- /// <summary>
- /// 褰撳墠鐨勭綉缁滆繛鎺ユā寮�
- /// </summary>
- private GatewayConnectMode nowGwConnectMode = GatewayConnectMode.None;
- /// <summary>
- /// 鏄惁瀛樺湪缃戝叧姝e湪鍗囩骇
- /// </summary>
- private bool hadGatewayUpdate = false;
-
- /// <summary>
- /// 褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
- /// </summary>
- /// <param name="connectMode">缃戝叧鍙樻洿鍚庣殑杩炴帴鏂瑰紡</param>
- public void CheckGatewayByConnectChanged(GatewayConnectMode connectMode)
- {
- this.nowGwConnectMode = connectMode;
- }
-
- /// <summary>
- /// 寮�鍚娴嬬綉鍏冲湪绾跨姸鎬佺殑绾跨▼(姝ゆ柟娉曟槸缁欒澶囧垪琛ㄧ晫闈㈢敤鐨�)
- /// </summary>
- /// <param name="frameLayout">鐣岄潰瀵硅薄</param>
- public void StartCheckGatewayOnlineThread(EditorCommonForm frameLayout)
- {
- HdlThreadLogic.Current.RunThread(() =>
- {
- int waitCount = 0;
- //濡傛灉浣忓畢ID鍙樻洿浜�,鍒欎笉鍐嶅鐞�
- while (frameLayout.Parent != null && Config.Instance.HomeId != string.Empty)
- {
- System.Threading.Thread.Sleep(1000);
- if (this.hadGatewayUpdate == true)
- {
- //缃戝叧姝e湪鍗囩骇,涓嶉渶瑕佹搷浣�
- continue;
- }
-
- waitCount++;
- if (this.nowGwConnectMode == GatewayConnectMode.Remote)
- {
- //杩滅▼姣�20绉掓娴嬩竴娆�
- if (waitCount < 20) { continue; }
- }
- else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
- {
- //灞�鍩熺綉姣�5绉掓娴嬩竴娆�
- if (waitCount < 5) { continue; }
- }
- waitCount = 0;
-
- //鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
- Dictionary<string, bool> dicOldOnline = this.GetOldGatewayOnlineStatu();
- if (dicOldOnline == null)
- {
- //鍒欎笉澶勭悊
- continue;
- }
- //鍙互鍙�4G
- if (this.nowGwConnectMode == GatewayConnectMode.Remote)
- {
- //鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
- this.CheckGatewayStatuByRemote(dicOldOnline);
- }
- //WIFI
- else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
- {
- //鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
- this.CheckGatewayStatuByWIFI(dicOldOnline);
- }
- }
- }, ShowErrorMode.NO);
- }
-
- /// <summary>
- /// 鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
- /// </summary>
- private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
- {
- //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧
- List<ZbGateway> list = this.GetAllGatewayFromGateway();
- foreach (var way in list)
- {
- //灏嗘爣璇嗙疆涓篺alse
- way.GatewayOnlineFlage = false;
- }
- //绛変釜2绉�
- System.Threading.Thread.Sleep(2000);
-
- //2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�
- var hadGwOnline = false;
- foreach (var way in list)
- {
- if (dicOldOnline.ContainsKey(way.GwId) == true)
- {
- if (way.GatewayOnlineFlage == true)
- {
- //鏈変竴涓綉鍏冲湪绾�,鍗冲湪绾�
- hadGwOnline = true;
- break;
- }
- }
- }
-
- foreach (var way in list)
- {
- string gwId = way.GwId;
- if (dicOldOnline.ContainsKey(gwId) == true)
- {
- //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ�佸惂
- this.PushGatewayOnlineStatuToForm(gwId, way.GatewayOnlineFlage, hadGwOnline);
- }
- else
- {
- //娌℃湁鍖呭惈,榛樿涓篺alse
- this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
- }
- }
- }
-
- /// <summary>
- /// 鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
- /// </summary>
- private void CheckGatewayStatuByRemote(Dictionary<string, bool> dicOldOnline)
- {
- //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
- Dictionary<string, GatewayResult> dicDbGateway = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
- if (dicDbGateway == null)
- {
- //濡傛灉缃戠粶涓嶉��,鍒欎篃寰�涓嬭蛋
- dicDbGateway = new Dictionary<string, GatewayResult>();
- }
-
- //2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�
- var hadGwOnline = false;
- foreach (var gwId in dicOldOnline.Keys)
- {
- //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
- if (dicDbGateway.ContainsKey(gwId) == true
- && dicDbGateway[gwId].MqttOnlineStatus == true)
- {
- //鏈変竴涓綉鍏冲湪绾�,鍗冲湪绾�
- hadGwOnline = true;
- break;
- }
- }
-
- foreach (var gwId in dicOldOnline.Keys)
- {
- //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
- if (dicDbGateway.ContainsKey(gwId) == true)
- {
- //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ��
- this.PushGatewayOnlineStatuToForm(gwId, dicDbGateway[gwId].MqttOnlineStatus, hadGwOnline);
- }
- else
- {
- //浜戠涓嶅寘鍚殑,褰撲笉鍦ㄧ嚎澶勭悊
- this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
- }
- }
- }
-
- /// <summary>
- /// 鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
- /// </summary>
- /// <returns></returns>
- private Dictionary<string, bool> GetOldGatewayOnlineStatu()
- {
- if (this.dicGateway.Count == 0)
- {
- //娌℃湁缃戝叧,鍒欎笉澶勭悊
- return null;
- }
-
- try
- {
- var dicOldOnline = new Dictionary<string, bool>();
- //濡傛灉鍦ㄥ惊鐜殑杩囩▼涓�,鍔ㄤ簡閲岄潰鐨勪笢瑗�,鎶ラ敊鍒欎笉鐞嗗畠,涓嬩竴鍥炲悎
- foreach (var zbway in this.dicGateway.Values)
- {
- //鑾峰彇鍓嶅洖鐨勫湪绾跨姸鎬�
- dicOldOnline[zbway.GwId] = zbway.GatewayOnlineFlage;
- }
- return dicOldOnline;
- }
- catch { return null; }
- }
-
- /// <summary>
- /// 灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
- /// </summary>
- /// <param name="gwId"></param>
- /// <param name="online"></param>
- /// <param name="hadGwOnline">2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�</param>
- private void PushGatewayOnlineStatuToForm(string gwId, bool online, bool hadGwOnline)
- {
- try
- {
- for (int i = 0; i < UserCenterResourse.listActionFormId.Count; i++)
- {
- string formId = UserCenterResourse.listActionFormId[i];
- if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
- {
- continue;
- }
- //缃戝叧鍦ㄧ嚎鎺ㄩ��
- var zbway = this.GetLocalGateway(gwId);
- if (zbway != null)
- {
- //鍒囨崲浣忓畢鏃�,杩欎釜涓滆タ鏈夊彲鑳芥槸null
- zbway.GatewayOnlineFlage = online;
- UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
- }
- }
- }
- catch { }
- }
-
- /// <summary>
- /// 璁剧疆瀛樺湪缃戝叧姝e湪鍗囩骇鐨勬爣璇�
- /// </summary>
- /// <param name="update">鏄惁鏈夌綉鍏冲湪鍗囩骇</param>
- public void SetHadGatewayUpdateFlage(bool update)
- {
- this.hadGatewayUpdate = update;
- }
-
- #endregion
-
- #region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <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
- }
-}
+ public bool DeleteDataBaseGateway(string strWayId)
+ {
+ var Pra = new DeleteGatewayPra();
+ Pra.BindGateways.Add(strWayId);
+ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+ Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+ List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
+
+ bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
+ if (result == false)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鏂綉澶囦唤鍙婄粦瀹氱綉鍏矷D_______________
+
+ /// <summary>
+ /// 鍦ㄦ病缃戠殑鎯呭喌涓嬪浠界綉鍏矷D
+ /// </summary>
+ /// <param name="zbGateway"></param>
+ public void BackupGatewayIdOnNotNetwork(ZbGateway zbGateway)
+ {
+ var listBackupGwId = new List<string>();
+ var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
+ if (fileData != null)
+ {
+ listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
+ }
+
+ if (listBackupGwId.Contains(zbGateway.GwId) == false)
+ {
+ listBackupGwId.Add(zbGateway.GwId);
+
+ //澶囦唤
+ HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
+ }
+ }
+
+ /// <summary>
+ /// 閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
+ /// </summary>
+ public bool ResetComandToBindBackupGateway()
+ {
+ var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
+ if (fileData == null)
+ {
+ return true;
+ }
+ var listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
+ var listTempId = new List<string>();
+ listTempId.AddRange(listBackupGwId);
+
+ //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�
+ var bindGateway = new BindGatewayPra();
+ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+ bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+ foreach (var gwId in listTempId)
+ {
+ if (this.IsGatewayExist(gwId) == true)
+ {
+ bindGateway.BindGateways.Clear();
+ bindGateway.BindGateways.Add(gwId);
+ var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
+ if (result == "Success")
+ {
+ listBackupGwId.Remove(gwId);
+ }
+ if (result == "Error")
+ {
+ break;
+ }
+ }
+ listBackupGwId.Remove(gwId);
+ }
+
+ if (listBackupGwId.Count == 0)
+ {
+ //濡傛灉娌℃湁浜嗗唴瀹�,鍒欏垹闄ゆ枃浠�
+ string file = DirNameResourse.BackupGatewayIdFile;
+ if (System.IO.File.Exists(file) == true)
+ {
+ System.IO.File.Delete(file);
+ }
+ return true;
+ }
+ else
+ {
+ //澶囦唤
+ HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
+ return false;
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鍙戦�佺綉鍏冲懡浠ょ粰缃戝叧_________________
+
+ /// <summary>
+ /// 鍙戦�佹暟鎹埌缃戝叧锛屽苟鎺ュ彈缃戝叧杩斿洖鐨勬暟鎹�(ReceiptData涓鸿繑鍥炲��)
+ /// </summary>
+ /// <param name="gateway">缃戝叧瀵硅薄</param>
+ /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
+ /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param>
+ /// <param name="receiptTopic">鎸囧畾鎺ユ敹鍝釜涓婚</param>
+ /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
+ /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
+ /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
+ public ReceiptGatewayResult SendJobjectDataToGateway(string gatewayId, string sendTopic, string sendData, string receiptTopic, int waitTime = 5, bool useLocalConnect = false)
+ {
+ var reResult = new ReceiptGatewayResult();
+
+ //閿欒涓婚
+ string errorTopic = gatewayId + "/" + "Error_Respon";
+ //妫�娴嬪璞$殑涓婚
+ string checkTopic = gatewayId + "/" + receiptTopic;
+
+ HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+ //缃戝叧鍥炲閿欒
+ if (topic == errorTopic)
+ {
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+ reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
+ }
+ //濡傛灉鏄寚瀹氱殑涓婚
+ if (topic == checkTopic)
+ {
+ reResult.ReceiptData = jobject["Data"].ToString();
+ }
+ });
+
+ //鍙戦�佹暟鎹�
+ this.SendJobjectData(gatewayId, sendTopic, sendData, useLocalConnect);
+
+ //瓒呮椂鏃堕棿
+ int TimeOut = 0;
+ waitTime = 20 * waitTime;
+ while (reResult.ReceiptData == null && TimeOut < waitTime)
+ {
+ //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
+ System.Threading.Thread.Sleep(50);
+ TimeOut++;
+ }
+ //绉婚櫎缃戝叧鐩戝惉浜嬩欢
+ HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+ if (reResult.ReceiptData == null)
+ {
+ reResult.ErrorMsgDiv = 0;
+ }
+
+ return reResult;
+ }
+
+ /// <summary>
+ /// 鍗曠函鎵ц鍙戦�乯son鏁版嵁鍒扮綉鍏�
+ /// </summary>
+ /// <param name="i_gatewayId">缃戝叧id</param>
+ /// <param name="topic">涓婚</param>
+ /// <param name="sendData">鍙戦�佺殑json鏁版嵁</param>
+ /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
+ public void SendJobjectData(string i_gatewayId, string topic, string sendData, bool useLocalConnect = false)
+ {
+ ZbGateway realWay = null;
+ for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
+ {
+ //瀵绘壘鐪熷疄鐗╃悊缃戝叧瀵硅薄
+ if (ZbGateway.GateWayList[i].GwId == i_gatewayId)
+ {
+ realWay = ZbGateway.GateWayList[i];
+ break;
+ }
+ }
+ if (realWay == null)
+ {
+ //濡傛灉缃戝叧瀵硅薄涓㈠け浜�,鍒欏垱寤轰釜鏂扮殑
+ realWay = new ZbGateway { IsVirtual = true, };
+ realWay.GwId = i_gatewayId;
+ realWay.HomeId = Config.Instance.HomeId;
+ ZbGateway.GateWayList.Add(realWay);
+ }
+ if (useLocalConnect == false)
+ {
+ realWay.Send(topic, System.Text.Encoding.UTF8.GetBytes(sendData));
+ }
+ else
+ {
+ //寮哄埗浣跨敤鏈湴杩炴帴
+ realWay.SendLocation(topic, System.Text.Encoding.UTF8.GetBytes(sendData));
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鏇存崲缃戝叧___________________________
+
+ /// <summary>
+ /// 鎵ц鏇存崲缃戝叧(閲岄潰鏄瓙绾跨▼鎵ц)
+ /// </summary>
+ /// <param name="i_realGateway">鏂扮綉鍏�</param>
+ /// <param name="i_targetGwId">琚浛鎹㈢殑鐩爣缃戝叧</param>
+ /// <param name="i_info">澶囦唤鏁版嵁</param>
+ /// <param name="finishEvent">-1:寮傚父澶辫触 0:娌℃湁澶囦唤鏁版嵁 1:鎴愬姛</param>
+ public void DoReplaceGateway(ZbGateway i_realGateway, string i_targetGwId, BackupListNameInfo i_info, Action<int> finishEvent)
+ {
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ //姝e湪鑾峰彇閰嶇疆鏁版嵁
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGettingConfigurationData));
+
+ System.Threading.Thread.Sleep(1000);
+
+ //棣栧厛鐨勬洿鏂颁簯绔�
+
+ //鐒跺悗鍙戞暟鎹粰缃戝叧,璁╃綉鍏冲幓涓嬭浇鏁版嵁
+ var result = HdlGatewayBackupLogic.Current.RecoverGateway(i_realGateway, i_info.Id, i_info.IsAutoBack, false);
+ if (result == false)
+ {
+ finishEvent?.Invoke(-1);
+ return;
+ }
+ //姝e湪鍙樻洿鏈湴閰嶇疆
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uChangingLocalConfiguration));
+ ProgressFormBar.Current.ResetProgressBar();
+
+ System.Threading.Thread.Sleep(1500);
+
+ //鏍煎紡鍖栨棫缃戝叧
+ string strComand = "{\"Cluster_ID\":0,\"Command\":160,\"Data\": {\"DelAllInfo\": 1}}";
+ this.SendJobjectData(i_targetGwId, "Formate", strComand, true);
+
+ //鍒犻櫎鎺夎鏇挎崲鐨勭綉鍏�
+ this.DeleteGatewayFile(i_targetGwId);
+ ProgressFormBar.Current.SetValue(1);
+
+ System.Threading.Thread.Sleep(500);
+ ProgressFormBar.Current.Close();
+
+ finishEvent?.Invoke(1);
+ });
+ }
+
+ /// <summary>
+ /// 鍦ㄧ綉鍏虫浛鎹箣鍓�,鑾峰彇缃戝叧鐨勪竴涓浠芥暟鎹�
+ /// </summary>
+ /// <param name="i_gwId">缃戝叧ID</param>
+ /// <param name="statu">-1:寮傚父澶辫触 0:娌℃湁澶囦唤鏁版嵁 1:鎴愬姛</param>
+ /// <returns></returns>
+ private BackupListNameInfo GetBackupInfoBeforeReplace(string i_gwId, ref int statu)
+ {
+ //鑾峰彇鑷姩澶囦唤鐨勬暟鎹�
+ var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(3, i_gwId);
+ if (pageData == null)
+ {
+ statu = -1;
+ return null;
+ }
+ //濡傛灉鑾峰彇涓嶅埌鑷姩澶囦唤,鍒欏幓鑾峰彇鎵嬪姩澶囦唤
+ if (pageData.Count == 0)
+ {
+ //浠庝簯绔幏鍙栨暟鎹�
+ pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(2, i_gwId);
+ if (pageData == null)
+ {
+ statu = -1;
+ return null;
+ }
+ }
+ else
+ {
+ //鑷姩澶囦唤
+ pageData[0].IsAutoBack = 1;
+ }
+ if (pageData.Count == 0)
+ {
+ //娌℃湁澶囦唤
+ statu = 0;
+ return null;
+ }
+ statu = 1;
+ return pageData[0];
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧鐩戣___________________________
+
+ /// <summary>
+ /// 褰撳墠鐨勭綉缁滆繛鎺ユā寮�
+ /// </summary>
+ private GatewayConnectMode nowGwConnectMode = GatewayConnectMode.None;
+ /// <summary>
+ /// 鏄惁瀛樺湪缃戝叧姝e湪鍗囩骇
+ /// </summary>
+ private bool hadGatewayUpdate = false;
+
+ /// <summary>
+ /// 褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮�
+ /// </summary>
+ /// <param name="connectMode">缃戝叧鍙樻洿鍚庣殑杩炴帴鏂瑰紡</param>
+ public void CheckGatewayByConnectChanged(GatewayConnectMode connectMode)
+ {
+ this.nowGwConnectMode = connectMode;
+ }
+
+ /// <summary>
+ /// 寮�鍚娴嬬綉鍏冲湪绾跨姸鎬佺殑绾跨▼(姝ゆ柟娉曟槸缁欒澶囧垪琛ㄧ晫闈㈢敤鐨�)
+ /// </summary>
+ /// <param name="frameLayout">鐣岄潰瀵硅薄</param>
+ public void StartCheckGatewayOnlineThread(EditorCommonForm frameLayout)
+ {
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ int waitCount = 0;
+ //濡傛灉浣忓畢ID鍙樻洿浜�,鍒欎笉鍐嶅鐞�
+ while (frameLayout.Parent != null && Config.Instance.HomeId != string.Empty)
+ {
+ System.Threading.Thread.Sleep(1000);
+ if (this.hadGatewayUpdate == true)
+ {
+ //缃戝叧姝e湪鍗囩骇,涓嶉渶瑕佹搷浣�
+ continue;
+ }
+
+ waitCount++;
+ if (this.nowGwConnectMode == GatewayConnectMode.Remote)
+ {
+ //杩滅▼姣�20绉掓娴嬩竴娆�
+ if (waitCount < 20) { continue; }
+ }
+ else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
+ {
+ //灞�鍩熺綉姣�8绉掓娴嬩竴娆�
+ if (waitCount < 8) { continue; }
+ }
+ waitCount = 0;
+
+ //鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
+ Dictionary<string, bool> dicOldOnline = this.GetOldGatewayOnlineStatu();
+ if (dicOldOnline == null)
+ {
+ //鍒欎笉澶勭悊
+ continue;
+ }
+ //鍙互鍙�4G
+ if (this.nowGwConnectMode == GatewayConnectMode.Remote)
+ {
+ //鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ this.CheckGatewayStatuByRemote(dicOldOnline);
+ }
+ //WIFI
+ else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
+ {
+ //鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ this.CheckGatewayStatuByWIFI(dicOldOnline);
+ }
+ }
+ }, ShowErrorMode.NO);
+ }
+
+ /// <summary>
+ /// 鍦╓IFI鐨勬潯浠朵笅锛屾鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ /// </summary>
+ private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
+ {
+ //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧
+ List<ZbGateway> list = this.GetAllLocalGateway();
+
+ //2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�
+ var hadGwOnline = false;
+ foreach (var way in list)
+ {
+ if (dicOldOnline.ContainsKey(way.GwId) == true
+ && this.CheckGatewayOnlineByFlage(way) == true)
+ {
+ //鏈変竴涓綉鍏冲湪绾�,鍗冲湪绾�
+ hadGwOnline = true;
+ break;
+ }
+ }
+
+ foreach (var way in list)
+ {
+ string gwId = way.GwId;
+ if (dicOldOnline.ContainsKey(gwId) == true)
+ {
+ //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ�佸惂
+ bool online = this.CheckGatewayOnlineByFlage(way);
+ this.PushGatewayOnlineStatuToForm(gwId, online, hadGwOnline);
+ }
+ else
+ {
+ //娌℃湁鍖呭惈,榛樿涓篺alse
+ this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鍦ㄨ繙绋嬬殑鏉′欢涓嬶紝妫�鏌ョ綉鍏崇殑鍦ㄧ嚎鐘舵��
+ /// </summary>
+ private void CheckGatewayStatuByRemote(Dictionary<string, bool> dicOldOnline)
+ {
+ //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
+ Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
+ if (dicDbGateway == null)
+ {
+ //濡傛灉缃戠粶涓嶉��,鍒欎篃寰�涓嬭蛋
+ dicDbGateway = new Dictionary<string, GatewayResult>();
+ }
+
+ //2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�
+ var hadGwOnline = false;
+ foreach (var gwId in dicOldOnline.Keys)
+ {
+ //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
+ if (dicDbGateway.ContainsKey(gwId) == true
+ && dicDbGateway[gwId].MqttOnlineStatus == true)
+ {
+ //鏈変竴涓綉鍏冲湪绾�,鍗冲湪绾�
+ hadGwOnline = true;
+ break;
+ }
+ }
+
+ foreach (var gwId in dicOldOnline.Keys)
+ {
+ //濡傛灉浜戠涓婇潰鏈夎繖涓綉鍏�
+ if (dicDbGateway.ContainsKey(gwId) == true)
+ {
+ //缃戝叧涔熶笉澶�,鐩存帴鎺ㄩ��
+ this.PushGatewayOnlineStatuToForm(gwId, dicDbGateway[gwId].MqttOnlineStatus, hadGwOnline);
+ }
+ else
+ {
+ //浜戠涓嶅寘鍚殑,褰撲笉鍦ㄧ嚎澶勭悊
+ this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍓嶅洖缃戝叧鐨勫湪绾跨姸鎬�
+ /// </summary>
+ /// <returns></returns>
+ private Dictionary<string, bool> GetOldGatewayOnlineStatu()
+ {
+ if (this.dicGateway.Count == 0)
+ {
+ //娌℃湁缃戝叧,鍒欎笉澶勭悊
+ return null;
+ }
+
+ try
+ {
+ var dicOldOnline = new Dictionary<string, bool>();
+ //濡傛灉鍦ㄥ惊鐜殑杩囩▼涓�,鍔ㄤ簡閲岄潰鐨勪笢瑗�,鎶ラ敊鍒欎笉鐞嗗畠,涓嬩竴鍥炲悎
+ foreach (var zbway in this.dicGateway.Values)
+ {
+ //鑾峰彇鍓嶅洖鐨勫湪绾跨姸鎬�
+ dicOldOnline[zbway.GwId] = this.CheckGatewayOnlineByFlage(zbway);
+ }
+ return dicOldOnline;
+ }
+ catch { return null; }
+ }
+
+ /// <summary>
+ /// 灏嗗彉鍖栫殑缃戝叧鎺ㄩ�佸埌鐣岄潰涓�
+ /// </summary>
+ /// <param name="gwId"></param>
+ /// <param name="online"></param>
+ /// <param name="hadGwOnline">2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�</param>
+ private void PushGatewayOnlineStatuToForm(string gwId, bool online, bool hadGwOnline)
+ {
+ try
+ {
+ for (int i = 0; i < UserCenterResourse.listActionFormId.Count; i++)
+ {
+ string formId = UserCenterResourse.listActionFormId[i];
+ if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
+ {
+ continue;
+ }
+ //缃戝叧鍦ㄧ嚎鎺ㄩ��
+ var zbway = this.GetLocalGateway(gwId);
+ if (zbway != null)
+ {
+ //鍒囨崲浣忓畢鏃�,杩欎釜涓滆タ鏈夊彲鑳芥槸null
+ if (online == true)
+ {
+ zbway.OnlineTime = DateTime.Now;
+ }
+ UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
+ }
+ }
+ }
+ catch { }
+ }
+
+ /// <summary>
+ /// 璁剧疆瀛樺湪缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+ /// </summary>
+ /// <param name="update">鏄惁鏈夌綉鍏冲湪鍗囩骇</param>
+ public void SetHadGatewayUpdateFlage(bool update)
+ {
+ this.hadGatewayUpdate = update;
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 鏄惁鏄痬ini缃戝叧
+ /// </summary>
+ /// <param name="i_zbGateway">缃戝叧瀵硅薄</param>
+ /// <returns></returns>
+ public bool IsMiniGateway(ZbGateway i_zbGateway)
+ {
+ if (i_zbGateway == null) { return false; }
+
+ if (i_zbGateway.LinuxImageType == 11 || i_zbGateway.LinuxImageType == 13)
+ {
+ //杩欎釜缃戝叧鏄痬ini缃戝叧
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇缃戝叧鏄惁鎷ユ湁铏氭嫙椹卞姩
+ /// </summary>
+ /// <param name="i_zbGateway">缃戝叧瀵硅薄</param>
+ /// <returns></returns>
+ public bool CheckGatewayHadDriveCode(ZbGateway i_zbGateway)
+ {
+ if (i_zbGateway == null) { return false; }
+
+ if (i_zbGateway.LinuxImageType != 6 && i_zbGateway.LinuxImageType != 12)
+ {
+ //杩欎釜缃戝叧娌℃湁铏氭嫙椹卞姩
+ return false;
+ }
+ return false;
+ }
+
+ /// <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