using CefSharp; using Client.Config; using Client.Config.SubModels; using CMS_Client.View; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CMS_Client.Browser_Tools { public class BrowserJSObject { //The first letter of All PUBLIC Variables and Methods must be Lower-Case (CEF Settings) private MainForm mainForm; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTOR_METHOD //Constructor Method public BrowserJSObject(MainForm f) { mainForm = f; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region FORM_BEHAVIOUR_METHODS //Minimize Main Window public void minimizeForm() { //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() { //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() { //If the mainform is disposed do nothing if (mainForm.IsDisposed) return; //Invoke method if is needed or call the method in STD mode if (mainForm.InvokeRequired) mainForm.Invoke((MethodInvoker)delegate () { mainForm.Close(); }); else { mainForm.Close(); } } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region NC_BEHAVIOUR_METHODS //Move NC Window public void moveNcWindow(int X,int Y) { if (Config.VendorHmiConfig.Enabled) NcWindow.MoveNcWindow(X, Y); } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region CHROMIUM_METHODS //Get the Version of Chromium public String getChromiumVersion() { return Cef.ChromiumVersion; } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region STEP_METHODS //Get the ID of STEP Client public ushort getClientID() { return Config.ConnectionConfig.Id; } public void forceStepFocus() { Debug.WriteLine("Forced"); NcWindow.ForceStepFocus(); } #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region PROCESSES_METHODS //Read all configured processes public String getConfiguredProcesses() { return JsonConvert.SerializeObject(Config.ExtSoftwaresConfig); } //Start a new process public void startNewProcess(String id) { Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.Id == id); if(sft != null) { Process.Start(sft.Path, sft.Arguments); } } //Open the last window or Start a new process public void openOrStartProcess(String id) { Software sft = Config.ExtSoftwaresConfig.FirstOrDefault(X => X.Id == 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); } } #endregion } }