| | |
| | | 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 (() => { |
| | |
| | | }); |
| | | } |
| | | 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; |
| | |
| | | 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 (); |
| | |
| | | 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) { |
| | |
| | | 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 刷新一次MasterToken |
| | | 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 (() => { |
| | |
| | | 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 (); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | //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 (); |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | try { |
| | | |
| | | //if (string.IsNullOrEmpty (UserConfig.Instance.GatewayMAC)) return; |
| | | if (!UserConfig.Instance.CheckHomeGateways () || string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) return; |
| | | //2020-01-11 没绑定MAC不允许上传备份 |
| | | 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, |
| | |
| | | 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; |
| | |
| | | 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 (() => { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// (1)Success 则[调用此接口操作成功],ResponseData则为null |
| | | // (2)ParameterOrEmpty,则响应字段中 [ErrorInfo] 为错误信息, ResponseData则为null |
| | | // (3)NoLogin,则响应字段中 [ErrorInfo] 为错误信息为 [无效登录Token!] |
| | | |
| | | ///(1)Success 则[调用此接口操作成功],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]为错误信息为 [您并不具有此分享者此住宅的权限!] |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传备份文件 |
| | | /// </summary> |
| | | /// <param name="mBackupClassId"></param> |
| | | /// <summary> |
| | | /// 上传备份文件 |
| | | /// </summary> |
| | | /// <param name="mBackupClassId"></param> |
| | | void UpLoadBackupFileToDB (string mBackupClassId) |
| | | { |
| | | |
| | |
| | | upData.UploadSubFileLists = list; |
| | | //获取控制主人账号的Token |
| | | 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 (); |
| | | //}); |
| | | } |
| | | |
| | | |
| | |
| | | requestObj2.PageSetting.Page = 1; |
| | | //获取控制主人账号的Token |
| | | 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; |
| | |
| | | mDownLoad.BackupClassId = BackupClassId; |
| | | //获取控制主人账号的Token |
| | | 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 (); |
| | | }); |
| | |
| | | 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 (); |