| | |
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// Log备份的名字
|
| | | /// </summary>
|
| | | private string LogBackupName = "##Log##";
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取备份名字列表___________________
|
| | |
| | | /// </summary>
|
| | | /// <param name="ZigbeeBackupType">0:App手动备份 1: App 自动备份 2:网关手动备份 3:网关自动备份</param>
|
| | | /// <param name="ZigbeeUniqueId">网关的唯一Id,获取网关备份需要</param>
|
| | | /// <param name="getLogBackup">是否获取Log备份</param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null)
|
| | | public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getLogBackup = false)
|
| | | {
|
| | | //备份名字很少的内存,可以直接一次性全部取完
|
| | | var pra = new GetBackupListPra();
|
| | |
| | | }
|
| | |
|
| | | var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult>(result);
|
| | | if (ZigbeeUniqueId != null)
|
| | | var list = new List<BackupListNameInfo>();
|
| | | foreach (var data2 in data.PageData)
|
| | | {
|
| | | var list = new List<BackupListNameInfo>();
|
| | | foreach (var data2 in data.PageData)
|
| | | if (ZigbeeUniqueId != null && data2.GatewayUniqueId != ZigbeeUniqueId)
|
| | | {
|
| | | if (data2.GatewayUniqueId == ZigbeeUniqueId)
|
| | | {
|
| | | list.Add(data2);
|
| | | }
|
| | | continue;
|
| | | }
|
| | | return list;
|
| | | if (getLogBackup == false && data2.BackupName == LogBackupName)
|
| | | {
|
| | | //不获取Log备份
|
| | | continue;
|
| | | }
|
| | | list.Add(data2);
|
| | | }
|
| | |
|
| | | return data.PageData;
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="BackupClassId">备份主键ID</param>
|
| | | /// <param name="ManualBackupType">手动备份类型(0:App手动备份,2:网关手动备份)</param>
|
| | | /// <param name="upPath">指定上传的是哪个文件夹的文件(全路径),不指定时,上传的是本地路径下的文件</param>
|
| | | /// <param name="setBarMaxValue">是否设置进度条的最大值(这个东西一般不用动它)</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "")
|
| | | public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool setBarMaxValue = true)
|
| | | {
|
| | | List<string> listAllFile = null;
|
| | | //文件夹的全路径
|
| | |
| | | }
|
| | |
|
| | | //开启进度条
|
| | | ProgressBar.SetMaxValue(listAllFile.Count);
|
| | | ProgressBar.Show();
|
| | | if (setBarMaxValue == true)
|
| | | {
|
| | | ProgressBar.SetMaxValue(listAllFile.Count);
|
| | | ProgressBar.Show();
|
| | | }
|
| | |
|
| | | //你说为什么这里不分一个函数出来(理论上是分函数出来的)
|
| | | //是因为如果分函数的话,会出现双重异步,导致主线程的进度条的百分比永远定死0%
|
| | |
| | | //设置进度值
|
| | | ProgressBar.SetValue(listPic.Count);
|
| | | }
|
| | |
|
| | | //上传Log备份
|
| | | if (upPath != UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory))
|
| | | {
|
| | | //里面有个回调自身的方法,所以这里加个判断,不然会死循环
|
| | | await this.UpLoadLogBackup();
|
| | | }
|
| | |
|
| | | //进度条关闭
|
| | | ProgressBar.Close();
|
| | |
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 上传Log备份________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 上传Log备份
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> UpLoadLogBackup()
|
| | | {
|
| | | string upPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory);
|
| | | if (HdlAutoBackupLogic.GetFileFromDirectory(upPath).Count == 0)
|
| | | {
|
| | | //没有Log文件
|
| | | return true;
|
| | | }
|
| | |
|
| | | //无视错误
|
| | | IMessageCommon.Current.IgnoreError = true;
|
| | | //从云端获取数据
|
| | | var pageData = await HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true);
|
| | | if (pageData == null)
|
| | | {
|
| | | //恢复
|
| | | IMessageCommon.Current.IgnoreError = false;
|
| | | return false;
|
| | | }
|
| | | for (int i = 0; i < pageData.Count; i++)
|
| | | {
|
| | | if (pageData[i].BackupName == LogBackupName)
|
| | | {
|
| | | //删除掉这个备份
|
| | | bool flage = await this.DeleteDbBackupData(pageData[i].Id);
|
| | | if (flage == false)
|
| | | {
|
| | | //恢复
|
| | | IMessageCommon.Current.IgnoreError = false;
|
| | | return false;
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | //创建新的备份
|
| | | string backupClassId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(LogBackupName);
|
| | | if (backupClassId == null)
|
| | | {
|
| | | //恢复
|
| | | IMessageCommon.Current.IgnoreError = false;
|
| | | return false;
|
| | | }
|
| | | //上传Log文件
|
| | | bool result = await this.UpLoadBackupFileToDB(backupClassId, 0, upPath, false);
|
| | | if (result == true)
|
| | | {
|
| | | try
|
| | | {
|
| | | //删除本地全部Log
|
| | | Global.CreateEmptyDirectory(Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory), true);
|
| | | }
|
| | | catch { }
|
| | | }
|
| | | //恢复
|
| | | IMessageCommon.Current.IgnoreError = false;
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 读取备份___________________________
|
| | |
|
| | | /// <summary>
|