| | |
| | | #region ■ 上传备份___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 执行上传自动备份数据(0:没有可上传的自动备份数据 1:成功 -1:失败)
|
| | | /// 手动执行上传自动备份数据(0:没有可上传的自动备份数据 1:成功 -1:失败)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static int DoUpLoadAutoBackupData()
|
| | | public static int DoUpLoadAutoBackupDataByHand()
|
| | | {
|
| | | //获取app的自动备份
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | |
|
| | | if (data.Count == 0)
|
| | | {
|
| | | //删除全部的自动备份的本地文件
|
| | | DeleteAllAutoBackupFile();
|
| | | //如果没有自动备份数据,则把本地全部东西上传
|
| | | var pathTemp = DirNameResourse.AutoBackupDirectory;
|
| | | //复制本地所有文件过去
|
| | | List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | | foreach (string fileName in listAllFile)
|
| | | {
|
| | | string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
| | | string newFile = System.IO.Path.Combine(pathTemp, fileName);
|
| | | //复制文件
|
| | | HdlFileLogic.Current.CopyFile(oldFile, newFile);
|
| | | }
|
| | | }
|
| | |
|
| | | //编辑文件
|
| | | List<string> listEditor = GetAutoBackupEditorFile();
|
| | | //删除文件
|
| | |
| | | /// <summary>
|
| | | /// 上传文件到云端
|
| | | /// </summary>
|
| | | /// <param name="listFile"></param>
|
| | | /// <param name="listFile">编辑或者添加的文件(目前已经不是上传它了)</param>
|
| | | /// <returns></returns>
|
| | | private static bool UpLoadBackupFileToDB(List<string> listFile)
|
| | | {
|
| | | int listFileCount = listFile.Count;
|
| | | string backUpDir = DirNameResourse.AutoBackupDirectory;
|
| | | for (int i = 0; i < listFile.Count; i++)
|
| | | string localPath = Config.Instance.FullPath;
|
| | |
|
| | | //将模板数据保存到到指定的文件夹中
|
| | | var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(new DateTime(2000, 12, 31, 12, 59, 57));
|
| | | var templateFile = TemplateData.TemplateCommonLogic.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)
|
| | | {
|
| | | string file = listFile[i];
|
| | | //判断指定文件是否需要上传(根目录的才判断)
|
| | | if (HdlBackupLogic.Current.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 datainfo = new FileInfoData();
|
| | | datainfo.BackupFileName = file;
|
| | | datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(backUpDir, file));
|
| | | datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(localPath, file));
|
| | | if (datainfo.BackupFileContent == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var list = new List<FileInfoData>();
|
| | | list.Add(datainfo);
|
| | |
|
| | | var upData = new UpLoadDataPra();
|
| | | upData.HomeId = Config.Instance.Home.Id;
|
| | | upData.UploadSubFileLists = new List<FileInfoData> { datainfo };
|
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | //执行是上传
|
| | | bool falge = DoUpLoadInfoToDB(list);
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | |
| | | //设置进度值
|
| | | ProgressFormBar.Current.SetValue(i + 1, listFileCount);
|
| | | }
|
| | |
|
| | | //删除掉这个模板文件
|
| | | HdlFileLogic.Current.DeleteFile(localTemplateName);
|
| | |
|
| | | //删除文件
|
| | | var backPath = DirNameResourse.AutoBackupDirectory;
|
| | | foreach (var file in listFile)
|
| | | {
|
| | | string fullName = System.IO.Path.Combine(backPath, file);
|
| | | HdlFileLogic.Current.DeleteFile(fullName);
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | //自动备份只有一个
|
| | | var autoBackupId = data[0].Id;
|
| | | var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
|
| | |
|
| | | var upData = new DeleteFilePra();
|
| | | upData.BackupClassId = autoBackupId;
|
| | | upData.HomeId = nowZigbeeNumHomeId;
|
| | | upData.HomeId = Config.Instance.Home.Id;
|
| | | upData.DeleteFileNameLists = listData;
|
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
| | | string fullName = System.IO.Path.Combine(backPath, file);
|
| | | HdlFileLogic.Current.DeleteFile(fullName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 执行上传文件到云端
|
| | | /// </summary>
|
| | | /// <param name="listData">上传的数据</param>
|
| | | /// <returns></returns>
|
| | | private static bool DoUpLoadInfoToDB(List<FileInfoData> listData)
|
| | | {
|
| | | var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
|
| | |
|
| | | var upData = new UpLoadDataPra();
|
| | | upData.HomeId = nowZigbeeNumHomeId;
|
| | | upData.UploadSubFileLists = listData;
|
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | var backPath = DirNameResourse.AutoBackupDirectory;
|
| | | foreach (var file in listData)
|
| | | {
|
| | | string fullName = System.IO.Path.Combine(backPath, file.BackupFileName);
|
| | | HdlFileLogic.Current.DeleteFile(fullName);
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | /// <returns></returns>
|
| | | public static int SynchronizeDbAutoBackupData()
|
| | | {
|
| | | //判断是否能够同步数据
|
| | | string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | if (System.IO.File.Exists(checkFile) == true)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | return 0;
|
| | | }
|
| | |
|
| | | //暂时不支持成员
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | | return 1;
|
| | | }
|
| | | //判断是否能够同步数据
|
| | | string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | if (System.IO.File.Exists(checkFile) == true)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | |
|
| | | //获取app的自动备份
|
| | |
| | | }
|
| | | if (data.Count == 0)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
|
| | | List<string> listFile2 = GetAutoBackupDeleteFile();
|
| | |
|
| | | if (listFile1.Count == 0 && listFile2.Count == 0)
|
| | | //判断是否有文件变更了
|
| | | if (CheckAutoBackupFileIsChanged() == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (listFile1.Count == 1 && listFile1[0] == "Room_Favorite.json")
|
| | | {
|
| | | //这个东西好像APP启动的时候都会创建的样子
|
| | | return;
|
| | | }
|
| | |
|
| | | //文件全路径
|
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile;
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | //判断能否显示自动备份的界面
|
| | | if (CheckCanShowAutoBackupForm() == true)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测自动备份文件是否变更过
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private static bool CheckAutoBackupFileIsChanged()
|
| | | {
|
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
|
| | | List<string> listFile2 = GetAutoBackupDeleteFile();
|
| | |
|
| | | if (listFile1.Count == 0 && listFile2.Count == 0)
|
| | | {
|
| | | //没有文件变更
|
| | | return false;
|
| | | }
|
| | | 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 static bool CheckCanShowAutoBackupForm()
|
| | | {
|
| | | //文件全路径
|
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile;
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | //本地没有存在这个文件
|
| | | return true;
|
| | | }
|
| | | BackupNotPrompted info = null;
|
| | | var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
|
| | |
| | | if (info.NotPrompted == true)
|
| | | {
|
| | | //不再提示
|
| | | return;
|
| | | return false;
|
| | | }
|
| | | if (info.Day == 0)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | | return true;
|
| | | }
|
| | |
|
| | | DateTime oldTime = Convert.ToDateTime(info.OldDay);
|
| | | int intDay = (DateTime.Now - oldTime).Days;
|
| | | //时间已经超过
|
| | | if (intDay > info.Day)
|
| | | if (intDay >= info.Day)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HdlBackup.HdlAutoBackupForm();
|
| | | form.AddForm();
|
| | | });
|
| | | return;
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | #endregion
|