From 0d9f64668fd7350d6a21fd157e32009a96d98134 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期三, 16 十二月 2020 13:09:08 +0800
Subject: [PATCH] 新云端代码Ver1.2

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs |  542 +++++++++++++++++++----------------------------------
 1 files changed, 197 insertions(+), 345 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
similarity index 83%
rename from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
rename to ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
index 4513675..0c4f93b 100644
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayLogic.cs
@@ -5,7 +5,7 @@
 using System.Threading.Tasks;
 using ZigBee.Device;
 
-namespace Shared.Phone.UserCenter
+namespace Shared.Phone
 {
     /// <summary>
     /// 缃戝叧涓氬姟鐨勯�昏緫绫�
@@ -79,25 +79,25 @@
         /// </summary>
         public void RefreshAppOldSelectGatewayId()
         {
-            GatewayResourse.AppOldSelectGatewayId = string.Empty;
+            HdlGatewayResourse.AppOldSelectGatewayId = string.Empty;
 
             //浠庢枃浠朵腑鑾峰彇涓婁竴娆¢�夋嫨鐨勭綉鍏砳d
-            byte[] data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.AppOldSelectGatewayFile);
+            byte[] data = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.AppOldSelectGatewayFile);
             if (data != null)
             {
                 string strvalue = System.Text.Encoding.UTF8.GetString(data);
-                GatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue);
+                HdlGatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue);
             }
             //濡傛灉鏈湴娌℃湁杩欎釜缃戝叧鐨勮瘽
-            if (this.IsGatewayExist(GatewayResourse.AppOldSelectGatewayId) == false)
+            if (this.IsGatewayExist(HdlGatewayResourse.AppOldSelectGatewayId) == false)
             {
-                GatewayResourse.AppOldSelectGatewayId = string.Empty;
+                HdlGatewayResourse.AppOldSelectGatewayId = string.Empty;
                 lock (dicGateway)
                 {
                     //闅忎究閫変竴涓綉鍏�
                     foreach (string wayId in this.dicGateway.Keys)
                     {
-                        GatewayResourse.AppOldSelectGatewayId = wayId;
+                        HdlGatewayResourse.AppOldSelectGatewayId = wayId;
                         break;
                     }
                 }
@@ -111,14 +111,14 @@
         public void SynchronizeDbGateway()
         {
             //浠庝簯绔幏鍙栫綉鍒楄〃ID
-            Dictionary<string, GatewayResult> result = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
+            Dictionary<string, GatewayResult> result = this.GetGateWayListFromDataBase(Config.Instance.Home.Id);
             if (result == null)
             {
                 return;
             }
 
             List<string> listBackupGwId = new List<string>();
-            var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
+            var fileData = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.BackupGatewayIdFile);
             if (fileData != null)
             {
                 //鏂板锛氳櫧鐒舵鐜囦綆锛屼絾鏄‘瀹炲彂鐢熶簡銆傚鏋滄湁缃戠粶鏃讹紝App閲嶆柊缁戝畾璁板綍鐨勭綉鍏冲け璐ョ殑璇�
@@ -138,13 +138,13 @@
             foreach (var gatewayId in listDelete)
             {
                 //鍒犻櫎鏈湴杩欎釜缃戝叧鎵�鏈夌殑璁惧
-                List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
+                List<CommonDevice> list = HdlDeviceCommonLogic.Current.GetDeviceByGatewayID(gatewayId);
                 foreach (var device in list)
                 {
                     //鍒犻櫎涓�鑸澶�
-                    Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+                    HdlDeviceCommonLogic.Current.DeleteMemmoryDevice(device, true);
                     //鍒犻櫎Ota璁惧
-                    Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
+                    HdlDeviceCommonLogic.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
                 }
                 //鍒犻櫎缃戝叧鏂囦欢
                 this.DeleteGatewayFile(gatewayId);
@@ -204,7 +204,7 @@
         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);
+            bool falge = this.SetGatewaySite(zbGateway.GwId, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO);
             if (falge == false)
             {
                 if (logMode == WriteLogMode.YES)
@@ -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)
@@ -310,7 +310,7 @@
             //璁剧疆浣忓畢ID鍒扮綉鍏�
             if (result.HomeId != Common.Config.Instance.HomeId)
             {
-                bool flage2 = this.SetHomeIdToGateway(zbGateway.GwId, Common.Config.Instance.HomeId, mode);
+                bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
                 if (flage2 == false)
                 {
                     if (mode == ShowErrorMode.YES)
@@ -328,7 +328,7 @@
             }
 
             //鏇存柊浜戠鏁版嵁搴�
-            int flage1 = this.SetGatewayIdToDataBase(zbGateway);
+            int flage1 = this.SetGatewayIdToDataBase(zbGateway.GwId);
             //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
             if (flage1 == 0)
             {
@@ -361,7 +361,7 @@
             if (isEsist == false)
             {
                 //娣诲姞澶囦唤
-                HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(this.dicGateway[gwID].FilePath);
             }
 
             return 1;
@@ -370,30 +370,22 @@
         /// <summary>
         /// 璁剧疆浣忓畢ID鍒扮綉鍏�(澶辫触鏃�,涓嶅脊鍑轰换浣曢敊璇俊鎭�,缃戝叧鏂綉闄ゅ)
         /// </summary>
-        /// <param name="i_gwId"></param>
+        /// <param name="zbGateway"></param>
         /// <param name="HomeId"></param>
         /// <returns></returns>
-        public bool SetHomeIdToGateway(string i_gwId, string HomeId, ShowErrorMode mode)
+        public 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;
-                }
+                accountId = Config.Instance.Guid;
             }
             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(i_gwId, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
+            var result = this.SendJobjectDataToGateway(zbGateway.GwId, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
             if (result.ErrorMsgDiv == -1)
             {
                 if (mode == ShowErrorMode.YES)
@@ -409,32 +401,6 @@
                 return false;
             }
             return true;
-        }
-
-        /// <summary>
-        /// 鏇存柊缃戝叧ID鍒颁簯绔暟鎹簱(1:姝e父  -1:寮傚父  0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
-        /// </summary>
-        /// <param name="zbGateway">缃戝叧瀵硅薄</param>
-        /// <returns></returns>
-        private int SetGatewayIdToDataBase(ZbGateway zbGateway)
-        {
-            //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖true寰�涓嬭蛋)
-            var bindGateway = new BindGatewayPra();
-            bindGateway.BindGateways.Add(zbGateway.GwId);
-            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-            bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-            var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
-            if (result == "Error")
-            {
-                return -1;
-            }
-            if (result == "BindGatewaysExists")
-            {
-                return 0;
-            }
-
-            return result == "Success" ? 1 : -1;
         }
 
         /// <summary>
@@ -480,14 +446,14 @@
                 return -1;
             }
             //璁剧疆缃戝叧鐨勭粡绾害
-            bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES);
+            bool falge = this.SetGatewaySite(zbGateway.GwId, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES);
             if (falge == false)
             {
                 return -1;
             }
 
             //璁剧疆浣忓畢ID鍒扮綉鍏�
-            bool flage2 = this.SetHomeIdToGateway(zbGateway.GwId, Common.Config.Instance.HomeId, ShowErrorMode.YES);
+            bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
             if (flage2 == false)
             {
                 //鍚戠綉鍏宠缃綇瀹匢D澶辫触
@@ -497,7 +463,7 @@
             }
 
             //鏇存柊浜戠鏁版嵁搴�
-            int flage1 = this.SetGatewayIdToDataBase(zbGateway);
+            int flage1 = this.SetGatewayIdToDataBase(zbGateway.GwId);
             //寮傚父涔熶笉楦熷畠,0鏄壒娈婂惈涔�
             if (flage1 == 0)
             {
@@ -506,7 +472,7 @@
             if (flage1 == -1)
             {
                 //澶囦唤澶辫触鐨勭綉鍏矷D
-                HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
+                this.BackupGatewayIdOnNotNetwork(zbGateway);
             }
 
             if (btnMsg == null)
@@ -529,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;
@@ -567,7 +533,7 @@
             if (isEsist == false)
             {
                 //娣诲姞澶囦唤
-                HdlAutoBackupLogic.AddOrEditorFile(this.dicGateway[gwID].FilePath);
+                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(this.dicGateway[gwID].FilePath);
             }
 
             //娣诲姞缃戝叧鐨勮瘽,寮哄埗涓婚〉鍒锋柊
@@ -576,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;
                     }
                 }
@@ -621,7 +587,7 @@
                 //缃戝叧鍚嶇О淇敼澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
                 //缃戝叧鍥炲瓒呮椂
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
                 return false;
             }
@@ -632,7 +598,7 @@
             this.dicGateway[gwID].ReSave();
 
             //娣诲姞鑷姩澶囦唤
-            HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath);
+            HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(zbGateway.FilePath);
 
             return true;
         }
@@ -702,7 +668,7 @@
             if (getGatewayInfo == true)
             {
                 //鑾峰彇缃戝叧淇℃伅
-                var info = this.GetGatewayInfo(realWay, false);
+                var info = this.RefreshGatewayInfo(realWay, false);
                 if (info == null)
                 {
                     //鍏抽棴杩涘害鏉�
@@ -717,7 +683,7 @@
             }
 
             //鑾峰彇鍏ㄩ儴璁惧
-            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false);
+            int result = HdlDeviceCommonLogic.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false);
             //鍏抽棴杩涘害鏉�
             ProgressBar.Close();
             if (result == -1)
@@ -733,8 +699,8 @@
         /// <param name="gatewayId"></param>
         public void SaveGatewayIdToLocation(string gatewayId)
         {
-            GatewayResourse.AppOldSelectGatewayId = gatewayId;
-            HdlFileLogic.Current.SaveFileContent(DirNameResourse.AppOldSelectGatewayFile, GatewayResourse.AppOldSelectGatewayId);
+            HdlGatewayResourse.AppOldSelectGatewayId = gatewayId;
+            HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.AppOldSelectGatewayFile, HdlGatewayResourse.AppOldSelectGatewayId);
         }
 
         #endregion
@@ -752,7 +718,7 @@
             //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触  涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒�
             if (realWay != null)
             {
-                this.SetHomeIdToGateway(realWay.GwId, string.Empty, ShowErrorMode.NO);
+                this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
             }
 
             //鍒犻櫎浜戠鐨勭綉鍏�
@@ -792,21 +758,21 @@
             //绉婚櫎缂撳瓨
             dicGateway.Remove(zbGatewayID);
             //鍒犻櫎鑷姩澶囦唤
-            HdlAutoBackupLogic.DeleteFile(file);
+            HdlBackupLogic.Current.DeleteAutoBackFileStatu(file);
 
             //鍒犻櫎璁惧鏂囦欢
-            List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGatewayID);
+            List<CommonDevice> list = HdlDeviceCommonLogic.Current.GetDeviceByGatewayID(zbGatewayID);
             foreach (var device in list)
             {
                 //鍒犻櫎璁惧鏂囦欢
-                Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
+                HdlDeviceCommonLogic.Current.DeleteMemmoryDevice(device, true);
                 //鍒犻櫎Ota璁惧
-                Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
+                HdlDeviceCommonLogic.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
             }
             //濡傛灉鏄富缃戝叧
             if (this.IsMainGateway(zbGatewayID) == 1)
             {
-                var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
+                var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                 foreach (var room in listAllRoom)
                 {
                     //鍒犻櫎鍦烘櫙鏂囦欢
@@ -882,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;
@@ -1123,7 +1089,7 @@
             {
                 //鑾峰彇鍗忚皟鍣ㄤ俊閬撳け璐�
                 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
             }
 
@@ -1175,7 +1141,7 @@
             {
                 //鑾峰彇鍗忚皟鍣∕ac澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
             }
 
@@ -1227,7 +1193,7 @@
             {
                 //鑾峰彇鍗忚皟鍣≒anID澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
             }
 
@@ -1281,7 +1247,7 @@
             {
                 //鑾峰彇缃戝叧鑷姩澶囦唤璁剧疆澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayAutoBackupStatuFail);
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
             }
 
@@ -1332,7 +1298,7 @@
             {
                 //璁剧疆缃戝叧鑷姩澶囦唤澶辫触
                 string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewayAutoBackupStatuFail);
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 this.ShowTipMsg(msg);
                 return false;
             }
@@ -1366,7 +1332,7 @@
                 return name;
             }
 
-            var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
+            var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
             if (nameContent != null)
             {
                 return nameContent.A澶囨敞鍚嶅瓧;
@@ -1406,7 +1372,7 @@
                 //濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇
                 if (zbGateway.LinuxImageType != -1)
                 {
-                    var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                    var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
                     if (nameContent != null)
                     {
                         button.Text = nameContent.A瀹樻柟鍚嶅瓧;
@@ -1417,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)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1425,7 +1391,7 @@
 
                             HdlThreadLogic.Current.RunMain(() =>
                             {
-                                var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                                var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
                                 if (nameContent != null)
                                 {
                                     button.Text = nameContent.A瀹樻柟鍚嶅瓧;
@@ -1437,7 +1403,7 @@
             }
             else
             {
-                var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
+                var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
                 if (nameContent != null)
                 {
                     button.Text = nameContent.A瀹樻柟鍚嶅瓧;
@@ -1450,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)
             {
@@ -1469,23 +1452,20 @@
                     //鑾峰彇缃戝叧淇℃伅澶辫触
                     string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
                     //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                    msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                     this.ShowErrorMsg(msg);
                 }
                 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;
         }
 
@@ -1497,8 +1477,6 @@
         /// <param name="saveFile">鏄惁淇濆瓨鏂囦欢</param>
         private void SetGatewayDataToLocalMemmory(ZbGateway localWay, ZbGatewayData.GetGwData data, bool saveFile = true)
         {
-            if (data == null) { return; }
-
             localWay.GwId = data.GwId;
             localWay.GwName = data.GwName;
             localWay.GwSerialNum = data.GWSN;
@@ -1576,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;
@@ -1589,7 +1567,7 @@
             }
 
             //娣诲姞缃戝叧鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�)
-            var flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
+            var flage = HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
                 localWay.LinuxHardVersion.ToString(),
                 localWay.LinuxImageType.ToString());
 
@@ -1597,19 +1575,19 @@
             if (flage == 1)
             {
                 //娌$綉鐨勬椂鍊欎笉鍐嶅鐞�
-                HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
+                HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
                     localWay.CoordinatorHardVersion.ToString(),
                     localWay.CoordinatorImageId.ToString());
             }
 
             //缃戝叧鐨勭増鏈�
-            var gatewayFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
+            var gatewayFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
                 localWay.LinuxHardVersion.ToString(),
                 localWay.LinuxImageType.ToString(),
                 localWay.LinuxFirmwareVersion);
 
             //鍗忚皟鍣ㄧ増鏈�
-            var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
+            var coordinatorFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A鍗忚皟鍣�,
                 localWay.CoordinatorHardVersion.ToString(),
                 localWay.CoordinatorImageId.ToString(),
                 localWay.CoordinatorFirmwareVersion);
@@ -1619,7 +1597,7 @@
             list.Add(coordinatorFirmware);
 
             //杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈
-            if (this.CheckGatewayHadDriveCode(localWay) == true)
+            if (HdlGatewayLogic.Current.CheckGatewayHadDriveCode(localWay) == true)
             {
                 //铏氭嫙椹卞姩鍙�
                 foreach (var data in localWay.DriveCodeList)
@@ -1627,13 +1605,13 @@
                     //娣诲姞铏氭嫙椹卞姩鐨勫崌绾у浐浠�(鎴愪笉鎴愬姛閮芥棤鎵�璋�) 蹇呴』鑳藉鑱旂綉鎵嶈
                     if (flage == 1)
                     {
-                        HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
+                        HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
                            data.DriveHwVersion.ToString(),
                            data.DriveImageType.ToString());
                     }
 
                     //铏氭嫙椹卞姩
-                    var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
+                    var virtualFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A铏氭嫙椹卞姩,
                         data.DriveHwVersion.ToString(),
                         data.DriveImageType.ToString(),
                         data.DriveFwVersion);
@@ -1737,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)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1775,7 +1753,7 @@
                     //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷
                     HdlThreadLogic.Current.RunThread(() =>
                     {
-                        var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
+                        var result = this.RefreshGatewayInfo(zbGateway, true, ShowErrorMode.NO);
                         if (result != null)
                         {
                             //灏嗙綉鍏崇殑鏁版嵁璁剧疆鍒版湰鍦扮紦瀛樹腑
@@ -1867,90 +1845,18 @@
 
         #endregion
 
-        #region 鈻� 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D___________
-
-        /// <summary>
-        /// 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D
-        /// </summary>
-        /// <returns>浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D</returns>
-        public Dictionary<string, GatewayResult> GetGateWayListFromDataBase()
-        {
-            Dictionary<string, GatewayResult> dicDbGateway = null;
-            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
-            {
-                //鎴愬憳
-                return dicDbGateway;
-            }
-
-            bool canBreak = false;
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                List<string> list = new List<string>() { "NotCheck" };
-
-                //璁剧疆璁块棶鎺ュ彛鐨勫弬鏁�
-                var pra = new GetGatewayPra();
-                pra.ReqDto.PageSetting.Page = 1;
-                pra.ReqDto.PageSetting.PageSize = 999;
-                //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-                pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-                var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
-                if (string.IsNullOrEmpty(result) == true)
-                {
-                    canBreak = true;
-                    return;
-                }
-                var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult>(result);
-
-                Dictionary<string, GatewayResult> dic = new Dictionary<string, GatewayResult>();
-                foreach (var data in infoResult.PageData)
-                {
-                    dic[data.GatewayUniqueId] = data;
-                }
-                dicDbGateway = dic;
-                canBreak = true;
-            });
-
-            int count = 0;
-            while (canBreak == false)
-            {
-                System.Threading.Thread.Sleep(200);
-                count++;
-                if (count == 25)
-                {
-                    //濡傛灉5绉掕繕涓嶈兘鑾峰彇寰楀埌鏁版嵁锛屽垯涓柇姝ゆ鎿嶄綔
-                    break;
-                }
-            }
-
-            return dicDbGateway;
-        }
-
-        #endregion
-
         #region 鈻� 璁剧疆缃戝叧缁忕含搴____________________
 
         /// <summary>
         /// 璁剧疆缃戝叧缁忕含搴�
         /// </summary>
-        /// <param name="gateway">缃戝叧瀵硅薄</param>
+        /// <param name="gatewayId">缃戝叧Id</param>
         /// <param name="Longitude">缁忓害</param>
         /// <param name="Latitude">缁村害</param>
         /// <param name="mode">鏄剧ず閿欒</param>
         /// <returns></returns>
-        public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
+        public bool SetGatewaySite(string gatewayId, double Longitude, double Latitude, ShowErrorMode mode)
         {
-            ZbGateway realWay = null;
-            if (this.GetRealGateway(ref realWay, gateway) == false)
-            {
-                if (mode == ShowErrorMode.YES)
-                {
-                    //閿欒:缃戝叧瀵硅薄涓㈠け
-                    string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
-                    this.ShowTipMsg(msg);
-                }
-                return false;
-            }
             if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
             {
                 //娌℃湁閰嶇疆杩囩粡绾害
@@ -1958,16 +1864,14 @@
             }
 
             int result = -1;
-            Action<string, string> action = (topic, message) =>
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
             {
-                var gatewayID = topic.Split('/')[0];
-                if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
+                if (topic == gatewayId + "/" + "Logic/SetSite_Respon")
                 {
                     var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                     result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
                 }
-            };
-            realWay.Actions += action;
+            });
             //涓や綅灏忔暟
             Longitude = Math.Round(Longitude, 2);
             Latitude = Math.Round(Latitude, 2);
@@ -1978,15 +1882,9 @@
             var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
             var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
             jObject.Add("Data", data);
-            if (this.IsGatewayExist(gateway) == true)
-            {
-                realWay.Send("Logic/SetSite", jObject.ToString());
-            }
-            else
-            {
-                //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
-                realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
-            }
+
+            //濡傛灉杩欎釜缃戝叧杩樻病鏈夌粦瀹氱殑璇濓紝鍒欏己鍒朵娇鐢ㄦ湰鍦拌繛鎺�
+            this.SendJobjectData(gatewayId, "Logic/SetSite", jObject.ToString(), this.IsGatewayExist(gatewayId) == false);
 
             int TimeOut = 0;
             while (result == -1 && TimeOut < 30)
@@ -1995,7 +1893,8 @@
                 TimeOut++;
             }
 
-            realWay.Actions -= action;
+            //绉婚櫎鐩戝惉浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
             if (result != 0)
             {
                 if (mode == ShowErrorMode.YES)
@@ -2004,38 +1903,13 @@
                     string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
                     if (result == -1)
                     {
-                        msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                        msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                     }
                     this.ShowTipMsg(msg);
                 }
                 return false;
             }
 
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 瑙g粦浜戠缃戝叧_______________________
-
-        /// <summary>
-        /// 瑙g粦浜戠缁戝畾鐨勭綉鍏�
-        /// </summary>
-        /// <param name="strWayId"></param>
-        public bool DeleteDataBaseGateway(string strWayId)
-        {
-            var Pra = new DeleteGatewayPra();
-            Pra.BindGateways.Add(strWayId);
-            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-            Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-            List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
-
-            bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
-            if (result == false)
-            {
-                return false;
-            }
             return true;
         }
 
@@ -2055,7 +1929,7 @@
                 listBackupGwId.Add(strId);
 
                 //澶囦唤
-                HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
+                HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.BackupGatewayIdFile, listBackupGwId);
             }
         }
 
@@ -2064,39 +1938,33 @@
         /// </summary>
         public bool ResetComandToBindBackupGateway()
         {
-            var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
+            var fileData = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.BackupGatewayIdFile);
             if (fileData == null)
             {
                 return true;
             }
-            this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
+            this.listBackupGwId = 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();
-
             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")
+                if (this.IsGatewayExist(gwId) == true)
                 {
-                    this.listBackupGwId.Remove(gwId);
+                    //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖true寰�涓嬭蛋)
+                    var result = this.SetGatewayIdToDataBase(gwId);
+                    if (result != 1)
+                    {
+                        break;
+                    }
                 }
-                if (result == "Error")
-                {
-                    break;
-                }
+                this.listBackupGwId.Remove(gwId);
             }
 
             if (this.listBackupGwId.Count == 0)
             {
                 //濡傛灉娌℃湁浜嗗唴瀹�,鍒欏垹闄ゆ枃浠�
-                string file = DirNameResourse.BackupGatewayIdFile;
+                string file = HdlFileNameResourse.BackupGatewayIdFile;
                 if (System.IO.File.Exists(file) == true)
                 {
                     System.IO.File.Delete(file);
@@ -2106,7 +1974,7 @@
             else
             {
                 //澶囦唤
-                HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
+                HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.BackupGatewayIdFile, listBackupGwId);
                 return false;
             }
         }
@@ -2142,7 +2010,7 @@
                 if (topic == errorTopic)
                 {
                     var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
-                    reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
+                    reResult.ErrorMsg = HdlCheckLogic.Current.CheckGatewayErrorCode(temp.Error);
                 }
                 //濡傛灉鏄寚瀹氱殑涓婚
                 if (topic == checkTopic)
@@ -2210,98 +2078,6 @@
                 //寮哄埗浣跨敤鏈湴杩炴帴
                 realWay.SendLocation(topic, System.Text.Encoding.UTF8.GetBytes(sendData));
             }
-        }
-
-        #endregion
-
-        #region 鈻� 鏇存崲缃戝叧___________________________
-
-        /// <summary>
-        /// 鎵ц鏇存崲缃戝叧(閲岄潰鏄瓙绾跨▼鎵ц)
-        /// </summary>
-        /// <param name="i_realGateway">鏂扮綉鍏�</param>
-        /// <param name="i_targetGwId">琚浛鎹㈢殑鐩爣缃戝叧</param>
-        /// <param name="i_info">澶囦唤鏁版嵁</param>
-        /// <param name="finishEvent">-1:寮傚父澶辫触 0:娌℃湁澶囦唤鏁版嵁 1:鎴愬姛</param>
-        public void DoReplaceGateway(ZbGateway i_realGateway, string i_targetGwId, BackupListNameInfo i_info, Action<int> finishEvent)
-        {
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                //姝e湪鑾峰彇閰嶇疆鏁版嵁
-                ProgressFormBar.Current.Start();
-                ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGettingConfigurationData));
-
-                System.Threading.Thread.Sleep(1000);
-
-                //棣栧厛鐨勬洿鏂颁簯绔�
-
-                //鐒跺悗鍙戞暟鎹粰缃戝叧,璁╃綉鍏冲幓涓嬭浇鏁版嵁
-                var result = HdlGatewayBackupLogic.Current.RecoverGateway(i_realGateway, i_info.Id, i_info.IsAutoBack, false);
-                if (result == false)
-                {
-                    finishEvent?.Invoke(-1);
-                    return;
-                }
-                //姝e湪鍙樻洿鏈湴閰嶇疆
-                ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uChangingLocalConfiguration));
-                ProgressFormBar.Current.ResetProgressBar();
-
-                System.Threading.Thread.Sleep(1500);
-
-                //鏍煎紡鍖栨棫缃戝叧
-                string strComand = "{\"Cluster_ID\":0,\"Command\":160,\"Data\": {\"DelAllInfo\": 1}}";
-                this.SendJobjectData(i_targetGwId, "Formate", strComand, true);
-
-                //鍒犻櫎鎺夎鏇挎崲鐨勭綉鍏�
-                this.DeleteGatewayFile(i_targetGwId);
-                ProgressFormBar.Current.SetValue(1);
-
-                System.Threading.Thread.Sleep(500);
-                ProgressFormBar.Current.Close();
-
-                finishEvent?.Invoke(1);
-            });
-        }
-
-        /// <summary>
-        /// 鍦ㄧ綉鍏虫浛鎹箣鍓�,鑾峰彇缃戝叧鐨勪竴涓浠芥暟鎹�
-        /// </summary>
-        /// <param name="i_gwId">缃戝叧ID</param>
-        /// <param name="statu">-1:寮傚父澶辫触 0:娌℃湁澶囦唤鏁版嵁 1:鎴愬姛</param>
-        /// <returns></returns>
-        private BackupListNameInfo GetBackupInfoBeforeReplace(string i_gwId, ref int statu)
-        {
-            //鑾峰彇鑷姩澶囦唤鐨勬暟鎹�
-            var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(3, i_gwId);
-            if (pageData == null)
-            {
-                statu = -1;
-                return null;
-            }
-            //濡傛灉鑾峰彇涓嶅埌鑷姩澶囦唤,鍒欏幓鑾峰彇鎵嬪姩澶囦唤
-            if (pageData.Count == 0)
-            {
-                //浠庝簯绔幏鍙栨暟鎹� 
-                pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(2, i_gwId);
-                if (pageData == null)
-                {
-                    statu = -1;
-                    return null;
-                }
-            }
-            else
-            {
-                //鑷姩澶囦唤
-                pageData[0].IsAutoBack = 1;
-            }
-            if (pageData.Count == 0)
-            {
-                //娌℃湁澶囦唤
-                statu = 0;
-                return null;
-            }
-            statu = 1;
-            return pageData[0];
         }
 
         #endregion
@@ -2425,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)
             {
                 //濡傛灉缃戠粶涓嶉��,鍒欎篃寰�涓嬭蛋
@@ -2498,13 +2274,9 @@
         {
             try
             {
-                for (int i = 0; i < UserCenterResourse.listActionFormId.Count; i++)
+                var listForm = HdlFormLogic.Current.GetAllOpenForm();
+                for (int i = 0; i < listForm.Count; i++)
                 {
-                    string formId = UserCenterResourse.listActionFormId[i];
-                    if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
-                    {
-                        continue;
-                    }
                     //缃戝叧鍦ㄧ嚎鎺ㄩ��
                     var zbway = this.GetLocalGateway(gwId);
                     if (zbway != null)
@@ -2514,7 +2286,7 @@
                         {
                             zbway.OnlineTime = DateTime.Now;
                         }
-                        UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
+                        listForm[i]?.GatewayOnlinePush(zbway, online, hadGwOnline);
                     }
                 }
             }
@@ -2532,9 +2304,89 @@
 
         #endregion
 
+        #region 鈻� 璋冪敤浜戠鎺ュ彛鐨勬柟娉昣________________
+
+        /// <summary>
+        /// 鏇存柊缃戝叧ID鍒颁簯绔暟鎹簱(1:姝e父  -1:寮傚父  0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�)
+        /// </summary>
+        /// <param name="i_gatewayIds">缃戝叧ID</param>
+        /// <returns></returns>
+        private int SetGatewayIdToDataBase(string i_gatewayId)
+        {
+            //璋冪敤鎺ュ彛锛岀粦瀹氱綉鍏�(鍗充娇澶辫触锛屼篃杩斿洖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璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return -1;
+            }
+            return 1;
+        }
+
+        /// <summary>
+        /// 浠庝簯绔幏鍙栧叏閮ㄧ綉鍏冲垪琛↖D
+        /// </summary>
+        /// <returns></returns>
+        public Dictionary<string, GatewayResult> GetGateWayListFromDataBase(string i_homeId)
+        {
+            //杩欎釜鎺ュ彛鐗规畩,涓嶉渶瑕佹娴嬫潈闄�
+            var pra = new { homeId = i_homeId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/getGatewayList", RestSharp.Method.POST, pra);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return null;
+            }
+            var listData = JsonConvert.DeserializeObject<List<GatewayResult>>(result.Data.ToString());
+
+            var dicDbGateway = new Dictionary<string, GatewayResult>();
+            foreach (var data in listData)
+            {
+                if (data.GatewayType == "ZIGBEEGATEWAY")
+                {
+                    dicDbGateway[data.Mac] = data;
+                }
+            }
+            return dicDbGateway;
+        }
+
+        /// <summary>
+        /// 瑙g粦浜戠缁戝畾鐨勭綉鍏�
+        /// </summary>
+        /// <param name="strWayId"></param>
+        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璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
         #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>

--
Gitblit v1.8.0