From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs | 737 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 737 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs new file mode 100644 index 0000000..dae74bf --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs @@ -0,0 +1,737 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter +{ + /// <summary> + /// 缃戝叧澶囦唤涓氬姟鐨勯�昏緫 + /// </summary> + public class HdlGatewayBackupLogic + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 澶囦唤涓氬姟鐨勯�昏緫 + /// </summary> + private static HdlGatewayBackupLogic m_Current = null; + /// <summary> + /// 澶囦唤涓氬姟鐨勯�昏緫 + /// </summary> + public static HdlGatewayBackupLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlGatewayBackupLogic(); + } + return m_Current; + } + } + + #endregion + + #region 鈻� 缃戝叧澶囦唤___________________________ + + /// <summary> + /// 缃戝叧鎵ц澶囦唤 + /// </summary> + /// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param> + /// <param name="backupName">闇�瑕佸垱寤虹殑澶囦唤鐨勫悕瀛�</param> + public void DoBackupGateway(ZbGateway realGateway, string backupName) + { + //灞曞紑杩涘害鏉� + ProgressFormBar.Current.Start(); + //鍒涘缓澶囦唤鏂囦欢 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uCreatBackupFile)); + System.Threading.Thread.Sleep(1000); + + //鍒涘缓涓�涓浠藉悕瀛� + string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, realGateway.GwId); + if (backupClassId == null) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return; + } + + //淇濆瓨鍗忚皟鍣ㄧ殑nv鍒嗗尯缁勭綉淇℃伅 + //bool result = this.SaveNVFile(realGateway); + //if (result == false) + //{ + // //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎 + // await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId); + // //鍏抽棴杩涘害鏉� + // ProgressFormBar.Current.Close(); + // return; + //} + + //鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳� + //result = this.OpenZbMsComSend(realGateway); + //if (result == false) + //{ + // //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎 + // await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId); + // //鍏抽棴杩涘害鏉� + // ProgressFormBar.Current.Close(); + // return; + //} + + //寮�濮嬩笂浼犳暟鎹� + bool result = this.StartUpLoadData(realGateway, backupClassId); + if (result == false) + { + //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎 + HdlBackupLogic.Current.DeleteDbBackupData(backupClassId); + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return; + } + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + } + + #endregion + + #region 鈻� 淇濆瓨鍗忚皟鍣ㄧ殑nv鍒嗗尯缁勭綉淇℃伅_________ + + /// <summary> + /// 淇濆瓨鍗忚皟鍣ㄧ殑nv鍒嗗尯缁勭綉淇℃伅 + /// </summary> + /// <param name="realGateway"></param> + /// <returns></returns> + private bool SaveNVFile(ZbGateway realGateway) + { + //姝e湪淇濆瓨鍗忚皟鍣╪v鍒嗗尯淇℃伅 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayNVFileSaving)); + ProgressFormBar.Current.SetValue(0); + System.Threading.Thread.Sleep(1000); + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "ZbGwOperation/SaveNVFile_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Flag"].ToString()); + } + }; + realGateway.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 500 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "ImageName", "NVImage.bin" }, { "ImagePath", "/etc/hdlDat/" } }; + jObject.Add("Data", data); + realGateway.Send("ZbGwOperation/SaveNVFile", jObject.ToString()); + + int TimeOut = 0; + while (result == -1 && TimeOut < 60) + { + System.Threading.Thread.Sleep(1000); + TimeOut++; + ProgressFormBar.Current.SetValue(TimeOut, 60); + } + realGateway.Actions -= action; + if (result != 0) + { + //淇濆瓨鍗忚皟鍣ㄧ殑nv鍒嗗尯缁勭綉淇℃伅澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uSaveGatewayNVFileFail); + if (result == -1) + { + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + } + this.ShowErrorMsg(msg); + return false; + } + + return true; + } + + #endregion + + #region 鈻� 鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳絖____________ + + /// <summary> + /// 鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳� + /// </summary> + /// <param name="realGateway"></param> + /// <returns></returns> + private bool OpenZbMsComSend(ZbGateway realGateway) + { + //姝e湪鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳� + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uZbMsComSendOpening)); + ProgressFormBar.Current.SetValue(0); + System.Threading.Thread.Sleep(1000); + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "OpenZbMsComSend_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Status"].ToString()); + } + }; + realGateway.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6119 } }; + realGateway.Send("OpenZbMsComSend", jObject.ToString()); + + int TimeOut = 0; + while (result == -1 && TimeOut < 30) + { + System.Threading.Thread.Sleep(1000); + TimeOut++; + } + realGateway.Actions -= action; + if (result != 0) + { + //鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳藉け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uOpenZbMsComSendFail); + if (result == -1) + { + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + } + this.ShowErrorMsg(msg); + return false; + } + + return true; + } + + #endregion + + #region 鈻� 寮�濮嬬綉鍏虫暟鎹浠絖__________________ + + /// <summary> + /// 寮�濮嬩笂浼犳暟鎹� + /// </summary> + /// <param name="realGateway"></param> + /// <param name="backupClassId"></param> + private bool StartUpLoadData(ZbGateway realGateway, string backupClassId) + { + //寮�濮嬪浠界綉鍏虫暟鎹� + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uStartBackupgatewayData)); + ProgressFormBar.Current.SetValue(0); + System.Threading.Thread.Sleep(1000); + + bool threadAction = true; + bool success = false; + //绛夊緟鏃堕棿 + int waitime = 60; + //璁℃椂鏃堕棿 + int TimeOut = 0; + + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/BackupGwDataFile_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString()); + if (statu == 1) + { + threadAction = false; + //缃戝叧鏁版嵁澶囦唤澶辫触 + this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail)); + return; + } + if (statu == 2) + { + threadAction = false; + success = true; + //涓婁紶鏁版嵁鎴愬姛 + string msg2 = Language.StringByID(R.MyInternationalizationString.uUploadDataSuccess); + this.ShowTipMsg(msg2); + } + //灏嗘椂闂村埛鏂�,鐒跺悗绛夊緟鏃堕棿鍙樻洿涓�30绉� + TimeOut = 0; + waitime = 300; + } + else if (topic == gatewayID + "/BackupGwDataFileProgress_Respon") + { + //鍒锋柊绛夊緟鏃堕棿 + TimeOut = 0; + //涓婁紶杩涘害鐧惧垎姣� + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString()); + if (statu != 0) + { + threadAction = false; + //缃戝叧鏁版嵁澶囦唤澶辫触 + this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail)); + return; + } + //璁剧疆杩涘害鐧惧垎姣� + var persent = Convert.ToInt32(jobject["Data"]["BackupPercent"].ToString()); + ProgressFormBar.Current.SetValue(persent, 100); + } + }; + realGateway.Actions += action; + + //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮� + string fullUrl = string.Empty; + var connectMode = UserCenterLogic.GetHttpConnectMode(true); + if (connectMode == HttpConnectMode.Normal) + { + //鏅�氳闂� + fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/UploadHomeAppGatewaySubFiles"}"; + } + else if (connectMode == HttpConnectMode.Admin) + { + //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛� + fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/UploadHomeAppGatewaySubFiles"}"; + } + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6200 } }; + var data = new Newtonsoft.Json.Linq.JObject { + { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion }, + { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "BackupClassId", backupClassId }, + { "ManualBackupType", 2 },{ "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} + }; + jObject.Add("Data", data); + realGateway.Send("BackupGwDataFile", jObject.ToString()); + + while (threadAction == true && TimeOut < waitime) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + realGateway.Actions -= action; + if (TimeOut >= waitime) + { + //鍝嶅簲瓒呮椂,缃戝叧鏁版嵁澶囦唤澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndBackupgatewayDataFail); + this.ShowErrorMsg(msg); + return false; + } + System.Threading.Thread.Sleep(1000); + + return success; + } + + #endregion + + #region 鈻� 缃戝叧杩樺師___________________________ + + /// <summary> + /// 鎵ц缃戝叧杩樺師鎿嶄綔 + /// </summary> + /// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param> + /// <param name="backupId">澶囦唤涓婚敭</param> + /// <param name="isAutoBack">0:鑾峰彇缃戝叧鎵嬪姩澶囦唤鏂囦欢鍒楄〃 1:鑾峰彇缃戝叧鑷姩澶囦唤鏂囦欢鍒楄〃</param> + /// <param name="closeBar">鏄惁鍏抽棴杩涘害鏉�</param> + public bool RecoverGateway(ZbGateway realGateway, string backupId, int isAutoBack, bool closeBar = true) + { + //灞曞紑杩涘害鏉� + ProgressFormBar.Current.Start(); + //浠庝簯绔幏鍙栧浠芥枃浠跺垪琛� + var result = this.GetGatewayFileList(realGateway, backupId, isAutoBack); + if (result == false) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return false; + } + + //浠庝簯绔笅杞藉浠芥枃浠� + result = this.DownloadGatewayFile(realGateway, backupId, isAutoBack); + if (result == false) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return false; + } + + ////鎭㈠鍗忚皟鍣╪v鍒嗗尯鐨勭粍缃戜俊鎭� + //result = this.RestoreGatewayNV(realGateway); + //if (result == false) + //{ + // //鍏抽棴杩涘害鏉� + // ProgressFormBar.Current.Close(); + // return false; + //} + + //鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳� + //result = this.OpenZbMsComSend(realGateway); + //if (result == false) + //{ + // //鍏抽棴杩涘害鏉� + // ProgressFormBar.Current.Close(); + // return false; + //} + + //閲嶅惎缃戝叧绯荤粺 + result = this.GatewayReboot(realGateway); + + if (result == true) + { + //鍒锋柊鍏ㄩ儴鍦烘櫙 + HdlSceneLogic.Current.RefreshSceneUIList(false); + //鑾峰彇鍏ㄩ儴璁惧 + Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(realGateway.GwId, false); + } + if (closeBar == true) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + } + return result; + } + + #endregion + + #region 鈻� 浠庝簯绔幏鍙栧浠芥枃浠跺垪琛╛____________ + + /// <summary> + /// 浠庝簯绔幏鍙栧浠芥枃浠跺垪琛� + /// </summary> + /// <param name="realGateway"></param> + /// <param name="backupClassId"></param> + /// <returns></returns> + private bool GetGatewayFileList(ZbGateway realGateway, string backupClassId, int isAutoBack) + { + //姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); + System.Threading.Thread.Sleep(1000); + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/GetDataFileList_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Status"].ToString()); + if (result != 0) + { + //鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触 + this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail)); + return; + } + } + }; + realGateway.Actions += action; + + //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮� + string fullUrl = string.Empty; + var connectMode = UserCenterLogic.GetHttpConnectMode(true); + if (connectMode == HttpConnectMode.Normal) + { + //鏅�氳闂� + fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/GetHomeDataBackupUploadListPagger"}"; + } + else if (connectMode == HttpConnectMode.Admin) + { + //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛� + fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/GetHomeDataBackupUploadListPagger"}"; + } + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6202 } }; + var data = new Newtonsoft.Json.Linq.JObject { + { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion }, + { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack }, + { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId}, + { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} + }; + jObject.Add("Data", data); + realGateway.Send("GetDataFileList", jObject.ToString()); + + int timeOut = 0; + while (result == -1 && timeOut < 30) + { + System.Threading.Thread.Sleep(1000); + timeOut++; + } + realGateway.Actions -= action; + if (result != 0) + { + string msg = Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail); + if (result == -1) + { + //鍝嶅簲瓒呮椂,鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触 + msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGetBackupFileListFail); + } + this.ShowErrorMsg(msg); + return false; + } + return true; + } + + #endregion + + #region 鈻� 浠庝簯绔笅杞藉浠芥枃浠禵________________ + + /// <summary> + /// 浠庝簯绔笅杞藉浠芥枃浠� + /// </summary> + /// <param name="realGateway"></param> + /// <param name="backupClassId"></param> + /// <returns></returns> + private bool DownloadGatewayFile(ZbGateway realGateway, string backupClassId, int isAutoBack) + { + //姝e湪涓嬭浇澶囦唤鏂囦欢 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading)); + ProgressFormBar.Current.ResetProgressBar(); + System.Threading.Thread.Sleep(1000); + + bool threadAction = true; + bool success = false; + int timeOut = 0; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/RestoreDataFileProgress_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + var result = Convert.ToInt32(jobject["Data"]["Status"].ToString()); + if (result == 1 || result == 3) + { + //涓嬭浇澶囦唤鏂囦欢澶辫触 + this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDownloadBackupFileFail)); + threadAction = false; + return; + } + else if (result == 2) + { + //涓嬭浇鎴愬姛 + success = true; + threadAction = false; + return; + } + else if (result == 0) + { + //鍒锋柊绛夊緟鏃堕棿 + timeOut = 0; + //璁剧疆杩涘害鐧惧垎姣� + var persent = Convert.ToInt32(jobject["Data"]["RestoreDataPercent"].ToString()); + //缃戝叧涓嬭浇瀹屾垚涔嬪悗锛屽畠鑷繁浼氬崱涓�浼氾紝鎵嶄細鍙戦��2杩囨潵 + ProgressFormBar.Current.SetValue(persent - 1, 100); + } + } + }; + realGateway.Actions += action; + + //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮� + string fullUrl = string.Empty; + var connectMode = UserCenterLogic.GetHttpConnectMode(true); + if (connectMode == HttpConnectMode.Normal) + { + //鏅�氳闂� + fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/DownloadSomeDataBackup"}"; + } + else if (connectMode == HttpConnectMode.Admin) + { + //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛� + fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/DownloadSomeDataBackup"}"; + } + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6203 } }; + var data = new Newtonsoft.Json.Linq.JObject { + { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion }, + { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack }, + { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId}, + { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} + }; + jObject.Add("Data", data); + realGateway.Send("GetDataFileList", jObject.ToString()); + + while (threadAction == true && timeOut < 30) + { + System.Threading.Thread.Sleep(1000); + timeOut++; + } + realGateway.Actions -= action; + if (timeOut >= 30) + { + //鍝嶅簲瓒呮椂,涓嬭浇澶囦唤鏂囦欢澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndDownloadBackupFileFail); + this.ShowErrorMsg(msg); + return false; + } + return success; + } + + #endregion + + #region 鈻� 鎭㈠鍗忚皟鍣╪v鍒嗗尯鐨勭粍缃戜俊鎭痏________ + + /// <summary> + /// 鎭㈠鍗忚皟鍣╪v鍒嗗尯鐨勭粍缃戜俊鎭� + /// </summary> + /// <param name="realGateway"></param> + /// <returns></returns> + private bool RestoreGatewayNV(ZbGateway realGateway) + { + //姝e湪鎭㈠鍗忚皟鍣╪v鍒嗗尯 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayNVRestoring)); + ProgressFormBar.Current.SetValue(0); + System.Threading.Thread.Sleep(1000); + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "ZbGwOperation/RestoreNV_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Flag"].ToString()); + } + }; + realGateway.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 501 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "ImageName", "NVImage.bin" }, { "ImagePath", "/etc/hdlDat/" } }; + jObject.Add("Data", data); + realGateway.Send("ZbGwOperation/RestoreNV", jObject.ToString()); + + int TimeOut = 0; + while (result == -1 && TimeOut < 60) + { + System.Threading.Thread.Sleep(1000); + TimeOut++; + ProgressFormBar.Current.SetValue(TimeOut, 60); + } + realGateway.Actions -= action; + if (result != 0) + { + //鎭㈠鍗忚皟鍣╪v鍒嗗尯澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayNVFail); + if (result == -1) + { + //鍝嶅簲瓒呮椂,鎭㈠鍗忚皟鍣╪v鍒嗗尯澶辫触 + msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndRestoreGatewayNVFail); + } + this.ShowErrorMsg(msg); + return false; + } + + return true; + } + + #endregion + + #region 鈻� 閲嶅惎缃戝叧绯荤粺_______________________ + + /// <summary> + /// 閲嶅惎缃戝叧绯荤粺 + /// </summary> + /// <param name="realGateway"></param> + /// <returns></returns> + private bool GatewayReboot(ZbGateway realGateway) + { + //姝e湪閲嶅惎缃戝叧绯荤粺 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayRerooting)); + ProgressFormBar.Current.ResetProgressBar(); + System.Threading.Thread.Sleep(1000); + + int result = -1; + Action<string, string> action = (topic, message) => + { + var gatewayID = topic.Split('/')[0]; + if (topic == gatewayID + "/" + "GwReboot_Respon") + { + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + result = Convert.ToInt32(jobject["Data"]["Result"].ToString()); + } + }; + realGateway.Actions += action; + + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 83 } }; + realGateway.Send("GwReboot", jObject.ToString()); + + int timeOut = 0; + while (result == -1 && timeOut < 30) + { + System.Threading.Thread.Sleep(1000); + timeOut++; + } + realGateway.Actions -= action; + if (result != 0) + { + //閲嶅惎缃戝叧绯荤粺澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uGatewayRerootFail); + if (result == -1) + { + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂"); + } + this.ShowErrorMsg(msg); + return false; + } + + //缃戝叧宸茬粡鎺ユ敹鍒伴噸鍚懡浠�,鎺ヤ笅鏉ュ幓鍒ゆ柇缃戝叧鏄惁閲嶅惎瀹屾垚 + timeOut = 0; + while (true) + { + //澶ф缃戝叧閲嶅惎瑕�60绉� + if (timeOut >= 65 && timeOut % 5 == 0) + { + //5绉掍竴娆�,鍘昏幏鍙栫増鏈� + var data = HdlGatewayLogic.Current.GetGatewayInfo(realGateway, false, ShowErrorMode.NO); + if (data != null) + { + break; + } + } + System.Threading.Thread.Sleep(1000); + timeOut++; + //璁剧疆杩涘害鍊� + ProgressFormBar.Current.SetValue(timeOut, 180); + if (timeOut >= 180) + { + //180绉掕繕绛変笉鍒扮殑璇濓紝缃戝叧搴旇鍑洪棶棰樹簡 + break; + } + } + if (timeOut < 180) + { + //璁剧疆杩涘害鍊�:100% + ProgressFormBar.Current.SetValue(1, 1); + System.Threading.Thread.Sleep(1000); + return true; + } + else + { + //鍝嶅簲瓒呮椂,閲嶅惎缃戝叧绯荤粺澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGatewayRerootFail); + this.ShowErrorMsg(msg); + return false; + } + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鏄剧ず閿欒淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowErrorMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Error, msg); + contr.Show(); + }); + } + + /// <summary> + /// 鏄剧ずTip淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowTipMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + contr.Show(); + }); + } + + #endregion + } +} -- Gitblit v1.8.0