From f500e14c0a994487070380c50c85e0929cbc8e63 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 05 一月 2021 10:48:04 +0800 Subject: [PATCH] 2021-01-05 1.更新 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs | 85 +++++++++++++++++++++++++++++++++--------- 1 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs index 1d87585..54cd864 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs @@ -890,7 +890,7 @@ mDownLoad.BackupFileName = file.BackupFileName; //var requestObj3 = new BackupDetailObj () { Id = file.Id }; var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (mDownLoad); - var revertObj3 = MainPage.RequestHttpsReturnByte (API.DownloadSomeDataBackup, requestJson3, false, mUrlHead); + var revertObj3 = MainPage.RequestHttpsReturnByteNew (API.DownloadSomeDataBackup, requestJson3, mUrlHead); if (revertObj3 != null) { IO.FileUtils.WriteFileByBytes (file.BackupFileName, revertObj3); @@ -916,6 +916,9 @@ } + private readonly object SendLocker = new object (); + private readonly object DownloadLocker = new object (); + /// <summary> /// 澶氱嚎绋嬩笅杞� /// </summary> @@ -925,7 +928,7 @@ int index = 0; int indexCount = 0; - var mFileList = dataList.FindAll ((obj) => obj.BackupFileName != "null" && obj.BackupFileName != UserConfig.configFile && obj.BackupFileName != UserInfo.GlobalRegisterFile && obj.BackupFileName != "AccountListDB"); + var mFileList = dataList.FindAll ((obj) => obj.BackupFileName != "null" && obj.BackupFileName != UserConfig.configFile && obj.BackupFileName != UserInfo.GlobalRegisterFile && obj.BackupFileName != "AccountListDB" && obj.BackupFileName != CommonConfig.ConfigFile); if (maxThreads > mFileList.Count) { maxThreads = mFileList.Count; } @@ -954,16 +957,44 @@ new System.Threading.Thread (() => { for (var j = startIndex1; j <= endIndex1; j++) { - var result = DownloadSomeDataBackup (mDownLoad, mUrlHead, mFileList [j]); - if (result) { - index++; - Application.RunOnMainThread (() => { - int pro = (int)(index * 1.0 / mFileList.Count * 100); - MainPage.Loading.Text = pro.ToString () + "%"; - }); - + try { + //濡傛灉澶辫触閲嶆柊涓嬭浇锛岄噸澶�3娆� + int errorCount = 0; + while (errorCount < 3) { + var result = DownloadSomeDataBackup (mDownLoad, mUrlHead, mFileList [j]); + if (result) { + lock (DownloadLocker) { + index++; + } + Application.RunOnMainThread (() => { + int pro = (int)(index * 1.0 / mFileList.Count * 100); + MainPage.Loading.Text = pro.ToString () + "%"; + }); + errorCount = 3; + } else { + errorCount++; + Utlis.WriteLine ($"涓嬭浇澶辫触锛� {mFileList [j].BackupFileName} 娆℃暟:{errorCount}"); + } + } + } catch { } finally { + lock (SendLocker) { + indexCount++; + } } - indexCount++; + + //var t1 = DateTime.Now.Second; + //var result = DownloadSomeDataBackup (mDownLoad, mUrlHead, mFileList [j]); + //if (result) { + // index++; + // Application.RunOnMainThread (() => { + // int pro = (int)(index * 1.0 / mFileList.Count * 100); + // MainPage.Loading.Text = pro.ToString () + "%"; + // }); + + //} else { + // Utlis.WriteLine ($"涓嬭浇澶辫触锛� {mFileList [j].BackupFileName} 鏃堕棿:{DateTime.Now.Second - t1}S"); + //} + //indexCount++; //Utlis.WriteLine ($"涓嬭浇绾跨▼锛歿id} 瀹屾垚index:{j} indexCount: {indexCount}"); } @@ -1052,7 +1083,7 @@ void UpLoadBackupFileToDBNew (string mBackupClassId, int maxThreads = 20) { var backuplist = IO.FileUtils.ReadFiles (); - var mFileList = backuplist.FindAll ((obj) => obj != "null" && obj != UserConfig.configFile && obj != UserInfo.GlobalRegisterFile && obj != "AccountListDB"); + var mFileList = backuplist.FindAll ((obj) => obj != "null" && obj != UserConfig.configFile && obj != UserInfo.GlobalRegisterFile && obj != "AccountListDB" && obj != CommonConfig.ConfigFile); if (mFileList.Count <= 0) return; if (maxThreads > mFileList.Count) { @@ -1160,14 +1191,30 @@ UploadHomeAppGatewaySubFilesObj mUpData = upData; mUpData.UploadSubFileLists = list; - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData); - var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead); - if (revertObj2.StateCode.ToUpper () == "SUCCESS") { - return true; - } else { - //鎻愮ず閿欒 - return false; + //var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData); + //var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead); + //if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + // return true; + //} else { + // //鎻愮ず閿欒 + // return false; + //} + + //2020-11-16 濡傛灉澶辫触閲嶆柊涓婁紶锛岄噸澶�3娆� + int errorCount = 0; + var result = false; + while (errorCount < 3) { + var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData); + var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead, MainPage.TIME_OUT_20); + if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + result = true; + errorCount = 3; + } else { + errorCount++; + //Utlis.WriteLine ($"涓婁紶澶辫触({startIndex1}-{endIndex1})锛屾鏁�:{errorCount}"); + } } + return result; } catch { return false; } -- Gitblit v1.8.0