From be95e839f40eb3ddf64706b60cba6dfcf4fad5e5 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 03 四月 2020 14:31:44 +0800 Subject: [PATCH] 2020-04-03 1.去掉登录前ping百度域名的网络监测。 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs | 244 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 193 insertions(+), 51 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs index f782a26..968c699 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs @@ -112,13 +112,13 @@ try { var backuplist = IO.FileUtils.ReadFiles (); int index = 0; - string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Name); + string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Id); IO.FileUtils.DeleteRegionFiles (oldRegionRootPath); foreach (var fileName in backuplist) { System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName); if (fileInfo.Exists) { fileInfo.MoveTo (oldRegionRootPath + fileName); - Console.WriteLine ("move file : " + fileName); + Utlis.WriteLine ("move file : " + fileName); } index++; Application.RunOnMainThread (() => { @@ -127,7 +127,7 @@ }); } IO.FileUtils.DeleteAllFile (); - string newRegionRootPath = IO.FileUtils.CreateRegionBackup (homeTemp.Name); + string newRegionRootPath = IO.FileUtils.CreateRegionBackup (homeTemp.Id); IO.FileUtils.RestoreRegionFiles (newRegionRootPath); UserConfig.Instance.RefreshUserConfig (); UserConfig.Instance.CurrentRegion = homeTemp; @@ -140,14 +140,14 @@ new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully), Language.StringByID (R.MyInternationalizationString.Close)).Show (); this.DatabackupShow (); - EquipmentPublicClass.CheckLinkRemote (2); + EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus); }); } catch (Exception ex) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -302,10 +302,16 @@ HomeId = UserConfig.Instance.CurrentRegion.Id, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; + string urlHead = MainPage.RequestHttpsHost; + if (requestObj.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } + //GetUserFolderObj requestObj = new GetUserFolderObj () { LevelID = UserConfig.Instance.CurrentRegion.Id }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); - var revertObj = MainPage.RequestHttps (API.GetHomeDataBackupPagger, requestJson); - if (revertObj.StateCode.ToUpper() == "SUCCESS") { + var revertObj = MainPage.RequestHttps (API.GetHomeDataBackupPagger, requestJson, urlHead); + if (revertObj.StateCode.ToUpper () == "SUCCESS") { var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult> (revertObj.ResponseData.ToString ()); //var list = new List<BackupListNameInfo> (); //foreach (var data2 in data.PageData) { @@ -324,11 +330,19 @@ if (data == null) return; Application.RunOnMainThread (() => { - foreach(var folder in data.PageData) - { + foreach (var folder in data.PageData) { addRow (folder.BackupName, folder.Id); } }); + } else { + //2020-01-11 鍒锋柊涓�娆asterToken + if (requestObj.IsOtherAccountCtrl) { + //if (revertObj.StateCode == "ParameterOrEmpty" || revertObj.StateCode == "NoLogin" || revertObj.StateCode == "HomeIdAndTokenNoConsistent") { + if (revertObj.StateCode != ErrorCode.NetworkError) { + UserConfig.Instance.CheckIfNeedGetMasterAccountToken (); + } + } + MainPage.ShowAlertOnMainThread ("Failed to get backup data list!"); } //var groupNames = service_backup.GetUserGroup (MainPage.LoginUser.MasterID, 0); //Application.RunOnMainThread (() => { @@ -451,9 +465,15 @@ HomeId = UserConfig.Instance.CurrentRegion.Id, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; + string urlHead = MainPage.RequestHttpsHost; + if (requestObj.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } + //DeleteFolderDataObj requestObj = new DeleteFolderDataObj () { Id = folderID }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); - var revertObj = MainPage.RequestHttps (API.DelHomeAppGatewayName, requestJson); + var revertObj = MainPage.RequestHttps (API.DelHomeAppGatewayName, requestJson, urlHead); if (revertObj.StateCode.ToUpper () == "SUCCESS") { Application.RunOnMainThread (() => { DatabackupShow (); @@ -467,6 +487,47 @@ }); } }); + + } + + //2020-01-11 + /// <summary> + /// 鍒犻櫎鏌愪釜澶囦唤 + /// </summary> + /// <param name="folderID"></param> + void DeleteFolderDataAfterUploadFailed (string folderID) + { + Application.RunOnMainThread (() => { + MainPage.Loading.Start ("Please wait..."); + }); + + + try { + var requestObj = new DelHomeAppGatewayNameObj () { + BackupClassId = folderID, + HomeId = UserConfig.Instance.CurrentRegion.Id, + LoginAccessToken = MainPage.LoginUser.LoginTokenString + }; + string urlHead = MainPage.RequestHttpsHost; + if (requestObj.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } + + //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") { + //鍒犻櫎鎴愬姛 + } else { + //鍒犻櫎澶辫触 + } + } catch { } finally { + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); + } + } @@ -522,7 +583,11 @@ try { //if (string.IsNullOrEmpty (UserConfig.Instance.GatewayMAC)) return; - if (!UserConfig.Instance.CheckHomeGateways () || string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) return; + //2020-01-11 娌$粦瀹歁AC涓嶅厑璁镐笂浼犲浠� + if (!UserConfig.Instance.CheckHomeGateways () || string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { + MainPage.ShowAlertOnMainThread (ErrorCode.BindGatewayFirst); + return; + } var requestObj = new AddHomeAppGatewayNameObj () { HomeId = UserConfig.Instance.CurrentRegion.Id, @@ -530,10 +595,15 @@ LoginAccessToken = MainPage.LoginUser.LoginTokenString, GatewayUniqueId = UserConfig.Instance.GatewayMAC }; + string urlHead = MainPage.RequestHttpsHost; + if (requestObj.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } //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); + var revertObj = MainPage.RequestHttps (API.AddHomeAppGatewayName, requestJson, urlHead); if (revertObj.StateCode.ToUpper () == "SUCCESS") { var DATA = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult> (revertObj.ResponseData.ToString()); var addFolderID = DATA.BackupClassId; @@ -549,7 +619,7 @@ Shared.Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); }); } finally { Shared.Application.RunOnMainThread (() => { @@ -564,13 +634,11 @@ } /// <summary> - /// (1)Success 鍒橻璋冪敤姝ゆ帴鍙f搷浣滄垚鍔焆,ResponseData鍒欎负null - // (2)ParameterOrEmpty,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭�, ResponseData鍒欎负null - // (3)NoLogin,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鏃犳晥鐧诲綍Token!] - + ///(1)Success 鍒橻璋冪敤姝ゆ帴鍙f搷浣滄垚鍔焆,ResponseData鍒欎负null + //(2)ParameterOrEmpty,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭�, ResponseData鍒欎负null + //(3)NoLogin,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [鏃犳晥鐧诲綍Token!] //(4)NoRecord,鍒欏搷搴斿瓧娈典腑 [ErrorInfo] 涓洪敊璇俊鎭负 [纭繚鎮ㄦ墍鎻愪氦 [椤圭洰 (浣忓畢)Id涓嶅瓨鍦�!] //(5)Exist, 鍒欏搷搴斿瓧娈典腑 [ErrorInfo]涓洪敊璇俊鎭负 [鎮ㄥ湪浣忓畢: XXX, 褰撳墠澶囦唤鍚�: XXXX宸插瓨鍦�, 璇锋崲涓浠藉啀鎻愪氦!] - //(6)NoBind, 鍒欏搷搴斿瓧娈典腑 [ErrorInfo]涓洪敊璇俊鎭负 [缃戝叧鐨勫敮涓�Id = XXX锛屼笌浣忓畢: XXXX骞朵笉瀛樺湪缁戝畾鍏崇郴!] //(7)NoPermission, 鍒欏搷搴斿瓧娈典腑 [ErrorInfo]涓洪敊璇俊鎭负 [鎮ㄥ苟涓嶅叿鏈夋鍒嗕韩鑰呮浣忓畢鐨勬潈闄�!] @@ -602,10 +670,10 @@ } - /// <summary> - /// 涓婁紶澶囦唤鏂囦欢 - /// </summary> - /// <param name="mBackupClassId"></param> + /// <summary> + /// 涓婁紶澶囦唤鏂囦欢 + /// </summary> + /// <param name="mBackupClassId"></param> void UpLoadBackupFileToDB (string mBackupClassId) { @@ -633,19 +701,43 @@ upData.UploadSubFileLists = list; //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken upData.LoginAccessToken = MainPage.LoginUser.LoginTokenString; + string urlHead = MainPage.RequestHttpsHost; + if (upData.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + upData.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } //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); + var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, urlHead); if (revertObj2.StateCode.ToUpper () == "SUCCESS") { + //index++; Application.RunOnMainThread (() => { int pro = (int)(index * 1.0 / backuplist.Count * 100); MainPage.Loading.Text = pro.ToString () + "%"; }); } else { //鎻愮ず閿欒 + break; } } + if (index != backuplist.Count) { + //2020-01-11 + DeleteFolderDataAfterUploadFailed (mBackupClassId); + Shared.Application.RunOnMainThread (() => { + new Alert ("", "Upload failed!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + MainPage.Loading.Hide (); + }); + + } + + //Shared.Application.RunOnMainThread (() => { + // if (index == 0) { + // new Alert ("", "Upload failed!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // } + + // MainPage.Loading.Hide (); + //}); } @@ -678,12 +770,16 @@ requestObj2.PageSetting.Page = 1; //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken requestObj2.LoginAccessToken = MainPage.LoginUser.LoginTokenString; - + string urlHead = MainPage.RequestHttpsHost; + if (requestObj2.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } //鑾峰彇鎵�鏈夋枃浠剁粍鍚� //var requestObj2 = new UserBackupListObj () { LevelID = folderID }; var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps (API.GetHomeDataBackupUploadListPagger, requestJson2); + var revertObj2 = MainPage.RequestHttps (API.GetHomeDataBackupUploadListPagger, requestJson2, urlHead); if (revertObj2.StateCode.ToUpper() == "SUCCESS") { var fileListData = Newtonsoft.Json.JsonConvert.DeserializeObject<LoadBackInfoResult> (revertObj2.ResponseData.ToString ()); var responseDataObj = fileListData.PageData; @@ -699,55 +795,101 @@ mDownLoad.BackupClassId = BackupClassId; //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken mDownLoad.LoginAccessToken = MainPage.LoginUser.LoginTokenString; + string mUrlHead = MainPage.RequestHttpsHost; + if (mDownLoad.IsOtherAccountCtrl) { + urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; + mDownLoad.LoginAccessToken = UserConfig.Instance.MasterAccountToken; + } int index = 0; + //foreach (var file in responseDataObj) { + // if (file.BackupFileName == "null" || "UserConfig" == file.BackupFileName) { + // continue; + // } + // 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); + // if (revertObj3 != null) { + // index++; + // IO.FileUtils.WriteFileByBytes (file.BackupFileName, revertObj3); + // Application.RunOnMainThread (() => { + // int pro = (int)(index * 1.0 / responseDataObj.Count * 100); + // MainPage.Loading.Text = pro.ToString () + "%"; + // }); + // } else { + + + // } + + // //if (revertObj3.StateCode.ToUpper() == "SUCCESS") { + // // var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject (revertObj3.ResponseData); + // // var byresss = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]> (jsonBytes); + // // index++; + // // //鏂板鍔犱簡浣忓畢鍖哄煙锛屾棫鐨勫浠芥暟鎹病鏈夊尯鍩熷睘鎬э紝褰撹幏鍙栧埌杩欎釜鏂囦欢鏃讹紝鎶婂綋鍓嶅埌浣忓畢淇℃伅鏇村埌褰撳墠澶囦唤鍒版暟鎹噷闈� + // // if ("UserConfig" == file.BackupFileName){ + // // //var regionTemp = UserConfig.Instance.CurrentRegion; + // // //UserConfig.Instance.RefreshUserConfig (); + // // //UserConfig.Instance.CurrentRegion = regionTemp; + // // //UserConfig.Instance.SaveUserConfig (); + // // ////UserConfig.Instance.GatewayList + // // continue; + // // } + // // IO.FileUtils.WriteFileByBytes (file.BackupFileName, byresss); + // // Application.RunOnMainThread (() => { + // // int pro = (int)(index * 1.0 / responseDataObj.Count * 100); + // // MainPage.Loading.Text = pro.ToString () + "%"; + // // }); + // //} else { + // // //閿欒鎻愮ず + + // //} + //} foreach (var file in responseDataObj) { + index++; if (file.BackupFileName == "null" || "UserConfig" == file.BackupFileName) { continue; } 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); + var revertObj3 = MainPage.RequestHttpsReturnByte (API.DownloadSomeDataBackup, requestJson3, false, mUrlHead); if (revertObj3 != null) { - index++; + IO.FileUtils.WriteFileByBytes (file.BackupFileName, revertObj3); Application.RunOnMainThread (() => { int pro = (int)(index * 1.0 / responseDataObj.Count * 100); MainPage.Loading.Text = pro.ToString () + "%"; }); + } else { + break; } - //if (revertObj3.StateCode.ToUpper() == "SUCCESS") { - // var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject (revertObj3.ResponseData); - // var byresss = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]> (jsonBytes); - // index++; - // //鏂板鍔犱簡浣忓畢鍖哄煙锛屾棫鐨勫浠芥暟鎹病鏈夊尯鍩熷睘鎬э紝褰撹幏鍙栧埌杩欎釜鏂囦欢鏃讹紝鎶婂綋鍓嶅埌浣忓畢淇℃伅鏇村埌褰撳墠澶囦唤鍒版暟鎹噷闈� - // if ("UserConfig" == file.BackupFileName){ - // //var regionTemp = UserConfig.Instance.CurrentRegion; - // //UserConfig.Instance.RefreshUserConfig (); - // //UserConfig.Instance.CurrentRegion = regionTemp; - // //UserConfig.Instance.SaveUserConfig (); - // ////UserConfig.Instance.GatewayList - // continue; - // } - // IO.FileUtils.WriteFileByBytes (file.BackupFileName, byresss); - // Application.RunOnMainThread (() => { - // int pro = (int)(index * 1.0 / responseDataObj.Count * 100); - // MainPage.Loading.Text = pro.ToString () + "%"; - // }); - //} else { - // //閿欒鎻愮ず - - //} } + + + if (index != responseDataObj.Count) { + //鍒犻櫎宸茬粡涓嬭浇鐨勬枃浠朵釜鏁伴敊璇� + var fileNames2 = IO.FileUtils.ReadFiles (); + foreach (var fileName in fileNames2) { + if (fileName == UserInfo.GlobalRegisterFile) { + continue; + } + IO.FileUtils.DeleteFile (fileName); + } + + MainPage.ShowAlertOnMainThread ("Download failed!"); + + return; + } + MainPage.LoginUser.SaveUserInfo (); Room.InitAllRoom (); Application.RunOnMainThread (() => { this.RemoveFromParent (); CommonPage.IsRemote = false; UserMiddle.Init (); - EquipmentPublicClass.CheckLinkRemote (2); + EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus); new Alert ("", Language.StringByID (R.MyInternationalizationString.RestoreFileIsSuccessfull), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); @@ -762,7 +904,7 @@ new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); - Console.WriteLine (ex.ToString()); + Utlis.WriteLine (ex.ToString()); } finally { Shared.Application.RunOnMainThread (() => { MainPage.Loading.Hide (); -- Gitblit v1.8.0