diff --git a/Client/View/MainForm.Designer.cs b/Client/View/MainForm.Designer.cs index 7420d1ab..7e9932b6 100644 --- a/Client/View/MainForm.Designer.cs +++ b/Client/View/MainForm.Designer.cs @@ -44,6 +44,7 @@ namespace Active_Client.View this.Browser.Size = new System.Drawing.Size(1920, 1080); this.Browser.TabIndex = 1; this.Browser.Text = "chromiumWebBrowser2"; + this.Browser.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Browser_KeyDown); // // MainForm // @@ -55,6 +56,7 @@ namespace Active_Client.View this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.KeyPreview = true; this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(1920, 1080); this.MinimizeBox = false; @@ -65,6 +67,7 @@ namespace Active_Client.View this.Text = "CMS-STEP Client"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.MainForm_Load); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); this.Resize += new System.EventHandler(this.MainForm_Resize); this.ResumeLayout(false); diff --git a/Client/View/MainForm.cs b/Client/View/MainForm.cs index 1b4f8fa0..5b599713 100644 --- a/Client/View/MainForm.cs +++ b/Client/View/MainForm.cs @@ -184,7 +184,6 @@ namespace Active_Client.View private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - } #endregion @@ -768,6 +767,19 @@ namespace Active_Client.View } } + private void MainForm_KeyDown(object sender, KeyEventArgs e) + { + if (e.Alt && e.KeyCode == Keys.F4) + { + e.Handled = true; + } + } + + private void Browser_KeyDown(object sender, KeyEventArgs e) + { + + } + //Windows Keys Handler public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key) diff --git a/Client/View/NcWindow.cs b/Client/View/NcWindow.cs index 0c928869..168f9db4 100644 --- a/Client/View/NcWindow.cs +++ b/Client/View/NcWindow.cs @@ -1025,7 +1025,6 @@ namespace Active_Client.View //if it has the border and a title execute focus if (ActiveNCWindowStyle != 0 && ActiveNCWindowBorder == WS_BORDER && ReadWindowTitle(hwnd) != "" && hwnd != ncprocess.MainWindowHandle) { - SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); } } diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index 4583c07a..074ed7a1 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -978,8 +978,6 @@ public static class ThreadsFunctions Thread.Sleep(1000); } - if (ServerStartupConfig.AutoOpenCmsClient) - StartCMSClient(null); if(NcConfig.NcVendor == NC_VENDOR.FANUC || NcConfig.NcVendor == NC_VENDOR.OSAI) @@ -994,11 +992,15 @@ public static class ThreadsFunctions // cmsError = toolTable.RestoreTableLock(); } } - - // Start/Restart NC threads - ThreadsHandler.StartWorkers(); + if (!cmsError.IsError()) + { + if (ServerStartupConfig.AutoOpenCmsClient) + StartCMSClient(); - reconnectionIsRunning = false; + // Start/Restart NC threads + ThreadsHandler.StartWorkers(); + reconnectionIsRunning = false; + } } public static void RestoreConnection() @@ -1163,22 +1165,38 @@ public static class ThreadsFunctions return sleep; } - public static void StartCMSClient(string url) + public static void StartCMSClient() { //Setup the Path Variable - string CMSClientPath = ""; if (!ClientIsRunning()) { - // Check if the system is 64/32 bit - if (Environment.Is64BitOperatingSystem && File.Exists(CLIENT_PATH_64)) - CMSClientPath = CLIENT_PATH_64; - else if (File.Exists(CLIENT_PATH_86)) - CMSClientPath = CLIENT_PATH_86; - if (!String.IsNullOrEmpty(CMSClientPath)) - Process.Start(CMSClientPath, url); + ThreadsHandler.StartClient = new Thread(() => clientProcess()); + ThreadsHandler.StartClient.Start(); } } + + private static void clientProcess() + { + string CMSClientPath = ""; + // Check if the system is 64/32 bit + if (Environment.Is64BitOperatingSystem && File.Exists(CLIENT_PATH_64)) + CMSClientPath = CLIENT_PATH_64; + else if (File.Exists(CLIENT_PATH_86)) + CMSClientPath = CLIENT_PATH_86; + + if (!String.IsNullOrEmpty(CMSClientPath)) + { + Process pr = Process.Start(CMSClientPath, null); + + if (ServerStartupConfig.AutoOpenCmsClient) + { + pr.WaitForExit(); + MessageServices.Current.Publish(SEND_STOP_SERVER); + } + } + } + private static bool ClientIsRunning() { Process[] p = Process.GetProcessesByName(CLIENT_EXE_NAME_NOEXT); diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs index a94a7824..98b01429 100644 --- a/Step.Core/ThreadsHandler.cs +++ b/Step.Core/ThreadsHandler.cs @@ -31,6 +31,8 @@ namespace Step.Core }; private volatile static List RunningThreadsList = new List(); + public static Thread StartClient; + internal volatile static Dictionary RunningThreadStatus = new Dictionary(); public static void Start() @@ -89,10 +91,18 @@ namespace Step.Core RunningThreadsList.ForEach(thread => { thread.Abort(); - }); + }); + + if(ThreadsHandler.StartClient != null) + ThreadsHandler.StartClient.Abort(); //Abort Connect Thread ThreadsFunctions.AbortNcConnection(); } + + public static void StartClientFromUI() + { + ThreadsFunctions.StartCMSClient(); + } } } \ No newline at end of file diff --git a/Step.UI/ServerControlWindow.cs b/Step.UI/ServerControlWindow.cs index b27ebacb..967924f1 100644 --- a/Step.UI/ServerControlWindow.cs +++ b/Step.UI/ServerControlWindow.cs @@ -1,4 +1,5 @@ -using Step.Model; +using Step.Core; +using Step.Model; using Step.Model.DTOModels; using Step.NC; using System; @@ -132,7 +133,7 @@ namespace Step.UI private void OpenUiButton_Click(object sender, EventArgs e) { //Open CMS Client - StartCMSClient(null); + ThreadsHandler.StartClientFromUI(); } private void StopServerButton_Click(object sender, EventArgs e) @@ -158,25 +159,6 @@ namespace Step.UI MessageServices.Current.Publish(SEND_STOP_SERVER); } - public static void StartCMSClient(string url) - { - //Setup the Path Variable - string CMSClientPath = ""; - if (!ClientIsRunning()) - { - // Check if the system is 64/32 bit - if (Environment.Is64BitOperatingSystem && File.Exists(CLIENT_PATH_64)) - CMSClientPath = CLIENT_PATH_64; - else if (File.Exists(CLIENT_PATH_86)) - CMSClientPath = CLIENT_PATH_86; - - if (!String.IsNullOrEmpty(CMSClientPath)) - Process.Start(CMSClientPath, url); - else - MessageBox.Show("CMS-Active Client not found"); - } - } - private void InitializeMessageListeners() { MVVMListeners = new List @@ -210,11 +192,12 @@ namespace Step.UI StepNotifyIcon.ShowBalloonTip(1000, message.Title, message.Message, (ToolTipIcon.Error)); //ShowMessage on UI - TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + message.Message; + TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + message.Message; + + // Notify user + if(MessageBox.Show(new Form { TopMost = true }, message.Message, message.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) + MessageServices.Current.Publish(SEND_STOP_SERVER); }); - // Notify user - if(MessageBox.Show(message.Message, message.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) - MessageServices.Current.Publish(SEND_STOP_SERVER); } }), // NC status handler diff --git a/Step.UI/Step.UI.csproj b/Step.UI/Step.UI.csproj index 8eeb14cb..537c3132 100644 --- a/Step.UI/Step.UI.csproj +++ b/Step.UI/Step.UI.csproj @@ -134,6 +134,10 @@ {3f5c2483-fc87-43ef-92a8-66ff7d0e440f} Step.Config + + {de54ff4c-8390-4489-882a-1bc7d99ef185} + Step.Core + {631375DD-06D3-49BB-8130-D9DDB34C429D} Step.Model diff --git a/Step.Utils/ExceptionManager.cs b/Step.Utils/ExceptionManager.cs index 0c4b8ff1..5cc07841 100644 --- a/Step.Utils/ExceptionManager.cs +++ b/Step.Utils/ExceptionManager.cs @@ -107,7 +107,7 @@ namespace Step.Utils { if (beforeFormReady) { - MessageBox.Show(error.Message, error.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(new Form { TopMost = true }, error.Message, error.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { @@ -121,13 +121,13 @@ namespace Step.Utils { // Notify user MessageServices.Current.Publish(SEND_STOP_THREADS); - MessageBox.Show(error.Message, error.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(new Form { TopMost = true }, error.Message, error.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageServices.Current.Publish(SEND_STOP_SERVER); } else { // Notify user - MessageServices.Current.Publish(SEND_STOP_THREADS); + //MessageServices.Current.Publish(SEND_STOP_THREADS); MessageServices.Current.Publish(SEND_MESSAGE, null, error); } } diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs index b8d2532d..41ffaeeb 100644 --- a/Step/Controllers/SignalR/NcHub.cs +++ b/Step/Controllers/SignalR/NcHub.cs @@ -235,11 +235,6 @@ namespace Step.Controllers.SignalR throw new HubException(cmsError.localizationKey); } } - - public void QuitServerApp() - { - if (ServerStartupConfig.AutoOpenCmsClient) - MessageServices.Current.Publish(SEND_STOP_SERVER); - } + } } \ No newline at end of file diff --git a/Step/program.cs b/Step/program.cs index 2efb28aa..ed0b01ec 100644 --- a/Step/program.cs +++ b/Step/program.cs @@ -3,6 +3,7 @@ using Step.Config; using Step.Core; using Step.Database; using Step.Listeners; +using Step.Model; using Step.NC; using Step.UI; using Step.Utils; @@ -43,8 +44,9 @@ namespace Step ServerConfigController.ReadStartupConfig(); // Start WinForm - ServerControlWindow.Start(); - + ServerControlWindow.Start(); + + DatabaseContext.SetUpDbConnectionAndDbConfig(); // Register listener to "close application" messages diff --git a/Step/wwwroot/src/app.business-logic.ts b/Step/wwwroot/src/app.business-logic.ts index b0e21b2b..7a6002c8 100644 --- a/Step/wwwroot/src/app.business-logic.ts +++ b/Step/wwwroot/src/app.business-logic.ts @@ -127,7 +127,6 @@ if (typeof cmsClient != "undefined") { Vue.filter('localize')("modal_confirm_close_application", "Sei sicuro di voler chiudere l'applicazione?"), () => { messageService.publishToChannel("close-scada"); - Hub.Current.QuitServerApp(); cmsClient.closeForm(); },null ,'modal'); } diff --git a/Step/wwwroot/src/services/hub.ts b/Step/wwwroot/src/services/hub.ts index 06e67093..bf7fae17 100644 --- a/Step/wwwroot/src/services/hub.ts +++ b/Step/wwwroot/src/services/hub.ts @@ -128,7 +128,7 @@ export class Hub { private static activeProgramData(data) { var oldPath = (store.state as AppModel).process.currentProgram; - + if (data.path && (!oldPath || data.path != oldPath.path)) { fileService.getActiveFileInfo(data.path).then(r => { processModelActions.setCurrentProgramImage(store, r.image); @@ -194,7 +194,7 @@ export class Hub { processModelActions.setProcessMessage(store, data.processMessage) processModelActions.setCurrentOrigin(store, data.activeOrigin); processModelActions.setCanLoadProgram(store, data.canLoadProgram); - processModelActions.setUnitMeasure(store, data.unitMeasure); + processModelActions.setUnitMeasure(store, data.unitMeasure); processModelActions.isRunning(store, data.isRunning); processModelActions.selectProcess(store, data.selectedProcess); processModelActions.selectAxis(store, data.selectedAxis); @@ -276,7 +276,7 @@ export class Hub { Factory.Get(MessageService).publishToChannel("force-ui-update", null); } if (status == "connected" && Hub._serverConnectionNotificationVisible) { - + var toast = document.querySelector('#serverConnection') as any; (iziToast as any).hide(toast); Hub._serverConnectionNotificationVisible = false; @@ -408,9 +408,9 @@ export class Hub { public ncSoftKeyClick(id: number) { this._hub.server.ncSoftKeyClick(id); - - if(typeof cmsClient != "undefined"){ - if(cmsClient.getNcWindowState() == 1) + + if (typeof cmsClient != "undefined") { + if (cmsClient.getNcWindowState() == 1) cmsClient.forceNcFocus(); } } @@ -431,10 +431,6 @@ export class Hub { this._hub.server.selectAxis(id); } - public QuitServerApp() { - try { this._hub.server.quitServerApp(); } catch (err) { } - } - public Hello() { this._hub.server.hello(); }