From e029f30acffca6c4dfe4e725fae245491937bead Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sun, 30 Sep 2018 10:44:22 -0500 Subject: [PATCH] added a few try/catch blocks around some rdp code. related to #853 --- .../Connection/Protocol/RDP/RdpProtocol.cs | 41 +++++++++++++------ .../Resources/Language/Language.Designer.cs | 18 ++++++++ mRemoteV1/Resources/Language/Language.resx | 6 +++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs index 198aabdbc..e1cda921d 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs @@ -316,10 +316,19 @@ namespace mRemoteNG.Connection.Protocol.RDP return; } - var size = !Fullscreen ? Control.Size : Screen.FromControl(Control).Bounds.Size; + try + { + Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, $"Resizing RDP connection to host '{_connectionInfo.Hostname}'"); + var size = !Fullscreen ? Control.Size : Screen.FromControl(Control).Bounds.Size; - IMsRdpClient8 msRdpClient8 = _rdpClient; - msRdpClient8.Reconnect((uint)size.Width, (uint)size.Height); + IMsRdpClient8 msRdpClient8 = _rdpClient; + msRdpClient8.Reconnect((uint)size.Width, (uint)size.Height); + } + catch (Exception ex) + { + Runtime.MessageCollector.AddExceptionMessage(string.Format(Language.ChangeConnectionResolutionError, _connectionInfo.Hostname), + ex, MessageClass.WarningMsg, false); + } } private void SetRdGateway() @@ -916,17 +925,25 @@ namespace mRemoteNG.Connection.Protocol.RDP #region Reconnect Stuff public void tmrReconnect_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { - var srvReady = PortScanner.IsPortOpen(_connectionInfo.Hostname, Convert.ToString(_connectionInfo.Port)); + try + { + var srvReady = PortScanner.IsPortOpen(_connectionInfo.Hostname, Convert.ToString(_connectionInfo.Port)); - ReconnectGroup.ServerReady = srvReady; + ReconnectGroup.ServerReady = srvReady; - if (ReconnectGroup.ReconnectWhenReady && srvReady) - { - tmrReconnect.Enabled = false; - ReconnectGroup.DisposeReconnectGroup(); - //SetProps() - _rdpClient.Connect(); - } + if (ReconnectGroup.ReconnectWhenReady && srvReady) + { + tmrReconnect.Enabled = false; + ReconnectGroup.DisposeReconnectGroup(); + //SetProps() + _rdpClient.Connect(); + } + } + catch (Exception ex) + { + Runtime.MessageCollector.AddExceptionMessage(string.Format(Language.AutomaticReconnectError, _connectionInfo.Hostname), + ex, MessageClass.WarningMsg, false); + } } #endregion } diff --git a/mRemoteV1/Resources/Language/Language.Designer.cs b/mRemoteV1/Resources/Language/Language.Designer.cs index d2c32ce51..423a874ee 100644 --- a/mRemoteV1/Resources/Language/Language.Designer.cs +++ b/mRemoteV1/Resources/Language/Language.Designer.cs @@ -60,6 +60,24 @@ namespace mRemoteNG { } } + /// + /// Looks up a localized string similar to An error occurred while trying to reconnect to RDP host '{0}'. + /// + internal static string AutomaticReconnectError { + get { + return ResourceManager.GetString("AutomaticReconnectError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to An error occurred while trying to change the connection resolution to host '{0}'. + /// + internal static string ChangeConnectionResolutionError { + get { + return ResourceManager.GetString("ChangeConnectionResolutionError", resourceCulture); + } + } + /// /// Looks up a localized string similar to Create a New Connection File. /// diff --git a/mRemoteV1/Resources/Language/Language.resx b/mRemoteV1/Resources/Language/Language.resx index 3eda78d61..8492d8174 100644 --- a/mRemoteV1/Resources/Language/Language.resx +++ b/mRemoteV1/Resources/Language/Language.resx @@ -2694,4 +2694,10 @@ This page will walk you through the process of upgrading your connections file o UltraVNC SingleClick + + An error occurred while trying to reconnect to RDP host '{0}' + + + An error occurred while trying to change the connection resolution to host '{0}' + \ No newline at end of file