diff --git a/Client/View/MainForm.cs b/Client/View/MainForm.cs index 17c668b2..92cef780 100644 --- a/Client/View/MainForm.cs +++ b/Client/View/MainForm.cs @@ -1,661 +1,664 @@ -using Client.Config; -using Client.Utils; -using System; -using System.Drawing; -using System.Linq; -using System.Windows.Forms; -using Chromium; -using Chromium.WebBrowser; -using Chromium.Event; -using Chromium.WebBrowser.Event; -using System.Diagnostics; -using CMS_Client.Browser_Tools; -using Chromium.Remote; -using Chromium.Remote.Event; -using System.IO; +using Chromium; +using Chromium.Event; +using Chromium.Remote.Event; +using Chromium.WebBrowser; +using Client.Config; +using Client.Utils; +using CMS_Client.Browser_Tools; +using System; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; using static Client.Utils.Constants; -namespace CMS_Client.View +namespace CMS_Client.View { - public partial class MainForm : Form - { - //Struct of PageError - private struct PageError + public partial class MainForm : Form { - public Boolean Error; - public String ErrorInfo; - } - Random rnd = new Random(); + //Struct of PageError + private struct PageError + { + public bool Error; + public string ErrorInfo; + } + Random rnd = new Random(); - //Internal Variables - private PageError LoadingError; - private NcForm NcFrm; - private LoadingForm LdFrm; - private static IntPtr MainHandle; - private static IntPtr NcHandle; - private int X = 0, Y = 0; - private string BrokenUrl; + //Internal Variables + private PageError LoadingError; + private NcForm NcFrm; + private LoadingForm LdFrm; + private static IntPtr MainHandle; + private static IntPtr NcHandle; + private int X = 0, Y = 0; + private string BrokenUrl; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region WINDOW_START_&_BEHAVIOUR_METHOD - //Instance Method - public MainForm() - { - LdFrm = new LoadingForm(); - LdFrm.Owner = this; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region WINDOW_START_&_BEHAVIOUR_METHOD + //Instance Method + public MainForm() + { + LdFrm = new LoadingForm(); + LdFrm.Owner = this; - //Set the Loading window - ShowLoading("Setup Main View..."); + //Set the Loading window + ShowLoading("Setup Main View..."); - //Initialize the Windows - InitializeComponent(); + //Initialize the Windows + InitializeComponent(); - //Start Client Setting - InitializeClientSettings(); + //Start Client Setting + InitializeClientSettings(); - //Initialize the Browser-Components - InitializeBrowser(); + //Initialize the Browser-Components + InitializeBrowser(); - //Set the client property - this.Text = Application.ProductName + " " + Application.ProductVersion; - this.Opacity = 0.0; + //Set the client property + Text = Application.ProductName + " " + Application.ProductVersion; + Opacity = 0.0; - //Initialize the Nc-Form - InitializeNcForm(); + //Initialize the Nc-Form + InitializeNcForm(); - //Load the page - Browser.LoadUrl(Config.ConnectionConfig.StartingUrl); - //Set the title of the window in "Loading" - SetWindowTitle("Loading..."); - ShowLoading("Loading Main View..."); + //Load the page + Browser.LoadUrl(Config.ConnectionConfig.StartingUrl); + //Set the title of the window in "Loading" + SetWindowTitle("Loading..."); + ShowLoading("Loading Main View..."); - NcWindow.mainFrm = this; - } + NcWindow.mainFrm = this; + } #if DEBUG - private void ChooseBestScreen() - { - var candidate = Screen.PrimaryScreen; - foreach (var s in Screen.AllScreens) - { - if (s.WorkingArea.Width == 1920) candidate = s; - } + private void ChooseBestScreen() + { + var candidate = Screen.PrimaryScreen; + // If primary screen is not full HD find another screen + if(candidate.WorkingArea.Width != 1920) + { + foreach (var s in Screen.AllScreens) + { + if (s.WorkingArea.Width == 1920) candidate = s; + } + + if (candidate != Screen.PrimaryScreen) + { + WindowState = FormWindowState.Normal; + X = Left = candidate.WorkingArea.Left; + Y = Top = candidate.WorkingArea.Top; + Width = candidate.WorkingArea.Width; + Height = candidate.WorkingArea.Height; + WindowState = FormWindowState.Maximized; + } + } + } - if (candidate != Screen.PrimaryScreen) - { - this.WindowState = FormWindowState.Normal; - this.X = this.Left = candidate.WorkingArea.Left; - this.Y = this.Top = candidate.WorkingArea.Top; - this.Width = candidate.WorkingArea.Width; - this.Height = candidate.WorkingArea.Height; - this.WindowState = FormWindowState.Maximized; - } - } #endif - //On windows-Load Method - private void MainForm_Load(object sender, EventArgs e) - { - this.DesktopLocation = new Point(X, Y); + //On windows-Load Method + private void MainForm_Load(object sender, EventArgs e) + { + DesktopLocation = new Point(X, Y); #if DEBUG - ChooseBestScreen(); + ChooseBestScreen(); #endif - } - - - - //On Resize Form - private void MainForm_Resize(object sender, EventArgs e) - { - if (this.WindowState == FormWindowState.Minimized) - { - NcWindow.ShowTaskBar(); - if (Config.VendorHmiConfig.Enabled) - NcFrm.Hide(); - } - else - { - if (Config.VendorHmiConfig.Enabled) - NcFrm.Show(); - - if (NcWindow.State == NcState.SHOW) - { - HideNCWindow(); - ShowNCWindow(); - } - else - HideNCWindow(); - } - - //Refresh Browser Paint - Browser.Refresh(); - this.Refresh(); - } - - - - //Before closing the Window -> Remove the Browser (Increase the speed of closing window) - private void MainForm_FormClosing(object sender, FormClosingEventArgs e) - { - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - //Show Taskbar - NcWindow.ShowTaskBar(); - - //Hide Window - this.Hide(); - - //Close Virtual Keyboard Runtime - if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) - NcWindow.closeVirtualKeyboard(); - - //Close the NC HMI && Stop Following Nc - if (Config.VendorHmiConfig.Enabled) - NcWindow.CloseNcWindow(false); - - - //Close Chromium Runtime - try - { - CfxRuntime.Shutdown(); - } - catch (Exception ex) - { - - } - } - - - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region SETUP_METHODS - - //Initialize CMS-Client Settings - private void InitializeClientSettings() - { - //Set the Transparency Key - if (Config.ClientConfig.RenderingMethod == Constants.Rendering.CPU && Environment.OSVersion.Version.Major < 10) - TransparencyKey = Config.ClientConfig.TranspColor; - - //Calculate Window Position - CalcWindowPosition(); - } - - - - //Initialize CMS-Client Settings - private void InitializeNcForm() - { - //Create the Nc-Form - if (Config.VendorHmiConfig.Enabled) - { - NcFrm = new NcForm(Config.ClientConfig.TranspColor, X, Y); - NcHandle = NcFrm.Handle; - NcFrm.Show(); - } - - //Steup the Step variables - MainHandle = this.Handle; - } - - - - //Initialize the Browser-Component - private void InitializeBrowser() - { - //Add Custom object to browser - Browser.GlobalObject.Add(Constants.BROWSER_JS_OBJ_NAME, new BrowserJSObject(this)); - - //Add all Handlers - Browser.DisplayHandler.OnTitleChange += BrowserTitleChanged; - Browser.LoadHandler.OnLoadingStateChange += BrowserLoadsChanged; - Browser.LoadHandler.OnLoadError += BrowserLoadsError; - Browser.KeyboardHandler.OnKeyEvent += BrowserKeyPress; - Browser.ContextMenuHandler.OnBeforeContextMenu += BrowserContextMenu; - Browser.DisplayHandler.OnConsoleMessage += BrowserConsoleMessage; - //Filter only < Win_10 Platform - if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) - ChromiumWebBrowser.RemoteProcessCreated += (e) => { e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged; }; - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region BROWSER_EVENT_HANDLERS_METHODS - - //On browser Load-Error. Event Handler called by Browser - private void BrowserLoadsError(object sender, CfxOnLoadErrorEventArgs e) - { - //Set the Load-Error global variable to TRUE - LoadingError.Error = true; - LoadingError.ErrorInfo = e.ErrorCode.GetHashCode() + " - " + e.ErrorText; - if (e.FailedUrl != Constants.errorPageUrl) - this.BrokenUrl = e.FailedUrl; - - //write the error in the Title Bar - SetWindowTitle(LoadingError.ErrorInfo); - } - - - - //On browser Load-Changed. Event Handler called by Browser - private void BrowserLoadsChanged(object sender, CfxOnLoadingStateChangeEventArgs e) - { - //if the State is NOT "loading" - if (!e.Browser.IsLoading) - { - //Hide Loading Window - HideLoadingWindow(); - - //Show the Main Window, when the page is loaded - ShowWindow(); - - //If is an Error Show the Error page - if (LoadingError.Error && !LoadingError.ErrorInfo.Contains("ERR_ABORTED")) - { - Browser.LoadString(Config.ConnectionConfig.ErrorPage, Constants.errorPageUrl); } - //Set focus on the page - BrowserFocus(); - - } - //if the State is "loading" - else - { - //Hide NC Window - NcWindow.SetState(0); - HideNCWindow(); - - //Set the title of the window in "Loading" - SetWindowTitle("Loading..."); - - //Set the Load-Error global variable to FALSE - LoadingError.Error = false; - } - } - - //On browser Title-Changed. Event Handler called by Browser - private void BrowserTitleChanged(object sender, CfxOnTitleChangeEventArgs e) - { - if (!LoadingError.Error) - SetWindowTitle(e.Title); - } - - - - // on Key-Press Browser - private void BrowserKeyPress(object sender, CfxOnKeyEventEventArgs e) - { - - } - - - - //Show Dev Tools Window - private void ShowDevTools() - { - //Setup Dev Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Dev Tools"; - windowInfo.X = 1120; - windowInfo.Y = 0; - windowInfo.Width = 800; - windowInfo.Height = 1080; - - //Show Dev Window - Browser.BrowserHost.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null); - } - - - - //Show Chrome GPU Window - private void ShowChromeGPU() - { - int w = 1600, h = 800; - - //Setup Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Graphic Tools"; - windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); - windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); - windowInfo.Width = w; - windowInfo.Height = h; - - //Show Window - CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://gpu/", ChromiumWebBrowser.DefaultBrowserSettings, null); - } - - - - //Show Chrome Version Window - private void ShowChromeVersion() - { - int w = 1600, h = 800; - - //Setup Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Chromium-Version Tools"; - windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); - windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); - windowInfo.Width = w; - windowInfo.Height = h; - - //Show Window - CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://version/", ChromiumWebBrowser.DefaultBrowserSettings, null); - } - - - - //Override default Browser Context Menu - private void BrowserContextMenu(object sender, CfxOnBeforeContextMenuEventArgs e) - { - e.Model.Clear(); - } - - - //Override Javascript Console Message - private void BrowserConsoleMessage(object sender, CfxOnConsoleMessageEventArgs e) - { - e.SetReturnValue(true); - } - - - //Node Changed Handler - private void BrowserNodeChanged(object sender, CfrOnFocusedNodeChangedEventArgs ev) - { - if (ev.Node != null) - { - String NodeName = ev.Node.ElementTagName.ToLower(); - //Filter if this node is an INPUT Node - if (NodeName != null && NodeName.Equals("input")) + //On Resize Form + private void MainForm_Resize(object sender, EventArgs e) { - String dom = ev.Node.GetElementAttribute("type").ToLower(); - - //Filter if the node Type is TEXT or PASSWORD - if (dom != null && (dom.Equals("text") || dom.Equals("password"))) - NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); - } - //Filter if this node is TEXTAREA Node - else if (NodeName != null && NodeName.Equals("textarea")) - NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); - else - NcWindow.hideVirtualKeyboard(); - } - else - NcWindow.hideVirtualKeyboard(); - - } - - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region INVOKES_&_OTHER_METHODS - - //Reload Broken Url - public void reloadBrokenPage() - { - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) - Browser.LoadUrl(this.BrokenUrl); - }); - else - { - if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) - Browser.LoadUrl(this.BrokenUrl); - } - } - } - - //Show MainWindow Method - private void ShowWindow() - { - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - this.WindowState = FormWindowState.Maximized; - this.Opacity = 1.0; - }); - else - { - this.WindowState = FormWindowState.Maximized; - this.Opacity = 1.0; - } - } - - - if (!NcWindow.isFollowing) - { - //Start following NC Window - if (Config.VendorHmiConfig.Enabled) - NcWindow.StartNcFollowing(MainHandle, NcHandle, NcFrm.Width, NcFrm.Height); - else - NcWindow.StartStepFollowing(MainHandle); - } - } - - - - //Show Hide window - private void HideLoadingWindow() - { - //Invoke method if is needed or call the method in STD mode - - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - LdFrm.Hide(); - }); - - else - { - LdFrm.Hide(); - } - } - } - - - - //Show Message window - private void ShowLoading(String Message) - { - //Invoke method if is needed or call the method in STD mode - - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - //Set Message Status - LdFrm.Show(Message); - LdFrm.Focus(); - }); - else - { - //Set Message Status - LdFrm.Show(Message); - } - } - } - - - - //Show MainWindow Method - private void BrowserFocus() - { - //Invoke method if is needed or call the method in STD mode - if (Browser.InvokeRequired) - Browser.Invoke((MethodInvoker)delegate () { Browser.Focus(); }); - - else - Browser.Focus(); - } - - - - //Set Window Title - private void SetWindowTitle(String Title) - { - //Setup product label - if (Environment.Is64BitProcess) - Title = Application.ProductName + " x64 | " + Title; - else - Title = Application.ProductName + " x86 | " + Title; - - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () { this.Text = Title; }); - else - this.Text = Title; - } - } - - - //Show NC Method - public void ShowNCWindow() - { - if (!Config.VendorHmiConfig.Enabled) - return; - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - if (this.NcFrm.Owner == null) + if (WindowState == FormWindowState.Minimized) { - this.Owner = null; - this.NcFrm.Owner = this; + NcWindow.ShowTaskBar(); + if (Config.VendorHmiConfig.Enabled) + NcFrm.Hide(); } - this.NcFrm.TopMost = true; - this.NcFrm.TopMost = false; - }); - - else - { - if (this.NcFrm.Owner == null) - { - this.Owner = null; - this.NcFrm.Owner = this; - } - this.NcFrm.TopMost = true; - this.NcFrm.TopMost = false; - } - } - - } - - - - //Hide NC Method - public void HideNCWindow() - { - if (!Config.VendorHmiConfig.Enabled) - return; - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - if (this.NcFrm.Owner != null) + else { - this.NcFrm.Owner = null; + if (Config.VendorHmiConfig.Enabled) + NcFrm.Show(); + + if (NcWindow.State == NcState.SHOW) + { + HideNCWindow(); + ShowNCWindow(); + } + else + HideNCWindow(); } - this.TopMost = true; - this.TopMost = false; - }); - else - { - if (this.NcFrm.Owner != null) - { - this.NcFrm.Owner = null; - } - this.TopMost = true; - this.TopMost = false; - } - } - } - - - //CAlculate Window Position - private void CalcWindowPosition() - { - //Position of the Window - if (Screen.AllScreens.Length > 1 && Config.ClientConfig.RunningOnSecondaryScreen) - { - Screen ps = Screen.AllScreens.FirstOrDefault(S => S.Primary == true); - Screen ss = Screen.AllScreens.FirstOrDefault(S => S.Primary == false); - X = ps.Bounds.Width; - if (ss.Bounds.Top != 0) - Y = ss.Bounds.Top; - } - } - - - //Windows Keys Handler - public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key) - { - //Work only if is a Developer mode - if (Config.ClientConfig.DeveloperMode && altPressed) - { - if (key == (int)Keys.F1) - Browser.GoBack(); - - if (key == (int)Keys.F2) - Browser.GoForward(); - - if (key == (int)Keys.F5) - { - if (Browser.Url.AbsoluteUri != Constants.errorPageUrl) - Browser.Browser.ReloadIgnoreCache(); - else - Browser.LoadUrl(this.BrokenUrl); + //Refresh Browser Paint + Browser.Refresh(); + Refresh(); } - if (key == (int)Keys.F10) - ShowChromeVersion(); - if (key == (int)Keys.F11) - ShowChromeGPU(); - if (key == (int)Keys.F12) - ShowDevTools(); - } + //Before closing the Window -> Remove the Browser (Increase the speed of closing window) + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + //Invoke method if is needed or call the method in STD mode + if (!IsDisposed) + { + //Show Taskbar + NcWindow.ShowTaskBar(); + + //Hide Window + Hide(); + + //Close Virtual Keyboard Runtime + if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) + NcWindow.closeVirtualKeyboard(); + + //Close the NC HMI && Stop Following Nc + if (Config.VendorHmiConfig.Enabled) + NcWindow.CloseNcWindow(false); + + + //Close Chromium Runtime + try + { + CfxRuntime.Shutdown(); + } + catch (Exception) + { + + } + } + + + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region SETUP_METHODS + + //Initialize CMS-Client Settings + private void InitializeClientSettings() + { + //Set the Transparency Key + if (Config.ClientConfig.RenderingMethod == Constants.Rendering.CPU && Environment.OSVersion.Version.Major < 10) + TransparencyKey = Config.ClientConfig.TranspColor; + + //Calculate Window Position + CalcWindowPosition(); + } + + + + //Initialize CMS-Client Settings + private void InitializeNcForm() + { + //Create the Nc-Form + if (Config.VendorHmiConfig.Enabled) + { + NcFrm = new NcForm(Config.ClientConfig.TranspColor, X, Y); + NcHandle = NcFrm.Handle; + NcFrm.Show(); + } + + //Steup the Step variables + MainHandle = Handle; + } + + + + //Initialize the Browser-Component + private void InitializeBrowser() + { + //Add Custom object to browser + Browser.GlobalObject.Add(Constants.BROWSER_JS_OBJ_NAME, new BrowserJSObject(this)); + + //Add all Handlers + Browser.DisplayHandler.OnTitleChange += BrowserTitleChanged; + Browser.LoadHandler.OnLoadingStateChange += BrowserLoadsChanged; + Browser.LoadHandler.OnLoadError += BrowserLoadsError; + Browser.KeyboardHandler.OnKeyEvent += BrowserKeyPress; + Browser.ContextMenuHandler.OnBeforeContextMenu += BrowserContextMenu; + Browser.DisplayHandler.OnConsoleMessage += BrowserConsoleMessage; + //Filter only < Win_10 Platform + if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) + ChromiumWebBrowser.RemoteProcessCreated += (e) => { e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged; }; + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region BROWSER_EVENT_HANDLERS_METHODS + + //On browser Load-Error. Event Handler called by Browser + private void BrowserLoadsError(object sender, CfxOnLoadErrorEventArgs e) + { + //Set the Load-Error global variable to TRUE + LoadingError.Error = true; + LoadingError.ErrorInfo = e.ErrorCode.GetHashCode() + " - " + e.ErrorText; + if (e.FailedUrl != Constants.errorPageUrl) + BrokenUrl = e.FailedUrl; + + //write the error in the Title Bar + SetWindowTitle(LoadingError.ErrorInfo); + } + + + + //On browser Load-Changed. Event Handler called by Browser + private void BrowserLoadsChanged(object sender, CfxOnLoadingStateChangeEventArgs e) + { + //if the State is NOT "loading" + if (!e.Browser.IsLoading) + { + //Hide Loading Window + HideLoadingWindow(); + + //Show the Main Window, when the page is loaded + ShowWindow(); + + //If is an Error Show the Error page + if (LoadingError.Error && !LoadingError.ErrorInfo.Contains("ERR_ABORTED")) + { + Browser.LoadString(Config.ConnectionConfig.ErrorPage, Constants.errorPageUrl); + } + + //Set focus on the page + BrowserFocus(); + + } + //if the State is "loading" + else + { + //Hide NC Window + NcWindow.SetState(0); + HideNCWindow(); + + //Set the title of the window in "Loading" + SetWindowTitle("Loading..."); + + //Set the Load-Error global variable to FALSE + LoadingError.Error = false; + } + } + + + + //On browser Title-Changed. Event Handler called by Browser + private void BrowserTitleChanged(object sender, CfxOnTitleChangeEventArgs e) + { + if (!LoadingError.Error) + SetWindowTitle(e.Title); + } + + + + // on Key-Press Browser + private void BrowserKeyPress(object sender, CfxOnKeyEventEventArgs e) + { + + } + + + + //Show Dev Tools Window + private void ShowDevTools() + { + //Setup Dev Window + CfxWindowInfo windowInfo = new CfxWindowInfo + { + Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE), + ParentWindow = MainHandle, + WindowName = Application.ProductName + " | CEF Dev Tools", + X = 1120, + Y = 0, + Width = 800, + Height = 1080 + }; + + //Show Dev Window + Browser.BrowserHost.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null); + } + + + + //Show Chrome GPU Window + private void ShowChromeGPU() + { + int w = 1600, h = 800; + + //Setup Window + CfxWindowInfo windowInfo = new CfxWindowInfo(); + windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); + windowInfo.ParentWindow = MainHandle; + windowInfo.WindowName = Application.ProductName + " | CEF Graphic Tools"; + windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); + windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); + windowInfo.Width = w; + windowInfo.Height = h; + + //Show Window + CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://gpu/", ChromiumWebBrowser.DefaultBrowserSettings, null); + } + + + + //Show Chrome Version Window + private void ShowChromeVersion() + { + int w = 1600, h = 800; + + //Setup Window + CfxWindowInfo windowInfo = new CfxWindowInfo(); + windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); + windowInfo.ParentWindow = MainHandle; + windowInfo.WindowName = Application.ProductName + " | CEF Chromium-Version Tools"; + windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); + windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); + windowInfo.Width = w; + windowInfo.Height = h; + + //Show Window + CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://version/", ChromiumWebBrowser.DefaultBrowserSettings, null); + } + + + + //Override default Browser Context Menu + private void BrowserContextMenu(object sender, CfxOnBeforeContextMenuEventArgs e) + { + e.Model.Clear(); + } + + + //Override Javascript Console Message + private void BrowserConsoleMessage(object sender, CfxOnConsoleMessageEventArgs e) + { + e.SetReturnValue(true); + } + + + //Node Changed Handler + private void BrowserNodeChanged(object sender, CfrOnFocusedNodeChangedEventArgs ev) + { + if (ev.Node != null) + { + string NodeName = ev.Node.ElementTagName.ToLower(); + //Filter if this node is an INPUT Node + if (NodeName != null && NodeName.Equals("input")) + { + string dom = ev.Node.GetElementAttribute("type").ToLower(); + + //Filter if the node Type is TEXT or PASSWORD + if (dom != null && (dom.Equals("text") || dom.Equals("password"))) + NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); + } + //Filter if this node is TEXTAREA Node + else if (NodeName != null && NodeName.Equals("textarea")) + NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); + else + NcWindow.hideVirtualKeyboard(); + } + else + NcWindow.hideVirtualKeyboard(); + + } + + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region INVOKES_&_OTHER_METHODS + + //Reload Broken Url + public void reloadBrokenPage() + { + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + if (!string.IsNullOrWhiteSpace(BrokenUrl)) + Browser.LoadUrl(BrokenUrl); + }); + else + { + if (!string.IsNullOrWhiteSpace(BrokenUrl)) + Browser.LoadUrl(BrokenUrl); + } + } + } + + //Show MainWindow Method + private void ShowWindow() + { + + //Invoke method if is needed or call the method in STD mode + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + WindowState = FormWindowState.Maximized; + Opacity = 1.0; + }); + else + { + WindowState = FormWindowState.Maximized; + Opacity = 1.0; + } + } + + + if (!NcWindow.isFollowing) + { + //Start following NC Window + if (Config.VendorHmiConfig.Enabled) + NcWindow.StartNcFollowing(MainHandle, NcHandle, NcFrm.Width, NcFrm.Height); + else + NcWindow.StartStepFollowing(MainHandle); + } + } + + + + //Show Hide window + private void HideLoadingWindow() + { + //Invoke method if is needed or call the method in STD mode + + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + LdFrm.Hide(); + }); + + else + { + LdFrm.Hide(); + } + } + } + + + + //Show Message window + private void ShowLoading(string Message) + { + //Invoke method if is needed or call the method in STD mode + + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + //Set Message Status + LdFrm.Show(Message); + LdFrm.Focus(); + }); + else + { + //Set Message Status + LdFrm.Show(Message); + } + } + } + + + + //Show MainWindow Method + private void BrowserFocus() + { + //Invoke method if is needed or call the method in STD mode + if (Browser.InvokeRequired) + Browser.Invoke((MethodInvoker)delegate () { Browser.Focus(); }); + + else + Browser.Focus(); + } + + + + //Set Window Title + private void SetWindowTitle(string Title) + { + //Setup product label + if (Environment.Is64BitProcess) + Title = Application.ProductName + " x64 | " + Title; + else + Title = Application.ProductName + " x86 | " + Title; + + + //Invoke method if is needed or call the method in STD mode + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () { Text = Title; }); + else + Text = Title; + } + } + + + //Show NC Method + public void ShowNCWindow() + { + if (!Config.VendorHmiConfig.Enabled) + return; + + //Invoke method if is needed or call the method in STD mode + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + if (NcFrm.Owner == null) + { + Owner = null; + NcFrm.Owner = this; + } + NcFrm.TopMost = true; + NcFrm.TopMost = false; + }); + + else + { + if (NcFrm.Owner == null) + { + Owner = null; + NcFrm.Owner = this; + } + NcFrm.TopMost = true; + NcFrm.TopMost = false; + } + } + + } + + + + //Hide NC Method + public void HideNCWindow() + { + if (!Config.VendorHmiConfig.Enabled) + return; + + //Invoke method if is needed or call the method in STD mode + if (!IsDisposed) + { + if (InvokeRequired) + Invoke((MethodInvoker)delegate () + { + if (NcFrm.Owner != null) + { + NcFrm.Owner = null; + } + TopMost = true; + TopMost = false; + }); + + else + { + if (NcFrm.Owner != null) + { + NcFrm.Owner = null; + } + TopMost = true; + TopMost = false; + } + } + } + + + //CAlculate Window Position + private void CalcWindowPosition() + { + //Position of the Window + if (Screen.AllScreens.Length > 1 && Config.ClientConfig.RunningOnSecondaryScreen) + { + Screen ps = Screen.AllScreens.FirstOrDefault(S => S.Primary == true); + Screen ss = Screen.AllScreens.FirstOrDefault(S => S.Primary == false); + X = ps.Bounds.Width; + if (ss.Bounds.Top != 0) + Y = ss.Bounds.Top; + } + } + + + //Windows Keys Handler + public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key) + { + //Work only if is a Developer mode + if (Config.ClientConfig.DeveloperMode && altPressed) + { + if (key == (int)Keys.F1) + Browser.GoBack(); + + if (key == (int)Keys.F2) + Browser.GoForward(); + + if (key == (int)Keys.F5) + { + if (Browser.Url.AbsoluteUri != Constants.errorPageUrl) + Browser.Browser.ReloadIgnoreCache(); + else + Browser.LoadUrl(BrokenUrl); + } + + if (key == (int)Keys.F10) + ShowChromeVersion(); + + if (key == (int)Keys.F11) + ShowChromeGPU(); + + if (key == (int)Keys.F12) + ShowDevTools(); + } + } + + + #endregion } - - - #endregion - } -} +} diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index fd105868..82e648eb 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml index dbc8112d..66484c93 100644 --- a/Step.Config/Config/serverConfig.xml +++ b/Step.Config/Config/serverConfig.xml @@ -1,7 +1,7 @@ - DEMO + SIEMENS true localhost 8080 diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index ab2971ef..16eafe95 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -734,24 +734,6 @@ public static class ThreadsFunctions case CMS_ERROR_CODES.PROC_NOT_FOUND: break; - case CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED: - break; - - case CMS_ERROR_CODES.BIT_NOT_IN_RANGE: - break; - - case CMS_ERROR_CODES.BYTE_NOT_IN_RANGE: - break; - - case CMS_ERROR_CODES.INTERNAL_ERROR: - break; - - case CMS_ERROR_CODES.INCORRECT_PARAMETERS: - break; - - case CMS_ERROR_CODES.NC_LANGUAGE_ERROR: - break; - case CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND: Manage(ERROR_LEVEL.FATAL, cmsError.localizationKey); break; diff --git a/Step.Database/Controllers/AlarmsController.cs b/Step.Database/Controllers/AlarmsController.cs index 3ac43f9c..a6bb00c3 100644 --- a/Step.Database/Controllers/AlarmsController.cs +++ b/Step.Database/Controllers/AlarmsController.cs @@ -4,7 +4,6 @@ using Step.Model.DTOModels.AlarmModels; using System; using System.Collections.Generic; using System.Data.Entity; -using System.Diagnostics; using System.IO; using System.Linq; using static Step.Model.Constants; @@ -27,41 +26,20 @@ namespace Step.Database.Controllers dbCtx.Dispose(); } - public List GetPaginated(int page, int pageSize) - { - Stopwatch st = new Stopwatch(); - st.Start(); - DateTime l = DateTime.Parse("2013/01/01"); - var paginated = dbCtx.AlarmOccurrences.Include("AlarmDescription").OrderBy(x => x.AlarmOccurrenceId) - .Where(x => x.TimeStamp < DateTime.Today && x.TimeStamp > l) - .Skip(page * pageSize) - .Take(pageSize) - .ToList(); - - Console.WriteLine(st.ElapsedMilliseconds); - - st.Stop(); - - return paginated; - } - public List GetPaginatedWithFilter(string message, ALARM_TYPE type, int page, int pageSize, DateTime startDate, DateTime endDate, List userIds) { var occurrences = dbCtx .AlarmOccurrences .OrderBy(x => x.AlarmOccurrenceId) .Where(x => - x.TimeStamp >= startDate && x.TimeStamp <= endDate + x.TimeStamp >= startDate && x.TimeStamp <= endDate && x.Type == type // && userIds.Any(y => x.Users.Select(z => z.UserId).Any(z => z == y)) ) .Skip(page * pageSize) .Take(pageSize) .Include("AlarmDescription") .ToList(); - - //var ids = occurrences.Select(x => x.Id).ToList(); - //var users = dbCtx.AlarmUsers.Where(x => ids.Contains(x.AlarmOccurrenceId) && userIds.Contains(x.UserId)).ToList(); - + return occurrences .Select(x => (DTOAlarmHistoricModel)x) .ToList(); @@ -191,7 +169,7 @@ namespace Step.Database.Controllers #endregion NOTES - #region Attachment + #region ATTACHMENT public List FindAttachmentByAlarmDescId(int alarmDescId) { @@ -253,6 +231,6 @@ namespace Step.Database.Controllers File.Delete(ALARM_ATTACHMENT_PATH + attachment.LocalFileName); } - #endregion Attachment + #endregion ATTACHMENT } } \ No newline at end of file diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index b3a6617b..4187638e 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Reflection; namespace Step.Model @@ -69,7 +68,7 @@ namespace Step.Model MACHINE_INTERVAL = 1, TIME_INTERVAL = 2 } - + public enum QUEUE_ITEM_STATUS { NOT_ACTIVE = 0, @@ -85,22 +84,26 @@ namespace Step.Model public const string SIEMENS = "SIEMENS"; public const string OSAI = "OSAI"; } + // Database config public const string DATABASE_USER = "root"; + public const string DATABASE_PWD = "root"; public const string DATABASE_NAME = "step"; - // Registry key + // Registry key public const string REGISTER_MACHINE_ID_KEY_NAME = "MachineUniqueId"; // Token fields Keys public const string MACHINE_ID_KEY = "machineId"; + public const string ROLE_LEVEL_KEY = "roleLevel"; public const string USERNAME_KEY = "username"; public const string USER_ID_KEY = "id"; // Names in the xml file public const string SERVER_CONFIG_KEY = "serverConfig"; + public const string NC_CONFIG_KEY = "ncConfig"; public const string AREAS_CONFIG_KEY = "areasConfig"; @@ -116,16 +119,17 @@ namespace Step.Model public const string SCADA_KEY = "scada"; public const string GENERAL_KEY = "general"; public const string UNDER_HOOD = "underHood"; - public const string JOBEDITOR_KEY = "jobeditor"; + public const string JOBEDITOR_KEY = "jobeditor"; } // Config File Names public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + public const string CONFIG_DIRECTORY = "Config\\"; public const string RESOURCE_DIRECTORY = @"Step.Config.Config."; public const string SERVER_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + @"serverConfigValidator.xsd"; public const string SERVER_CONFIG_PATH = CONFIG_DIRECTORY + "serverConfig.xml"; - + public const string AREAS_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + "areasConfigValidator.xsd"; public const string AREAS_CONFIG_PATH = CONFIG_DIRECTORY + "areasConfig.xml"; @@ -156,14 +160,16 @@ namespace Step.Model // MVVM Messages to server UI public const string SEND_STOP_SERVER = "STOP_SERVER"; + public const string SEND_MESSAGE = "SEND_MESSAGE"; public const string SEND_NC_STATUS = "NC_STATUS"; public const string SEND_THREADS_STATUS = "THREAD_STATUS"; public const string SHOW_MSG_UI = "SHOW_MSG_UI"; public const string SEND_ERROR_TO_UI = "SEND_ERROR_TO_UI"; - // MVVM Messages to signalR tasks + // MVVM Messages to signalR tasks public const string SEND_ALARMS = "SEND_ALARMS"; + public const string SEND_POWER_ON_DATA = "SEND_POWER_ON_DATA"; public const string SEND_GENERIC_DATA = "SEND_GENERIC_DATA"; public const string SEND_AXES = "SEND_AXES"; @@ -184,6 +190,7 @@ namespace Step.Model // ID prefix public const string MAINTENANCE_PREFIX_ID = "maint_"; + public const string MAINTENANCE_DESC_PREFIX_ID = "maint_desc_"; public const string SOFTKEY_PREFIX_ID = "softkey_"; public const string SOFTKEY_HEAD_ID = "Head_"; @@ -217,6 +224,7 @@ namespace Step.Model public const string CLIENT_EXE_NAME = @"CMS-Active Client.exe"; public const string CLIENT_EXE_NAME_NOEXT = @"CMS-Active Client"; public const string MAINTENANCE_ATTACHMENT_PATH = @"C:\CMS\STEP\attachment\maintenance\"; + public const string ALARM_ATTACHMENT_PATH = @"C:\CMS\STEP\attachment\alarm\"; public const string TEMP_FOLDER = @"C:\CMS\STEP\TMP\"; public const string TEMP_PP_FOLDER = TEMP_FOLDER + @"pp\"; @@ -232,4 +240,4 @@ namespace Step.Model public const string JOB_METADATA_FILENAME = "metadata.json"; public static string[] JOB_EXTENSIONS = { ".job", ".zip" }; } -} +} \ No newline at end of file diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 1d9b6adb..d132bbf7 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -39,6 +39,11 @@ namespace Step.NC numericalControl.NC_Disconnect(); } + public void Disconnect() + { + numericalControl.NC_Disconnect(); + } + public CmsError Connect() { // Connect NC diff --git a/Step.Utils/languages/IT.xml b/Step.Utils/languages/IT.xml index bc1799c1..cfb8efa1 100644 --- a/Step.Utils/languages/IT.xml +++ b/Step.Utils/languages/IT.xml @@ -269,7 +269,7 @@ Ut. In pos fissa Ut. Misurato Ut. in CU - Ut. in Uso + Ut. in Uso Ut. in Preallarme Raffreddamento principale Raffreddamento 1 diff --git a/Step.Utils/languages/en.xml b/Step.Utils/languages/en.xml index d091f150..a0af09af 100644 --- a/Step.Utils/languages/en.xml +++ b/Step.Utils/languages/en.xml @@ -268,7 +268,7 @@ Tool In Fixed Place Tool Measured Tool in Tool Change - Tool in Use + Tool in Use Tool in Prealarm Main Cooling Cooling 1 diff --git a/Step.Utils/languages/zh.xml b/Step.Utils/languages/zh.xml index 040e001b..e067c596 100644 --- a/Step.Utils/languages/zh.xml +++ b/Step.Utils/languages/zh.xml @@ -180,7 +180,7 @@ 工具在固定的地方 測量工具 刀具更換中的工具 - 正在使用的工具 + 正在使用的工具 預報警中的工具 冷卻1 冷卻2 diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index f7208079..5f6cb44c 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -1,20 +1,17 @@ -using Step.Model.DTOModels; +using CMS_CORE_Library.Models; +using Step.Model.DTOModels; using Step.NC; -using Step.Utils; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; -using static Step.Model.Constants; -using System.Text; using System.Threading.Tasks; using System.Web.Http; -using System.Linq; -using static Step.Config.ServerConfig; -using System.ComponentModel.DataAnnotations; -using CMS_CORE_Library.Models; using static CMS_CORE_Library.Models.DataStructures; +using static Step.Config.ServerConfig; +using static Step.Model.Constants; namespace Step.Controllers.WebApi { @@ -28,7 +25,7 @@ namespace Step.Controllers.WebApi { ncHandler.Connect(); - CmsError cmsError = ncHandler.GetFileList(filePath, out List fileList); + CmsError cmsError = ncHandler.GetFileList(filePath, out List fileList); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); @@ -37,7 +34,7 @@ namespace Step.Controllers.WebApi } [Route("file/info"), HttpGet] - public IHttpActionResult GetFileInfo([FromUri]string filePath) + public IHttpActionResult GetFileInfo([FromUri]string filePath) { using (NcHandler ncHandler = new NcHandler()) { @@ -93,7 +90,7 @@ namespace Step.Controllers.WebApi return BadRequest(cmsError.localizationKey); return Ok(fileInfo); - } + } } [Route("upload"), HttpPost] @@ -110,7 +107,7 @@ namespace Step.Controllers.WebApi { if (item.IsAFile) { - if(item.ParameterName == "file") + if (item.ParameterName == "file") { using (NcHandler ncHandler = new NcHandler()) { @@ -123,7 +120,7 @@ namespace Step.Controllers.WebApi return BadRequest(cmsError.localizationKey); } } - else if(item.ParameterName == "image") + else if (item.ParameterName == "image") { File.WriteAllBytes(PART_PRG_IMAGES + item.FileName, item.Data); } @@ -133,8 +130,7 @@ namespace Step.Controllers.WebApi return Ok(); } - - [Route("shared_files"), HttpGet] + [Route("shared_files"), HttpGet] public IHttpActionResult GetSharedFolderFileList(string sharedPath) { List filelist = new List(); @@ -172,7 +168,6 @@ namespace Step.Controllers.WebApi return Ok(filelist); } - #region Queue Manager [Route("queue/add"), HttpPost] @@ -242,7 +237,7 @@ namespace Step.Controllers.WebApi CmsError cmsError = ncHandler.MoveQueueItems(processId, itemsPositions.ObjectId, itemsPositions.NewPosition, out List queue); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); - + return Ok(queue); } } @@ -258,7 +253,7 @@ namespace Step.Controllers.WebApi CmsError cmsError = ncHandler.EditQueueItemReps(processId, itemId, reps.Reps, out DTOQueueModel queueItem); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); - + return Ok(queueItem); } } @@ -282,10 +277,10 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { ncHandler.Connect(); - + CmsError cmsError = ncHandler.StartWorkingQueue(processId); if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); + return BadRequest(cmsError.localizationKey); return Ok(); } @@ -324,6 +319,6 @@ namespace Step.Controllers.WebApi public int Reps; } - #endregion + #endregion Queue Manager } } \ No newline at end of file diff --git a/Step/Step.csproj b/Step/Step.csproj index 33eb37ab..8ee32a58 100644 --- a/Step/Step.csproj +++ b/Step/Step.csproj @@ -14,7 +14,7 @@ WinExe Properties Step - CMS-Active + CMS Active v4.6.2 @@ -117,7 +117,6 @@ - ..\packages\Microsoft.AspNet.WebApi.Cors.5.2.3\lib\net45\System.Web.Http.Cors.dll diff --git a/Step/program.cs b/Step/program.cs index 2169fe7c..752edef4 100644 --- a/Step/program.cs +++ b/Step/program.cs @@ -37,6 +37,9 @@ namespace Step // Start WinForm ServerControlWindow.Start(); + // Create unhandled exception handler + // AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler); + // Read config ServerConfigController.ReadStartupConfig(); @@ -80,6 +83,10 @@ namespace Step // Wait interrupt from client StopRequest.WaitOne(); + + using (NcHandler ncHandler = new NcHandler()) + ncHandler.Disconnect(); + LogInfo("Application closed"); } @@ -106,5 +113,13 @@ namespace Step return false; } + + private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args) + { + using (NcHandler ncHandler = new NcHandler()) + ncHandler.Disconnect(); + + LogException((Exception)args.ExceptionObject, ERROR_LEVEL.FATAL); + } } } \ No newline at end of file