From 2029e64ec0491f7e511dc15bffaf821bfbabe2de Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 20 七月 2020 14:10:22 +0800
Subject: [PATCH] 上传一个很特别的新版本

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs |  160 ++++++++++++++++++++++-------------------------------
 1 files changed, 67 insertions(+), 93 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index 22eced4..fc831b0 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -263,18 +263,7 @@
                 return -1;
             }
             //鑾峰彇缃戝叧鐨勪俊鎭�
-            var result = await zbGateway.GetZbGwInfoAsync();
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                if (mode == ShowErrorMode.YES)
-                {
-                    this.ShowTipMsg(error);
-                }
-                return -1;
-            }
-
+            var result = this.GetGatewayInfo(zbGateway, true, mode);
             if (result == null)
             {
                 if (mode == ShowErrorMode.YES)
@@ -286,28 +275,20 @@
                 return -1;
             }
 
-            if (result.getGwData == null)
-            {
-                if (mode == ShowErrorMode.YES)
-                {
-                    //鑾峰彇缃戝叧淇℃伅澶辫触
-                    string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
-                    this.ShowTipMsg(msg);
-                }
-                return -1;
-            }
-
             //璁剧疆浣忓畢ID鍒扮綉鍏�
-            bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
-            if (flage2 == false)
+            if (result.HomeId != Common.Config.Instance.HomeId)
             {
-                if (mode == ShowErrorMode.YES)
+                bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
+                if (flage2 == false)
                 {
-                    //鍚戠綉鍏宠缃綇瀹匢D澶辫触
-                    string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
-                    this.ShowTipMsg(msg);
+                    if (mode == ShowErrorMode.YES)
+                    {
+                        //鍚戠綉鍏宠缃綇瀹匢D澶辫触
+                        string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
+                        this.ShowTipMsg(msg);
+                    }
+                    return -1;
                 }
-                return -1;
             }
 
             //鏇存柊浜戠鏁版嵁搴�
@@ -337,9 +318,9 @@
             //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
             this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
-            this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
+            this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
             //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
-            this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
+            this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
 
             if (isEsist == false)
             {
@@ -492,12 +473,12 @@
             await Task.Delay(8000);
 
             //鑾峰彇缃戝叧鐨勪俊鎭�
-            ZbGatewayData.GetGwAllData result = null;
+            ZbGatewayData.GetGwData result = null;
             int count = 5;
             while (count >= 0)
             {
-                result = await zbGateway.GetZbGwInfoAsync();
-                if (result != null && result.getGwData != null)
+                result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+                if (result != null)
                 {
                     break;
                 }
@@ -505,15 +486,7 @@
                 //鏈�澶氬啀绛�20绉�
                 await Task.Delay(4000);
             }
-            //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜
-            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
-            if (error != null)
-            {
-                this.ShowTipMsg(error);
-                return -1;
-            }
-
-            if (result == null || result.getGwData == null)
+            if (result == null)
             {
                 //鑾峰彇缃戝叧淇℃伅澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
@@ -535,9 +508,9 @@
             //鍒锋柊鐨勬槸缂撳瓨,涓嶅埛鏂扮湡瀹炵墿鐞嗙綉鍏�
             this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
-            this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
+            this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
             //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
-            this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
+            this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
 
             if (isEsist == false)
             {
@@ -609,15 +582,14 @@
         public async Task<bool> DoSwitchGateway(string gatewayId)
         {
             var zbGateway = this.GetLocalGateway(gatewayId);
-            if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
+
+            //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
+            var result = await this.GetOnlineGatewayInfo(gatewayId);
+            if (result == false)
             {
-                //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
-                var result = await this.GetOnlineGatewayInfo(gatewayId);
-                if (result == false)
-                {
-                    return false;
-                }
+                return false;
             }
+
             //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
             this.SaveGatewayIdToLocation(gatewayId);
             //鍒囨崲缃戝叧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
@@ -666,7 +638,7 @@
             if (getGatewayInfo == true)
             {
                 //鑾峰彇缃戝叧淇℃伅
-                var info = this.GetGatewayInfo(realWay);
+                var info = this.GetGatewayInfo(realWay, false);
                 if (info == null)
                 {
                     //鍏抽棴杩涘害鏉�
@@ -676,7 +648,7 @@
             }
 
             //鑾峰彇鍏ㄩ儴璁惧
-            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
+            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay, false);
             //鍏抽棴杩涘害鏉�
             ProgressBar.Close();
             if (result == -1)
@@ -717,20 +689,11 @@
         public async Task<bool> DeleteGateway(string zbGatewayID)
         {
             ZbGateway realWay = null;
-            bool hadReal = this.GetRealGateway(ref realWay, zbGatewayID);
-
-            //鏆備笉鏀寔鍒嗕韩
-            if (hadReal == true && realWay.GatewayOnlineFlage == true)
+            this.GetRealGateway(ref realWay, zbGatewayID);
+            //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触  涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
+            if (realWay != null)
             {
-                //娓呯┖缃戝叧鐨勪綇瀹匢D
-                bool result = await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.YES);
-                if (result == false)
-                {
-                    //缃戝叧瑙g粦澶辫触  涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
-                    string msg = Language.StringByID(R.MyInternationalizationString.uGatewayUnBindFail);
-                    //this.ShowErrorMsg(msg);
-                    //return false;
-                }
+                await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
             }
 
             //鍒犻櫎浜戠鐨勭綉鍏�
@@ -742,7 +705,10 @@
             //绉婚櫎
             ZbGateway.GateWayList.RemoveAll((obj) => obj.GwId == zbGatewayID);
             //鏂紑mqtt杩炴帴
-            realWay.DisConnectLocalMqttClient("GD");
+            if (realWay != null)
+            {
+                realWay.DisConnectLocalMqttClient("GD");
+            }
 
             return true;
         }
@@ -1308,6 +1274,8 @@
         /// <returns></returns>
         public string GetGatewayName(ZbGateway zbGateway)
         {
+            if (zbGateway == null) { return string.Empty; }
+
             string gwId = zbGateway.GwId;
             if (this.dicGateway.ContainsKey(gwId) == false)
             {
@@ -1321,11 +1289,10 @@
                 return name;
             }
 
-            string keyName = Common.LocalDevice.deviceModelIdName + localWay.LinuxImageType;
-            if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
+            var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
+            if (nameContent != null)
             {
-                //娌℃湁鍚嶇О鏃讹紝鍒欎娇鐢≧鏂囦欢閲岄潰璁剧疆鐨勯粯璁よ澶囧悕绉�
-                return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
+                return nameContent.A澶囨敞鍚嶅瓧;
             }
 
             return string.Empty;
@@ -1362,11 +1329,10 @@
                 //濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇
                 if (zbGateway.LinuxImageType != -1)
                 {
-                    string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
-                    if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
+                    var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                    if (nameContent != null)
                     {
-                        //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
-                        button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
+                        button.Text = nameContent.A瀹樻柟鍚嶅瓧;
                     }
                 }
                 else
@@ -1374,7 +1340,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
+                        var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1382,11 +1348,10 @@
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
-                                string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
-                                if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
+                                var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                                if (nameContent != null)
                                 {
-                                    //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
-                                    button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
+                                    button.Text = nameContent.A瀹樻柟鍚嶅瓧;
                                 }
                             });
                         }
@@ -1395,11 +1360,10 @@
             }
             else
             {
-                string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].LinuxImageType;
-                if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
+                var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                if (nameContent != null)
                 {
-                    //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗�
-                    button.TextID = Common.LocalDevice.Current.dicDeviceAllNameID[keyName];
+                    button.Text = nameContent.A瀹樻柟鍚嶅瓧;
                 }
             }
         }
@@ -1412,13 +1376,14 @@
         /// 鑾峰彇缃戝叧淇℃伅(鐗堟湰淇℃伅,闀滃儚绫诲瀷,鍩烘湰淇℃伅绛夈�傚彧鍒锋柊鏈湴缃戝叧鐨勭紦瀛�)
         /// </summary>
         /// <param name="zbGateway"></param>
+        /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
         /// <param name="mode"></param>
         /// <returns></returns>
-        public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
+        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");
+            var result = this.SendJobjectDataToGateway(zbGateway, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
 
             if (result.ErrorMsgDiv != 1)
             {
@@ -1467,6 +1432,7 @@
             localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
             localWay.CoordinatorImageId = data.ZbImageType;
             localWay.DriveCodeList = data.DriveCodeList;
+            localWay.GwVersionDate = data.AppVersion;
             if (saveFile == true)
             {
                 localWay.ReSave();
@@ -1554,7 +1520,7 @@
         public List<FirmwareVersionInfo> GetGatewayAllNewVersion(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
         {
             //鑾峰彇缃戝叧鐗堟湰淇℃伅
-            var result = this.GetGatewayInfo(zbGateway, mode);
+            var result = this.GetGatewayInfo(zbGateway, false, mode);
             if (result == null)
             {
                 return null;
@@ -1704,7 +1670,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
+                        var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1742,7 +1708,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
+                        var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -2070,8 +2036,9 @@
         /// <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)
+        public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5, bool useLocalConnect = false)
         {
             var reResult = new ReceiptGatewayResult();
 
@@ -2108,7 +2075,14 @@
             };
             myGateway.Actions += receiptAction;
             //鍙戦�佹暟鎹�
-            myGateway.Send(sendTopic, sendData);
+            if (useLocalConnect == false)
+            {
+                myGateway.Send(sendTopic, sendData);
+            }
+            else
+            {
+                myGateway.SendLocation(sendTopic, System.Text.Encoding.UTF8.GetBytes(sendData));
+            }
 
             //瓒呮椂鏃堕棿
             int TimeOut = 0;

--
Gitblit v1.8.0