From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs |  162 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 123 insertions(+), 39 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
index 1429709..7d36d23 100644
--- a/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
@@ -111,7 +111,7 @@
         public void SynchronizeDbGateway()
         {
             //浠庝簯绔幏鍙栫綉鍒楄〃ID
-            Dictionary<string, GatewayResult> result = this.GetGateWayListFromDataBase();
+            Dictionary<string, GatewayResult> result = this.GetGateWayListFromDataBase(Config.Instance.Home.Id);
             if (result == null)
             {
                 return;
@@ -244,12 +244,12 @@
             if (Config.Instance.Home.TemplateMode == 2)
             {
                 //濡傛灉杩欎釜绫诲瀷鐨勭綉鍏冲彧鏈変竴涓ā鏉�,鍒欒嚜鍔ㄥ尮閰�
-                var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
+                var dicName = HdlTemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
                 if (dicName.Count == 1)
                 {
                     foreach (var tempId in dicName.Keys)
                     {
-                        TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
+                        HdlTemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
                         break;
                     }
                 }
@@ -291,7 +291,7 @@
                 return -1;
             }
             //鑾峰彇缃戝叧鐨勪俊鎭�
-            var result = this.GetGatewayInfo(zbGateway, true, mode);
+            var result = this.RefreshGatewayInfo(zbGateway, true, mode);
             if (result == null)
             {
                 if (mode == ShowErrorMode.YES)
@@ -361,7 +361,7 @@
             if (isEsist == false)
             {
                 //娣诲姞澶囦唤
-                HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(this.dicGateway[gwID].FilePath);
             }
 
             return 1;
@@ -495,7 +495,7 @@
             int count = 5;
             while (count >= 0)
             {
-                result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+                result = this.RefreshGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                 if (result != null)
                 {
                     break;
@@ -533,7 +533,7 @@
             if (isEsist == false)
             {
                 //娣诲姞澶囦唤
-                HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(this.dicGateway[gwID].FilePath);
             }
 
             //娣诲姞缃戝叧鐨勮瘽,寮哄埗涓婚〉鍒锋柊
@@ -542,12 +542,12 @@
             if (Config.Instance.Home.TemplateMode == 2)
             {
                 //濡傛灉杩欎釜绫诲瀷鐨勭綉鍏冲彧鏈変竴涓ā鏉�,鍒欒嚜鍔ㄥ尮閰�
-                var dicName = TemplateData.TemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
+                var dicName = HdlTemplateCommonLogic.Current.GetGatewayCanSelectTemplateName(zbGateway);
                 if (dicName.Count == 1)
                 {
                     foreach (var tempId in dicName.Keys)
                     {
-                        TemplateData.TemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
+                        HdlTemplateCommonLogic.Current.AddGatewayTemplateSelect(zbGateway.GwId, tempId);
                         break;
                     }
                 }
@@ -598,7 +598,7 @@
             this.dicGateway[gwID].ReSave();
 
             //娣诲姞鑷姩澶囦唤
-            HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath);
+            HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(zbGateway.FilePath);
 
             return true;
         }
@@ -668,7 +668,7 @@
             if (getGatewayInfo == true)
             {
                 //鑾峰彇缃戝叧淇℃伅
-                var info = this.GetGatewayInfo(realWay, false);
+                var info = this.RefreshGatewayInfo(realWay, false);
                 if (info == null)
                 {
                     //鍏抽棴杩涘害鏉�
@@ -758,7 +758,7 @@
             //绉婚櫎缂撳瓨
             dicGateway.Remove(zbGatewayID);
             //鍒犻櫎鑷姩澶囦唤
-            HdlAutoBackupLogic.DeleteFile(file);
+            HdlBackupLogic.Current.DeleteAutoBackFileStatu(file);
 
             //鍒犻櫎璁惧鏂囦欢
             List<CommonDevice> list = HdlDeviceCommonLogic.Current.GetDeviceByGatewayID(zbGatewayID);
@@ -848,7 +848,7 @@
         private void RefreshGatewayOnlineOnRemode(List<ZbGateway> listGateway)
         {
             //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
-            Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
+            Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase(Config.Instance.Home.Id);
             if (dicDbGateway == null)
             {
                 return;
@@ -1383,7 +1383,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
+                        var result = this.RefreshGatewayInfo(zbGateway, false, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1416,17 +1416,34 @@
         #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)
+        public ZbGatewayData.GetGwData RefreshGatewayInfo(ZbGateway zbGateway, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
+        {
+            //浠庣綉鍏抽偅閲屽埛鏂扮綉鍏充俊鎭�
+            var getGwInfo = this.RefreshGatewayInfo(zbGateway.GwId, useLocalConnect, mode);
+            //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
+            this.SetGatewayDataToLocalMemmory(zbGateway, getGwInfo, false);
+
+            return getGwInfo;
+        }
+
+        /// <summary>
+        /// 浠庣綉鍏抽偅閲屽埛鏂扮綉鍏充俊鎭�
+        /// </summary>
+        /// <param name="gatewateId">缃戝叧ID</param>
+        /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
+        /// <param name="mode"></param>
+        /// <returns></returns>
+        public ZbGatewayData.GetGwData RefreshGatewayInfo(string gatewateId, 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);
+            var result = this.SendJobjectDataToGateway(gatewateId, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
 
             if (result.ErrorMsgDiv != 1)
             {
@@ -1440,18 +1457,15 @@
                 }
                 return null;
             }
+
             var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(result.ReceiptData);
-            string gwID = zbGateway.GwId;
-            if (this.dicGateway.ContainsKey(gwID) == true)
+            if (this.dicGateway.ContainsKey(gatewateId) == true)
             {
                 //鍒锋柊缂撳瓨
-                ZbGateway localWay = this.dicGateway[gwID];
+                ZbGateway localWay = this.dicGateway[gatewateId];
                 //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
                 this.SetGatewayDataToLocalMemmory(localWay, getGwInfo);
             }
-            //椤轰究杩欎釜鍙橀噺涔熻缃竴涓�
-            this.SetGatewayDataToLocalMemmory(zbGateway, getGwInfo, false);
-
             return getGwInfo;
         }
 
@@ -1540,7 +1554,7 @@
                 return new List<FirmwareVersionInfo> { null, null, null };
             }
             //鑾峰彇缃戝叧鐗堟湰淇℃伅
-            var result = this.GetGatewayInfo(zbGateway, false, mode);
+            var result = this.RefreshGatewayInfo(zbGateway, false, mode);
             if (result == null)
             {
                 return null;
@@ -1583,7 +1597,7 @@
             list.Add(coordinatorFirmware);
 
             //杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈
-            if (localWay.LinuxImageType != 6)
+            if (HdlGatewayLogic.Current.CheckGatewayHadDriveCode(localWay) == true)
             {
                 //铏氭嫙椹卞姩鍙�
                 foreach (var data in localWay.DriveCodeList)
@@ -1683,7 +1697,7 @@
         #region 鈻� 璁剧疆缃戝叧鍥剧墖_______________________
 
         /// <summary>
-        /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗�
+        /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗�(宸插簾寮�)
         /// </summary>
         /// <param name="button"></param>
         /// <param name="zbGateway"></param>
@@ -1701,7 +1715,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+                        var result = this.RefreshGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1732,21 +1746,21 @@
             {
                 if (zbGateway.LinuxImageType != -1)
                 {
-                    button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.LinuxImageType + ".png";
+                    this.SetgatewayIcon(button, "Gateway/GatewayIcon" + zbGateway.LinuxImageType + ".png");
                 }
                 else
                 {
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+                        var result = this.RefreshGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
                             this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
                             HdlThreadLogic.Current.RunMain(() =>
                             {
-                                button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
+                                this.SetgatewayIcon(button, "Gateway/GatewayIcon" + result.LinuxImageType + ".png");
                             });
                         }
                     });
@@ -1754,8 +1768,24 @@
             }
             else
             {
-                button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.LinuxImageType + ".png";
+                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
@@ -1906,12 +1936,12 @@
         /// <summary>
         /// 閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
         /// </summary>
-        public void ResetComandToBindBackupGateway()
+        public bool ResetComandToBindBackupGateway()
         {
             var fileData = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.BackupGatewayIdFile);
             if (fileData == null)
             {
-                return;
+                return true;
             }
             this.listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
             var listTempId = new List<string>();
@@ -1939,11 +1969,13 @@
                 {
                     System.IO.File.Delete(file);
                 }
+                return true;
             }
             else
             {
                 //澶囦唤
                 HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.BackupGatewayIdFile, listBackupGwId);
+                return false;
             }
         }
 
@@ -2169,7 +2201,7 @@
         private void CheckGatewayStatuByRemote(Dictionary<string, bool> dicOldOnline)
         {
             //鑾峰彇浜戠涓婇潰鐨勭綉鍏�
-            Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase();
+            Dictionary<string, GatewayResult> dicDbGateway = this.GetGateWayListFromDataBase(Config.Instance.Home.Id);
             if (dicDbGateway == null)
             {
                 //濡傛灉缃戠粶涓嶉��,鍒欎篃寰�涓嬭蛋
@@ -2283,7 +2315,7 @@
         {
             //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖true寰�涓嬭蛋)
             var pra = new { homeId = Config.Instance.Home.Id, mac = i_gatewayId, gatewayType = "ZIGBEEGATEWAY" };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/bindGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/bindGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
             if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
             {
                 return -1;
@@ -2295,11 +2327,11 @@
         /// 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D
         /// </summary>
         /// <returns></returns>
-        public Dictionary<string, GatewayResult> GetGateWayListFromDataBase()
+        public Dictionary<string, GatewayResult> GetGateWayListFromDataBase(string i_homeId)
         {
             //杩欎釜鎺ュ彛鐗规畩,涓嶉渶瑕佹娴嬫潈闄�
-            var pra = new { homeId = Config.Instance.Home.Id };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/getGatewayList", RestSharp.Method.POST, pra);
+            var pra = new { homeId = i_homeId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/getGatewayList", RestSharp.Method.POST, pra);
             if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
             {
                 return null;
@@ -2324,7 +2356,7 @@
         public bool DeleteDataBaseGateway(string strWayId)
         {
             var pra = new { homeId = Config.Instance.Home.Id, mac = strWayId };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/untieGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/gateway/untieGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
             if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
             {
                 return false;
@@ -2337,6 +2369,58 @@
         #region 鈻� 涓�鑸柟娉昣__________________________
 
         /// <summary>
+        /// 妫�娴嬫湰鍦板叏閮ㄧ綉鍏�,鏄惁閮芥敮鎸佸彂閫佸惎鍔ㄦā鏉垮鍏ョ殑Json鍛戒护(杩斿洖鐨勬槸涓嶆敮鎸佸惎鍔ㄥ懡浠ょ殑缃戝叧ID)
+        /// </summary>
+        /// <returns></returns>
+        public List<string> CheckAllGatewayCanSendSetupComand()
+        {
+            var list = new List<string>();
+            foreach (var gateway in this.dicGateway.Values)
+            {
+                if (gateway.LinuxFirmwareVersion < 10205)
+                {
+                    //缃戝叧灏忎簬杩欎釜鐗堟湰,閮介渶瑕佸崌绾�
+                    list.Add(gateway.GwId);
+                }
+            }
+            return list;
+        }
+
+        /// <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>

--
Gitblit v1.8.0