Added Backup features

This commit is contained in:
Thermo_SIM
2021-03-15 14:51:24 +01:00
parent 9de1286290
commit 1f769677d1
5 changed files with 66 additions and 2 deletions
@@ -26,6 +26,7 @@ namespace Client2020.BrowserTools
private static Dictionary<string, IntPtr> _editorOpened = new Dictionary<string, IntPtr>();
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)
{
@@ -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;
}
}
}
+1
View File
@@ -76,6 +76,7 @@
<Compile Include="BrowserTools\Models\Drive.cs" />
<Compile Include="BrowserTools\Models\Errors\ErrorContainer.cs" />
<Compile Include="BrowserTools\Models\File.cs" />
<Compile Include="BrowserTools\Models\FolderBackup.cs" />
<Compile Include="BrowserTools\Models\InfoFile.cs" />
<Compile Include="BrowserTools\Models\JobToStep.cs" />
<Compile Include="BrowserTools\Models\MetadataToFile.cs" />
@@ -15,13 +15,18 @@ export default class backupRecipe extends Vue {
@Prop()
deferred: Deferred<string>;
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",
@@ -7,6 +7,15 @@
</button>
</header>
<div class="form-group">
<label>{{'select_folder_name' | localize('Cartella')}}</label>
<select v-model="folder" :placeholder="'folder_name' | localize('Nuova Cartella')" >
<optgroup :label="'select_folder_all' | localize('Tutte')">
<option value="ALL_SUBFOLDERS">{{'select_folder_all_folder' | localize('Tutte le cartelle')}}</option>
</optgroup>
<optgroup :label="'select_folder_sub' | localize('Sottocartelle')">
<option v-for="folder in folderlist" :value="folder">{{folder}}</option>
</optgroup>
</select>
<label>{{'select_devices' | localize('Select Devices')}}</label>
<select v-model="device" :placeholder="'select_devices' | localize('Select Devices')">
<option v-for="device in devicelist" :value="device.Path">{{device.Name}}</option>