From d87400af518ebc9274f4447f06476959c3aa5102 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 14 七月 2020 16:29:42 +0800
Subject: [PATCH] Merge branch 'dev-tzy' into dev-2020xm

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs |  160 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 119 insertions(+), 41 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
index 7a1f143..fffeefb 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
@@ -5,7 +5,6 @@
 using System.IO;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Shared.Phone.UserCenter
 {
@@ -46,7 +45,7 @@
         /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,鑾峰彇缃戝叧澶囦唤闇�瑕�</param>
         /// <param name="getOptionBackup">鏄惁鑾峰彇鍔熻兘澶囦唤</param>
         /// <returns></returns>
-        public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false)
+        public List<BackupListNameInfo> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false)
         {
             //澶囦唤鍚嶅瓧寰堝皯鐨勫唴瀛橈紝鍙互鐩存帴涓�娆℃�у叏閮ㄥ彇瀹�
             var pra = new GetBackupListPra();
@@ -58,8 +57,7 @@
             pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
             //璁块棶鎺ュ彛
-            var listNotShow = new List<string>() { "NotSetAgain" };
-            string result = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupPagger", true, pra, listNotShow);
+            string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupPagger", true, pra);
             if (string.IsNullOrEmpty(result) == true)
             {
                 return null;
@@ -91,18 +89,18 @@
         /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param>
         /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param>
         /// <returns></returns>
-        public async Task<string> GetBackFileFromDBAndSetToLocation(string BackupClassId, bool IsGatewayAutoBackup = false, string ZigbeeUniqueId = null)
+        public string GetBackFileFromDBAndSetToLocation(string BackupClassId, bool IsGatewayAutoBackup = false, string ZigbeeUniqueId = null)
         {
             //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭
             Shared.Common.CommonPage.BackKeyCanClick = false;
             UserCenterResourse.AccountOption.AppCanSignout = false;
 
             //棣栧厛鍏堝垱寤轰竴涓复鏃舵枃浠跺す,瀛樺湪鏂囦欢鍒欐竻绌�
-            string newDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadBackupTempDirectory);
-            Global.CreateEmptyDirectory(newDir, true);
+            string newDir = DirNameResourse.DownLoadBackupTempDirectory;
+            HdlFileLogic.Current.CreateDirectory(newDir, true);
 
             //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢
-            List<string> listFile = await GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId);
+            List<string> listFile = GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId);
             if (listFile == null)
             {
                 //鍏抽棴杩涘害鏉�
@@ -138,7 +136,7 @@
 
                 //鈽呰缃渶瑕佽幏鍙栫殑鏂囦欢鍚嶅瓧鈽�
                 pra.BackupFileName = fileName;
-                var result = await UserCenterLogic.GetByteResponseDataByRequestHttps("App/DownloadSomeDataBackup", true, pra);
+                var result = UserCenterLogic.GetByteResponseDataByRequestHttps("App/DownloadSomeDataBackup", true, pra, null, true);
                 if (result == null)
                 {
                     //鍏抽棴杩涘害鏉�
@@ -149,7 +147,7 @@
                     return null;
                 }
                 //灏嗚緭鍏ュ啓鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
-                Global.WriteFileToDirectoryByBytes(newDir, fileName, result);
+                HdlFileLogic.Current.SaveTextToFile(System.IO.Path.Combine(newDir, fileName), System.Text.Encoding.UTF8.GetString(result));
                 //璁剧疆杩涘害鍊�
                 ProgressFormBar.Current.SetValue(i + 1, listFileCount);
             }
@@ -169,7 +167,7 @@
         /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param>
         /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param>
         /// <returns></returns>
-        private async Task<List<string>> GetBackFileIDFromDB(string BackupClassId, bool IsGatewayAutoBackup, string ZigbeeUniqueId)
+        private List<string> GetBackFileIDFromDB(string BackupClassId, bool IsGatewayAutoBackup, string ZigbeeUniqueId)
         {
             var pra = new LoadBackInfoPra();
             pra.BackupClassId = BackupClassId;
@@ -181,8 +179,8 @@
             pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
             //棣栧厛鍏堣幏鍙栦簯绔湁浠�涔堟枃浠�
-            string result = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupUploadListPagger", true, pra);
-            if (result == null)
+            string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupUploadListPagger", true, pra);
+            if (string.IsNullOrEmpty(result) == true)
             {
                 return null;
             }
@@ -208,7 +206,7 @@
         /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param>
         /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,褰揗anualBackupType=2鏃�,姝ゅ�间笉鑳戒负绌�!</param>
         /// <returns></returns>
-        public async Task<string> CreatNewBackupNameToDB(string backupName, int ManualBackupType = 0, string ZigbeeUniqueId = null)
+        public string CreatNewBackupNameToDB(string backupName, int ManualBackupType = 0, string ZigbeeUniqueId = null)
         {
             var pra = new AddBackUpNamePra();
             pra.BackupName = backupName;
@@ -217,8 +215,8 @@
             //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
             pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-            var result = await UserCenterLogic.GetResponseDataByRequestHttps("App/AddHomeAppGatewayName", true, pra);
-            if (result == null)
+            var result = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHomeAppGatewayName", true, pra);
+            if (string.IsNullOrEmpty(result) == true)
             {
                 return null;
             }
@@ -239,7 +237,7 @@
         /// <param name="upPath">鎸囧畾涓婁紶鐨勬槸鍝釜鏂囦欢澶圭殑鏂囦欢(鍏ㄨ矾寰�),涓嶆寚瀹氭椂锛屼笂浼犵殑鏄湰鍦拌矾寰勪笅鐨勬枃浠�</param>
         /// <param name="showBar">鏄惁璁剧疆鏄剧ず杩涘害鏉�</param>
         /// <returns></returns>
-        public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true)
+        public bool UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true)
         {
             List<string> listAllFile = null;
             //鏂囦欢澶圭殑鍏ㄨ矾寰�
@@ -247,12 +245,12 @@
             if (upPath == string.Empty)
             {
                 //鑾峰彇鏈湴鏂囦欢
-                listAllFile = Global.FileListByHomeId();
-                fullDir = UserCenterLogic.CombinePath();
+                listAllFile = HdlFileLogic.Current.GetRootPathListFile();
+                fullDir = Common.Config.Instance.FullPath;
             }
             else
             {
-                listAllFile = HdlAutoBackupLogic.GetFileFromDirectory(upPath);
+                listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath);
                 fullDir = upPath;
             }
             if (listAllFile.Count == 0)
@@ -267,7 +265,8 @@
 
             foreach (string fileName in listAllFile)
             {
-                if (fileName.EndsWith(".png") == true)
+                if (fileName.EndsWith(".png") == true
+                    || fileName.EndsWith(".bin") == true)
                 {
                     //鍥剧墖鏂囦欢
                     listPicFile.Add(fileName);
@@ -313,13 +312,13 @@
                 var datainfo = new FileInfoData();
                 datainfo.BackupFileName = file;
                 string fullFileName = System.IO.Path.Combine(fullDir, file);
-                datainfo.BackupFileContent = Shared.IO.FileUtils.ReadFile(fullFileName);
+                datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(fullFileName);
 
                 var list = new List<FileInfoData>();
                 list.Add(datainfo);
 
                 //鎵ц涓婁紶
-                bool falge = await DoUpLoadInfoToDB(BackupClassId, list, ManualBackupType);
+                bool falge = DoUpLoadInfoToDB(BackupClassId, list, ManualBackupType);
                 if (falge == false)
                 {
                     //鍏抽棴杩涘害鏉�
@@ -381,7 +380,7 @@
         /// <param name="listData">涓婁紶鐨勬暟鎹�</param>
         /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param>
         /// <returns></returns>
-        private async Task<bool> DoUpLoadInfoToDB(string BackupClassId, List<FileInfoData> listData, int ManualBackupType = 0)
+        private bool DoUpLoadInfoToDB(string BackupClassId, List<FileInfoData> listData, int ManualBackupType = 0)
         {
             var upData = new UpLoadDataPra();
             upData.ManualBackupType = ManualBackupType;
@@ -390,7 +389,7 @@
             //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
             upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-            bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/UploadHomeAppGatewaySubFiles", true, upData);
+            bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/UploadHomeAppGatewaySubFiles", true, upData, null, true);
             if (falge == false)
             {
                 return false;
@@ -529,10 +528,10 @@
         /// 涓婁紶Log澶囦唤(闅愬尶鍔熻兘)
         /// </summary>
         /// <returns></returns>
-        public async Task<bool> UpLoadLogBackup()
+        public bool UpLoadLogBackup()
         {
-            string upPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory);
-            if (HdlAutoBackupLogic.GetFileFromDirectory(upPath).Count == 0)
+            string upPath = DirNameResourse.LogDirectory;
+            if (HdlFileLogic.Current.GetFileFromDirectory(upPath).Count == 0)
             {
                 //娌℃湁Log鏂囦欢
                 return true;
@@ -542,7 +541,7 @@
             ProgressFormBar.Current.SetMsg("姝e湪涓婁紶Log鏂囦欢");
 
             //浠庝簯绔幏鍙栨暟鎹�
-            var pageData = await HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true);
+            var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true);
             if (pageData == null)
             {
                 ProgressFormBar.Current.Close();
@@ -561,7 +560,7 @@
             if (backId == string.Empty)
             {
                 //鍒涘缓鏂扮殑澶囦唤
-                backId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName);
+                backId = HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName);
                 if (backId == null)
                 {
                     ProgressFormBar.Current.Close();
@@ -569,12 +568,12 @@
                 }
             }
             //涓婁紶Log鏂囦欢
-            bool result = await this.UpLoadBackupFileToDB(backId, 0, upPath, false);
+            bool result = this.UpLoadBackupFileToDB(backId, 0, upPath, false);
             if (result == true)
             {
                 try
                 {
-                    var listAllFile = HdlAutoBackupLogic.GetFileFromDirectory(upPath);
+                    var listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath);
                     if (listAllFile.Count > 10)
                     {
                         listAllFile.Sort();
@@ -598,6 +597,85 @@
             return result;
         }
 
+        /// <summary>
+        /// 涓婁紶涓滆タ鍒伴殣鍖垮姛鑳藉浠�
+        /// </summary>
+        /// <param name="fileName"></param>
+        /// <param name="byteData"></param>
+        /// <returns></returns>
+        public bool UpLoadByteDataToOptionBackup(string fileName, byte[] byteData)
+        {
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg("姝e湪涓婁紶鏂囦欢");
+
+            //浠庝簯绔幏鍙栨暟鎹�
+            var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true);
+            if (pageData == null)
+            {
+                ProgressFormBar.Current.Close();
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var contr = new ShowMsgControl(ShowMsgType.Tip, "鑾峰彇鍔熻兘澶囦唤澶辫触");
+                    contr.Show();
+                });
+                return false;
+            }
+            string backId = string.Empty;
+            for (int i = 0; i < pageData.Count; i++)
+            {
+                if (pageData[i].BackupName == DirNameResourse.OptionBackupName)
+                {
+                    //鑾峰彇鍔熻兘澶囦唤鐨処D
+                    backId = pageData[i].Id;
+                    break;
+                }
+            }
+            if (backId == string.Empty)
+            {
+                //鍒涘缓鏂扮殑澶囦唤
+                backId = this.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName);
+                if (backId == null)
+                {
+                    ProgressFormBar.Current.Close();
+                    HdlThreadLogic.Current.RunMain(() =>
+                    {
+                        var contr = new ShowMsgControl(ShowMsgType.Tip, "鍒涘缓鍔熻兘澶囦唤澶辫触");
+                        contr.Show();
+                    });
+                    return false;
+                }
+            }
+            //涓婁紶Log鏂囦欢
+            var datainfo = new FileInfoData();
+            datainfo.BackupFileName = fileName;
+            datainfo.BackupFileContent = byteData;
+
+            var list = new List<FileInfoData>();
+            list.Add(datainfo);
+
+            //鎵ц涓婁紶
+            bool falge = DoUpLoadInfoToDB(backId, list, 0);
+            //鍏抽棴杩涘害鏉�
+            ProgressFormBar.Current.Close();
+
+            if (falge == false)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛");
+                    contr.Show();
+                });
+                return false;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛");
+                contr.Show();
+            });
+
+            return true;
+        }
+
         #endregion
 
         #region 鈻� 璇诲彇闅愬尶鍔熻兘閰嶇疆___________________
@@ -606,7 +684,7 @@
         /// 璇诲彇闅愬尶鍔熻兘閰嶇疆(涓嶈鍦ㄦ剰杩斿洖鍊�)
         /// </summary>
         /// <returns></returns>
-        public async Task<bool> LoadHideOption()
+        public bool LoadHideOption()
         {
             //鍏堝垵濮嬪寲
             UserCenterResourse.HideOption = new HideOptionInfo();
@@ -618,7 +696,7 @@
             //鏃犺閿欒
             IMessageCommon.Current.IgnoreError = true;
             //浠庝簯绔幏鍙栨暟鎹�
-            var pageData = await this.GetBackupListNameFromDB(0, null, true);
+            var pageData = this.GetBackupListNameFromDB(0, null, true);
             if (pageData == null)
             {
                 //鎭㈠
@@ -642,7 +720,7 @@
                 return true;
             }
             //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢
-            List<string> listFile = await GetBackFileIDFromDB(backId, false, null);
+            List<string> listFile = GetBackFileIDFromDB(backId, false, null);
             if (listFile == null)
             {
                 //鎭㈠
@@ -689,14 +767,14 @@
         /// 璇诲彇APP澶囦唤鏂囨。(鍑芥暟鍐呴儴鏈夎繘搴︽潯)
         /// </summary>
         /// <param name="BackupClassId"></param>
-        public async Task<bool> LoadAppBackupInfo(string BackupClassId)
+        public bool LoadAppBackupInfo(string BackupClassId)
         {
             //鎵撳紑杩涘害鏉� 姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃
             ProgressFormBar.Current.Start();
             ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
 
             //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
-            string tempDirectory = await GetBackFileFromDBAndSetToLocation(BackupClassId);
+            string tempDirectory = GetBackFileFromDBAndSetToLocation(BackupClassId);
             if (tempDirectory == null)
             {
                 //鍏抽棴杩涘害鏉�
@@ -707,10 +785,10 @@
             ProgressFormBar.Current.Close();
 
             //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠�
-            UserCenterLogic.DeleteAllLocationFile(false);
+            HdlFileLogic.Current.DeleteAllLocationFile(false);
 
             //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰
-            Global.MoveDirectoryFileToHomeDirectory(tempDirectory, true);
+            HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDirectory, true);
 
             //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�)
             HdlAutoBackupLogic.DeleteAllAutoBackupFile();
@@ -730,14 +808,14 @@
         /// </summary>
         /// <param name="BackupClassId">澶囦唤鐨勪富閿�</param>
         /// <returns></returns>
-        public async Task<bool> DeleteDbBackupData(string BackupClassId)
+        public bool DeleteDbBackupData(string BackupClassId)
         {
             var Pra = new LoadBackInfoPra();
             Pra.BackupClassId = BackupClassId;
             //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
             Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
-            bool success = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHomeAppGatewayName", true, Pra);
+            bool success = UserCenterLogic.GetResultStatuByRequestHttps("App/DelHomeAppGatewayName", true, Pra);
 
             return success;
         }

--
Gitblit v1.8.0