From 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 19 十一月 2020 10:23:45 +0800
Subject: [PATCH] Evoyo.Home1.1.0120111601_Release

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs |  185 +++++++++++++++++++++------------------------
 1 files changed, 86 insertions(+), 99 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index 73158b0..b6df0c0 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -200,16 +200,21 @@
         /// </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)
             {
+                if (logMode == WriteLogMode.YES)
+                {
+                    HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 璁剧疆缁忕含搴﹀け璐�");
+                }
                 return falge;
             }
             //鎵ц娣诲姞缃戝叧鍒板唴瀛�
-            var result = this.DoAddGatewayToMemory(zbGateway, mode);
+            var result = this.DoAddGatewayToMemory(zbGateway, mode, logMode);
             //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
             if (result == 0)
             {
@@ -222,6 +227,10 @@
                         msg = string.Format(msg, "\r\n");
                     }
                     this.ShowTipMsg(msg);
+                }
+                if (logMode == WriteLogMode.YES)
+                {
+                    HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰,浜戠涓嶇粰缁戝畾");
                 }
                 return false;
             }
@@ -267,8 +276,9 @@
         /// </summary>
         /// <param name="zbGateway">缃戝叧瀵硅薄</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
+        /// <param name="logMode">鏄惁鍐橪og</param>
         /// <returns></returns>
-        private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
+        private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO)
         {
             if (zbGateway == null)
             {
@@ -290,6 +300,10 @@
                     string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
                     this.ShowTipMsg(msg);
                 }
+                if (logMode == WriteLogMode.YES)
+                {
+                    HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 鑾峰彇缃戝叧淇℃伅澶辫触");
+                }
                 return -1;
             }
 
@@ -304,6 +318,10 @@
                         //鍚戠綉鍏宠缃綇瀹匢D澶辫触
                         string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
                         this.ShowTipMsg(msg);
+                    }
+                    if (logMode == WriteLogMode.YES)
+                    {
+                        HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 鍚戠綉鍏宠缃綇瀹匢D澶辫触");
                     }
                     return -1;
                 }
@@ -748,7 +766,7 @@
             //鏂紑mqtt杩炴帴
             if (realWay != null)
             {
-                realWay.DisConnectLocalMqttClient("GD");
+                realWay.CloseLocalConnectionOnForce();
             }
 
             return true;
@@ -847,8 +865,8 @@
         {
             foreach (var zbway in listGateway)
             {
-                //鏄惁瀛樺湪缃戝叧瀛樺湪浜嶹IFI涓�
-                if (this.CheckGatewayOnlineByFlage(zbway) == true)
+                //濡傛灉骞挎挱寰楀埌缃戝叧,鍒欎細鍒锋柊OnlineTime,濡傛灉涓庡綋鍓嶆椂闂寸浉宸皯浜庢寚瀹氱鏁�,鍒欏垽鏂负瀛樺湪缃戝叧瀛樺湪浜嶹IFI涓�
+                if ((DateTime.Now - zbway.OnlineTime).TotalSeconds <= ZigBee.Common.Application.SendTime * 2)
                 {
                     return true;
                 }
@@ -903,13 +921,29 @@
             }
 
             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>
+        /// <returns></returns>
         private bool CheckGatewayOnlineByFlage(ZbGateway zbGateway)
         {
             if (this.nowGwConnectMode == GatewayConnectMode.Remote)
@@ -1487,52 +1521,6 @@
 
         #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>
@@ -1544,7 +1532,7 @@
             //鏂紑mqtt杩炴帴(鍗充娇淇濆瓨鍦ㄥ唴瀛樺綋涓篃娌¢棶棰�,鍥犱负濡傛灉骞挎挱涓嶅埌,鍒欏畠涓嶄細寤虹珛閾炬帴)
             for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
             {
-                ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G");
+                ZbGateway.GateWayList[i].CloseLocalConnectionOnForce();
             }
             //鍔犺浇鏈湴缃戝叧瀵硅薄
             if (roadGateway == true)
@@ -2056,54 +2044,53 @@
         /// <summary>
         /// 閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
         /// </summary>
-        public void ResetComandToBindBackupGateway()
+        public bool ResetComandToBindBackupGateway()
         {
-            HdlThreadLogic.Current.RunThread(() =>
+            var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
+            if (fileData == null)
             {
-                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);
+                return true;
+            }
+            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();
+            //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�
+            var bindGateway = new BindGatewayPra();
+            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+            bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-                foreach (var gwId in listTempId)
+            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")
                 {
-                    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;
-                    }
+                    this.listBackupGwId.Remove(gwId);
                 }
+                if (result == "Error")
+                {
+                    break;
+                }
+            }
 
-                if (this.listBackupGwId.Count == 0)
+            if (this.listBackupGwId.Count == 0)
+            {
+                //濡傛灉娌℃湁浜嗗唴瀹�,鍒欏垹闄ゆ枃浠�
+                string file = DirNameResourse.BackupGatewayIdFile;
+                if (System.IO.File.Exists(file) == true)
                 {
-                    //濡傛灉娌℃湁浜嗗唴瀹�,鍒欏垹闄ゆ枃浠�
-                    string file = DirNameResourse.BackupGatewayIdFile;
-                    if (System.IO.File.Exists(file) == true)
-                    {
-                        System.IO.File.Delete(file);
-                    }
+                    System.IO.File.Delete(file);
                 }
-                else
-                {
-                    //澶囦唤
-                    HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
-                }
-            });
+                return true;
+            }
+            else
+            {
+                //澶囦唤
+                HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
+                return false;
+            }
         }
 
         #endregion
@@ -2191,9 +2178,9 @@
             if (realWay == null)
             {
                 //濡傛灉缃戝叧瀵硅薄涓㈠け浜�,鍒欏垱寤轰釜鏂扮殑
-                realWay = new ZbGateway { IsVirtual = true, };
-                realWay.GwId = i_gatewayId;
-                realWay.HomeId = Config.Instance.HomeId;
+                realWay = new ZbGateway { IsVirtual = true, };
+                realWay.GwId = i_gatewayId;
+                realWay.HomeId = Config.Instance.HomeId;
                 ZbGateway.GateWayList.Add(realWay);
             }
             if (useLocalConnect == false)
@@ -2290,7 +2277,7 @@
         private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
         {
             //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑缃戝叧
-            List<ZbGateway> list = this.GetAllGatewayFromGateway();
+            List<ZbGateway> list = this.GetAllLocalGateway();
 
             //2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�
             var hadGwOnline = false;

--
Gitblit v1.8.0