From 68768ca1d0a16f7368735ad8ded9ea8ce7564471 Mon Sep 17 00:00:00 2001 From: Nicola Carminati Date: Thu, 8 Mar 2018 11:43:53 +0100 Subject: [PATCH] Client: added Browser-error-page --- Client.Config/ConfigController.cs | 8 +- Client.Config/SubModels/Connection.cs | 2 +- Client.Utils/Client.Utils.csproj | 5 + Client.Utils/Constants.cs | 4 + Client.Utils/error.pg | 1953 +++++++++++++++++++++++ Client/Browser_Tools/BrowserJSObject.cs | 11 +- Client/Client.csproj | 4 +- Client/View/MainForm.cs | 44 +- 8 files changed, 2017 insertions(+), 14 deletions(-) create mode 100644 Client.Utils/error.pg diff --git a/Client.Config/ConfigController.cs b/Client.Config/ConfigController.cs index bd4550b8..36212661 100644 --- a/Client.Config/ConfigController.cs +++ b/Client.Config/ConfigController.cs @@ -78,7 +78,13 @@ namespace Client.Config //ReadConfig Url compositing Config.ConnectionConfig.ReadConfigUrl = "http://" + Config.ConnectionConfig.ServerUrl + ":" + Config.ConnectionConfig.ServerPort + "/" + Constants.ConfigPage; Config.ConnectionConfig.StartingUrl = "http://" + Config.ConnectionConfig.ServerUrl + ":" + Config.ConnectionConfig.ServerPort + "/" + Constants.StartingPage; - + + //ErrorPage content + if (File.Exists(Constants.errorPageFile)) + Config.ConnectionConfig.ErrorPage = File.ReadAllText(Constants.errorPageFile); + else + throw new Exception(@"File Error: """ + Constants.errorPageFile + @""" not found"); + } private static void ValidationHandler(object sender, ValidationEventArgs e) diff --git a/Client.Config/SubModels/Connection.cs b/Client.Config/SubModels/Connection.cs index e48c1964..f5d80f37 100644 --- a/Client.Config/SubModels/Connection.cs +++ b/Client.Config/SubModels/Connection.cs @@ -15,6 +15,6 @@ namespace Client.Config.SubModels public string ReadConfigUrl { get; set; } public Boolean DeleteCahceFolderOnStartup { get; set; } public Boolean BypassReadConfiguration { get; set; } - + public string ErrorPage { get; set; } } } diff --git a/Client.Utils/Client.Utils.csproj b/Client.Utils/Client.Utils.csproj index 38fb5273..16fb682e 100644 --- a/Client.Utils/Client.Utils.csproj +++ b/Client.Utils/Client.Utils.csproj @@ -44,5 +44,10 @@ + + + Always + + \ No newline at end of file diff --git a/Client.Utils/Constants.cs b/Client.Utils/Constants.cs index 532de5d5..09290d6b 100644 --- a/Client.Utils/Constants.cs +++ b/Client.Utils/Constants.cs @@ -68,6 +68,10 @@ namespace Client.Utils public const string StartingPage = "index.html"; public const string ConfigPage = "api/configuration/client"; + public const string errorPageFile = @"./error.pg"; + public const string errorPageUrl = @"error://error/"; + + } } diff --git a/Client.Utils/error.pg b/Client.Utils/error.pg new file mode 100644 index 00000000..c477e3b9 --- /dev/null +++ b/Client.Utils/error.pg @@ -0,0 +1,1953 @@ + + + + + + + + + Step - Error + + + + + + +
+ +
+ + +
+
+ + \ No newline at end of file diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index e5e53f80..ebddaab5 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -37,6 +37,7 @@ namespace CMS_Client.Browser_Tools AddFunction("maximizeForm").Execute += maximizeForm; AddFunction("closeForm").Execute += closeForm; AddFunction("forceStepFocus").Execute += forceStepFocus; + AddFunction("reloadBrokenPage").Execute += reloadBrokenPage; AddFunction("setNcWindowState").Execute += setNcWindowState; AddFunction("getNcWindowState").Execute += getNcWindowState; @@ -47,7 +48,6 @@ namespace CMS_Client.Browser_Tools AddFunction("startNewProcess").Execute += startNewProcess; AddFunction("openOrStartProcess").Execute += openOrStartProcess; AddFunction("isVirtualKeybConfigured").Execute += isVirtualKeybConfigured; - } #endregion @@ -99,12 +99,19 @@ namespace CMS_Client.Browser_Tools //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) diff --git a/Client/Client.csproj b/Client/Client.csproj index e1b876d6..cccd4b3c 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -254,9 +254,7 @@ - - - + diff --git a/Client/View/MainForm.cs b/Client/View/MainForm.cs index 0915c559..92836f42 100644 --- a/Client/View/MainForm.cs +++ b/Client/View/MainForm.cs @@ -12,6 +12,7 @@ using System.Diagnostics; using CMS_Client.Browser_Tools; using Chromium.Remote; using Chromium.Remote.Event; +using System.IO; namespace CMS_Client.View { @@ -33,6 +34,7 @@ namespace CMS_Client.View private static IntPtr NcHandle; private int X = 0, Y = 0; private bool CntrlPressed; + private string BrokenUrl; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region WINDOW_START_&_BEHAVIOUR_METHOD @@ -191,7 +193,6 @@ namespace CMS_Client.View ChromiumWebBrowser.RemoteProcessCreated += (e) =>{e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged;}; } - #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -202,14 +203,16 @@ namespace CMS_Client.View { //Set the Load-Error global variable to TRUE LoadingError.Error = true; - LoadingError.ErrorInfo = e.ErrorCode.GetTypeCode() + " - " + e.ErrorText; + 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) { @@ -224,7 +227,9 @@ namespace CMS_Client.View //If is an Error Show the Error page if (LoadingError.Error && !LoadingError.ErrorInfo.Contains("ERR_ABORTED")) - MessageBox.Show("Error While Loading the Page: " + LoadingError.ErrorInfo + "\nPress:\n - F5: reload the Page\n - F1: Back to last Page"); + { + Browser.LoadString(Config.ConnectionConfig.ErrorPage, Constants.errorPageUrl); + } //Set focus on the page BrowserFocus(); @@ -272,13 +277,18 @@ namespace CMS_Client.View if (Config.ClientConfig.DeveloperMode) { if (e.Event.WindowsKeyCode == (int)Keys.F1) - Browser.Browser.GoBack(); + Browser.GoBack(); if (e.Event.WindowsKeyCode == (int)Keys.F2) - Browser.Browser.GoForward(); + Browser.GoForward(); if (e.Event.WindowsKeyCode == (int)Keys.F5) - Browser.Browser.ReloadIgnoreCache(); + { + if (Browser.Url.AbsoluteUri != Constants.errorPageUrl) + Browser.Browser.ReloadIgnoreCache(); + else + Browser.LoadUrl(this.BrokenUrl); + } if (e.Event.WindowsKeyCode == (int)Keys.F10) ShowChromeVersion(); @@ -398,11 +408,31 @@ namespace CMS_Client.View 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()