Lauch client on CNC Connected

This commit is contained in:
Nicola Carminati
2019-04-17 11:17:20 +02:00
parent e496502dd4
commit 22d5da7790
3 changed files with 46 additions and 8 deletions
+45 -3
View File
@@ -7,10 +7,12 @@ using Step.Model.DTOModels.AlarmModels;
using Step.Model.DTOModels.Scada;
using Step.Model.DTOModels.ToolModels;
using Step.NC;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using TeamDev.SDK.MVVM;
using static CMS_CORE_Library.Models.DataStructures;
@@ -967,11 +969,14 @@ public static class ThreadsFunctions
else if (cmsError.errorCode != CMS_ERROR_CODES.OK)
ncHandler.Dispose();
Thread.Sleep(1000);
// Send status to UI
MessageServices.Current.Publish(SEND_NC_STATUS, null, ncHandler.numericalControl.NC_IsConnected());
}
Thread.Sleep(1000);
}
if (ServerConfig.ServerStartupConfig.AutoOpenCmsClient)
StartCMSClient(null);
NcToolTableHandler toolTable = new NcToolTableHandler();
// After reconecction write option
@@ -1141,6 +1146,43 @@ public static class ThreadsFunctions
return sleep;
}
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);
}
}
private static bool ClientIsRunning()
{
Process[] p = Process.GetProcessesByName(CLIENT_EXE_NAME_NOEXT);
foreach (Process pr in p)
{
if (pr.MainWindowHandle != IntPtr.Zero)
{
ShowWindow(pr.MainWindowHandle, 9);
SetForegroundWindow(pr.MainWindowHandle);
return true;
}
}
return false;
}
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
#endregion SupportFunctions
}