From ecba45c93391066bc30c7bd602c3a7683fbb99a7 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 31 七月 2020 10:56:12 +0800
Subject: [PATCH] 临时备份

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs |  151 +++++++++++++++++--------------------------------
 1 files changed, 53 insertions(+), 98 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
index 605bbc4..fc831b0 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -196,7 +196,7 @@
         /// </summary>
         /// <param name="zbGateway">缃戝叧</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
-        public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
+        public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode)
         {
             //璁剧疆缃戝叧鐨勭粡绾害
             bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO);
@@ -205,7 +205,7 @@
                 return falge;
             }
             //鎵ц娣诲姞缃戝叧鍒板唴瀛�
-            var result = this.DoAddGatewayToMemory(zbGateway, mode);
+            var result = await this.DoAddGatewayToMemory(zbGateway, mode);
             //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰
             if (result == 0)
             {
@@ -250,7 +250,7 @@
         /// <param name="zbGateway">缃戝叧瀵硅薄</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
         /// <returns></returns>
-        private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
+        private async Task<int> DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
         {
             if (zbGateway == null)
             {
@@ -278,7 +278,7 @@
             //璁剧疆浣忓畢ID鍒扮綉鍏�
             if (result.HomeId != Common.Config.Instance.HomeId)
             {
-                bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
+                bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
                 if (flage2 == false)
                 {
                     if (mode == ShowErrorMode.YES)
@@ -337,28 +337,10 @@
         /// <param name="zbGateway"></param>
         /// <param name="HomeId"></param>
         /// <returns></returns>
-        public bool SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
+        public async Task<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)
+            ZbGateway realWay = null;
+            if (this.GetRealGateway(ref realWay, zbGateway) == false)
             {
                 if (mode == ShowErrorMode.YES)
                 {
@@ -368,11 +350,13 @@
                 }
                 return false;
             }
-            if (result.ErrorMsgDiv == 0)
+
+            var info = await realWay.GwSetHomeIdAsync(HomeId);
+            if (info != null && info.gwSetHomeIdData != null)
             {
-                return false;
+                return true;
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -388,7 +372,7 @@
             //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
             bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-            var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
+            var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" });
             if (result == "Error")
             {
                 return -1;
@@ -434,7 +418,7 @@
         /// </summary>
         /// <param name="zbGateway">缃戝叧</param>
         /// <param name="btnMsg">娑堟伅鎺т欢</param>
-        public int ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
+        public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
         {
             if (zbGateway == null)
             {
@@ -451,7 +435,7 @@
             }
 
             //璁剧疆浣忓畢ID鍒扮綉鍏�
-            bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
+            bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
             if (flage2 == false)
             {
                 //鍚戠綉鍏宠缃綇瀹匢D澶辫触
@@ -486,7 +470,7 @@
                     btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
                 });
             }
-            System.Threading.Thread.Sleep(8000);
+            await Task.Delay(8000);
 
             //鑾峰彇缃戝叧鐨勪俊鎭�
             ZbGatewayData.GetGwData result = null;
@@ -500,7 +484,7 @@
                 }
                 count--;
                 //鏈�澶氬啀绛�20绉�
-                System.Threading.Thread.Sleep(4000);
+                await Task.Delay(4000);
             }
             if (result == null)
             {
@@ -595,10 +579,12 @@
         /// 鎵ц鍒囨崲缃戝叧鎿嶄綔
         /// </summary>
         /// <param name="gatewayId"></param>
-        public bool DoSwitchGateway(string gatewayId)
+        public async Task<bool> DoSwitchGateway(string gatewayId)
         {
+            var zbGateway = this.GetLocalGateway(gatewayId);
+
             //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
-            var result = this.GetOnlineGatewayInfo(gatewayId);
+            var result = await this.GetOnlineGatewayInfo(gatewayId);
             if (result == false)
             {
                 return false;
@@ -617,7 +603,7 @@
         /// </summary>
         /// <param name="gatewayId"></param>
         /// <returns></returns>
-        private bool GetOnlineGatewayInfo(string gatewayId)
+        private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
         {
             //鏄剧ず杩涘害鏉�
             ProgressBar.Show();
@@ -630,7 +616,7 @@
                 //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
                 if (this.HomeIdIsEmpty(realWay.HomeId) == true)
                 {
-                    int result2 = this.ReBindNewGateway(realWay);
+                    int result2 = await this.ReBindNewGateway(realWay);
                     if (result2 == 0)
                     {
                         //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇�
@@ -659,11 +645,6 @@
                     ProgressBar.Close();
                     return false;
                 }
-            }
-            //鍒锋柊鍏ㄩ儴鍦烘櫙
-            if (this.IsMainGateway(realWay) == 1)
-            {
-                HdlSceneLogic.Current.RefreshSceneUIList(false);
             }
 
             //鑾峰彇鍏ㄩ儴璁惧
@@ -694,15 +675,25 @@
         /// <summary>
         /// 鍒犻櫎缃戝叧锛屽寘鎷簯绔拰鏈湴(澶辫触鏃朵笉浼氭樉绀轰俊鎭紝骞朵笖浼氳繑鍥瀟rue)
         /// </summary>
+        /// <param name="zbGateway"></param>
+        public async Task<bool> DeleteGateway(ZbGateway zbGateway)
+        {
+            //绉婚櫎鏈湴缃戝叧淇℃伅
+            return await this.DeleteGateway(zbGateway.GwId);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎缃戝叧锛屽寘鎷簯绔拰鏈湴(澶辫触鏃朵笉浼氭樉绀轰俊鎭紝骞朵笖浼氳繑鍥瀟rue)
+        /// </summary>
         /// <param name="zbGatewayID"></param>
-        public bool DeleteGateway(string zbGatewayID)
+        public async Task<bool> DeleteGateway(string zbGatewayID)
         {
             ZbGateway realWay = null;
             this.GetRealGateway(ref realWay, zbGatewayID);
             //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触  涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
             if (realWay != null)
             {
-                this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
+                await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
             }
 
             //鍒犻櫎浜戠鐨勭綉鍏�
@@ -1496,39 +1487,24 @@
 
         #endregion
 
-        #region 鈻� 娓呯┖鐪熷疄缃戝叧閾炬帴___________________
+        #region 鈻� 娓呯┖鐪熷疄缃戝叧鍒楄〃___________________
 
         /// <summary>
-        /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏崇殑閾炬帴
+        /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏冲璞�
         /// </summary>
-        /// <param name="roadGateway">鏄惁鍔犺浇鏈湴鐨勭綉鍏冲璞″埌鐪熷疄鍒楄〃涓�</param>
-        public void ClearAllRealGatewayConection(bool roadGateway)
+        public void ClearAllRealGateway()
         {
-            //鏂紑mqtt杩炴帴(鍗充娇淇濆瓨鍦ㄥ唴瀛樺綋涓篃娌¢棶棰�,鍥犱负濡傛灉骞挎挱涓嶅埌,鍒欏畠涓嶄細寤虹珛閾炬帴)
-            for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
+            //鍥犱负閭d竴鐬棿锛屾湁鍙兘mqtt浼氬姞鍥炴潵,鎵�浠ュ厛鍔犵紦瀛�
+            var list = new List<ZbGateway>();
+            list.AddRange(ZbGateway.GateWayList);
+            //鐒跺悗娓呯┖鎺�
+            ZbGateway.GateWayList.Clear();
+            //鏈�鍚庡啀鏂紑mqtt杩炴帴
+            for (int i = 0; i < list.Count; i++)
             {
-                ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G");
+                list[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;
-                    }
-                    var tempWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == gateway.GwId));
-                    if (tempWay == null)
-                    {
-                        ZbGateway.GateWayList.Add(tempWay);
-                    }
-                }
-            }
+            list.Clear();
         }
 
         #endregion
@@ -1543,11 +1519,6 @@
         /// <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)
@@ -1633,13 +1604,6 @@
         /// <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)
@@ -1675,16 +1639,12 @@
         /// <returns></returns>
         public int IsMainGateway(string waiID)
         {
-            var realWay = ZbGateway.GateWayList.Find((obj) =>
-            {
-                return obj.GwId == waiID;
-            });
-            //铏氭嫙缃戝叧涔熻繑鍥� 0
-            if (realWay == null || realWay.IsVirtual == true)
+            ZbGateway zbGateway = null;
+            if (this.GetRealGateway(ref zbGateway, waiID) == false)
             {
                 return 0;
             }
-            return realWay.IsMainGateWay == true ? 1 : 2;
+            return zbGateway.IsMainGateWay == true ? 1 : 2;
         }
 
         #endregion
@@ -1851,7 +1811,7 @@
                 //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
                 pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-                var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
+                var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list);
                 if (string.IsNullOrEmpty(result) == true)
                 {
                     canBreak = true;
@@ -1907,11 +1867,6 @@
                     this.ShowTipMsg(msg);
                 }
                 return false;
-            }
-            if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
-            {
-                //娌℃湁閰嶇疆杩囩粡绾害
-                return true;
             }
 
             int result = -1;
@@ -1988,7 +1943,7 @@
 
             List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
 
-            bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
+            bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError);
             if (result == false)
             {
                 return false;
@@ -2041,7 +1996,7 @@
                 {
                     bindGateway.BindGateways.Clear();
                     bindGateway.BindGateways.Add(gwId);
-                    var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
+                    var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" });
                     if (result == "Success")
                     {
                         this.listBackupGwId.Remove(gwId);

--
Gitblit v1.8.0