From 1f769677d18990462a71ce15343269ce6674ef88 Mon Sep 17 00:00:00 2001 From: Thermo_SIM Date: Mon, 15 Mar 2021 14:51:24 +0100 Subject: [PATCH] Added Backup features --- Client2020/BrowserTools/BrowserJSObject.cs | 27 +++++++++++++++++++ .../BrowserTools/Models/FolderBackup.cs | 14 ++++++++++ Client2020/Client2020.csproj | 1 + .../app_modules_thermo/save/backupRecipe.ts | 17 ++++++++++-- .../app_modules_thermo/save/backupRecipe.vue | 9 +++++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Client2020/BrowserTools/Models/FolderBackup.cs diff --git a/Client2020/BrowserTools/BrowserJSObject.cs b/Client2020/BrowserTools/BrowserJSObject.cs index 4df542ee..a7b92f8b 100644 --- a/Client2020/BrowserTools/BrowserJSObject.cs +++ b/Client2020/BrowserTools/BrowserJSObject.cs @@ -26,6 +26,7 @@ namespace Client2020.BrowserTools private static Dictionary _editorOpened = new Dictionary(); public static string RECENT_FOLDER_KEY = "RECENT"; private const string THERMO_RECIPE_PATH = @"C:\CMS\Recipes"; + private const string THERMO_RECIPE_FOLDER_NAME = @"Recipes"; private const string THERMO_SCREENSHOT_PATH = @"C:\CMS\Screenshots"; private const string CMS_PATH = @"C:\CMS"; @@ -313,6 +314,32 @@ namespace Client2020.BrowserTools return JsonConvert.SerializeObject(""); } + public string backupSubRecipes(String p, String folder) + { + if (!Directory.Exists(p)) + { + return (JsonConvert.SerializeObject(new ErrorContainer("path_not_exists"))); + } + + folder = folder.Remove(0,THERMO_RECIPE_FOLDER_NAME.Length); + + try + { + string finalPath = p + "Backup_Recipes_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); + Directory.CreateDirectory(finalPath); + this.CopyFilesRecursively(new DirectoryInfo(THERMO_RECIPE_PATH + folder), new DirectoryInfo(finalPath)); + File.WriteAllText(finalPath + "\\data.json", JsonConvert.SerializeObject(new FolderBackup(folder))); + Process.Start(finalPath); + } + catch (Exception e) + { + return (JsonConvert.SerializeObject(new ErrorContainer("error_during_backup"))); + } + + return JsonConvert.SerializeObject(""); + } + + // Read all files in directory public string getFileList(string p) { diff --git a/Client2020/BrowserTools/Models/FolderBackup.cs b/Client2020/BrowserTools/Models/FolderBackup.cs new file mode 100644 index 00000000..3922c87a --- /dev/null +++ b/Client2020/BrowserTools/Models/FolderBackup.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace Client2020.BrowserTools.Models +{ + public class FolderBackup + { + public String AbsolutePath; + public FolderBackup(String Str) + { + this.AbsolutePath = Str; + } + } +} diff --git a/Client2020/Client2020.csproj b/Client2020/Client2020.csproj index 79fecaac..809ece83 100644 --- a/Client2020/Client2020.csproj +++ b/Client2020/Client2020.csproj @@ -76,6 +76,7 @@ + diff --git a/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.ts b/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.ts index 38e2f098..45957cf0 100644 --- a/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.ts +++ b/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.ts @@ -15,13 +15,18 @@ export default class backupRecipe extends Vue { @Prop() deferred: Deferred; + folderlist = []; devicelist = []; device = ""; + folder = ""; canDo = false; + + mounted() { if (typeof cmsClient != "undefined") { this.devicelist = JSON.parse(cmsClient.getOSextDriveList()); + this.folderlist = JSON.parse(cmsClient.getAllRecipeDirectories()); } this.canDo = false; } @@ -29,13 +34,21 @@ export default class backupRecipe extends Vue { @Watch("device") valueCHange(){ - this.canDo = this.device.trim() != ""; + this.canDo = this.device.trim() != "" && this.folder.trim() != ""; + } + + @Watch("folder") + folderCHange(){ + this.canDo = this.device.trim() != "" && this.folder.trim() != ""; } run() { if (typeof cmsClient != "undefined") { this.canDo = false; - var obj = JSON.parse(cmsClient.backupRecipes(this.device)); + if(this.folder == "ALL_SUBFOLDERS") + var obj = JSON.parse(cmsClient.backupRecipes(this.device)); + else + var obj = JSON.parse(cmsClient.backupSubRecipes(this.device,this.folder)); if (obj.error) { (iziToast as any).error({ title: "error", diff --git a/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.vue b/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.vue index 03210beb..5334f882 100644 --- a/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.vue +++ b/Thermo.Active/wwwroot/src/app_modules_thermo/save/backupRecipe.vue @@ -7,6 +7,15 @@
+ +