From 16604a593202f2f87adf71abd57d036fe7da3b52 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 18 十一月 2019 10:39:42 +0800 Subject: [PATCH] 同步了全部的代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 392 insertions(+), 4 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs index b641687..e07d3bc 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs @@ -104,7 +104,7 @@ /// <returns></returns> private bool SaveNVFile(ZbGateway realGateway) { - //姝e湪淇濆瓨鍗忚皟鍣╪v鍒嗗尯缁勭綉淇℃伅 + //姝e湪淇濆瓨鍗忚皟鍣╪v鍒嗗尯淇℃伅 ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayNVFileSaving)); ProgressFormBar.Current.SetValue(0); System.Threading.Thread.Sleep(1000); @@ -131,7 +131,7 @@ { System.Threading.Thread.Sleep(1000); TimeOut++; - ProgressFormBar.Current.SetValue2(TimeOut, 60); + ProgressFormBar.Current.SetValue(TimeOut, 60); } realGateway.Actions -= action; if (result != 0) @@ -183,7 +183,7 @@ int TimeOut = 0; while (result == -1 && TimeOut < 30) { - System.Threading.Thread.Sleep(100); + System.Threading.Thread.Sleep(1000); TimeOut++; } realGateway.Actions -= action; @@ -267,7 +267,7 @@ } //璁剧疆杩涘害鐧惧垎姣� var persent = Convert.ToInt32(jobject["Data"]["BackupPercent"].ToString()); - ProgressFormBar.Current.SetValue2(persent, 100); + ProgressFormBar.Current.SetValue(persent, 100); } }; realGateway.Actions += action; @@ -313,6 +313,394 @@ #endregion + #region 鈻� 缃戝叧杩樺師___________________________ + + /// <summary> + /// 鎵ц缃戝叧杩樺師鎿嶄綔 + /// </summary> + /// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param> + /// <param name="backupId">澶囦唤涓婚敭</param> + public bool RecoverGateway(ZbGateway realGateway, string backupId) + { + //灞曞紑杩涘害鏉� + ProgressFormBar.Current.Start(); + //浠庝簯绔幏鍙栧浠芥枃浠跺垪琛� + var result = this.GetGatewayFileList(realGateway, backupId); + if (result == false) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return false; + } + + //浠庝簯绔笅杞藉浠芥枃浠� + result = this.DownloadGatewayFile(realGateway, backupId); + 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); + //鍏抽棴杩涘害鏉� + 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) + { + //姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); + 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 + "/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", 0 }, + { "BackupClassId", backupClassId },{ "GatewayUniqueId",HdlGatewayLogic.Current.GetGatewayId(realGateway)}, + { "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) + { + //姝e湪涓嬭浇澶囦唤鏂囦欢 + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading)); + ProgressFormBar.Current.SetValue(0); + 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()); + 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/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", 0 }, + { "BackupClassId", backupClassId },{ "GatewayUniqueId",HdlGatewayLogic.Current.GetGatewayId(realGateway)}, + { "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.SetValue(0); + 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; + } + + //缃戝叧宸茬粡鎺ユ敹鍒伴噸鍚懡浠�,鎺ヤ笅鏉ュ幓鍒ゆ柇缃戝叧鏄惁閲嶅惎瀹屾垚 + bool gatewatAction = false; + bool threadAction = true; + HdlThreadLogic.Current.RunThread(async () => + { + timeOut = 0; + while (gatewatAction == false) + { + //澶ф缃戝叧閲嶅惎瑕�60绉� + if (timeOut >= 65 && timeOut % 5 == 0) + { + //5绉掍竴娆�,鍘昏幏鍙栫増鏈� + var data = await HdlGatewayLogic.Current.GetGatewayNewInfoAsync(realGateway, ShowErrorMode.NO); + if (data != null) + { + gatewatAction = true; + threadAction = false; + break; + } + } + await System.Threading.Tasks.Task.Delay(1000); + timeOut++; + //璁剧疆杩涘害鍊� + ProgressFormBar.Current.SetValue(timeOut, 180); + if (timeOut >= 180) + { + //180绉掕繕绛変笉鍒扮殑璇濓紝缃戝叧搴旇鍑洪棶棰樹簡 + threadAction = false; + break; + } + } + }); + while (threadAction == true) + { + System.Threading.Thread.Sleep(4000); + } + if (gatewatAction == true) + { + //缃戝叧鏁版嵁鎭㈠鎴愬姛! + string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayDataSuccess); + this.ShowTipMsg(msg); + return true; + } + else + { + //鍝嶅簲瓒呮椂,閲嶅惎缃戝叧绯荤粺澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGatewayRerootFail); + this.ShowErrorMsg(msg); + return false; + } + } + + #endregion + #region 鈻� 涓�鑸柟娉昣__________________________ /// <summary> -- Gitblit v1.8.0