From 4f0ab0ad21ce450b7856d50f98322a7899361386 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 22 九月 2020 10:30:01 +0800
Subject: [PATCH] 不要下载这个备份
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs | 448 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 421 insertions(+), 27 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs
index b641687..12770b5 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs
@@ -40,16 +40,16 @@
/// </summary>
/// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param>
/// <param name="backupName">闇�瑕佸垱寤虹殑澶囦唤鐨勫悕瀛�</param>
- public async void DoBackupGateway(ZbGateway realGateway, string backupName)
+ public void DoBackupGateway(ZbGateway realGateway, string backupName)
{
//灞曞紑杩涘害鏉�
ProgressFormBar.Current.Start();
//鍒涘缓澶囦唤鏂囦欢
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uCreatBackupFile));
- await System.Threading.Tasks.Task.Delay(1000);
+ System.Threading.Thread.Sleep(1000);
//鍒涘缓涓�涓浠藉悕瀛�
- string backupClassId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, HdlGatewayLogic.Current.GetGatewayId(realGateway));
+ string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, realGateway.GwId);
if (backupClassId == null)
{
//鍏抽棴杩涘害鏉�
@@ -58,33 +58,33 @@
}
//淇濆瓨鍗忚皟鍣ㄧ殑nv鍒嗗尯缁勭綉淇℃伅
- bool result = this.SaveNVFile(realGateway);
- if (result == false)
- {
- //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎
- await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
- //鍏抽棴杩涘害鏉�
- ProgressFormBar.Current.Close();
- return;
- }
+ //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;
- }
+ //result = this.OpenZbMsComSend(realGateway);
+ //if (result == false)
+ //{
+ // //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎
+ // await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
+ // //鍏抽棴杩涘害鏉�
+ // ProgressFormBar.Current.Close();
+ // return;
+ //}
//寮�濮嬩笂浼犳暟鎹�
- result = this.StartUpLoadData(realGateway, backupClassId);
+ bool result = this.StartUpLoadData(realGateway, backupClassId);
if (result == false)
{
//濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎
- await HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
+ HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
//鍏抽棴杩涘害鏉�
ProgressFormBar.Current.Close();
return;
@@ -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;
@@ -308,11 +308,405 @@
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>
+ public bool RecoverGateway(ZbGateway realGateway, string backupId, int isAutoBack)
+ {
+ //灞曞紑杩涘害鏉�
+ 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);
+ //鍏抽棴杩涘害鏉�
+ 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));
+ 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", 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.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", 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.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(() =>
+ {
+ timeOut = 0;
+ while (gatewatAction == false)
+ {
+ //澶ф缃戝叧閲嶅惎瑕�60绉�
+ if (timeOut >= 65 && timeOut % 5 == 0)
+ {
+ //5绉掍竴娆�,鍘昏幏鍙栫増鏈�
+ var data = HdlGatewayLogic.Current.GetGatewayInfo(realGateway, false, ShowErrorMode.NO);
+ if (data != null)
+ {
+ gatewatAction = true;
+ threadAction = false;
+ break;
+ }
+ }
+ System.Threading.Thread.Sleep(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)
+ {
+ //璁剧疆杩涘害鍊�:100%
+ ProgressFormBar.Current.SetValue(1, 1);
+ System.Threading.Thread.Sleep(1000);
+ //缃戝叧鏁版嵁鎭㈠鎴愬姛!
+ 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