From 081ea8d273048fd03756718ac6fb48a3c09218e9 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期二, 29 十月 2019 13:10:00 +0800 Subject: [PATCH] Merge branch 'dev-tzy' into DEV_GXC --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs | 272 +++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 208 insertions(+), 64 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs index c62be4d..97e642b 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs @@ -391,7 +391,7 @@ /// 閲嶆柊缁戝畾缃戝叧(1:姝e父 -1:寮傚父 0:褰撳墠鐨勭綉鍏崇粦瀹氬湪浜嗗綋鍓嶈处鍙蜂笅鐨勪笉鍚屼綇瀹呴噷闈�) /// </summary> /// <param name="zbGateway">缃戝叧</param> - public async Task<int> ReBindNewGateway(ZbGateway zbGateway) + public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) { if (zbGateway == null) { @@ -424,9 +424,19 @@ HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway); } - //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚� - ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait)); - + if (btnMsg == null) + { + //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚� + ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait)); + } + else + { + HdlThreadLogic.Current.RunMain(() => + { + //缃戝叧鍐呴儴鏁版嵁鍙樻洿涓�,璇风◢鍚� + btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait; + }); + } await System.Threading.Tasks.Task.Delay(8000); //鑾峰彇缃戝叧鐨勪俊鎭� @@ -538,8 +548,104 @@ HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath); return true; - } - + } + + #endregion + + #region 鈻� 缃戝叧鍒囨崲___________________________ + + /// <summary> + /// 鎵ц鍒囨崲缃戝叧鎿嶄綔 + /// </summary> + /// <param name="gatewayId"></param> + public async Task<bool> DoSwitchGateway(string gatewayId) + { + var zbGateway = this.GetLocalGateway(gatewayId); + if (this.CheckGatewayOnlineByFlag(zbGateway) == true) + { + //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭� + var result = await this.GetOnlineGatewayInfo(gatewayId); + if (result == false) + { + return false; + } + } + //鍒囨崲缃戝叧,淇濆瓨缂撳瓨 + this.SaveGatewayIdToLocation(gatewayId); + return true; + } + + /// <summary> + /// 鑾峰彇鍦ㄧ嚎缃戝叧淇℃伅 + /// </summary> + /// <param name="gatewayId"></param> + /// <returns></returns> + private async Task<bool> GetOnlineGatewayInfo(string gatewayId) + { + //鏄剧ず杩涘害鏉� + ProgressBar.Show(); + + //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D + ZbGateway realWay = null; + bool getGatewayInfo = true; + if (this.GetRealGateway(ref realWay, gatewayId) == true) + { + //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆) + if (this.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true) + { + int result2 = await this.ReBindNewGateway(realWay); + if (result2 == 0) + { + //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇� + this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain)); + //鍏抽棴杩涘害鏉� + ProgressBar.Close(); + } + else if (result2 == -1) + { + //鍏抽棴杩涘害鏉� + ProgressBar.Close(); + return false; + } + //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭� + getGatewayInfo = false; + } + } + + if (getGatewayInfo == true) + { + //鑾峰彇缃戝叧淇℃伅 + var info = await this.GetGatewayNewInfoAsync(realWay); + if (info == null) + { + //鍏抽棴杩涘害鏉� + ProgressBar.Close(); + return false; + } + } + + //鑾峰彇鍏ㄩ儴璁惧 + bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay); + //鍏抽棴杩涘害鏉� + ProgressBar.Close(); + if (result == false) + { + return false; + } + return true; + } + + /// <summary> + /// 淇濆瓨閫夋嫨鐨勭綉鍏矷D鍒版湰鍦� + /// </summary> + /// <param name="gatewayId"></param> + public void SaveGatewayIdToLocation(string gatewayId) + { + GatewayResourse.AppOldSelectGatewayId = gatewayId; + byte[] data = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId)); + Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data); + } + #endregion #region 鈻� 鍒犻櫎缃戝叧___________________________ @@ -678,8 +784,8 @@ if (waitTime == true) { - //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟3绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage) - System.Threading.Thread.Sleep(3000); + //杩欐槸绗竴閬撳潕,寮哄埗妫�鏌IFI:绛夊緟2绉�(鍥犱负wifi鐨勬椂鍊欙紝瀹冧細鑷姩鍘诲埛鏂癴lage) + System.Threading.Thread.Sleep(2000); //妫�鏌ユ槸鍚︽嫢鏈夌綉鍏冲瓨鍦ㄤ簬WIFi涓� if (this.CheckHadGatewayInWifi(listRealWay) == false) { @@ -1053,38 +1159,60 @@ } /// <summary> - /// 鑾峰彇缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛� + /// 璁剧疆缃戝叧闀滃儚绫诲瀷鐨勭炕璇戝悕瀛� /// </summary> + /// <param name="button"></param> /// <param name="zbGateway"></param> /// <returns></returns> - public string GetGatewayImageText(ZbGateway zbGateway) + public void SetGatewayImageText(Button button, ZbGateway zbGateway) { + //鍒濆鍊�:鏃犳硶璇嗗埆鐨勭綉鍏宠澶� + button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice; + string gwId = this.GetGatewayId(zbGateway); - int imageType = -1; if (this.dicGateway.ContainsKey(gwId) == false || this.dicGateway[gwId].getGwInfo == null) { //濡傛灉杩欎釜缃戝叧娌℃湁淇℃伅锛屽垯浠庢柊鑾峰彇 - var result = this.GetGatewayNewInfo(zbGateway, ShowErrorMode.NO); - if (result == null) + if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0) { - //鏃犳硶璇嗗埆鐨勭綉鍏宠澶� - return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice); + string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType; + if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true) + { + //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗� + button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName]; + } } - imageType = result.LinuxImageType; + else + { + //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷 + HdlThreadLogic.Current.RunThread(async () => + { + var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO); + if (result != null) + { + zbGateway.getGwInfo = result; + HdlThreadLogic.Current.RunMain(() => + { + string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType; + if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true) + { + //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗� + button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName]; + } + }); + } + }); + } } else { - imageType = Convert.ToInt32(this.GetGwInfoAttribute(this.dicGateway[gwId], "LinuxImageType")); + string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType; + if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true) + { + //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗� + button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]; + } } - string keyName = Common.LocalDevice.deviceModelIdName + imageType; - if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true) - { - //浣跨敤R鏂囦欢閲岄潰璁剧疆鐨勪笢瑗� - return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]); - } - - //鏃犳硶璇嗗埆鐨勭綉鍏宠澶� - return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice); } #endregion @@ -1314,7 +1442,7 @@ #region 鈻� 涓荤綉鍏冲垽瀹歘________________________ /// <summary> - /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� -1:杩滅▼妯″紡,涓嶅瓨鍦ㄥ暐涓荤綉鍏崇殑璇存硶) + /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�) /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <returns></returns> @@ -1325,7 +1453,7 @@ } /// <summary> - /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� -1:杩滅▼妯″紡,涓嶅瓨鍦ㄥ暐涓荤綉鍏崇殑璇存硶) + /// 鍒ゆ柇鏄惁涓荤綉鍏�(1:涓荤綉鍏� 0:涓嶅湪绾� 2:瀛愮綉鍏�) /// </summary> /// <param name="waiID">缃戝叧id</param> /// <returns></returns> @@ -1336,7 +1464,7 @@ { return 0; } - return zbGateway.IsMainGateWay == true ? 1 : 0; + return zbGateway.IsMainGateWay == true ? 1 : 2; } #endregion @@ -1344,7 +1472,7 @@ #region 鈻� 璁剧疆缃戝叧鍥剧墖_______________________ /// <summary> - /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗囷紝瑙勬牸锛�915X492 + /// 璁剧疆鐪熷疄缃戝叧鐨勫浘鐗� /// </summary> /// <param name="button"></param> /// <param name="zbGateway"></param> @@ -1354,30 +1482,35 @@ var localWay = this.GetLocalGateway(gwID); if (localWay == null || localWay.getGwInfo == null) { - //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷 - HdlThreadLogic.Current.RunThread(async () => + if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0) { - var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO); - if (result != null) + button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.getGwInfo.LinuxImageType + ".png"; + } + else + { + //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷 + HdlThreadLogic.Current.RunThread(async () => { - Application.RunOnMainThread(() => + var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO); + if (result != null) { - if (button != null) + zbGateway.getGwInfo = result; + HdlThreadLogic.Current.RunMain(() => { button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png"; - } - }); - } - }); + }); + } + }); + } } else { - button.UnSelectedImagePath = "Gateway/RealGateway" + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString() + ".png"; + button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.getGwInfo.LinuxImageType + ".png"; } } /// <summary> - /// 璁剧疆缃戝叧鍥炬爣锛岃鏍硷細110X110 + /// 璁剧疆缃戝叧鍥炬爣 /// </summary> /// <param name="button"></param> /// <param name="zbGateway"></param> @@ -1387,28 +1520,30 @@ var localWay = this.GetLocalGateway(gwID); if (localWay == null || localWay.getGwInfo == null) { - //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷 - HdlThreadLogic.Current.RunThread(async () => + if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0) { - var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO); - if (result != null) + button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.getGwInfo.LinuxImageType + ".png"; + } + else + { + //缁欎竴涓嚎绋嬪幓鑾峰彇瀹冪殑闀滃儚绫诲瀷 + HdlThreadLogic.Current.RunThread(async () => { - Application.RunOnMainThread(() => + var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO); + if (result != null) { - if (button != null) + zbGateway.getGwInfo = result; + HdlThreadLogic.Current.RunMain(() => { button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png"; - button.SelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + "Selected.png"; - } - }); - } - }); + }); + } + }); + } } else { - string linType = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString(); - button.UnSelectedImagePath = "Gateway/GatewayIcon" + linType + ".png"; - button.SelectedImagePath = "Gateway/GatewayIcon" + linType + "Selected.png"; + button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.getGwInfo.LinuxImageType + ".png"; } } @@ -1443,13 +1578,13 @@ #endregion - #region 鈻� 娴嬭瘯缃戝叧___________________________ + #region 鈻� 缃戝叧瀹氫綅___________________________ /// <summary> - /// 鍙戦�佹祴璇曟寚浠ゅ埌璁惧(缃戝叧LED闂儊璇嗗埆) + /// 鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) /// </summary> /// <param name="zbGateway"></param> - public void SetTestCommand(ZbGateway zbGateway) + public void SetFixedPositionCommand(ZbGateway zbGateway) { ZbGateway realWay = null; if (this.GetRealGateway(ref realWay, zbGateway) == false) @@ -2112,19 +2247,19 @@ else if (backType == GatewayBackupEnum.APir鐏厜閰嶇疆) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData)); - result = await HdlPirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData); + result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData); } else if (backType == GatewayBackupEnum.A骞叉帴鐐归鑹茶皟鑺�) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.KeyColorData>(System.Text.Encoding.UTF8.GetString(byteData)); - result = await HdlPanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData); + result = await HdlDevicePanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData); } else if (backType == GatewayBackupEnum.A骞叉帴鐐逛寒搴﹁皟鑺�) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData)); int directionsLevel = Convert.ToInt32(recoverData["directionsLevel"]); int backlightLevel = Convert.ToInt32(recoverData["backlightLevel"]); - result = await HdlPanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel); + result = await HdlDevicePanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel); } else if (backType == GatewayBackupEnum.A骞叉帴鐐硅妭鑳芥ā寮�) { @@ -2132,12 +2267,21 @@ bool modeEnable = Convert.ToBoolean(recoverData["modeEnable"]); int modeTime = Convert.ToInt32(recoverData["modeTime"]); int level = Convert.ToInt32(recoverData["level"]); - result = await HdlPanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level); + result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level); } else if (backType == GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�) { var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData)); - result = await HdlPanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData); + result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData); + } + else if (backType == GatewayBackupEnum.A绐楀笜鏂瑰悜) + { + } + else if (backType == GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗) + { + } + else if (backType == GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅) + { } return result == true ? 1 : -1; } -- Gitblit v1.8.0