File was renamed from ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayBackupLogic.cs |
| | |
| | | using System.Text; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 网关备份业务的逻辑 |
| | |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uCreatBackupFile)); |
| | | System.Threading.Thread.Sleep(1000); |
| | | |
| | | //☆マーク☆ |
| | | //创建一个备份名字 |
| | | //string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, realGateway.GwId); |
| | | string backupClassId = null; |
| | | string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, realGateway.GwId); |
| | | if (backupClassId == null) |
| | | { |
| | | //关闭进度条 |
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSaveGatewayNVFileFail); |
| | | if (result == -1) |
| | | { |
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | } |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uOpenZbMsComSendFail); |
| | | if (result == -1) |
| | | { |
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | } |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | |
| | | }; |
| | | realGateway.Actions += action; |
| | | |
| | | //☆マーク☆ |
| | | ////获取接口的连接模式 |
| | | //string fullUrl = string.Empty; |
| | | //var connectMode = HdlUserCenterLogic.GetHttpConnectMode(true); |
| | | //if (connectMode == HttpConnectMode.Normal) |
| | | //{ |
| | | // //普通访问 |
| | | // fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/UploadHomeAppGatewaySubFiles"}"; |
| | | //} |
| | | //else if (connectMode == HttpConnectMode.Admin) |
| | | //{ |
| | | // //以管理员的身份访问,自身是成员 |
| | | // fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/UploadHomeAppGatewaySubFiles"}"; |
| | | //} |
| | | //获取接口的连接模式 |
| | | 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", HdlUserCenterLogic.GetConnectMainToken() }, { "BackupClassId", backupClassId }, |
| | | // { "ManualBackupType", 2 },{ "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} |
| | | //}; |
| | | //jObject.Add("Data", data); |
| | | //realGateway.Send("BackupGwDataFile", jObject.ToString()); |
| | | 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) |
| | | { |
| | |
| | | /// <param name="realGateway">真实物理网关对象</param> |
| | | /// <param name="backupId">备份主键</param> |
| | | /// <param name="isAutoBack">0:获取网关手动备份文件列表 1:获取网关自动备份文件列表</param> |
| | | public bool RecoverGateway(ZbGateway realGateway, string backupId, int isAutoBack) |
| | | /// <param name="closeBar">是否关闭进度条</param> |
| | | public bool RecoverGateway(ZbGateway realGateway, string backupId, int isAutoBack, bool closeBar = true) |
| | | { |
| | | //展开进度条 |
| | | ProgressFormBar.Current.Start(); |
| | |
| | | |
| | | //重启网关系统 |
| | | result = this.GatewayReboot(realGateway); |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | if (result == true) |
| | | { |
| | | //刷新全部场景 |
| | | HdlSceneLogic.Current.RefreshSceneUIList(false); |
| | | //获取全部设备 |
| | | Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(realGateway.GwId, false); |
| | | } |
| | | if (closeBar == true) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | { |
| | | //正在获取备份文件列表 |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); |
| | | ProgressFormBar.Current.SetValue(0); |
| | | System.Threading.Thread.Sleep(1000); |
| | | |
| | | int result = -1; |
| | |
| | | }; |
| | | realGateway.Actions += action; |
| | | |
| | | //☆マーク☆ |
| | | ////获取接口的连接模式 |
| | | //string fullUrl = string.Empty; |
| | | //var connectMode = HdlUserCenterLogic.GetHttpConnectMode(true); |
| | | //if (connectMode == HttpConnectMode.Normal) |
| | | //{ |
| | | // //普通访问 |
| | | // fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/GetHomeDataBackupUploadListPagger"}"; |
| | | //} |
| | | //else if (connectMode == HttpConnectMode.Admin) |
| | | //{ |
| | | // //以管理员的身份访问,自身是成员 |
| | | // fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/GetHomeDataBackupUploadListPagger"}"; |
| | | //} |
| | | //获取接口的连接模式 |
| | | 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", HdlUserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack }, |
| | | // { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId}, |
| | | // { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} |
| | | //}; |
| | | //jObject.Add("Data", data); |
| | | //realGateway.Send("GetDataFileList", jObject.ToString()); |
| | | 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) |
| | |
| | | { |
| | | //正在下载备份文件 |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading)); |
| | | ProgressFormBar.Current.SetValue(0); |
| | | ProgressFormBar.Current.ResetProgressBar(); |
| | | System.Threading.Thread.Sleep(1000); |
| | | |
| | | bool threadAction = true; |
| | |
| | | timeOut = 0; |
| | | //设置进度百分比 |
| | | var persent = Convert.ToInt32(jobject["Data"]["RestoreDataPercent"].ToString()); |
| | | ProgressFormBar.Current.SetValue(persent, 100); |
| | | //网关下载完成之后,它自己会卡一会,才会发送2过来 |
| | | ProgressFormBar.Current.SetValue(persent - 1, 100); |
| | | } |
| | | } |
| | | }; |
| | | realGateway.Actions += action; |
| | | |
| | | //☆マーク☆ |
| | | ////获取接口的连接模式 |
| | | //string fullUrl = string.Empty; |
| | | //var connectMode = HdlUserCenterLogic.GetHttpConnectMode(true); |
| | | //if (connectMode == HttpConnectMode.Normal) |
| | | //{ |
| | | // //普通访问 |
| | | // fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/DownloadSomeDataBackup"}"; |
| | | //} |
| | | //else if (connectMode == HttpConnectMode.Admin) |
| | | //{ |
| | | // //以管理员的身份访问,自身是成员 |
| | | // fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/DownloadSomeDataBackup"}"; |
| | | //} |
| | | //获取接口的连接模式 |
| | | 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", HdlUserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack }, |
| | | // { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId}, |
| | | // { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0} |
| | | //}; |
| | | //jObject.Add("Data", data); |
| | | //realGateway.Send("GetDataFileList", jObject.ToString()); |
| | | 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) |
| | | { |
| | |
| | | { |
| | | //正在重启网关系统 |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayRerooting)); |
| | | ProgressFormBar.Current.SetValue(0); |
| | | ProgressFormBar.Current.ResetProgressBar(); |
| | | System.Threading.Thread.Sleep(1000); |
| | | |
| | | int result = -1; |
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayRerootFail); |
| | | if (result == -1) |
| | | { |
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | } |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | |
| | | //网关已经接收到重启命令,接下来去判断网关是否重启完成 |
| | | bool gatewatAction = false; |
| | | bool threadAction = true; |
| | | HdlThreadLogic.Current.RunThread(() => |
| | | timeOut = 0; |
| | | while (true) |
| | | { |
| | | timeOut = 0; |
| | | while (gatewatAction == false) |
| | | //大概网关重启要60秒 |
| | | if (timeOut >= 65 && timeOut % 5 == 0) |
| | | { |
| | | //大概网关重启要60秒 |
| | | if (timeOut >= 65 && timeOut % 5 == 0) |
| | | //5秒一次,去获取版本 |
| | | var data = HdlGatewayLogic.Current.GetGatewayInfo(realGateway, false, ShowErrorMode.NO); |
| | | if (data != null) |
| | | { |
| | | //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); |
| | | System.Threading.Thread.Sleep(1000); |
| | | timeOut++; |
| | | //设置进度值 |
| | | ProgressFormBar.Current.SetValue(timeOut, 180); |
| | | if (timeOut >= 180) |
| | | { |
| | | //180秒还等不到的话,网关应该出问题了 |
| | | break; |
| | | } |
| | | } |
| | | if (gatewatAction == true) |
| | | if (timeOut < 180) |
| | | { |
| | | //设置进度值:100% |
| | | ProgressFormBar.Current.SetValue(1, 1); |
| | | System.Threading.Thread.Sleep(1000); |
| | | //网关数据恢复成功! |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayDataSuccess); |
| | | this.ShowTipMsg(msg); |
| | | return true; |
| | | } |
| | | else |