| | |
| | | using Shared.Common; |
| | | using Newtonsoft.Json; |
| | | using Shared.Common; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.Specialized; |
| | |
| | | public List<BackupListNameInfo> GetBackupListNameFromDB(BackUpMode backupDiv, ShowNetCodeMode mode = ShowNetCodeMode.YES, bool getOptionBackup = false) |
| | | { |
| | | var pra = new { homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/folder/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/folder/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | |
| | | //一个个的下载文件 |
| | | int listFileCount = dicFile.Count; |
| | | int fileCount = 0; |
| | | foreach(string fileName in dicFile.Keys) |
| | | foreach (string fileName in dicFile.Keys) |
| | | { |
| | | fileCount++; |
| | | //账号已经退出 |
| | |
| | | |
| | | //★设置需要获取的文件名字★ |
| | | var pra = new { fileId = dicFile[fileName], folderId = i_folderId, homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/backup/file/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, true, 10); |
| | | var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/app/backup/file/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (result == null || result.Length == 0) |
| | | { |
| | |
| | | { |
| | | //获取这个备份下的文件列表 |
| | | var pra = new { folderId = i_folderId, homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/file/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/file/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | |
| | | folderName = backupName, |
| | | homeId = Config.Instance.Home.Id |
| | | }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/folder/create", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/folder/create", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | |
| | | } |
| | | var data = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult>(result.Data.ToString()); |
| | | return data.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存本地备份到APP(调试宝专用) |
| | | /// </summary> |
| | | /// <param name="backupName">备份名字</param> |
| | | /// <param name="finishEvent">完成后的回调事件(参数为文件夹名字)</param> |
| | | public void SaveBackupDataToApp(string backupName, Action<string> finishEvent = null) |
| | | { |
| | | //获取本机保存的全部住宅备份数据 |
| | | var listLocalHouse = HdlResidenceLogic.Current.GetAllLocalResidenceListByDirectory(false); |
| | | var directoryName = "BackupResidenceData_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); |
| | | foreach (var house in listLocalHouse) |
| | | { |
| | | if (house.Id == Config.Instance.Home.Id && house.Name == backupName |
| | | && house.HouseDataDiv != 1) |
| | | { |
| | | //如果本地拥有相同名字的备份的话,则直接覆盖 |
| | | directoryName = house.SaveDirctoryName; |
| | | //备份数据已经存在,是否覆盖? |
| | | HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.BackUpDataIsEsixtAndPickUp), () => |
| | | { |
| | | //将本地文件复制到指定的文件夹中 |
| | | this.CopyLocalFileToDirectory(directoryName, backupName, finishEvent); |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | //将本地文件复制到指定的文件夹中 |
| | | this.CopyLocalFileToDirectory(directoryName, backupName, finishEvent); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将本地文件复制到指定的文件夹中(调试宝专用) |
| | | /// </summary> |
| | | /// <param name="directoryName">保存的文件夹名字</param> |
| | | /// <param name="backUpName">备份名字</param> |
| | | /// <param name="finishEvent">完成后的回调事件(参数为文件夹名字)</param> |
| | | private void CopyLocalFileToDirectory(string directoryName, string backUpName, Action<string> finishEvent = null) |
| | | { |
| | | //当前路径 |
| | | var localPath = Common.Config.Instance.FullPath; |
| | | //需要保存的路径 |
| | | var savePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid, directoryName); |
| | | |
| | | if (System.IO.Directory.Exists(savePath) == false) |
| | | { |
| | | //创建文件夹 |
| | | System.IO.Directory.CreateDirectory(savePath); |
| | | } |
| | | else |
| | | { |
| | | //如果存在,则清空全部文件 |
| | | var files = System.IO.Directory.GetFiles(savePath); |
| | | foreach (var file in files) |
| | | { |
| | | HdlFileLogic.Current.DeleteFile(file); |
| | | } |
| | | } |
| | | |
| | | //本地全部的文件 |
| | | var listLocalFile = HdlFileLogic.Current.GetRootPathListFile(); |
| | | foreach (var file in listLocalFile) |
| | | { |
| | | //判断指定文件是否需要复制过去 |
| | | if (file.StartsWith("House_") == true |
| | | || this.IsNotUpLoadFile(file) == true) |
| | | { |
| | | continue; |
| | | } |
| | | string localFile = System.IO.Path.Combine(localPath, file); |
| | | string newFile = System.IO.Path.Combine(savePath, file); |
| | | try |
| | | { |
| | | //复制 |
| | | System.IO.File.Copy(localFile, newFile); |
| | | } |
| | | catch { } |
| | | } |
| | | //序列化住宅对象 |
| | | string oldHomeName = Common.Config.Instance.Home.Name; |
| | | Common.Config.Instance.Home.Name = backUpName; |
| | | HdlFileLogic.Current.SaveFileContent(System.IO.Path.Combine(savePath, Common.Config.Instance.Home.FileName), Common.Config.Instance.Home); |
| | | Common.Config.Instance.Home.Name = oldHomeName; |
| | | |
| | | //将模板数据保存到到指定的文件夹中 |
| | | var templateName = HdlTemplateCommonLogic.Current.GetNewTemplateFileName(); |
| | | var templateFile = HdlTemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, backUpName); |
| | | |
| | | //将模板bin文件移动到备份文件夹中 |
| | | try { System.IO.File.Move(templateFile, System.IO.Path.Combine(savePath, templateName)); } |
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "移动模板失败"); } |
| | | |
| | | //本地备份保存成功 |
| | | if (finishEvent == null) |
| | | { |
| | | HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.SaveLocalBackDataSuccess)); |
| | | } |
| | | else |
| | | { |
| | | //调用回调函数 |
| | | finishEvent.Invoke(directoryName); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | |
| | | if (upPath == string.Empty) |
| | | { |
| | | //将模板数据保存到到指定的文件夹中 |
| | | var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(); |
| | | var templateFile = TemplateData.TemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate"); |
| | | var templateName = HdlTemplateCommonLogic.Current.GetNewTemplateFileName(); |
| | | var templateFile = HdlTemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate"); |
| | | |
| | | //将模板bin文件移动到备份文件夹中 |
| | | localTemplateName = System.IO.Path.Combine(Config.Instance.FullPath, templateName); |
| | |
| | | dicQuery["fileName"] = i_fileName; |
| | | dicQuery["homeId"] = Config.Instance.Home.Id; |
| | | |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/file/create", RestSharp.Method.POST, i_content, dicQuery, null, CheckMode.A账号权限, true, 10); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/file/create", RestSharp.Method.POST, i_content, dicQuery, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | |
| | | public bool EditorBackupName(string i_folderId, string i_backName, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | { |
| | | var pra = new { folderId = i_folderId, folderName = i_backName, homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/folder/update", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/folder/update", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 下载备份___________________________ |
| | | |
| | | /// <summary> |
| | | /// 下载APP备份文档(函数内部有进度条,调试宝专用) |
| | | /// </summary> |
| | | /// <param name="BackupClassId"></param> |
| | | /// <param name="BackupName">云端显示的名字</param> |
| | | /// <param name="finishEvent">成功之后的事件,参数为保存备份的路径文件夹(全路径)</param> |
| | | public void DownLoadAppBackupInfo(string BackupClassId, string BackupName, Action<string> finishEvent = null) |
| | | { |
| | | //获取本机保存的全部住宅备份数据 |
| | | var listLocalHouse = HdlResidenceLogic.Current.GetAllLocalResidenceListByDirectory(false); |
| | | var directoryName = "DownLoadResidenceData_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); |
| | | foreach (var house in listLocalHouse) |
| | | { |
| | | //如果名字和住宅base数据的名字一样也可以保存 |
| | | if (house.Name == BackupName && house.HouseDataDiv != 1) |
| | | { |
| | | //如果本地拥有相同名字的备份的话,则直接覆盖 |
| | | directoryName = house.SaveDirctoryName; |
| | | //备份数据已经存在,是否覆盖? |
| | | HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.BackUpDataIsEsixtAndPickUp), () => |
| | | { |
| | | //下载APP备份文档,然后存入固定的文件夹中 |
| | | HdlThreadLogic.Current.RunThread(() => |
| | | { |
| | | this.DownLoadAppBackupInfoAndSetToDirectory(BackupClassId, directoryName, finishEvent); |
| | | }); |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | //下载APP备份文档,然后存入固定的文件夹中 |
| | | this.DownLoadAppBackupInfoAndSetToDirectory(BackupClassId, directoryName, finishEvent); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载APP备份文档,然后存入固定的文件夹中(调试宝专用) |
| | | /// </summary> |
| | | /// <param name="BackupClassId"></param> |
| | | /// <param name="targetDir">目标文件夹</param> |
| | | /// <param name="finishEvent">成功之后的事件,参数为保存备份的路径文件夹(全路径)</param> |
| | | private void DownLoadAppBackupInfoAndSetToDirectory(string BackupClassId, string targetDir, Action<string> finishEvent = null) |
| | | { |
| | | //全路径 |
| | | targetDir = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid, targetDir); |
| | | //打开进度条 正在获取备份文件列表 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); |
| | | |
| | | //从云端获取备份的文件,然后存入本地的临时文件夹 |
| | | string tempDirectory = GetBackFileFromDBAndSetToLocation(BackupClassId); |
| | | if (tempDirectory == null) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return; |
| | | } |
| | | tempDirectory = System.IO.Path.Combine(Config.Instance.FullPath, tempDirectory); |
| | | |
| | | if (System.IO.Directory.Exists(targetDir) == false) |
| | | { |
| | | //创建文件夹 |
| | | System.IO.Directory.CreateDirectory(targetDir); |
| | | } |
| | | else |
| | | { |
| | | //如果存在,则清空全部文件 |
| | | var files = System.IO.Directory.GetFiles(targetDir); |
| | | foreach (var file in files) |
| | | { |
| | | HdlFileLogic.Current.DeleteFile(file); |
| | | } |
| | | } |
| | | //获取下载到的全部的文件 |
| | | var listFile = HdlFileLogic.Current.GetFileFromDirectory(tempDirectory); |
| | | foreach (var file in listFile) |
| | | { |
| | | var sourseFile = System.IO.Path.Combine(tempDirectory, file); |
| | | var targetFile = System.IO.Path.Combine(targetDir, file); |
| | | //移动文件 |
| | | try { System.IO.File.Move(sourseFile, targetFile); } |
| | | catch { } |
| | | } |
| | | |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | //调用回调函数 |
| | | finishEvent?.Invoke(targetDir); |
| | | finishEvent = null; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 读取备份___________________________ |
| | | |
| | | /// <summary> |
| | | /// 读取APP备份文档(函数内部有进度条,Home专用) |
| | | /// </summary> |
| | | /// <param name="i_folderId"></param> |
| | | /// <param name="mode">失败时是否显示tip消息</param> |
| | | public bool LoadAppBackupInfo(string i_folderId, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | { |
| | | //打开进度条 正在获取备份文件列表 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); |
| | | |
| | | //从云端获取备份的文件,然后存入本地的临时文件夹 |
| | | string tempDirectory = GetBackFileFromDBAndSetToLocation(i_folderId, mode); |
| | | if (tempDirectory == null) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | } |
| | | |
| | | //清空全部房间 |
| | | HdlRoomLogic.Current.DeleteAllRoom(); |
| | | //清空本地全部的场景数据 |
| | | HdlSceneLogic.Current.DeleteAllLocalScene(); |
| | | //如果读取到的文件完全没有问题,则清理本地的文件 |
| | | HdlFileLogic.Current.DeleteAllLocationFile(false); |
| | | |
| | | //清理本地的模板文件 |
| | | HdlTemplateCommonLogic.Current.DeleteAllLocalFile(); |
| | | |
| | | //没有错误的话,则移动到当前住宅文件夹下面 |
| | | HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDirectory, true); |
| | | |
| | | //删除全部的自动备份的本地文件(此函数用于读取自动备份的时候使用) |
| | | this.DeleteAllAutoBackupFile(); |
| | | |
| | | //刷新本地缓存 |
| | | HdlUserCenterLogic.Current.RefreshAllMemory(); |
| | | |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 加载备份___________________________ |
| | | |
| | | /// <summary> |
| | | /// 加载本地的备份数据(调试宝专用) |
| | | /// </summary> |
| | | /// <param name="strDirectory">备份数据所在的文件夹(不是全路径)</param> |
| | | public void LoadLocalBackupData(string strDirectory) |
| | | { |
| | | //全路径 |
| | | strDirectory = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid, strDirectory); |
| | | |
| | | //清空全部房间 |
| | | HdlRoomLogic.Current.DeleteAllRoom(); |
| | | //清空本地全部的场景数据 |
| | | HdlSceneLogic.Current.DeleteAllLocalScene(); |
| | | //清理本地的文件 |
| | | HdlFileLogic.Current.DeleteAllLocationFile(false); |
| | | //清理本地的模板文件 |
| | | HdlTemplateCommonLogic.Current.DeleteAllLocalFile(); |
| | | |
| | | string localDir = Common.Config.Instance.FullPath; |
| | | //获取全部的文件 |
| | | var listFile = HdlFileLogic.Current.GetFileFromDirectory(strDirectory); |
| | | foreach (var file in listFile) |
| | | { |
| | | var sourseFile = System.IO.Path.Combine(strDirectory, file); |
| | | if (file.StartsWith("ModelData_") == true) |
| | | { |
| | | //复制模板数据文件到指定文件夹 |
| | | HdlTemplateCommonLogic.Current.CopyTemplateFileToLocalDirectory2(sourseFile); |
| | | continue; |
| | | } |
| | | //其他文件都移到本地 |
| | | var targetFile = System.IO.Path.Combine(localDir, file); |
| | | //复制文件 |
| | | try { System.IO.File.Copy(sourseFile, targetFile, true); } |
| | | catch { } |
| | | } |
| | | |
| | | //刷新本地缓存 |
| | | HdlUserCenterLogic.Current.RefreshAllMemory(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 恢复临时备份_______________________ |
| | | |
| | | /// <summary> |
| | | /// 恢复临时备份 |
| | | /// </summary> |
| | | public void RestoreTemporaryBackupData() |
| | | { |
| | | //如果本地存在临时备份的文件夹的话,则说明用户在查看模板的时候,强制关闭了App |
| | | //这个时候,App再次启动的时候,则还原数据 |
| | | if (System.IO.Directory.Exists(HdlFileNameResourse.TemporaryBackupLocalFileDirectory) == false) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //清空全部房间 |
| | | HdlRoomLogic.Current.DeleteAllRoom(); |
| | | //清空本地全部的场景数据 |
| | | HdlSceneLogic.Current.DeleteAllLocalScene(); |
| | | //清理本地的文件 |
| | | HdlFileLogic.Current.DeleteAllLocationFile(false); |
| | | //清理本地的模板文件 |
| | | HdlTemplateCommonLogic.Current.DeleteAllLocalFile(); |
| | | //将备份中的模板文件复制到模板的文件夹 |
| | | HdlFileLogic.Current.CopyDirectoryFileToDirectory(HdlFileNameResourse.TemporaryBackupTemplateFileDirectory, HdlFileNameResourse.LocalTemplateDirectory); |
| | | //将备份中的根目录文件复制到根目录 |
| | | HdlFileLogic.Current.CopyDirectoryFileToDirectory(HdlFileNameResourse.TemporaryBackupLocalFileDirectory, Common.Config.Instance.FullPath); |
| | | //删除掉这个临时备份的文件夹 |
| | | HdlFileLogic.Current.DeleteDirectory(HdlFileNameResourse.TemporaryBackupLocalFileDirectory); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 删除备份___________________________ |
| | | |
| | | /// <summary> |
| | | /// 删除云端备份 |
| | | /// </summary> |
| | | /// <param name="i_folderId">备份的主键</param> |
| | | /// <param name="mode">失败时是否显示tip消息</param> |
| | | /// <returns></returns> |
| | | public bool DeleteDbBackupData(string i_folderId, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | { |
| | | var pra = new { folderId = i_folderId, homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/backup/folder/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除本地备份 |
| | | /// </summary> |
| | | /// <param name="dirctoryName">文件夹名字</param> |
| | | public void DeleteLocalBackupData(string dirctoryName) |
| | | { |
| | | string strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid, dirctoryName); |
| | | if (System.IO.Directory.Exists(strPath) == true) |
| | | { |
| | | try { System.IO.Directory.Delete(strPath, true); } |
| | | catch (Exception ex) |
| | | { HdlLogLogic.Current.WriteLog(ex, "删除本地备份文件失败"); } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 上传自动备份_______________________ |
| | | |
| | | /// <summary> |
| | | /// 手动执行上传自动备份数据(0:没有可上传的自动备份数据 1:成功 -1:失败) |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public int DoUpLoadAutoBackupDataByHand() |
| | | { |
| | | //编辑文件 |
| | | List<string> listEditor = this.GetLocalAutoBackupEditorFile(); |
| | | //删除文件 |
| | | List<string> listDelete = this.GetLocalAutoBackupDeleteFile(); |
| | | //没有数据 |
| | | if (listEditor.Count == 0 && listDelete.Count == 0) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | //开启进度条 正在上传备份文件 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading)); |
| | | |
| | | //上传文件到云端 |
| | | bool result = UpLoadAutoBackupFileToDB(listEditor); |
| | | if (result == false) |
| | | { |
| | | ProgressFormBar.Current.Close(); |
| | | return -1; |
| | | } |
| | | |
| | | //删除文件 |
| | | result = DoDeleteAutoBackFileFromDB(listDelete); |
| | | if (result == false) |
| | | { |
| | | ProgressFormBar.Current.Close(); |
| | | return -1; |
| | | } |
| | | |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传文件到云端 |
| | | /// </summary> |
| | | /// <param name="listFile">编辑或者添加的文件(目前已经不是上传它了)</param> |
| | | /// <returns></returns> |
| | | private bool UpLoadAutoBackupFileToDB(List<string> listFile) |
| | | { |
| | | //获取app的自动备份 |
| | | var listBackData = this.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | if (listBackData == null) |
| | | { |
| | | return false; |
| | | } |
| | | string strBackId = string.Empty; |
| | | if (listBackData.Count == 0) |
| | | { |
| | | //创建一个新的备份 |
| | | strBackId = this.CreatNewBackupNameToDB("AutoBackup", BackUpMode.A自动备份); |
| | | if (strBackId == null) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //自动备份只有一个 |
| | | strBackId = listBackData[0].Id; |
| | | } |
| | | |
| | | string localPath = Config.Instance.FullPath; |
| | | |
| | | //将模板数据保存到到指定的文件夹中 |
| | | var templateName = HdlTemplateCommonLogic.Current.GetNewTemplateFileName(new DateTime(2000, 12, 31, 12, 59, 57)); |
| | | var templateFile = HdlTemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate"); |
| | | |
| | | //将模板bin文件移动到备份文件夹中 |
| | | var localTemplateName = System.IO.Path.Combine(localPath, templateName); |
| | | try { System.IO.File.Move(templateFile, localTemplateName); } |
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "移动模板失败"); } |
| | | |
| | | //获取本地文件 |
| | | var listAllFile = HdlFileLogic.Current.GetRootPathListFile(); |
| | | var listUpFile = new List<string>(); |
| | | foreach (string fileName in listAllFile) |
| | | { |
| | | //判断指定文件是否需要上传(根目录的才判断) |
| | | if (this.IsNotUpLoadFile(fileName) == true) |
| | | { |
| | | continue; |
| | | } |
| | | //其他图片的资源文件,只有在变更了的时候,才上传 |
| | | if (fileName.EndsWith(".png") == true && listFile.Contains(fileName) == false) |
| | | { |
| | | continue; |
| | | } |
| | | listUpFile.Add(fileName); |
| | | } |
| | | |
| | | int listFileCount = listUpFile.Count; |
| | | for (int i = 0; i < listUpFile.Count; i++) |
| | | { |
| | | string file = listUpFile[i]; |
| | | //读取文件内容 |
| | | var fileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(localPath, file)); |
| | | if (fileContent == null) |
| | | { |
| | | continue; |
| | | } |
| | | //执行上传 |
| | | var falge = this.DoUpLoadInfoToDB(strBackId, file, fileContent); |
| | | if (falge == false) |
| | | { |
| | | return false; |
| | | } |
| | | //设置进度值 |
| | | ProgressFormBar.Current.SetValue(i + 1, listFileCount); |
| | | } |
| | | |
| | | //删除掉这个模板文件 |
| | | HdlFileLogic.Current.DeleteFile(localTemplateName); |
| | | |
| | | //删除文件 |
| | | var backPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | foreach (var file in listFile) |
| | | { |
| | | string fullName = System.IO.Path.Combine(backPath, file); |
| | | HdlFileLogic.Current.DeleteFile(fullName); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 云端执行删除指定文件 |
| | | /// </summary> |
| | | /// <param name="listData">删除的文件</param> |
| | | /// <returns></returns> |
| | | private bool DoDeleteAutoBackFileFromDB(List<string> listData) |
| | | { |
| | | if (listData.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | //获取app的自动备份 |
| | | var data = this.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | if (data == null || data.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | //自动备份只有一个 |
| | | var result = this.DeleteDbBackupData(data[0].Id); |
| | | if (result == false) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | //删除文件 |
| | | var backPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | foreach (var file in listData) |
| | | { |
| | | string fullName = System.IO.Path.Combine(backPath, file); |
| | | HdlFileLogic.Current.DeleteFile(fullName); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取本地自动备份文件_______________ |
| | | |
| | | /// <summary> |
| | | /// 获取本地自动备份目录下的添加或者编辑的文件 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<string> GetLocalAutoBackupEditorFile() |
| | | { |
| | | return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupDirectory); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取本地自动备份目录下的删除的文件 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<string> GetLocalAutoBackupDeleteFile() |
| | | { |
| | | return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupdeleteDirectory); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 设置自动备份文件状态_______________ |
| | | |
| | | /// <summary> |
| | | /// 变更自动备份添加或者修改文件的状态 |
| | | /// </summary> |
| | | /// <param name="fileName">文件的名字,不含路径</param> |
| | | public void AddOrEditorAutoBackFileStatu(string fileName) |
| | | { |
| | | fileName = System.IO.Path.GetFileName(fileName); |
| | | //自动备份目录 |
| | | string strBackPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | if (System.IO.Directory.Exists(strBackPath) == false) |
| | | { |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | } |
| | | |
| | | //自动删除备份目录 |
| | | string strdelBackPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | //如果删除列表里面有这个东西的话,移除掉 |
| | | string delFile = System.IO.Path.Combine(strdelBackPath, fileName); |
| | | HdlFileLogic.Current.DeleteFile(delFile); |
| | | |
| | | string soureFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, fileName); |
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName); |
| | | |
| | | //原原本本的复制文件到指定文件夹 |
| | | HdlFileLogic.Current.CopyFile(soureFile, newFile); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 变更自动备份删除文件的状态 |
| | | /// </summary> |
| | | /// <param name="fileName">文件的名字,不含路径</param> |
| | | public void DeleteAutoBackFileStatu(string fileName) |
| | | { |
| | | fileName = System.IO.Path.GetFileName(fileName); |
| | | //自动删除备份目录 |
| | | string strBackPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName); |
| | | |
| | | //创建一个空文件 |
| | | var file = System.IO.File.Create(newFile); |
| | | file.Close(); |
| | | |
| | | //自动备份目录 |
| | | strBackPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | //如果备份列表里面有这个东西的话,移除掉 |
| | | string delFile = System.IO.Path.Combine(strBackPath, fileName); |
| | | |
| | | HdlFileLogic.Current.DeleteFile(delFile); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 同步数据___________________________ |
| | | |
| | | /// <summary> |
| | | /// 同步云端数据(仅限APP启动之后) -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public int SynchronizeDbAutoBackupData() |
| | | { |
| | | //暂时不支持成员 |
| | | if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) |
| | | { |
| | | //同步服务器的分享内容 |
| | | HdlShardLogic.Current.SynchronizeDbSharedContent(); |
| | | return 1; |
| | | } |
| | | //判断是否能够同步数据 |
| | | string checkFile = HdlFileNameResourse.AutoDownLoadBackupCheckFile; |
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原 |
| | | if (System.IO.File.Exists(checkFile) == true) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | //获取app的自动备份 |
| | | var listData = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | if (listData == null) |
| | | { |
| | | return -1; |
| | | } |
| | | if (listData.Count == 0) |
| | | { |
| | | //创建一个空文件(标识已经完成同步) |
| | | var file = System.IO.File.Create(checkFile); |
| | | file.Close(); |
| | | return 2; |
| | | } |
| | | //自动备份只有一个 |
| | | string backId = listData[0].Id; |
| | | |
| | | //账号数据同步中 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing)); |
| | | |
| | | //从云端获取备份的文件,然后存入本地指定的临时文件夹 |
| | | string tempDir = HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId); |
| | | if (tempDir == null) |
| | | { |
| | | //删除检测文件 |
| | | System.IO.File.Delete(checkFile); |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | //同步失败 |
| | | return -1; |
| | | } |
| | | //如果读取到的文件完全没有问题,则清理本地的文件 |
| | | HdlFileLogic.Current.DeleteAllLocationFile(false); |
| | | |
| | | //没有错误的话,则移动到当前住宅文件夹下面 |
| | | HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDir, true); |
| | | |
| | | //创建一个空文件(标识已经完成同步) |
| | | var file2 = System.IO.File.Create(checkFile); |
| | | file2.Close(); |
| | | |
| | | //重新刷新住宅对象 |
| | | HdlUserCenterLogic.Current.RefreshHomeObject(); |
| | | //根据模板文件,恢复数据 |
| | | HdlTemplateCommonLogic.Current.RecoverDataByTemplateBinFile(); |
| | | //强制生成设备和网关文件 |
| | | HdlTemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce(); |
| | | |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 读取备份___________________________ |
| | | #region ■ 备份提醒___________________________ |
| | | |
| | | /// <summary> |
| | | /// 读取APP备份文档(函数内部有进度条) |
| | | /// 保存备份提醒设置到本地 |
| | | /// </summary> |
| | | /// <param name="i_folderId"></param> |
| | | /// <param name="mode">失败时是否显示tip消息</param> |
| | | public bool LoadAppBackupInfo(string i_folderId, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | /// <param name="notPrompted">不再提示</param> |
| | | /// <param name="day"></param> |
| | | public void SaveBackupNotPrompted(bool notPrompted, int day = -1) |
| | | { |
| | | //打开进度条 正在获取备份文件列表 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); |
| | | |
| | | //从云端获取备份的文件,然后存入本地的临时文件夹 |
| | | string tempDirectory = GetBackFileFromDBAndSetToLocation(i_folderId, mode); |
| | | if (tempDirectory == null) |
| | | //文件全路径 |
| | | string fullName = HdlFileNameResourse.AutoBackupNotPromptedFile; |
| | | BackupNotPrompted info = null; |
| | | if (System.IO.File.Exists(fullName) == true) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | var data = HdlFileLogic.Current.ReadFileByteContent(fullName); |
| | | info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data)); |
| | | } |
| | | if (info == null) |
| | | { |
| | | info = new BackupNotPrompted(); |
| | | } |
| | | |
| | | //清空全部房间 |
| | | HdlRoomLogic.Current.DeleteAllRoom(); |
| | | //清空本地全部的场景数据 |
| | | HdlSceneLogic.Current.DeleteAllLocalScene(); |
| | | //如果读取到的文件完全没有问题,则清理本地的文件 |
| | | HdlFileLogic.Current.DeleteAllLocationFile(false); |
| | | |
| | | //清理本地的模板文件 |
| | | TemplateData.TemplateCommonLogic.Current.DeleteAllLocalFile(); |
| | | |
| | | //没有错误的话,则移动到当前住宅文件夹下面 |
| | | HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDirectory, true); |
| | | |
| | | //删除全部的自动备份的本地文件(此函数用于读取自动备份的时候使用) |
| | | HdlAutoBackupLogic.DeleteAllAutoBackupFile(); |
| | | |
| | | //刷新本地缓存 |
| | | HdlUserCenterLogic.Current.RefreshAllMemory(); |
| | | |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return true; |
| | | info.NotPrompted = notPrompted; |
| | | if (day != -1) |
| | | { |
| | | info.OldDay = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | info.Day = day; |
| | | } |
| | | //保存 |
| | | HdlFileLogic.Current.SaveFileContent(fullName, info); |
| | | } |
| | | |
| | | #endregion |
| | | /// <summary> |
| | | /// 显示自动备份的界面 |
| | | /// </summary> |
| | | public void ShowAutoBackupPromptedForm() |
| | | { |
| | | if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) |
| | | { |
| | | //暂不支持成员 |
| | | return; |
| | | } |
| | | |
| | | #region ■ 删除备份___________________________ |
| | | //判断是否有文件变更了 |
| | | if (CheckAutoBackupFileIsChanged() == false) |
| | | { |
| | | return; |
| | | } |
| | | //判断能否显示自动备份的界面 |
| | | if (this.CheckCanShowAutoBackupForm() == true) |
| | | { |
| | | //HdlThreadLogic.Current.RunMain(() => |
| | | //{ |
| | | // var form = new UserCenter.HdlBackup.HdlAutoBackupForm(); |
| | | // form.AddForm(); |
| | | //}); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除云端备份 |
| | | /// 检测自动备份文件是否变更过 |
| | | /// </summary> |
| | | /// <param name="i_folderId">备份的主键</param> |
| | | /// <param name="mode">失败时是否显示tip消息</param> |
| | | /// <returns></returns> |
| | | public bool DeleteDbBackupData(string i_folderId, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | private bool CheckAutoBackupFileIsChanged() |
| | | { |
| | | var pra = new { folderId = i_folderId, homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/backup/folder/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupDirectory); |
| | | List<string> listFile2 = this.GetLocalAutoBackupDeleteFile(); |
| | | |
| | | if (listFile1.Count == 0 && listFile2.Count == 0) |
| | | { |
| | | //没有文件变更 |
| | | return false; |
| | | } |
| | | return true; |
| | | if (listFile2.Count > 0) |
| | | { |
| | | //有文件被删除 |
| | | return true; |
| | | } |
| | | foreach (var fileName in listFile1) |
| | | { |
| | | //住宅和收藏文件,不作为判断标准 |
| | | if (fileName.StartsWith("House_") == true |
| | | || fileName == "Room_Favorite.json") |
| | | { |
| | | continue; |
| | | } |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测能否显示自动备份的界面 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private bool CheckCanShowAutoBackupForm() |
| | | { |
| | | //文件全路径 |
| | | string fullName = HdlFileNameResourse.AutoBackupNotPromptedFile; |
| | | if (System.IO.File.Exists(fullName) == false) |
| | | { |
| | | //本地没有存在这个文件 |
| | | return true; |
| | | } |
| | | BackupNotPrompted info = null; |
| | | var data = HdlFileLogic.Current.ReadFileByteContent(fullName); |
| | | info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data)); |
| | | if (info.NotPrompted == true) |
| | | { |
| | | //不再提示 |
| | | return false; |
| | | } |
| | | if (info.Day == 0) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | DateTime oldTime = Convert.ToDateTime(info.OldDay); |
| | | int intDay = (DateTime.Now - oldTime).Days; |
| | | //时间已经超过 |
| | | if (intDay >= info.Day) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// </summary> |
| | | /// <param name="i_mode"></param> |
| | | /// <returns></returns> |
| | | private string GetBackUpModeText(BackUpMode i_mode) |
| | | public string GetBackUpModeText(BackUpMode i_mode) |
| | | { |
| | | if (i_mode == BackUpMode.A自动备份) |
| | | { |
| | |
| | | return "USER_DEFINED_BACKUP"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除全部的自动备份的本地文件(此函数用于读取自动备份的时候使用) |
| | | /// </summary> |
| | | public void DeleteAllAutoBackupFile() |
| | | { |
| | | //清空自动备份【文件夹】(编辑,追加) |
| | | string dirPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true); |
| | | |
| | | //清空自动备份【文件夹】(删除) |
| | | dirPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 数据结构___________________________ |
| | | |
| | | /// <summary> |
| | | /// 自动备份不需要再次提醒的结构体 |
| | | /// </summary> |
| | | private class BackupNotPrompted |
| | | { |
| | | /// <summary> |
| | | /// 不再提示 |
| | | /// </summary> |
| | | public bool NotPrompted = false; |
| | | /// <summary> |
| | | /// 前一次的日期:2019-01-01(格式) |
| | | /// </summary> |
| | | public string OldDay = string.Empty; |
| | | /// <summary> |
| | | /// 相隔日期天数 |
| | | /// </summary> |
| | | public int Day = 0; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |