File was renamed from ZigbeeApp/Shared/Phone/Common/Logic/HdlAutoBackupLogic.cs |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace Shared.Phone |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 自动备份的逻辑 |
| | |
| | | /// <returns></returns> |
| | | private static bool UpLoadBackupFileToDB(List<string> listFile) |
| | | { |
| | | //获取app的自动备份 |
| | | var listBackData = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | if (listBackData == null) |
| | | { |
| | | return false; |
| | | } |
| | | string strBackId = string.Empty; |
| | | if (listBackData.Count == 0) |
| | | { |
| | | //创建一个新的备份 |
| | | strBackId = HdlBackupLogic.Current.CreatNewBackupNameToDB("AutoBackup", BackUpMode.A自动备份); |
| | | if (strBackId == null) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //自动备份只有一个 |
| | | strBackId = listBackData[0].Id; |
| | | } |
| | | |
| | | string localPath = Config.Instance.FullPath; |
| | | |
| | | //将模板数据保存到到指定的文件夹中 |
| | |
| | | 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) |
| | | var datainfo = new FileInfoData(); |
| | | datainfo.BackupFileName = file; |
| | | datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(localPath, file)); |
| | | if (datainfo.BackupFileContent == null) |
| | | { |
| | | continue; |
| | | } |
| | | //执行上传 |
| | | var falge = HdlBackupLogic.Current.DoUpLoadInfoToDB(strBackId, file, fileContent); |
| | | |
| | | var upData = new UpLoadDataPra(); |
| | | upData.HomeId = Config.Instance.Home.Id; |
| | | upData.UploadSubFileLists = new List<FileInfoData> { datainfo }; |
| | | //获取控制主人账号的Token |
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | //执行是上传 |
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true); |
| | | if (falge == false) |
| | | { |
| | | return false; |
| | |
| | | HdlFileLogic.Current.DeleteFile(localTemplateName); |
| | | |
| | | //删除文件 |
| | | var backPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | var backPath = DirNameResourse.AutoBackupDirectory; |
| | | foreach (var file in listFile) |
| | | { |
| | | string fullName = System.IO.Path.Combine(backPath, file); |
| | |
| | | } |
| | | |
| | | //获取app的自动备份 |
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1); |
| | | if (data == null || data.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | //自动备份只有一个 |
| | | var result = HdlBackupLogic.Current.DeleteDbBackupData(data[0].Id); |
| | | if (result == false) |
| | | var autoBackupId = data[0].Id; |
| | | |
| | | var upData = new DeleteFilePra(); |
| | | upData.BackupClassId = autoBackupId; |
| | | upData.HomeId = Config.Instance.Home.Id; |
| | | upData.DeleteFileNameLists = listData; |
| | | //获取控制主人账号的Token |
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData); |
| | | if (falge == false) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | //删除文件 |
| | | var backPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | var backPath = DirNameResourse.AutoBackupdeleteDirectory; |
| | | foreach (var file in listData) |
| | | { |
| | | string fullName = System.IO.Path.Combine(backPath, file); |
| | |
| | | /// <returns></returns> |
| | | public static List<string> GetAutoBackupEditorFile() |
| | | { |
| | | return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupDirectory); |
| | | return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public static List<string> GetAutoBackupDeleteFile() |
| | | { |
| | | return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupdeleteDirectory); |
| | | return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupdeleteDirectory); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | { |
| | | fileName = System.IO.Path.GetFileName(fileName); |
| | | //自动备份目录 |
| | | string strBackPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | string strBackPath = DirNameResourse.AutoBackupDirectory; |
| | | if (System.IO.Directory.Exists(strBackPath) == false) |
| | | { |
| | | //预创建个人中心全部的文件夹 |
| | |
| | | } |
| | | |
| | | //自动删除备份目录 |
| | | string strdelBackPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | string strdelBackPath = DirNameResourse.AutoBackupdeleteDirectory; |
| | | //如果删除列表里面有这个东西的话,移除掉 |
| | | string delFile = System.IO.Path.Combine(strdelBackPath, fileName); |
| | | HdlFileLogic.Current.DeleteFile(delFile); |
| | |
| | | { |
| | | fileName = System.IO.Path.GetFileName(fileName); |
| | | //自动删除备份目录 |
| | | string strBackPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | string strBackPath = DirNameResourse.AutoBackupdeleteDirectory; |
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName); |
| | | |
| | | //创建一个空文件 |
| | |
| | | file.Close(); |
| | | |
| | | //自动备份目录 |
| | | strBackPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | strBackPath = DirNameResourse.AutoBackupDirectory; |
| | | //如果备份列表里面有这个东西的话,移除掉 |
| | | string delFile = System.IO.Path.Combine(strBackPath, fileName); |
| | | |
| | |
| | | public static int SynchronizeDbAutoBackupData() |
| | | { |
| | | //暂时不支持成员 |
| | | if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3) |
| | | { |
| | | //同步服务器的分享内容 |
| | | HdlShardLogic.Current.SynchronizeDbSharedContent(); |
| | | return 1; |
| | | } |
| | | //判断是否能够同步数据 |
| | | string checkFile = HdlFileNameResourse.AutoDownLoadBackupCheckFile; |
| | | string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile; |
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原 |
| | | if (System.IO.File.Exists(checkFile) == true) |
| | | { |
| | |
| | | } |
| | | |
| | | //获取app的自动备份 |
| | | var listData = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A自动备份); |
| | | if (listData == null) |
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1); |
| | | if (data == null) |
| | | { |
| | | return -1; |
| | | } |
| | | if (listData.Count == 0) |
| | | if (data.Count == 0) |
| | | { |
| | | //创建一个空文件(标识已经完成同步) |
| | | var file = System.IO.File.Create(checkFile); |
| | |
| | | return 2; |
| | | } |
| | | //自动备份只有一个 |
| | | string backId = listData[0].Id; |
| | | string backId = data[0].Id; |
| | | |
| | | //账号数据同步中 |
| | | ProgressFormBar.Current.Start(); |
| | |
| | | file2.Close(); |
| | | |
| | | //重新刷新住宅对象 |
| | | HdlUserCenterLogic.Current.RefreshHomeObject(); |
| | | UserCenterLogic.RefreshHomeObject(); |
| | | //根据模板文件,恢复数据 |
| | | TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile(); |
| | | //强制生成设备和网关文件 |
| | |
| | | public static void DeleteAllAutoBackupFile() |
| | | { |
| | | //清空自动备份【文件夹】(编辑,追加) |
| | | string dirPath = HdlFileNameResourse.AutoBackupDirectory; |
| | | string dirPath = DirNameResourse.AutoBackupDirectory; |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true); |
| | | |
| | | //清空自动备份【文件夹】(删除) |
| | | dirPath = HdlFileNameResourse.AutoBackupdeleteDirectory; |
| | | dirPath = DirNameResourse.AutoBackupdeleteDirectory; |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true); |
| | | } |
| | |
| | | public static void SaveBackupNotPrompted(bool notPrompted, int day = -1) |
| | | { |
| | | //文件全路径 |
| | | string fullName = HdlFileNameResourse.AutoBackupNotPromptedFile; |
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile; |
| | | BackupNotPrompted info = null; |
| | | if (System.IO.File.Exists(fullName) == true) |
| | | { |
| | |
| | | /// </summary> |
| | | public static void ShowAutoBackupPromptedForm() |
| | | { |
| | | if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3) |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3) |
| | | { |
| | | //暂不支持成员 |
| | | return; |
| | |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | var form = new UserCenter.HdlBackup.HdlAutoBackupForm(); |
| | | var form = new HdlBackup.HdlAutoBackupForm(); |
| | | form.AddForm(); |
| | | }); |
| | | } |
| | |
| | | /// <returns></returns> |
| | | private static bool CheckAutoBackupFileIsChanged() |
| | | { |
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.AutoBackupDirectory); |
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory); |
| | | List<string> listFile2 = GetAutoBackupDeleteFile(); |
| | | |
| | | if (listFile1.Count == 0 && listFile2.Count == 0) |
| | |
| | | private static bool CheckCanShowAutoBackupForm() |
| | | { |
| | | //文件全路径 |
| | | string fullName = HdlFileNameResourse.AutoBackupNotPromptedFile; |
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile; |
| | | if (System.IO.File.Exists(fullName) == false) |
| | | { |
| | | //本地没有存在这个文件 |