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/ZigBee/Device/ZbGateway.cs | 110 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 79 insertions(+), 31 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs index 5802128..eccff57 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs @@ -26,7 +26,7 @@ /// <summary> /// 涓荤綉鍏� /// </summary> - /// <value>The main gate way.</value> + [Newtonsoft.Json.JsonIgnore] public static ZbGateway MainGateWay { get @@ -2664,44 +2664,50 @@ //璁㈤槄涓�涓尋涓嬬嚎鐨勪富棰� await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze"); - await initGateWayBaseInfomation(); - - //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅 - var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId); - if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null) + //濡傛灉杩欎釜鍑芥暟鍗′箙浜嗙殑璇濓紝浼氭帴鏀跺埌浜戠鎺ㄩ�佺殑鎸や笅绾夸富棰橈紝涓嶇煡閬撲负浠�涔� + new Thread(async () => { - if (gateWayList.Count == 1) + await initGateWayBaseInfomation(); + + //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅 + var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId); + if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null) { - gateWayList[0].IsMainGateWay = true; - } - else - { - for (int i = 0; i < gateWayList.Count; i++) + if (gateWayList.Count == 1) { - var gateWay = gateWayList[i]; - var info = await gateWay.GetZbGwInfoAsync(); - if (info == null || info.getGwData == null) + gateWayList[0].IsMainGateWay = true; + } + else + { + for (int i = 0; i < gateWayList.Count; i++) { - continue; - } - if (info.getGwData.IsDominant == 1) - { - for (int j = 0; j < gateWayList.Count; j++) + var gateWay = gateWayList[i]; + var info = await gateWay.GetZbGwInfoAsync(); + if (info == null || info.getGwData == null) { - if (gateWayList[i].GwId == info.getGwData.GwId) - { - gateWayList[i].IsMainGateWay = true; - } - else - { - gateWayList[i].IsMainGateWay = false; - } + continue; } - break; + if (info.getGwData.IsDominant == 1) + { + for (int j = 0; j < gateWayList.Count; j++) + { + if (gateWayList[i].GwId == info.getGwData.GwId) + { + gateWayList[i].IsMainGateWay = true; + } + else + { + gateWayList[i].IsMainGateWay = false; + } + } + break; + } } } } - } + }) + { IsBackground = true }.Start(); + }); } #endregion @@ -2816,6 +2822,24 @@ { DebugPrintLog($"Local鏂紑閫氳杩炴帴鍑哄紓甯�:{ex.Message}"); } + } + + /// <summary> + /// 寮哄埗鏂紑鏈湴鐨勭綉鍏宠繛鎺� + /// </summary> + public async Task CloseLocalConnectionOnForce() + { + try + { + await localMqttClient.DisconnectAsync(); + } + catch { } + finally + { + localIsConnected = false; + //杩欎釜涓滆タ涔熻寮� + localMqttIsConnecting = false; + } } /// <summary> @@ -2838,6 +2862,25 @@ catch (Exception e) { DebugPrintLog($"Remote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}"); + } + } + + /// <summary> + /// 寮哄埗鏂紑杩滅▼Mqtt鐨勯摼鎺� + /// </summary> + /// <returns></returns> + public static async Task CloseRemoteConnectionOnForce() + { + try + { + await RemoteMqttClient.DisconnectAsync(); + } + catch { } + finally + { + remoteIsConnected = false; + //杩欎釜涓滆タ涔熻寮� + remoteMqttIsConnecting = false; } } @@ -3537,6 +3580,11 @@ /// </summary> public void ReSave() { + if (Shared.Common.Config.Instance.Home.IsShowTemplate == true) + { + //灞曠ず妯℃澘鏃�,涓嶅厑璁镐繚瀛樻枃浠�(闃叉灞炴�т笂鎶ョ敤鐨�) + return; + } Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); } #endregion @@ -3553,7 +3601,7 @@ #if DEBUG if (flage == true) { - if (msg.Contains("DeviceStatusReport") == false) + //if (msg.Contains("DeviceInfoRespon") == true) { System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); } -- Gitblit v1.8.0