From 0087dd7734e71dfcfd1bb54db394ad7855021ffd Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期五, 24 七月 2020 10:18:08 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 129 +++++++++++++++++++++++++----------------- 1 files changed, 76 insertions(+), 53 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs index fc831b0..bb9ce8a 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 async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) + public 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 = await this.DoAddGatewayToMemory(zbGateway, mode); + var result = this.DoAddGatewayToMemory(zbGateway, mode); //鍓嶇殑缃戝叧缁戝畾鍦ㄤ簡褰撳墠璐﹀彿涓嬬殑涓嶅悓浣忓畢閲岄潰 if (result == 0) { @@ -250,7 +250,7 @@ /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> /// <returns></returns> - private async Task<int> DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode) + private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode) { if (zbGateway == null) { @@ -278,7 +278,7 @@ //璁剧疆浣忓畢ID鍒扮綉鍏� if (result.HomeId != Common.Config.Instance.HomeId) { - bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode); + bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode); if (flage2 == false) { if (mode == ShowErrorMode.YES) @@ -337,10 +337,28 @@ /// <param name="zbGateway"></param> /// <param name="HomeId"></param> /// <returns></returns> - public async Task<bool> SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode) + public bool SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode) { - ZbGateway realWay = null; - if (this.GetRealGateway(ref realWay, zbGateway) == false) + //璐﹀彿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) { if (mode == ShowErrorMode.YES) { @@ -350,13 +368,11 @@ } return false; } - - var info = await realWay.GwSetHomeIdAsync(HomeId); - if (info != null && info.gwSetHomeIdData != null) + if (result.ErrorMsgDiv == 0) { - return true; + return false; } - return false; + return true; } /// <summary> @@ -372,7 +388,7 @@ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }); + var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false); if (result == "Error") { return -1; @@ -418,7 +434,7 @@ /// </summary> /// <param name="zbGateway">缃戝叧</param> /// <param name="btnMsg">娑堟伅鎺т欢</param> - public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) + public int ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) { if (zbGateway == null) { @@ -435,7 +451,7 @@ } //璁剧疆浣忓畢ID鍒扮綉鍏� - bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES); + bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES); if (flage2 == false) { //鍚戠綉鍏宠缃綇瀹匢D澶辫触 @@ -470,7 +486,7 @@ btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait; }); } - await Task.Delay(8000); + System.Threading.Thread.Sleep(8000); //鑾峰彇缃戝叧鐨勪俊鎭� ZbGatewayData.GetGwData result = null; @@ -484,7 +500,7 @@ } count--; //鏈�澶氬啀绛�20绉� - await Task.Delay(4000); + System.Threading.Thread.Sleep(4000); } if (result == null) { @@ -579,12 +595,10 @@ /// 鎵ц鍒囨崲缃戝叧鎿嶄綔 /// </summary> /// <param name="gatewayId"></param> - public async Task<bool> DoSwitchGateway(string gatewayId) + public bool DoSwitchGateway(string gatewayId) { - var zbGateway = this.GetLocalGateway(gatewayId); - //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭� - var result = await this.GetOnlineGatewayInfo(gatewayId); + var result = this.GetOnlineGatewayInfo(gatewayId); if (result == false) { return false; @@ -603,7 +617,7 @@ /// </summary> /// <param name="gatewayId"></param> /// <returns></returns> - private async Task<bool> GetOnlineGatewayInfo(string gatewayId) + private bool GetOnlineGatewayInfo(string gatewayId) { //鏄剧ず杩涘害鏉� ProgressBar.Show(); @@ -616,7 +630,7 @@ //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆) if (this.HomeIdIsEmpty(realWay.HomeId) == true) { - int result2 = await this.ReBindNewGateway(realWay); + int result2 = this.ReBindNewGateway(realWay); if (result2 == 0) { //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇� @@ -675,25 +689,15 @@ /// <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 async Task<bool> DeleteGateway(string zbGatewayID) + public bool DeleteGateway(string zbGatewayID) { ZbGateway realWay = null; this.GetRealGateway(ref realWay, zbGatewayID); //娓呯┖缃戝叧鐨勪綇瀹匢D 缃戝叧瑙g粦澶辫触 涓嶇悊瀹�,鍥犱负缃戝叧鍙互鎸夋寜閿己鍒舵悳绱㈠緱鍒� if (realWay != null) { - await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO); + this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO); } //鍒犻櫎浜戠鐨勭綉鍏� @@ -1487,24 +1491,39 @@ #endregion - #region 鈻� 娓呯┖鐪熷疄缃戝叧鍒楄〃___________________ + #region 鈻� 娓呯┖鐪熷疄缃戝叧閾炬帴___________________ /// <summary> - /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏冲璞� + /// 娓呯┖鍏ㄩ儴鐨勭湡瀹炵墿鐞嗙綉鍏崇殑閾炬帴 /// </summary> - public void ClearAllRealGateway() + /// <param name="roadGateway">鏄惁鍔犺浇鏈湴鐨勭綉鍏冲璞″埌鐪熷疄鍒楄〃涓�</param> + public void ClearAllRealGatewayConection(bool roadGateway) { - //鍥犱负閭d竴鐬棿锛屾湁鍙兘mqtt浼氬姞鍥炴潵,鎵�浠ュ厛鍔犵紦瀛� - var list = new List<ZbGateway>(); - list.AddRange(ZbGateway.GateWayList); - //鐒跺悗娓呯┖鎺� - ZbGateway.GateWayList.Clear(); - //鏈�鍚庡啀鏂紑mqtt杩炴帴 - for (int i = 0; i < list.Count; i++) + //鏂紑mqtt杩炴帴(鍗充娇淇濆瓨鍦ㄥ唴瀛樺綋涓篃娌¢棶棰�,鍥犱负濡傛灉骞挎挱涓嶅埌,鍒欏畠涓嶄細寤虹珛閾炬帴) + for (int i = 0; i < ZbGateway.GateWayList.Count; i++) { - list[i].DisConnectLocalMqttClient("G"); + ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G"); } - list.Clear(); + //鍔犺浇鏈湴缃戝叧瀵硅薄 + 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); + } + } + } } #endregion @@ -1639,12 +1658,16 @@ /// <returns></returns> public int IsMainGateway(string waiID) { - ZbGateway zbGateway = null; - if (this.GetRealGateway(ref zbGateway, waiID) == false) + var realWay = ZbGateway.GateWayList.Find((obj) => + { + return obj.GwId == waiID; + }); + //铏氭嫙缃戝叧涔熻繑鍥� 0 + if (realWay == null || realWay.IsVirtual == true) { return 0; } - return zbGateway.IsMainGateWay == true ? 1 : 2; + return realWay.IsMainGateWay == true ? 1 : 2; } #endregion @@ -1811,7 +1834,7 @@ //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list); + var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false); if (string.IsNullOrEmpty(result) == true) { canBreak = true; @@ -1943,7 +1966,7 @@ List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" }; - bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError); + bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false); if (result == false) { return false; @@ -1996,7 +2019,7 @@ { bindGateway.BindGateways.Clear(); bindGateway.BindGateways.Add(gwId); - var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }); + var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false); if (result == "Success") { this.listBackupGwId.Remove(gwId); -- Gitblit v1.8.0