黄学彪
2019-11-18 16604a593202f2f87adf71abd57d036fe7da3b52
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
@@ -89,7 +89,7 @@
        }
        /// <summary>
        /// <para>从云端获取备份的文件,然后存入本地指定的临时文件夹(函数内部有进度条)</para>
        /// <para>从云端获取备份的文件,然后存入本地指定的临时文件夹</para>
        /// <para>返回文件夹名字(里面存放着全部的文件),返回null时,代表失败</para>
        /// </summary>
        /// <param name="BackupClassId">BackupClassId</param>
@@ -106,22 +106,17 @@
            string newDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadBackupTempDirectory);
            Global.CreateEmptyDirectory(newDir, true);
            //开启进度条
            ProgressBar.Show();
            //获取这个备份下面有多少个文件
            List<string> listFile = await GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId);
            if (listFile == null)
            {
                //关闭进度条
                ProgressBar.Close();
                ProgressFormBar.Current.Close();
                //允许按系统的返回键
                Shared.Common.CommonPage.BackKeyCanClick = true;
                UserCenterResourse.Option.AppCanSignout = true;
                return null;
            }
            //设置最大值
            ProgressBar.SetMaxValue(listFile.Count);
            var pra = new LoadBackInfoPra();
            pra.BackupClassId = BackupClassId;
@@ -131,13 +126,15 @@
            pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
            //一个个的下载文件
            foreach (string fileName in listFile)
            int listFileCount = listFile.Count;
            for (int i = 0; i < listFile.Count; i++)
            {
                string fileName = listFile[i];
                //账号已经退出
                if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
                {
                    //关闭进度条
                    ProgressBar.Close(true);
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
@@ -150,7 +147,7 @@
                if (result == null)
                {
                    //关闭进度条
                    ProgressBar.Close();
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
@@ -159,10 +156,10 @@
                //将输入写入本地的临时文件夹
                Global.WriteFileToDirectoryByBytes(newDir, fileName, result);
                //设置进度值
                ProgressBar.SetValue(1);
                ProgressFormBar.Current.SetValue(i + 1, listFileCount);
            }
            //关闭进度条
            ProgressBar.Close();
            ProgressFormBar.Current.Close();
            //允许按系统的返回键
            Shared.Common.CommonPage.BackKeyCanClick = true;
            UserCenterResourse.Option.AppCanSignout = true;
@@ -245,9 +242,9 @@
        /// <param name="BackupClassId">备份主键ID</param>
        /// <param name="ManualBackupType">手动备份类型(0:App手动备份,2:网关手动备份)</param>
        /// <param name="upPath">指定上传的是哪个文件夹的文件(全路径),不指定时,上传的是本地路径下的文件</param>
        /// <param name="setBarMaxValue">是否设置进度条的最大值(这个东西一般不用动它)</param>
        /// <param name="showBar">是否设置显示进度条</param>
        /// <returns></returns>
        public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool setBarMaxValue = true)
        public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true)
        {
            List<string> listAllFile = null;
            //文件夹的全路径
@@ -285,10 +282,12 @@
            }
            //开启进度条
            if (setBarMaxValue == true)
            int listFileCount = listAllFile.Count;
            if (showBar == true)
            {
                ProgressBar.SetMaxValue(listAllFile.Count);
                ProgressBar.Show();
                //开启进度条 正在上传备份文件
                ProgressFormBar.Current.Start();
                ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading));
            }
            //不允许按系统的返回键
@@ -297,13 +296,14 @@
            //你说为什么这里不分一个函数出来(理论上是分函数出来的)
            //是因为如果分函数的话,会出现双重异步,导致主线程的进度条的百分比永远定死0%
            foreach (string file in listNormalFile)
            for (int i = 0; i < listNormalFile.Count; i++)
            {
                string file = listNormalFile[i];
                //账号已经退出
                if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
                {
                    //关闭进度条
                    ProgressBar.Close(true);
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
@@ -328,23 +328,24 @@
                if (falge == false)
                {
                    //关闭进度条
                    ProgressBar.Close();
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
                    return false;
                }
                //设置进度值
                ProgressBar.SetValue(list.Count);
                ProgressFormBar.Current.SetValue(i + 1, listFileCount);
            }
            foreach (string file in listPicFile)
            for (int i = 0; i < listPicFile.Count; i++)
            {
                string file = listPicFile[i];
                //账号已经退出
                if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
                {
                    //关闭进度条
                    ProgressBar.Close(true);
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
@@ -359,14 +360,14 @@
                if (result == false)
                {
                    //关闭进度条
                    ProgressBar.Close();
                    ProgressFormBar.Current.Close();
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.Option.AppCanSignout = true;
                    return false;
                }
                //设置进度值
                ProgressBar.SetValue(listPic.Count);
                ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount);
            }
            //上传Log备份
@@ -377,7 +378,7 @@
            }
            //进度条关闭
            ProgressBar.Close();
            ProgressFormBar.Current.Close();
            //允许按系统的返回键
            Shared.Common.CommonPage.BackKeyCanClick = true;
            UserCenterResourse.Option.AppCanSignout = true;
@@ -612,12 +613,20 @@
        /// <param name="BackupClassId"></param>
        public async Task<bool> LoadAppBackupInfo(string BackupClassId)
        {
            //打开进度条 正在获取备份文件列表
            ProgressFormBar.Current.Start();
            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
            //从云端获取备份的文件,然后存入本地的临时文件夹
            string tempDirectory = await GetBackFileFromDBAndSetToLocation(BackupClassId);
            if (tempDirectory == null)
            {
                //关闭进度条
                ProgressFormBar.Current.Close();
                return false;
            }
            //关闭进度条
            ProgressFormBar.Current.Close();
            //如果读取到的文件完全没有问题,则清理本地的文件
            UserCenterLogic.DeleteAllLocationFile(false);
@@ -632,30 +641,6 @@
            UserCenterLogic.RefreshAllMemory();
            return true;
        }
        /// <summary>
        /// 读取网关备份文档(函数内部有进度条)
        /// </summary>
        /// <param name="BackupClassId"></param>
        /// <param name="zbGateway">网关对象(请传入真实物理网关对象)</param>
        /// <param name="listGatewayFile">网关现有的文件名</param>
        public async Task<bool> LoadGatewayBackupInfo(string BackupClassId, ZigBee.Device.ZbGateway zbGateway, List<string> listGatewayFile)
        {
            //添加附加情报:获取备份数据
            ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uGetBackupData));
            //从云端获取备份的文件,然后存入本地的临时文件夹
            string tempDirectory = await GetBackFileFromDBAndSetToLocation(BackupClassId, false, HdlGatewayLogic.Current.GetGatewayId(zbGateway));
            //清空附加情报
            ProgressBar.SetAppendText(string.Empty);
            if (tempDirectory == null)
            {
                return false;
            }
            //恢复网关配置
            return await HdlGatewayLogic.Current.RecoverGatewaySettion(zbGateway, listGatewayFile, tempDirectory);
        }
        #endregion