diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index ebfbc2a5..25e33ed4 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -22,425 +22,440 @@ using static Client.Utils.Constants; namespace CMS_Client.Browser_Tools { - public class BrowserJSObject : JSObject + public class BrowserJSObject : JSObject + { + //The first letter of All PUBLIC Variables and Methods must be Lower-Case (CEF Settings) + + private MainForm mainForm; + private static readonly string[] _validExtensions = { ".txt", ".cnc", ".ini" }; + private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" }; + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region CONSTRUCTOR_METHOD + //Constructor Method + public BrowserJSObject(MainForm f) { - //The first letter of All PUBLIC Variables and Methods must be Lower-Case (CEF Settings) + mainForm = f; + + AddFunction("minimizeForm").Execute += minimizeForm; + AddFunction("maximizeForm").Execute += maximizeForm; + AddFunction("closeForm").Execute += closeForm; + AddFunction("forceStepFocus").Execute += forceStepFocus; + AddFunction("reloadBrokenPage").Execute += reloadBrokenPage; + + AddFunction("setNcWindowState").Execute += setNcWindowState; + AddFunction("getNcWindowState").Execute += getNcWindowState; + AddFunction("getScreenBase64").Execute += getScreenBase64; + AddFunction("getChromiumVersion").Execute += getChromiumVersion; + AddFunction("getClientID").Execute += getClientID; + AddFunction("getConfiguredProcesses").Execute += getConfiguredProcesses; + AddFunction("startNewProcess").Execute += startNewProcess; + AddFunction("openOrStartProcess").Execute += openOrStartProcess; + AddFunction("isVirtualKeybConfigured").Execute += isVirtualKeybConfigured; + AddFunction("sendHMICommand").Execute += sendHMICommand; + AddFunction("getHMICommandCount").Execute += getHMICommandCount; + AddFunction("getOSdriveList").Execute += getOSdriveList; + AddFunction("getFileList").Execute += getFileList; + AddFunction("getProgramInfo").Execute += getProgramInfo; + + AddFunction("uploadProgram").Execute += uploadProgram; + AddFunction("activateProgram").Execute += activateProgram; - private MainForm mainForm; - private static readonly string[] _validExtensions = { ".txt", ".cnc", ".ini" }; - private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" }; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region CONSTRUCTOR_METHOD - //Constructor Method - public BrowserJSObject(MainForm f) - { - mainForm = f; - - AddFunction("minimizeForm").Execute += minimizeForm; - AddFunction("maximizeForm").Execute += maximizeForm; - AddFunction("closeForm").Execute += closeForm; - AddFunction("forceStepFocus").Execute += forceStepFocus; - AddFunction("reloadBrokenPage").Execute += reloadBrokenPage; - - AddFunction("setNcWindowState").Execute += setNcWindowState; - AddFunction("getNcWindowState").Execute += getNcWindowState; - AddFunction("getScreenBase64").Execute += getScreenBase64; - AddFunction("getChromiumVersion").Execute += getChromiumVersion; - AddFunction("getClientID").Execute += getClientID; - AddFunction("getConfiguredProcesses").Execute += getConfiguredProcesses; - AddFunction("startNewProcess").Execute += startNewProcess; - AddFunction("openOrStartProcess").Execute += openOrStartProcess; - AddFunction("isVirtualKeybConfigured").Execute += isVirtualKeybConfigured; - AddFunction("sendHMICommand").Execute += sendHMICommand; - AddFunction("getHMICommandCount").Execute += getHMICommandCount; - AddFunction("getOSdriveList").Execute += getOSdriveList; - AddFunction("getFileList").Execute += getFileList; - AddFunction("getProgramInfo").Execute += getProgramInfo; - - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region FORM_BEHAVIOUR_METHODS - - //Minimize Main Window - public void minimizeForm(object sender, CfrV8HandlerExecuteEventArgs e) - { - //Invoke method if is needed or call the method in STD mode - if (mainForm.InvokeRequired) - mainForm.Invoke((MethodInvoker)delegate () { - mainForm.WindowState = FormWindowState.Minimized; - }); - - else - { - mainForm.WindowState = FormWindowState.Minimized; - } - } - - - - //Maximize Main Window - public void maximizeForm(object sender, CfrV8HandlerExecuteEventArgs e) - { - //Invoke method if is needed or call the method in STD mode - if (mainForm.InvokeRequired) - mainForm.Invoke((MethodInvoker)delegate () { - mainForm.WindowState = FormWindowState.Maximized; - }); - - else - { - mainForm.WindowState = FormWindowState.Maximized; - } - } - - - - //Close Main Window - public void closeForm(object sender, CfrV8HandlerExecuteEventArgs e) - { - //If the mainform is disposed do nothing - if (mainForm.IsDisposed) - return; - - //Invoke method if is needed or call the method in STD mode - mainForm.Close(); - } - - //Reload Broken Page - private void reloadBrokenPage(object sender, CfrV8HandlerExecuteEventArgs e) - { - //Invoke method if is needed or call the method in STD mode - mainForm.reloadBrokenPage(); - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region NC_BEHAVIOUR_METHODS - - public void setNcWindowState(object sender, CfrV8HandlerExecuteEventArgs e) - { - if (e.Arguments.Count() == 0) - return; - - NcWindow.SetState((NcState) e.Arguments[0].IntValue ); - - if (NcWindow.State == NcState.SHOW) - mainForm.ShowNCWindow(); - else - mainForm.HideNCWindow(); - } - - public void getNcWindowState(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue((int) NcWindow.State); - } - - public void getScreenBase64(object sender, CfrV8HandlerExecuteEventArgs e) - { - if (e.Arguments.Count() > 0 && e.Arguments[0].BoolValue) - NcWindow.CaptureHMI(); - e.SetReturnValue(NcWindow.NcCapture); - } - - //Send a command to HMI - public void sendHMICommand(object sender, CfrV8HandlerExecuteEventArgs e) - { - if (e.Arguments.Count() == 0) - return; - - int val = e.Arguments[0].IntValue - 1; - - if (val < 0 || val > (NcWindow.NcWindowCommand.Count - 1)) - return; - - NcWindow.SendCommandKey(NcWindow.NcWindowCommand[val]); - - if (NcWindow.State == NcState.SHOW) - { - Thread.Sleep(1000); - mainForm.HideNCWindow(); - mainForm.ShowNCWindow(); - NcWindow.ActivateNcWindow(); - } - } - - //Get command vounts to HMI - public void getHMICommandCount(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue(NcWindow.NcWindowCommand.Count); - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region CHROMIUM_METHODS - - //Get the Version of Chromium - public void getChromiumVersion(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue(CfxRuntime.GetChromeVersion()); - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region STEP_METHODS - - //Get the ID of STEP Client - public void getClientID(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue((int) Config.ConnectionConfig.Id); - } - - public void forceStepFocus(object sender, CfrV8HandlerExecuteEventArgs e) - { - NcWindow.ForceStepFocus(); - } - - //Get the option of virtual Keyb configured - private void isVirtualKeybConfigured(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue((Boolean)Config.ClientConfig.ShowVirtualKeyboard); - } - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region PROCESSES_METHODS - - //Read all configured processes - public void getConfiguredProcesses(object sender, CfrV8HandlerExecuteEventArgs e) - { - e.SetReturnValue(JsonConvert.SerializeObject(Config.ExtSoftwaresConfig)); - } - - - - //Start a new process - public void startNewProcess(object sender, CfrV8HandlerExecuteEventArgs e) - { - if (e.Arguments.Count() == 0) - return; - - Thread t = new Thread(new ParameterizedThreadStart(OpenNew)); - t.Start(e.Arguments[0].StringValue); - } - - - - //Open the last window or Start a new process - public void openOrStartProcess(object sender, CfrV8HandlerExecuteEventArgs e) - { - if (e.Arguments.Count() == 0) - return; - - Thread t = new Thread(new ParameterizedThreadStart(OpenStartNew)); - t.Start(e.Arguments[0].StringValue); - } - - - //Function used in Thread - private void OpenStartNew(object id) - { - Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.id == (string)id); - - if (sft != null) - { - Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(sft.path)).OrderByDescending(X => X.StartTime).ToArray(); - - if (p.Count() > 0 && p[0].MainWindowHandle != IntPtr.Zero) - NcWindow.ForceExtFocus(p[0].MainWindowHandle); - else - Process.Start(sft.path, sft.arguments); - } - } - - - //Function used in Thread - private void OpenNew(object id) - { - Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.id == (string)id); - if (sft != null) - Process.Start(sft.path, sft.arguments); - } - #endregion - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region FILESYSTEM_METHODS - - //Read all drives in Operating System - public void getOSdriveList(object sender, CfrV8HandlerExecuteEventArgs e) - { - List drivelist = new List(); - - foreach (var drive in DriveInfo.GetDrives()) - { - if(drive.IsReady) - drivelist.Add(new Drive() { - Name = ElaborateName(drive.VolumeLabel, drive.DriveType), - Path = drive.RootDirectory.ToString(), - Type = ElaborateType(drive.DriveType) - }); - } - - drivelist.Add(new Drive() - { - Name = ElaborateName("Desktop", DriveType.Unknown), - Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"\\", - Type = "SPFO" - }); - e.SetReturnValue(JsonConvert.SerializeObject(drivelist)); - } - - - //Read all files in directory - public void getFileList(object sender, CfrV8HandlerExecuteEventArgs e) - { - List filelist = new List(); - if (e.Arguments.Count() == 0) - { - e.SetReturnValue(JsonConvert.SerializeObject(new List())); - return; - } - - String p = e.Arguments[0].StringValue; - if (!Directory.Exists(p)) - { - e.SetReturnValue(JsonConvert.SerializeObject(new List())); - return; - } - - try - { - foreach (String item in Directory.GetDirectories(p)) - { - - filelist.Add(new Models.File - { - Name = Path.GetFileName(item), - AbsolutePath = Path.GetFullPath(item), - IsDirectory = true - }); - - } - } - catch (Exception ex) - { - } - try - { - foreach (String item in Directory.GetFiles(p)) - { - if (_validExtensions.Contains(Path.GetExtension(item).ToLower())) - filelist.Add(new Models.File - { - Name = Path.GetFileName(item), - AbsolutePath = Path.GetFullPath(item), - IsDirectory = false - }); - - } - } - catch (Exception ex) - { - } - - e.SetReturnValue(JsonConvert.SerializeObject(filelist)); - } - - - //Read info of a file - public void getProgramInfo(object sender, CfrV8HandlerExecuteEventArgs e) - { - InfoFile file = new InfoFile(); - string line,imagePath,imageDirectory; - int counter = 0; - - if (e.Arguments.Count() == 0) - { - e.SetReturnValue(JsonConvert.SerializeObject(new InfoFile())); - return; - } - - String p = e.Arguments[0].StringValue; - if (!System.IO.File.Exists(p)) - { - e.SetReturnValue(JsonConvert.SerializeObject(new InfoFile())); - return; - } - - FileInfo f = new FileInfo(p); - file.Name = f.Name; - file.CreationDate = f.CreationTime; - file.LastModDate = f.LastAccessTime; - imagePath = Path.GetFileNameWithoutExtension(p); - imageDirectory = Path.GetDirectoryName(p); - - file.Content = new List(); - try - { - - StreamReader fileRead = new StreamReader(p); - while ((line = fileRead.ReadLine()) != null && counter<10) - { - file.Content.Add(line); - counter++; - } - fileRead.Close(); - - foreach(string ext in _validImages) - { - if (System.IO.File.Exists(imageDirectory + "/" + imagePath + ext)) - { - file.PreviewBase64 = "data:image/"+ext+";base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(imageDirectory + "/" + imagePath + ext)); - break; - } - } - - } - catch(Exception ex) - { - } - - e.SetReturnValue(JsonConvert.SerializeObject(file)); - } - - - //Private functions... - private String ElaborateName(String name,DriveType type) - { - if (!String.IsNullOrWhiteSpace(name)) - return name; - else - { - switch (type) - { - case DriveType.Fixed: return "Hard_Disk"; - case DriveType.Removable: return "Usb_Disk"; - case DriveType.Network: return "Netword_Disk"; - } - return "Undefined Drive"; - } - - } - - private String ElaborateType(DriveType type) - { - switch (type) - { - case DriveType.Fixed: return "HD"; - case DriveType.Removable: return "USB"; - case DriveType.Network: return "NTW"; - } - return "SPFO"; - - } - - #endregion } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region FORM_BEHAVIOUR_METHODS + + //Minimize Main Window + public void minimizeForm(object sender, CfrV8HandlerExecuteEventArgs e) + { + //Invoke method if is needed or call the method in STD mode + if (mainForm.InvokeRequired) + mainForm.Invoke((MethodInvoker)delegate () + { + mainForm.WindowState = FormWindowState.Minimized; + }); + + else + { + mainForm.WindowState = FormWindowState.Minimized; + } + } + + + + //Maximize Main Window + public void maximizeForm(object sender, CfrV8HandlerExecuteEventArgs e) + { + //Invoke method if is needed or call the method in STD mode + if (mainForm.InvokeRequired) + mainForm.Invoke((MethodInvoker)delegate () + { + mainForm.WindowState = FormWindowState.Maximized; + }); + + else + { + mainForm.WindowState = FormWindowState.Maximized; + } + } + + + + //Close Main Window + public void closeForm(object sender, CfrV8HandlerExecuteEventArgs e) + { + //If the mainform is disposed do nothing + if (mainForm.IsDisposed) + return; + + //Invoke method if is needed or call the method in STD mode + mainForm.Close(); + } + + //Reload Broken Page + private void reloadBrokenPage(object sender, CfrV8HandlerExecuteEventArgs e) + { + //Invoke method if is needed or call the method in STD mode + mainForm.reloadBrokenPage(); + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region NC_BEHAVIOUR_METHODS + + public void setNcWindowState(object sender, CfrV8HandlerExecuteEventArgs e) + { + if (e.Arguments.Count() == 0) + return; + + NcWindow.SetState((NcState)e.Arguments[0].IntValue); + + if (NcWindow.State == NcState.SHOW) + mainForm.ShowNCWindow(); + else + mainForm.HideNCWindow(); + } + + public void getNcWindowState(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue((int)NcWindow.State); + } + + public void getScreenBase64(object sender, CfrV8HandlerExecuteEventArgs e) + { + if (e.Arguments.Count() > 0 && e.Arguments[0].BoolValue) + NcWindow.CaptureHMI(); + e.SetReturnValue(NcWindow.NcCapture); + } + + //Send a command to HMI + public void sendHMICommand(object sender, CfrV8HandlerExecuteEventArgs e) + { + if (e.Arguments.Count() == 0) + return; + + int val = e.Arguments[0].IntValue - 1; + + if (val < 0 || val > (NcWindow.NcWindowCommand.Count - 1)) + return; + + NcWindow.SendCommandKey(NcWindow.NcWindowCommand[val]); + + if (NcWindow.State == NcState.SHOW) + { + Thread.Sleep(1000); + mainForm.HideNCWindow(); + mainForm.ShowNCWindow(); + NcWindow.ActivateNcWindow(); + } + } + + //Get command vounts to HMI + public void getHMICommandCount(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue(NcWindow.NcWindowCommand.Count); + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region CHROMIUM_METHODS + + //Get the Version of Chromium + public void getChromiumVersion(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue(CfxRuntime.GetChromeVersion()); + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region STEP_METHODS + + //Get the ID of STEP Client + public void getClientID(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue((int)Config.ConnectionConfig.Id); + } + + public void forceStepFocus(object sender, CfrV8HandlerExecuteEventArgs e) + { + NcWindow.ForceStepFocus(); + } + + //Get the option of virtual Keyb configured + private void isVirtualKeybConfigured(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue((Boolean)Config.ClientConfig.ShowVirtualKeyboard); + } + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region PROCESSES_METHODS + + //Read all configured processes + public void getConfiguredProcesses(object sender, CfrV8HandlerExecuteEventArgs e) + { + e.SetReturnValue(JsonConvert.SerializeObject(Config.ExtSoftwaresConfig)); + } + + + + //Start a new process + public void startNewProcess(object sender, CfrV8HandlerExecuteEventArgs e) + { + if (e.Arguments.Count() == 0) + return; + + Thread t = new Thread(new ParameterizedThreadStart(OpenNew)); + t.Start(e.Arguments[0].StringValue); + } + + + + //Open the last window or Start a new process + public void openOrStartProcess(object sender, CfrV8HandlerExecuteEventArgs e) + { + if (e.Arguments.Count() == 0) + return; + + Thread t = new Thread(new ParameterizedThreadStart(OpenStartNew)); + t.Start(e.Arguments[0].StringValue); + } + + + //Function used in Thread + private void OpenStartNew(object id) + { + Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.id == (string)id); + + if (sft != null) + { + Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(sft.path)).OrderByDescending(X => X.StartTime).ToArray(); + + if (p.Count() > 0 && p[0].MainWindowHandle != IntPtr.Zero) + NcWindow.ForceExtFocus(p[0].MainWindowHandle); + else + Process.Start(sft.path, sft.arguments); + } + } + + + //Function used in Thread + private void OpenNew(object id) + { + Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.id == (string)id); + if (sft != null) + Process.Start(sft.path, sft.arguments); + } + #endregion + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region FILESYSTEM_METHODS + + //Read all drives in Operating System + public void getOSdriveList(object sender, CfrV8HandlerExecuteEventArgs e) + { + List drivelist = new List(); + + foreach (var drive in DriveInfo.GetDrives()) + { + if (drive.IsReady) + drivelist.Add(new Drive() + { + Name = ElaborateName(drive.VolumeLabel, drive.DriveType), + Path = drive.RootDirectory.ToString(), + Type = ElaborateType(drive.DriveType) + }); + } + + drivelist.Add(new Drive() + { + Name = ElaborateName("Desktop", DriveType.Unknown), + Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\", + Type = "SPFO" + }); + e.SetReturnValue(JsonConvert.SerializeObject(drivelist)); + } + + + //Read all files in directory + public void getFileList(object sender, CfrV8HandlerExecuteEventArgs e) + { + List filelist = new List(); + if (e.Arguments.Count() == 0) + { + e.SetReturnValue(JsonConvert.SerializeObject(new List())); + return; + } + + String p = e.Arguments[0].StringValue; + if (!Directory.Exists(p)) + { + e.SetReturnValue(JsonConvert.SerializeObject(new List())); + return; + } + + try + { + foreach (String item in Directory.GetDirectories(p)) + { + + filelist.Add(new Models.File + { + Name = Path.GetFileName(item), + AbsolutePath = Path.GetFullPath(item), + IsDirectory = true + }); + + } + } + catch (Exception ex) + { + } + try + { + foreach (String item in Directory.GetFiles(p)) + { + if (_validExtensions.Contains(Path.GetExtension(item).ToLower())) + filelist.Add(new Models.File + { + Name = Path.GetFileName(item), + AbsolutePath = Path.GetFullPath(item), + IsDirectory = false + }); + + } + } + catch (Exception ex) + { + } + + e.SetReturnValue(JsonConvert.SerializeObject(filelist)); + } + + public void uploadProgram(object sender, CfrV8HandlerExecuteEventArgs e) + { + var fileToUpload = JsonConvert.DeserializeObject(e.Arguments[0].StringValue); + } + + public void activateProgram(object sender, CfrV8HandlerExecuteEventArgs e) + { + var fileToUpload = JsonConvert.DeserializeObject(e.Arguments[0].StringValue); + } + + //Read info of a file + public void getProgramInfo(object sender, CfrV8HandlerExecuteEventArgs e) + { + InfoFile file = new InfoFile(); + string line, imagePath, imageDirectory; + int counter = 0; + + if (e.Arguments.Count() == 0) + { + e.SetReturnValue(JsonConvert.SerializeObject(new InfoFile())); + return; + } + + String p = e.Arguments[0].StringValue; + if (!System.IO.File.Exists(p)) + { + e.SetReturnValue(JsonConvert.SerializeObject(new InfoFile())); + return; + } + + FileInfo f = new FileInfo(p); + file.Name = f.Name; + file.CreationDate = f.CreationTime; + file.LastModDate = f.LastAccessTime; + imagePath = Path.GetFileNameWithoutExtension(p); + imageDirectory = Path.GetDirectoryName(p); + + file.Content = new List(); + try + { + + StreamReader fileRead = new StreamReader(p); + while ((line = fileRead.ReadLine()) != null && counter < 10) + { + file.Content.Add(line); + counter++; + } + fileRead.Close(); + + foreach (string ext in _validImages) + { + if (System.IO.File.Exists(imageDirectory + "/" + imagePath + ext)) + { + file.PreviewBase64 = "data:image/" + ext + ";base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(imageDirectory + "/" + imagePath + ext)); + break; + } + } + + } + catch (Exception ex) + { + } + + e.SetReturnValue(JsonConvert.SerializeObject(file)); + } + + + //Private functions... + private String ElaborateName(String name, DriveType type) + { + if (!String.IsNullOrWhiteSpace(name)) + return name; + else + { + switch (type) + { + case DriveType.Fixed: return "Hard_Disk"; + case DriveType.Removable: return "Usb_Disk"; + case DriveType.Network: return "Netword_Disk"; + } + return "Undefined Drive"; + } + + } + + private String ElaborateType(DriveType type) + { + switch (type) + { + case DriveType.Fixed: return "HD"; + case DriveType.Removable: return "USB"; + case DriveType.Network: return "NTW"; + } + return "SPFO"; + + } + + #endregion + } } diff --git a/Step/wwwroot/src/modules/base-components/modal-load-program.ts b/Step/wwwroot/src/modules/base-components/modal-load-program.ts index 2c218d76..17c2244d 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.ts +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.ts @@ -185,4 +185,17 @@ export default class ModalLoadProgram extends Vue { getDate(date) { return moment(date).format("L"); } + + async loadProgram(path: string) { + if (this.isLocalNavigation && typeof cmsClient != "undefined") { + await cmsClient.uploadProgram(path); + await cmsClient.activateProgram(path); + this.close(); + } + + if (!this.isLocalNavigation) { + await fileService.activateProgram(path); + this.close(); + } + } } diff --git a/Step/wwwroot/src/modules/base-components/modal-load-program.vue b/Step/wwwroot/src/modules/base-components/modal-load-program.vue index cc61fdaf..460b60fc 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.vue +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.vue @@ -99,7 +99,9 @@ diff --git a/Step/wwwroot/src/services/fileService.ts b/Step/wwwroot/src/services/fileService.ts index fd7d8703..1ab32376 100644 --- a/Step/wwwroot/src/services/fileService.ts +++ b/Step/wwwroot/src/services/fileService.ts @@ -4,11 +4,19 @@ export class FileService extends baseRestService { BASE_URL = "api/file_manager/"; async getFiles(path: string): Promise> { - return await this.Get(this.BASE_URL + "files", true, { filePath: path }); + return await this.Get(this.BASE_URL + "files", true, { + filePath: path + }); } - async getFileInfo(path: string){ - return await this.Get(this.BASE_URL + "file/info", true, { filePath: path }); + async getFileInfo(path: string) { + return await this.Get(this.BASE_URL + "file/info", true, { + filePath: path + }); + } + + async activateProgram(path: string) { + return await this.Put(this.BASE_URL + "file/info?filePath=" + path, null); } }