bit more refactoring

This commit is contained in:
David Sparer
2018-02-09 15:25:55 -06:00
parent b3b961c647
commit 36ed189177
6 changed files with 77 additions and 81 deletions

View File

@@ -288,8 +288,10 @@ namespace mRemoteNG.Connection
var prot = (ProtocolBase)sender;
if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return;
if (Convert.ToInt32(errorMessage) > -1)
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpProtocol.FatalErrors.GetError(errorMessage)));
var errorMessageAsInt = Convert.ToInt32(errorMessage);
if (errorMessageAsInt > -1)
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpErrorTranslator.Translate(errorMessageAsInt)));
}
catch (Exception ex)
{

View File

@@ -0,0 +1,13 @@
using System;
namespace mRemoteNG.Connection.Protocol.RDP
{
public static class RdpVersion
{
public static readonly Version RDC60 = new Version(6, 0, 6000);
public static readonly Version RDC61 = new Version(6, 0, 6001);
public static readonly Version RDC70 = new Version(6, 1, 7600);
public static readonly Version RDC80 = new Version(6, 2, 9200);
public static readonly Version RDC81 = new Version(6, 3, 9600);
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections;
using mRemoteNG.App;
namespace mRemoteNG.Connection.Protocol.RDP
{
public static class RdpErrorTranslator
{
private static Hashtable _description;
private static void InitDescription()
{
_description = new Hashtable
{
{0, Language.strRdpErrorUnknown},
{1, Language.strRdpErrorCode1},
{2, Language.strRdpErrorOutOfMemory},
{3, Language.strRdpErrorWindowCreation},
{4, Language.strRdpErrorCode2},
{5, Language.strRdpErrorCode3},
{6, Language.strRdpErrorCode4},
{7, Language.strRdpErrorConnection},
{100, Language.strRdpErrorWinsock}
};
}
/// <summary>
/// Translates the provided RDP error ID to
/// a user-friendly error message.
/// </summary>
/// <param name="id"></param>
public static string Translate(int id)
{
try
{
if (_description == null)
InitDescription();
return (string)_description?[id];
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionStackTrace(Language.strRdpErrorGetFailure, ex);
return string.Format(Language.strRdpErrorUnknown, id);
}
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
@@ -145,7 +144,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
_rdpClient.AdvancedSettings2.overallConnectionTimeout = Settings.Default.ConRDPOverallConnectionTimeout;
_rdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(_connectionInfo.CacheBitmaps);
if (_rdpVersion >= Versions.RDC61)
if (_rdpVersion >= RdpVersion.RDC61)
{
_rdpClient.AdvancedSettings7.EnableCredSspSupport = _connectionInfo.UseCredSsp;
_rdpClient.AdvancedSettings8.AudioQualityMode = (uint)_connectionInfo.SoundQuality;
@@ -290,7 +289,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
private void ReconnectForResize()
{
if (_rdpVersion < Versions.RDC80)
if (_rdpVersion < RdpVersion.RDC80)
{
return;
}
@@ -341,7 +340,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
{
_rdpClient.TransportSettings.GatewayCredsSource = 1; // TSC_PROXY_CREDS_MODE_SMARTCARD
}
if (_rdpVersion >= Versions.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials)
if (_rdpVersion >= RdpVersion.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials)
{
if (_connectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.Yes)
{
@@ -388,7 +387,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
value = _connectionInfo.UseConsoleSession;
}
if (_rdpVersion >= Versions.RDC61)
if (_rdpVersion >= RdpVersion.RDC61)
{
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strRdpSetConsoleSwitch, _rdpVersion), true);
_rdpClient.AdvancedSettings7.ConnectToAdministerServer = value;
@@ -644,7 +643,6 @@ namespace mRemoteNG.Connection.Protocol.RDP
}
}
private void RDPEvent_OnFatalError(int errorCode)
{
Event_ErrorOccured(this, Convert.ToString(errorCode));
@@ -693,28 +691,13 @@ namespace mRemoteNG.Connection.Protocol.RDP
private void RDPEvent_OnLeaveFullscreenMode()
{
Fullscreen = false;
_leaveFullscreenEvent?.Invoke(this, new EventArgs());
LeaveFullscreen?.Invoke(this, new EventArgs());
}
#endregion
#region Public Events & Handlers
public delegate void LeaveFullscreenEventHandler(object sender, EventArgs e);
private LeaveFullscreenEventHandler _leaveFullscreenEvent;
public event LeaveFullscreenEventHandler LeaveFullscreen
{
add
{
_leaveFullscreenEvent = (LeaveFullscreenEventHandler)Delegate.Combine(_leaveFullscreenEvent, value);
}
remove
{
_leaveFullscreenEvent = (LeaveFullscreenEventHandler)Delegate.Remove(_leaveFullscreenEvent, value);
}
}
#endregion
public event LeaveFullscreenEventHandler LeaveFullscreen;
#region Enums
public enum Defaults
{
Colors = RdpColors.Colors16Bit,
@@ -722,7 +705,6 @@ namespace mRemoteNG.Connection.Protocol.RDP
Resolution = RdpResolutions.FitToWindow,
Port = 3389
}
#endregion
#region Resolution
public static Rectangle GetResolutionRectangle(RdpResolutions resolution)
@@ -736,60 +718,9 @@ namespace mRemoteNG.Connection.Protocol.RDP
{
return new Rectangle(0, 0, 0, 0);
}
else
{
return new Rectangle(0, 0, Convert.ToInt32(resolutionParts[0]), Convert.ToInt32(resolutionParts[1]));
}
return new Rectangle(0, 0, Convert.ToInt32(resolutionParts[0]), Convert.ToInt32(resolutionParts[1]));
}
#endregion
public static class Versions
{
public static readonly Version RDC60 = new Version(6, 0, 6000);
public static readonly Version RDC61 = new Version(6, 0, 6001);
public static readonly Version RDC70 = new Version(6, 1, 7600);
public static readonly Version RDC80 = new Version(6, 2, 9200);
public static readonly Version RDC81 = new Version(6, 3, 9600);
}
#region Fatal Errors
public static class FatalErrors
{
private static Hashtable _description;
private static void InitDescription()
{
_description = new Hashtable
{
{"0", "Language.strRdpErrorUnknown"},
{"1", "Language.strRdpErrorCode1"},
{"2", "Language.strRdpErrorOutOfMemory"},
{"3", "Language.strRdpErrorWindowCreation"},
{"4", "Language.strRdpErrorCode2"},
{"5", "Language.strRdpErrorCode3"},
{"6", "Language.strRdpErrorCode4"},
{"7", "Language.strRdpErrorConnection"},
{"100", "Language.strRdpErrorWinsock"}
};
}
public static string GetError(string id)
{
try
{
if (_description == null)
InitDescription();
return (string)_description?[id];
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionStackTrace(Language.strRdpErrorGetFailure, ex);
return string.Format(Language.strRdpErrorUnknown, id);
}
}
}
#endregion
#endregion
#region Reconnect Stuff
public void tmrReconnect_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

View File

@@ -470,10 +470,10 @@ namespace mRemoteNG.UI.Window
System.Windows.Forms.Application.DoEvents();
}
if (!(new Version(rdpClient.Version) >= RdpProtocol.Versions.RDC80))
if (!(new Version(rdpClient.Version) >= RdpVersion.RDC80))
{
throw new Exception(
$"Found RDC Client version {rdpClient.Version} but version {RdpProtocol.Versions.RDC80} or higher is required.");
$"Found RDC Client version {rdpClient.Version} but version {RdpVersion.RDC80} or higher is required.");
}
pbCheck1.Image = Resources.Good_Symbol;

View File

@@ -236,6 +236,7 @@
<Compile Include="Connection\IHasParent.cs" />
<Compile Include="Connection\Protocol\Http\Connection.Protocol.HTTPS.CertEvent.cs" />
<Compile Include="Connection\Protocol\ProtocolFactory.cs" />
<Compile Include="Connection\Protocol\RDP\Enums\RdpVersion.cs" />
<Compile Include="Connection\Protocol\RDP\Enums\RdpAuthenticationLevel.cs" />
<Compile Include="Connection\Protocol\RDP\AzureLoadBalanceInfoEncoder.cs" />
<Compile Include="Connection\Protocol\RDP\Enums\RDGatewayUsageMethod.cs" />
@@ -245,6 +246,7 @@
<Compile Include="Connection\Protocol\RDP\Enums\RdpResolutions.cs" />
<Compile Include="Connection\Protocol\RDP\Enums\RdpSoundQuality.cs" />
<Compile Include="Connection\Protocol\RDP\Enums\RdpSounds.cs" />
<Compile Include="Connection\Protocol\RDP\RdpErrorTranslator.cs" />
<Compile Include="Connection\Protocol\VNC\VNCEnum.cs" />
<Compile Include="Connection\WebHelper.cs" />
<Compile Include="Credential\PlaceholderCredentialRecord.cs" />