黄学彪
2019-12-05 b3e96fce4cc01113128ddf8e0a18fc19594a9e56
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
@@ -35,11 +35,6 @@
            }
        }
        /// <summary>
        /// Log备份的名字
        /// </summary>
        private string LogBackupName = "##Log##";
        #endregion
        #region ■ 获取备份名字列表___________________
@@ -49,9 +44,9 @@
        /// </summary>
        /// <param name="ZigbeeBackupType">0:App手动备份 1: App 自动备份 2:网关手动备份 3:网关自动备份</param>
        /// <param name="ZigbeeUniqueId">网关的唯一Id,获取网关备份需要</param>
        /// <param name="getLogBackup">是否获取Log备份</param>
        /// <param name="getOptionBackup">是否获取功能备份</param>
        /// <returns></returns>
        public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getLogBackup = false)
        public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false)
        {
            //备份名字很少的内存,可以直接一次性全部取完
            var pra = new GetBackupListPra();
@@ -78,9 +73,9 @@
                {
                    continue;
                }
                if (getLogBackup == false && data2.BackupName == LogBackupName)
                if (getOptionBackup == false && data2.BackupName == DirNameResourse.OptionBackupName)
                {
                    //不获取Log备份
                    //不获取功能备份
                    continue;
                }
                list.Add(data2);
@@ -370,13 +365,6 @@
                ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount);
            }
            //上传Log备份
            if (upPath != UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory))
            {
                //里面有个回调自身的方法,所以这里加个判断,不然会死循环
                await this.UpLoadLogBackup();
            }
            //进度条关闭
            ProgressFormBar.Current.Close();
            //允许按系统的返回键
@@ -541,10 +529,10 @@
        #region ■ 上传Log备份________________________
        /// <summary>
        /// 上传Log备份
        /// 上传Log备份(隐匿功能)
        /// </summary>
        /// <returns></returns>
        private async Task<bool> UpLoadLogBackup()
        public async Task<bool> UpLoadLogBackup()
        {
            string upPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory);
            if (HdlAutoBackupLogic.GetFileFromDirectory(upPath).Count == 0)
@@ -553,41 +541,38 @@
                return true;
            }
            //无视错误
            IMessageCommon.Current.IgnoreError = true;
            ProgressFormBar.Current.Start();
            ProgressFormBar.Current.SetMsg("正在上传Log文件");
            //从云端获取数据
            var pageData = await HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true);
            if (pageData == null)
            {
                //恢复
                IMessageCommon.Current.IgnoreError = false;
                ProgressFormBar.Current.Close();
                return false;
            }
            string backId = string.Empty;
            for (int i = 0; i < pageData.Count; i++)
            {
                if (pageData[i].BackupName == LogBackupName)
                if (pageData[i].BackupName == DirNameResourse.OptionBackupName)
                {
                    //删除掉这个备份
                    bool flage = await this.DeleteDbBackupData(pageData[i].Id);
                    if (flage == false)
                    {
                        //恢复
                        IMessageCommon.Current.IgnoreError = false;
                        return false;
                    }
                    //获取功能备份的ID
                    backId = pageData[i].Id;
                    break;
                }
            }
            //创建新的备份
            string backupClassId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(LogBackupName);
            if (backupClassId == null)
            if (backId == string.Empty)
            {
                //恢复
                IMessageCommon.Current.IgnoreError = false;
                //创建新的备份
                backId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName);
                if (backId == null)
                {
                    ProgressFormBar.Current.Close();
                return false;
            }
            }
            //上传Log文件
            bool result = await this.UpLoadBackupFileToDB(backupClassId, 0, upPath, false);
            bool result = await this.UpLoadBackupFileToDB(backId, 0, upPath, false);
            if (result == true)
            {
                try
@@ -597,14 +582,81 @@
                }
                catch { }
            }
            //恢复
            IMessageCommon.Current.IgnoreError = false;
            ProgressFormBar.Current.Close();
            return result;
        }
        #endregion
        #region ■ 读取隐匿功能配置___________________
        /// <summary>
        /// 读取隐匿功能配置(不要在意返回值)
        /// </summary>
        /// <returns></returns>
        public async Task<bool> LoadHideOption()
        {
            //先初始化
            UserCenterResourse.HideOption = new HideOptionInfo();
            if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2)
            {
                return true;
            }
            //无视错误
            IMessageCommon.Current.IgnoreError = true;
            //从云端获取数据
            var pageData = await this.GetBackupListNameFromDB(0, null, true);
            if (pageData == null)
            {
                //恢复
                IMessageCommon.Current.IgnoreError = false;
                return false;
            }
            string backId = string.Empty;
            for (int i = 0; i < pageData.Count; i++)
            {
                if (pageData[i].BackupName == DirNameResourse.OptionBackupName)
                {
                    //获取功能备份的ID
                    backId = pageData[i].Id;
                    break;
                }
            }
            if (backId == string.Empty)
            {
                //没有功能配置
                IMessageCommon.Current.IgnoreError = false;
                return true;
            }
            //获取这个备份下面有多少个文件
            List<string> listFile = await GetBackFileIDFromDB(backId, false, null);
            if (listFile == null)
            {
                //恢复
                IMessageCommon.Current.IgnoreError = false;
                return false;
            }
            if (listFile.Contains(DirNameResourse.ShowOptionMenuFile) == true)
            {
                //显示主页隐藏菜单(Debug用)
                UserCenterResourse.HideOption.CenterHideMenu = 1;
            }
            if (listFile.Contains(DirNameResourse.DetailedLogFile) == true)
            {
                //出力详细Log(Debug用)
                UserCenterResourse.HideOption.DetailedLog = 1;
            }
            //恢复
            IMessageCommon.Current.IgnoreError = false;
            return true;
        }
        #endregion
        #region ■ 读取备份___________________________
        /// <summary>