From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期一, 11 一月 2021 16:11:20 +0800 Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs | 116 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 84 insertions(+), 32 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs index 60f529d..29af1dc 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs @@ -73,7 +73,7 @@ var btnPoint = new Button () { Width = Application.GetRealWidth (10), - Height = Application.GetRealHeight (10), + Height = Application.GetRealWidth (10), X = Application.GetRealWidth (50), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", @@ -311,7 +311,7 @@ //GetUserFolderObj requestObj = new GetUserFolderObj () { LevelID = UserConfig.Instance.CurrentRegion.Id }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.GetHomeDataBackupPagger, requestJson, urlHead); - if (revertObj.StateCode.ToUpper () == "SUCCESS") { + if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) { var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult> (revertObj.ResponseData.ToString ()); //var list = new List<BackupListNameInfo> (); //foreach (var data2 in data.PageData) { @@ -390,13 +390,18 @@ alert.Show (); }; - if (MainPage.LoginUser.AccountType != 1) { + //if (MainPage.LoginUser.AccountType != 1) { + // rowView.AddRightView (btnDelFile); + //} + + //2020-07-01 褰撳墠浣忓畢灞炰簬鑷繁鐨� 鍏佽鍒犻櫎澶囦唤 + if (!MainPage.IsAdministrator) { rowView.AddRightView (btnDelFile); } var btnPoint = new Button () { Width = Application.GetRealWidth (10), - Height = Application.GetRealHeight (10), + Height = Application.GetRealWidth (10), X = Application.GetRealWidth (25), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", @@ -434,8 +439,8 @@ rowView.AddChidren (backupIcon); var Backup_restores = new Button () { - Width = Application.GetRealWidth (56), - Height = Application.GetRealHeight (57), + Width = Application.GetMinRealAverage (56), + Height = Application.GetMinRealAverage (57), X = backupIcon.Right + Application.GetRealWidth (20), UnSelectedImagePath = "Register/Backup_ restores.png", SelectedImagePath = "Register/Backup_ restores_on.png", @@ -474,7 +479,7 @@ //DeleteFolderDataObj requestObj = new DeleteFolderDataObj () { Id = folderID }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.DelHomeAppGatewayName, requestJson, urlHead); - if (revertObj.StateCode.ToUpper () == "SUCCESS") { + if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) { Application.RunOnMainThread (() => { DatabackupShow (); }); @@ -517,7 +522,7 @@ //DeleteFolderDataObj requestObj = new DeleteFolderDataObj () { Id = folderID }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.DelHomeAppGatewayName, requestJson, urlHead); - if (revertObj.StateCode.ToUpper () == "SUCCESS") { + if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) { //鍒犻櫎鎴愬姛 } else { //鍒犻櫎澶辫触 @@ -584,7 +589,7 @@ //if (string.IsNullOrEmpty (UserConfig.Instance.GatewayMAC)) return; //2020-01-11 娌$粦瀹歁AC涓嶅厑璁镐笂浼犲浠� - if (!UserConfig.Instance.CheckHomeGateways () || string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { + if (!UserConfig.Instance.CheckHomeGatewaysNotEmpty()) { MainPage.ShowAlertOnMainThread (ErrorCode.BindGatewayFirst); return; } @@ -604,7 +609,7 @@ //AddFolderObj requestObj = new AddFolderObj () { LevelID = UserConfig.Instance.CurrentRegion.Id ,Name = groupName }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.AddHomeAppGatewayName, requestJson, urlHead); - if (revertObj.StateCode.ToUpper () == "SUCCESS") { + if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) { var DATA = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult> (revertObj.ResponseData.ToString ()); var addFolderID = DATA.BackupClassId; //UpLoadBackupFileToDB (addFolderID); @@ -711,7 +716,7 @@ // //AddUserBackupObj requestObj2 = new AddUserBackupObj () { LevelID = Convert.ToInt32 (revertObj.ResponseData), Name = fileName, DetailByte = IO.FileUtils.ReadFile (fileName) }; // var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (upData); // var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, urlHead); - // if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + // if (revertObj2.StateCode.ToUpper () == StateCode.SUCCESS) { // //index++; // Application.RunOnMainThread (() => { // int pro = (int)(index * 1.0 / backuplist.Count * 100); @@ -781,7 +786,7 @@ //var requestObj2 = new UserBackupListObj () { LevelID = folderID }; var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); var revertObj2 = MainPage.RequestHttps (API.GetHomeDataBackupUploadListPagger, requestJson2, urlHead); - if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + if (revertObj2.StateCode.ToUpper () == StateCode.SUCCESS) { var fileListData = Newtonsoft.Json.JsonConvert.DeserializeObject<LoadBackInfoResult> (revertObj2.ResponseData.ToString ()); var responseDataObj = fileListData.PageData; ////鑾峰彇鏂囦欢鍚嶅瓧 @@ -885,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); @@ -911,6 +916,9 @@ } + private readonly object SendLocker = new object (); + private readonly object DownloadLocker = new object (); + /// <summary> /// 澶氱嚎绋嬩笅杞� /// </summary> @@ -920,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; } @@ -949,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}"); } @@ -1025,7 +1061,7 @@ var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData); var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead); - if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + if (revertObj2.StateCode.ToUpper () == StateCode.SUCCESS) { return true; } else { //鎻愮ず閿欒 @@ -1047,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) { @@ -1155,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 () == StateCode.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 () == StateCode.SUCCESS) { + result = true; + errorCount = 3; + } else { + errorCount++; + //Utlis.WriteLine ($"涓婁紶澶辫触({startIndex1}-{endIndex1})锛屾鏁�:{errorCount}"); + } } + return result; } catch { return false; } -- Gitblit v1.8.0