| | |
| | | /// 执行上传自动备份数据(0:没有可上传的自动备份数据 1:成功 -1:失败)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public async static Task<int> DoUpLoadAutoBackupData()
|
| | | public static int DoUpLoadAutoBackupData()
|
| | | {
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null)
|
| | | {
|
| | | return -1;
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | //开启进度条
|
| | | ProgressBar.SetMaxValue(listEditor.Count + listDelete.Count);
|
| | | ProgressBar.Show();
|
| | | //开启进度条 正在上传备份文件
|
| | | ProgressFormBar.Current.Start();
|
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading));
|
| | |
|
| | | //上传文件到云端
|
| | | bool result = await UpLoadBackupFileToDB(listEditor);
|
| | | bool result = UpLoadBackupFileToDB(listEditor);
|
| | | if (result == false)
|
| | | {
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | result = await DoDeleteFileFromDB(listDelete);
|
| | | result = DoDeleteFileFromDB(listDelete);
|
| | | if (result == false)
|
| | | {
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return -1;
|
| | | }
|
| | |
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | |
|
| | | return 1;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="listFile"></param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> UpLoadBackupFileToDB(List<string> listFile)
|
| | | private static bool UpLoadBackupFileToDB(List<string> listFile)
|
| | | {
|
| | | int listFileCount = listFile.Count;
|
| | | string backUpDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | foreach (string file in listFile)
|
| | | for (int i = 0; i < listFile.Count; i++)
|
| | | {
|
| | | string file = listFile[i];
|
| | | var datainfo = new FileInfoData();
|
| | | datainfo.BackupFileName = file;
|
| | | datainfo.BackupFileContent = ReadDirctoryFileByName(backUpDir, file);
|
| | |
| | | list.Add(datainfo);
|
| | |
|
| | | //执行是上传
|
| | | bool falge = await DoUpLoadInfoToDB(list);
|
| | | bool falge = DoUpLoadInfoToDB(list);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //设置进度值
|
| | | ProgressBar.SetValue(list.Count);
|
| | | ProgressFormBar.Current.SetValue(i + 1, listFileCount);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="listData">删除的文件</param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> DoDeleteFileFromDB(List<string> listData)
|
| | | private static bool DoDeleteFileFromDB(List<string> listData)
|
| | | {
|
| | | if (listData.Count == 0)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null || data.Count == 0)
|
| | | {
|
| | | return true;
|
| | |
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | string strroot = UserCenterResourse.LocalRootPath;
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | | foreach (var file in listData)
|
| | | {
|
| | |
| | | /// </summary>
|
| | | /// <param name="listData">上传的数据</param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> DoUpLoadInfoToDB(List<FileInfoData> listData)
|
| | | private static bool DoUpLoadInfoToDB(List<FileInfoData> listData)
|
| | | {
|
| | | var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
|
| | |
|
| | |
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData);
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | string strroot = UserCenterResourse.LocalRootPath;
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | foreach (var file in listData)
|
| | | {
|
| | |
| | | /// <returns></returns>
|
| | | public static List<string> GetAutoBackupEditorFile()
|
| | | {
|
| | | string strroot = UserCenterResourse.LocalRootPath; |
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | | return GetFileFromDirectory(path);
|
| | |
| | | /// <returns></returns>
|
| | | public static List<string> GetAutoBackupDeleteFile()
|
| | | {
|
| | | string strroot = UserCenterResourse.LocalRootPath; |
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | |
|
| | | return GetFileFromDirectory(path);
|
| | |
| | | public static void AddOrEditorFile(string fileName)
|
| | | {
|
| | | //根目录
|
| | | string strroot = UserCenterResourse.LocalRootPath;
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | if (strroot == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //自动备份目录
|
| | | string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | |
| | | public static void DeleteFile(string fileName)
|
| | | {
|
| | | //根目录
|
| | | string strroot = UserCenterResourse.LocalRootPath;
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | if (strroot == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //自动删除备份目录
|
| | | string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | |
|
| | |
| | | //创建一个空文件
|
| | | var file = System.IO.File.Create(newFile);
|
| | | file.Close();
|
| | |
|
| | | //自动备份目录
|
| | | strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | //如果备份列表里面有这个东西的话,移除掉
|
| | | string delFile = System.IO.Path.Combine(strBackPath, fileName);
|
| | | if (System.IO.File.Exists(delFile) == true)
|
| | | {
|
| | | System.IO.File.Delete(delFile);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | #region ■ 同步数据___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 同步云端数据(仅限APP启动之后) -1:异常 0:已经同步过,不需要同步 1:正常同步 |
| | | /// 同步云端数据(仅限APP启动之后) -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static async Task<int> SynchronizeDbAutoBackupData()
|
| | | public static int SynchronizeDbAutoBackupData()
|
| | | {
|
| | | //判断是否能够同步数据
|
| | | string checkFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | if (System.IO.File.Exists(checkFile) == true)
|
| | | {
|
| | | //同步服务器的取消了的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDeleteSharedContent();
|
| | | //同步服务器的分享内容
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | return 0;
|
| | | }
|
| | | //创建一个空文件
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | |
|
| | | //暂时不支持成员
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | | return 1;
|
| | | }
|
| | |
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null)
|
| | | {
|
| | | //异常,删除检测文件
|
| | | System.IO.File.Delete(checkFile);
|
| | | return -1;
|
| | | }
|
| | | if (data.Count == 0)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | return 1;
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | | return 2;
|
| | | }
|
| | | //自动备份只有一个
|
| | | string backId = data[0].Id;
|
| | |
|
| | | //强制指定文本附加信息:账号数据同步中
|
| | | ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
|
| | | //账号数据同步中
|
| | | ProgressFormBar.Current.Start();
|
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
|
| | |
|
| | | //从云端获取备份的文件,然后存入本地指定的临时文件夹
|
| | | string tempDir = await HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
|
| | | string tempDir = HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
|
| | | if (tempDir == null)
|
| | | {
|
| | | //删除检测文件
|
| | |
| | | //没有错误的话,则移动到当前住宅文件夹下面
|
| | | Global.MoveDirectoryFileToHomeDirectory(tempDir, true);
|
| | |
|
| | | //同步服务器的取消了的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDeleteSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file2 = System.IO.File.Create(checkFile);
|
| | | file2.Close();
|
| | |
|
| | | //重新刷新住宅对象
|
| | | UserCenterLogic.RefreshHomeObject();
|
| | |
|
| | | return 1;
|
| | | }
|
| | |
|
| | |
| | | //暂不支持成员
|
| | | return;
|
| | | }
|
| | | string strroot = UserCenterResourse.LocalRootPath; |
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | | List<string> listFile1 = GetFileFromDirectory(path);
|
| | |
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupSettionForm();
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | |
| | | }
|
| | | if (info.Day == 0)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupSettionForm();
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | |
| | | //时间已经超过
|
| | | if (intDay > info.Day)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupSettionForm();
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|