refactored relationship between protocol objects and interfacecontrol

This commit is contained in:
David Sparer
2018-02-11 20:35:14 -06:00
parent d85c46930f
commit 5bd43afcd3
30 changed files with 246 additions and 246 deletions

View File

@@ -81,7 +81,7 @@ namespace mRemoteNGTests.Connection
{ {
var eventWasCalled = false; var eventWasCalled = false;
_connectionInfo.PropertyChanged += (sender, args) => eventWasCalled = true; _connectionInfo.PropertyChanged += (sender, args) => eventWasCalled = true;
_connectionInfo.OpenConnections.Add(new ProtocolSSH2()); _connectionInfo.OpenConnections.Add(new ProtocolSSH2(_connectionInfo));
Assert.That(eventWasCalled); Assert.That(eventWasCalled);
} }
@@ -90,7 +90,7 @@ namespace mRemoteNGTests.Connection
{ {
var nameOfModifiedProperty = ""; var nameOfModifiedProperty = "";
_connectionInfo.PropertyChanged += (sender, args) => nameOfModifiedProperty = args.PropertyName; _connectionInfo.PropertyChanged += (sender, args) => nameOfModifiedProperty = args.PropertyName;
_connectionInfo.OpenConnections.Add(new ProtocolSSH2()); _connectionInfo.OpenConnections.Add(new ProtocolSSH2(_connectionInfo));
Assert.That(nameOfModifiedProperty, Is.EqualTo("OpenConnections")); Assert.That(nameOfModifiedProperty, Is.EqualTo("OpenConnections"));
} }

View File

@@ -1,5 +1,4 @@
using System.Collections.ObjectModel; using mRemoteNG.App;
using mRemoteNG.App;
using mRemoteNG.Connection; using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol; using mRemoteNG.Connection.Protocol;
using mRemoteNG.Tools; using mRemoteNG.Tools;
@@ -12,7 +11,7 @@ namespace mRemoteNGTests.Connection.Protocol
{ {
public class IntegratedProgramTests public class IntegratedProgramTests
{ {
private readonly ExternalTool _extTool = new ExternalTool private readonly ExternalTool _extTool = new ExternalTool
{ {
DisplayName = "notepad", DisplayName = "notepad",
FileName = @"%windir%\system32\notepad.exe", FileName = @"%windir%\system32\notepad.exe",
@@ -20,13 +19,13 @@ namespace mRemoteNGTests.Connection.Protocol
TryIntegrate = true TryIntegrate = true
}; };
[Test] [Test]
public void CanStartExternalApp() public void CanStartExternalApp()
{ {
SetExternalToolList(_extTool); SetExternalToolList(_extTool);
var sut = new IntegratedProgram(); var connectionInfo = new ConnectionInfo { ExtApp = _extTool.DisplayName };
sut.InterfaceControl = BuildInterfaceControl("notepad", sut); var sut = new IntegratedProgram(connectionInfo);
sut.InterfaceControl = BuildInterfaceControl(sut);
sut.Initialize(); sut.Initialize();
var appStarted = sut.Connect(); var appStarted = sut.Connect();
sut.Disconnect(); sut.Disconnect();
@@ -37,8 +36,9 @@ namespace mRemoteNGTests.Connection.Protocol
public void ConnectingToExternalAppThatDoesntExistDoesNothing() public void ConnectingToExternalAppThatDoesntExistDoesNothing()
{ {
SetExternalToolList(_extTool); SetExternalToolList(_extTool);
var sut = new IntegratedProgram(); var connectionInfo = new ConnectionInfo { ExtApp = "doesntExist" };
sut.InterfaceControl = BuildInterfaceControl("doesntExist", sut); var sut = new IntegratedProgram(connectionInfo);
sut.InterfaceControl = BuildInterfaceControl(sut);
var appInitialized = sut.Initialize(); var appInitialized = sut.Initialize();
Assert.That(appInitialized, Is.False); Assert.That(appInitialized, Is.False);
} }
@@ -48,11 +48,10 @@ namespace mRemoteNGTests.Connection.Protocol
Runtime.ExternalToolsService.ExternalTools = new FullyObservableCollection<ExternalTool> {externalTool}; Runtime.ExternalToolsService.ExternalTools = new FullyObservableCollection<ExternalTool> {externalTool};
} }
private InterfaceControl BuildInterfaceControl(string extAppName, ProtocolBase sut) private InterfaceControl BuildInterfaceControl(ProtocolBase sut)
{ {
var connectionWindow = new ConnectionWindow(new DockContent()); var connectionWindow = new ConnectionWindow(new DockContent());
var connectionInfo = new ConnectionInfo {ExtApp = extAppName}; return new InterfaceControl(connectionWindow, sut);
return new InterfaceControl(connectionWindow, sut, connectionInfo);
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Specialized; using System.Collections.Specialized;
using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol; using mRemoteNG.Connection.Protocol;
using mRemoteNG.Connection.Protocol.SSH; using mRemoteNG.Connection.Protocol.SSH;
using mRemoteNG.Connection.Protocol.Telnet; using mRemoteNG.Connection.Protocol.Telnet;
@@ -21,9 +22,9 @@ namespace mRemoteNGTests.Connection.Protocol
public void Setup() public void Setup()
{ {
_protocolList = new ProtocolList(); _protocolList = new ProtocolList();
_protocol1 = new ProtocolTelnet(); _protocol1 = new ProtocolTelnet(new ConnectionInfo());
_protocol2 = new ProtocolSSH2(); _protocol2 = new ProtocolSSH2(new ConnectionInfo());
_protocol3 = new ProtocolVNC(); _protocol3 = new ProtocolVNC(new ConnectionInfo());
} }
[TearDown] [TearDown]

View File

@@ -100,7 +100,7 @@ namespace mRemoteNG.Connection
var connectionContainer = SetConnectionContainer(connectionInfo, connectionForm); var connectionContainer = SetConnectionContainer(connectionInfo, connectionForm);
SetConnectionFormEventHandlers(newProtocol, connectionForm); SetConnectionFormEventHandlers(newProtocol, connectionForm);
SetConnectionEventHandlers(newProtocol); SetConnectionEventHandlers(newProtocol);
BuildConnectionInterfaceController(connectionInfo, newProtocol, connectionContainer); BuildConnectionInterfaceController(newProtocol, connectionContainer);
newProtocol.Force = force; newProtocol.Force = force;
@@ -144,7 +144,7 @@ namespace mRemoteNG.Connection
{ {
var ic = t.Controls[0] as InterfaceControl; var ic = t.Controls[0] as InterfaceControl;
if (ic == null) continue; if (ic == null) continue;
if (ic.Info == connectionInfo) if (ic.Protocol.Info == connectionInfo)
{ {
return ic; return ic;
} }
@@ -213,9 +213,9 @@ namespace mRemoteNG.Connection
newProtocol.ErrorOccured += Prot_Event_ErrorOccured; newProtocol.ErrorOccured += Prot_Event_ErrorOccured;
} }
private static void BuildConnectionInterfaceController(ConnectionInfo connectionInfo, ProtocolBase newProtocol, Control connectionContainer) private static void BuildConnectionInterfaceController(ProtocolBase newProtocol, Control connectionContainer)
{ {
newProtocol.InterfaceControl = new InterfaceControl(connectionContainer, newProtocol, connectionInfo); newProtocol.InterfaceControl = new InterfaceControl(connectionContainer, newProtocol);
} }
#endregion #endregion
@@ -233,7 +233,7 @@ namespace mRemoteNG.Connection
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strProtocolEventDisconnected, disconnectedMessage), true); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strProtocolEventDisconnected, disconnectedMessage), true);
var prot = (ProtocolBase)sender; var prot = (ProtocolBase)sender;
if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return; if (prot.Info.Protocol != ProtocolType.RDP) return;
var reasonCode = disconnectedMessage.Split("\r\n".ToCharArray())[0]; var reasonCode = disconnectedMessage.Split("\r\n".ToCharArray())[0];
var desc = disconnectedMessage.Replace("\r\n", " "); var desc = disconnectedMessage.Replace("\r\n", " ");
@@ -253,19 +253,20 @@ namespace mRemoteNG.Connection
var prot = (ProtocolBase)sender; var prot = (ProtocolBase)sender;
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnenctionCloseEvent, true); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnenctionCloseEvent, true);
string connDetail; string connDetail;
if (prot.InterfaceControl.Info.Hostname == "" && prot.InterfaceControl.Info.Protocol == ProtocolType.IntApp) if (prot.Info.Hostname == "" && prot.Info.Protocol == ProtocolType.IntApp)
connDetail = prot.InterfaceControl.Info.ExtApp; connDetail = prot.Info.ExtApp;
else if (prot.InterfaceControl.Info.Hostname != "") else if (prot.Info.Hostname != "")
connDetail = prot.InterfaceControl.Info.Hostname; connDetail = prot.Info.Hostname;
else else
connDetail = "UNKNOWN"; connDetail = "UNKNOWN";
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strConnenctionClosedByUser, connDetail, prot.InterfaceControl.Info.Protocol, Environment.UserName)); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
prot.InterfaceControl.Info.OpenConnections.Remove(prot); string.Format(Language.strConnenctionClosedByUser, connDetail, prot.Info.Protocol, Environment.UserName));
prot.Info.OpenConnections.Remove(prot);
if (prot.InterfaceControl.Info.PostExtApp == "") return; if (prot.Info.PostExtApp == "") return;
var extA = Runtime.ExternalToolsService.GetExtAppByName(prot.InterfaceControl.Info.PostExtApp); var extA = Runtime.ExternalToolsService.GetExtAppByName(prot.Info.PostExtApp);
extA?.Start(prot.InterfaceControl.Info); extA?.Start(prot.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -277,7 +278,8 @@ namespace mRemoteNG.Connection
{ {
var prot = (ProtocolBase)sender; var prot = (ProtocolBase)sender;
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventConnected, true); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventConnected, true);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strConnectionEventConnectedDetail, prot.InterfaceControl.Info.Hostname, prot.InterfaceControl.Info.Protocol, Environment.UserName, prot.InterfaceControl.Info.Description, prot.InterfaceControl.Info.UserField)); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
string.Format(Language.strConnectionEventConnectedDetail, prot.Info.Hostname, prot.Info.Protocol, Environment.UserName, prot.Info.Description, prot.Info.UserField));
} }
private static void Prot_Event_ErrorOccured(object sender, string errorMessage) private static void Prot_Event_ErrorOccured(object sender, string errorMessage)
@@ -287,11 +289,12 @@ namespace mRemoteNG.Connection
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventErrorOccured, true); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventErrorOccured, true);
var prot = (ProtocolBase)sender; var prot = (ProtocolBase)sender;
if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return; if (prot.Info.Protocol != ProtocolType.RDP) return;
var errorMessageAsInt = Convert.ToInt32(errorMessage); var errorMessageAsInt = Convert.ToInt32(errorMessage);
if (errorMessageAsInt > -1) if (errorMessageAsInt > -1)
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpErrorTranslator.Translate(errorMessageAsInt))); Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg,
string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpErrorTranslator.Translate(errorMessageAsInt)));
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -10,15 +10,12 @@ namespace mRemoteNG.Connection
public sealed partial class InterfaceControl public sealed partial class InterfaceControl
{ {
public ProtocolBase Protocol { get; set; } public ProtocolBase Protocol { get; set; }
public ConnectionInfo Info { get; set; }
public InterfaceControl(Control parent, ProtocolBase protocol)
public InterfaceControl(Control parent, ProtocolBase protocol, ConnectionInfo info)
{ {
try try
{ {
Protocol = protocol; Protocol = protocol;
Info = info;
Parent = parent; Parent = parent;
Location = new Point(0, 0); Location = new Point(0, 0);
Size = Parent.Size; Size = Parent.Size;

View File

@@ -3,7 +3,8 @@ namespace mRemoteNG.Connection.Protocol.Http
public class ProtocolHTTP : HTTPBase public class ProtocolHTTP : HTTPBase
{ {
public ProtocolHTTP(RenderingEngine RenderingEngine) : base(RenderingEngine) public ProtocolHTTP(ConnectionInfo connectionInfo, RenderingEngine renderingEngine)
: base(connectionInfo, renderingEngine)
{ {
httpOrS = "http"; httpOrS = "http";
defaultPort = (int)Defaults.Port; defaultPort = (int)Defaults.Port;

View File

@@ -9,20 +9,19 @@ namespace mRemoteNG.Connection.Protocol.Http
{ {
public class HTTPBase : ProtocolBase public class HTTPBase : ProtocolBase
{ {
#region Private Properties
private Control wBrowser; private Control wBrowser;
private string tabTitle;
protected string httpOrS; protected string httpOrS;
protected int defaultPort; protected int defaultPort;
private string tabTitle;
#endregion
#region Public Methods #region Public Methods
protected HTTPBase(RenderingEngine RenderingEngine) protected HTTPBase(ConnectionInfo connectionInfo, RenderingEngine renderingEngine)
{ : base(connectionInfo)
{
try try
{ {
if (RenderingEngine == RenderingEngine.Gecko) if (renderingEngine == RenderingEngine.Gecko)
{ {
if(!Xpcom.IsInitialized) if(!Xpcom.IsInitialized)
Xpcom.Initialize("Firefox"); Xpcom.Initialize("Firefox");
@@ -58,7 +57,7 @@ namespace mRemoteNG.Connection.Protocol.Http
{ {
wBrowser = Control; wBrowser = Control;
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) if (Info.RenderingEngine == RenderingEngine.Gecko)
{ {
var GeckoBrowser = (GeckoWebBrowser) wBrowser; var GeckoBrowser = (GeckoWebBrowser) wBrowser;
if (GeckoBrowser != null) if (GeckoBrowser != null)
@@ -96,7 +95,7 @@ namespace mRemoteNG.Connection.Protocol.Http
{ {
try try
{ {
var strHost = InterfaceControl.Info.Hostname; var strHost = Info.Hostname;
/* /*
* Commenting out since this codes doesn't actually do anything at this time... * Commenting out since this codes doesn't actually do anything at this time...
* Possibly related to MR-221 and/or MR-533 ???? * Possibly related to MR-221 and/or MR-533 ????
@@ -108,7 +107,7 @@ namespace mRemoteNG.Connection.Protocol.Http
strAuth = "Authorization: Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(InterfaceControl.Info.Username + ":" + InterfaceControl.Info.Password)) + Environment.NewLine; strAuth = "Authorization: Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(InterfaceControl.Info.Username + ":" + InterfaceControl.Info.Password)) + Environment.NewLine;
} }
*/ */
if (InterfaceControl.Info.Port != defaultPort) if (Info.Port != defaultPort)
{ {
if (strHost.EndsWith("/")) if (strHost.EndsWith("/"))
{ {
@@ -120,13 +119,13 @@ namespace mRemoteNG.Connection.Protocol.Http
strHost = httpOrS + "://" + strHost; strHost = httpOrS + "://" + strHost;
} }
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) if (Info.RenderingEngine == RenderingEngine.Gecko)
{ {
((GeckoWebBrowser)wBrowser).Navigate(strHost + ":" + InterfaceControl.Info.Port); ((GeckoWebBrowser)wBrowser).Navigate(strHost + ":" + Info.Port);
} }
else else
{ {
((WebBrowser)wBrowser).Navigate(strHost + ":" + InterfaceControl.Info.Port); ((WebBrowser)wBrowser).Navigate(strHost + ":" + Info.Port);
} }
} }
else else
@@ -136,7 +135,7 @@ namespace mRemoteNG.Connection.Protocol.Http
strHost = httpOrS + "://" + strHost; strHost = httpOrS + "://" + strHost;
} }
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) if (Info.RenderingEngine == RenderingEngine.Gecko)
{ {
((GeckoWebBrowser)wBrowser).Navigate(strHost); ((GeckoWebBrowser)wBrowser).Navigate(strHost);
} }
@@ -181,7 +180,7 @@ namespace mRemoteNG.Connection.Protocol.Http
if (tabP == null) return; if (tabP == null) return;
string shortTitle; string shortTitle;
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) if (Info.RenderingEngine == RenderingEngine.Gecko)
{ {
if (((GeckoWebBrowser) wBrowser).DocumentTitle.Length >= 15) if (((GeckoWebBrowser) wBrowser).DocumentTitle.Length >= 15)
{ {
@@ -229,7 +228,7 @@ namespace mRemoteNG.Connection.Protocol.Http
if (tabP == null) return; if (tabP == null) return;
string shortTitle; string shortTitle;
if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) if (Info.RenderingEngine == RenderingEngine.Gecko)
{ {
if (((GeckoWebBrowser)wBrowser).DocumentTitle.Length >= 15) if (((GeckoWebBrowser)wBrowser).DocumentTitle.Length >= 15)
{ {

View File

@@ -2,8 +2,8 @@ namespace mRemoteNG.Connection.Protocol.Http
{ {
public class ProtocolHTTPS : HTTPBase public class ProtocolHTTPS : HTTPBase
{ {
public ProtocolHTTPS(ConnectionInfo connectionInfo, RenderingEngine renderingEngine)
public ProtocolHTTPS(RenderingEngine RenderingEngine) : base(RenderingEngine) : base(connectionInfo, renderingEngine)
{ {
httpOrS = "https"; httpOrS = "https";
defaultPort = (int)Defaults.Port; defaultPort = (int)Defaults.Port;

View File

@@ -16,11 +16,11 @@ namespace mRemoteNG.Connection.Protocol.ICA
public class IcaProtocol : ProtocolBase public class IcaProtocol : ProtocolBase
{ {
private AxICAClient _icaClient; private AxICAClient _icaClient;
private ConnectionInfo _info;
private readonly FrmMain _frmMain = FrmMain.Default; private readonly FrmMain _frmMain = FrmMain.Default;
#region Public Methods #region Public Methods
public IcaProtocol() public IcaProtocol(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
try try
{ {
@@ -39,7 +39,6 @@ namespace mRemoteNG.Connection.Protocol.ICA
try try
{ {
_icaClient = (AxICAClient)Control; _icaClient = (AxICAClient)Control;
_info = InterfaceControl.Info;
_icaClient.CreateControl(); _icaClient.CreateControl();
while (!_icaClient.Created) while (!_icaClient.Created)
@@ -48,7 +47,7 @@ namespace mRemoteNG.Connection.Protocol.ICA
Application.DoEvents(); Application.DoEvents();
} }
_icaClient.Address = _info.Hostname; _icaClient.Address = Info.Hostname;
SetCredentials(); SetCredentials();
SetResolution(); SetResolution();
SetColors(); SetColors();
@@ -78,8 +77,8 @@ namespace mRemoteNG.Connection.Protocol.ICA
_icaClient.Hotkey11Shift = null; _icaClient.Hotkey11Shift = null;
_icaClient.Hotkey11Char = null; _icaClient.Hotkey11Char = null;
_icaClient.PersistentCacheEnabled = _info.CacheBitmaps; _icaClient.PersistentCacheEnabled = Info.CacheBitmaps;
_icaClient.Title = _info.Name; _icaClient.Title = Info.Name;
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
@@ -117,9 +116,9 @@ namespace mRemoteNG.Connection.Protocol.ICA
return; return;
} }
var user = _info?.Username ?? ""; var user = Info?.Username ?? "";
var pass = _info?.Password ?? ""; var pass = Info?.Password ?? "";
var dom = _info?.Domain ?? ""; var dom = Info?.Domain ?? "";
if (string.IsNullOrEmpty(user)) if (string.IsNullOrEmpty(user))
{ {
@@ -187,22 +186,22 @@ namespace mRemoteNG.Connection.Protocol.ICA
return; return;
} }
if (InterfaceControl.Info.Resolution == RdpResolutions.FitToWindow) if (Info.Resolution == RdpResolutions.FitToWindow)
{ {
_icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, InterfaceControl.Size.Width, InterfaceControl.Size.Height, 0); _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, InterfaceControl.Size.Width, InterfaceControl.Size.Height, 0);
} }
else if (InterfaceControl.Info.Resolution == RdpResolutions.SmartSize) else if (Info.Resolution == RdpResolutions.SmartSize)
{ {
_icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, InterfaceControl.Size.Width, InterfaceControl.Size.Height, 0); _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, InterfaceControl.Size.Width, InterfaceControl.Size.Height, 0);
} }
else if (InterfaceControl.Info.Resolution == RdpResolutions.Fullscreen) else if (Info.Resolution == RdpResolutions.Fullscreen)
{ {
_icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, Screen.FromControl(_frmMain).Bounds.Width, Screen.FromControl(_frmMain).Bounds.Height, 0); _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, Screen.FromControl(_frmMain).Bounds.Width, Screen.FromControl(_frmMain).Bounds.Height, 0);
_icaClient.FullScreenWindow(); _icaClient.FullScreenWindow();
} }
else else
{ {
var resolution = _info.Resolution.GetResolutionRectangle(); var resolution = Info.Resolution.GetResolutionRectangle();
_icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, resolution.Width, resolution.Height, 0); _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, resolution.Width, resolution.Height, 0);
} }
} }
@@ -215,7 +214,7 @@ namespace mRemoteNG.Connection.Protocol.ICA
private void SetColors() private void SetColors()
{ {
// ReSharper disable once SwitchStatementMissingSomeCases // ReSharper disable once SwitchStatementMissingSomeCases
switch (_info.Colors) switch (Info.Colors)
{ {
case RdpColors.Colors256: case RdpColors.Colors256:
_icaClient.SetProp("DesiredColor", "2"); _icaClient.SetProp("DesiredColor", "2");
@@ -235,7 +234,7 @@ namespace mRemoteNG.Connection.Protocol.ICA
private void SetSecurity() private void SetSecurity()
{ {
// ReSharper disable once SwitchStatementMissingSomeCases // ReSharper disable once SwitchStatementMissingSomeCases
switch (_info.ICAEncryptionStrength) switch (Info.ICAEncryptionStrength)
{ {
case EncryptionStrength.Encr128BitLogonOnly: case EncryptionStrength.Encr128BitLogonOnly:
_icaClient.Encrypt = true; _icaClient.Encrypt = true;
@@ -312,7 +311,7 @@ namespace mRemoteNG.Connection.Protocol.ICA
#region Reconnect Stuff #region Reconnect Stuff
public void tmrReconnect_Elapsed(object sender, ElapsedEventArgs e) public void tmrReconnect_Elapsed(object sender, ElapsedEventArgs e)
{ {
var srvReady = PortScanner.IsPortOpen(_info.Hostname, Convert.ToString(_info.Port)); var srvReady = PortScanner.IsPortOpen(Info.Hostname, Convert.ToString(Info.Port));
ReconnectGroup.ServerReady = srvReady; ReconnectGroup.ServerReady = srvReady;

View File

@@ -11,27 +11,30 @@ namespace mRemoteNG.Connection.Protocol
{ {
public class IntegratedProgram : ProtocolBase public class IntegratedProgram : ProtocolBase
{ {
#region Private Fields
private ExternalTool _externalTool; private ExternalTool _externalTool;
private IntPtr _handle; private IntPtr _handle;
private Process _process; private Process _process;
#endregion
public IntegratedProgram(ConnectionInfo connectionInfo)
: base(connectionInfo)
{
}
#region Public Methods #region Public Methods
public override bool Initialize() public override bool Initialize()
{ {
if (InterfaceControl.Info == null) if (Info == null)
return base.Initialize(); return base.Initialize();
_externalTool = Runtime.ExternalToolsService.GetExtAppByName(InterfaceControl.Info.ExtApp); _externalTool = Runtime.ExternalToolsService.GetExtAppByName(Info.ExtApp);
if (_externalTool == null) if (_externalTool == null)
{ {
Runtime.MessageCollector?.AddMessage(MessageClass.ErrorMsg, string.Format(Language.CouldNotFindExternalTool, InterfaceControl.Info.ExtApp)); Runtime.MessageCollector?.AddMessage(MessageClass.ErrorMsg, string.Format(Language.CouldNotFindExternalTool, Info.ExtApp));
return false; return false;
} }
_externalTool.ConnectionInfo = InterfaceControl.Info; _externalTool.ConnectionInfo = Info;
return base.Initialize(); return base.Initialize();
} }
@@ -44,7 +47,7 @@ namespace mRemoteNG.Connection.Protocol
if (_externalTool.TryIntegrate == false) if (_externalTool.TryIntegrate == false)
{ {
_externalTool.Start(InterfaceControl.Info); _externalTool.Start(Info);
/* Don't call close here... There's nothing for the override to do in this case since /* Don't call close here... There's nothing for the override to do in this case since
* _process is not created in this scenario. When returning false, ProtocolBase.Close() * _process is not created in this scenario. When returning false, ProtocolBase.Close()
* will be called - which is just going to call IntegratedProgram.Close() again anyway... * will be called - which is just going to call IntegratedProgram.Close() again anyway...

View File

@@ -41,6 +41,7 @@ namespace mRemoteNG.Connection.Protocol
protected Control Control { get; set; } protected Control Control { get; set; }
public ConnectionInfo Info { get; set; }
#endregion #endregion
public ConnectionInfo.Force Force { get; set; } public ConnectionInfo.Force Force { get; set; }
@@ -49,12 +50,19 @@ namespace mRemoteNG.Connection.Protocol
protected ReconnectGroup ReconnectGroup; protected ReconnectGroup ReconnectGroup;
#endregion #endregion
protected ProtocolBase(string name) protected ProtocolBase(ConnectionInfo connectionInfo, string name)
{ {
if (connectionInfo == null)
throw new ArgumentNullException(nameof(connectionInfo));
if (name == null)
throw new ArgumentNullException(nameof(name));
Info = connectionInfo;
Name = name; Name = name;
} }
protected ProtocolBase() protected ProtocolBase(ConnectionInfo connectionInfo)
: this(connectionInfo, "")
{ {
} }
@@ -108,7 +116,7 @@ namespace mRemoteNG.Connection.Protocol
public virtual bool Connect() public virtual bool Connect()
{ {
if (InterfaceControl.Info.Protocol == ProtocolType.RDP) return false; if (Info.Protocol == ProtocolType.RDP) return false;
RaiseConnectionConnectedEvent(this); RaiseConnectionConnectedEvent(this);
return true; return true;
} }

View File

@@ -22,35 +22,35 @@ namespace mRemoteNG.Connection.Protocol
newProtocol = new RdpProtocolFactory().CreateProtocol(connectionInfo); newProtocol = new RdpProtocolFactory().CreateProtocol(connectionInfo);
break; break;
case ProtocolType.VNC: case ProtocolType.VNC:
newProtocol = new ProtocolVNC(); newProtocol = new ProtocolVNC(connectionInfo);
break; break;
case ProtocolType.SSH1: case ProtocolType.SSH1:
newProtocol = new ProtocolSSH1(); newProtocol = new ProtocolSSH1(connectionInfo);
break; break;
case ProtocolType.SSH2: case ProtocolType.SSH2:
newProtocol = new ProtocolSSH2(); newProtocol = new ProtocolSSH2(connectionInfo);
break; break;
case ProtocolType.Telnet: case ProtocolType.Telnet:
newProtocol = new ProtocolTelnet(); newProtocol = new ProtocolTelnet(connectionInfo);
break; break;
case ProtocolType.Rlogin: case ProtocolType.Rlogin:
newProtocol = new ProtocolRlogin(); newProtocol = new ProtocolRlogin(connectionInfo);
break; break;
case ProtocolType.RAW: case ProtocolType.RAW:
newProtocol = new RawProtocol(); newProtocol = new RawProtocol(connectionInfo);
break; break;
case ProtocolType.HTTP: case ProtocolType.HTTP:
newProtocol = new ProtocolHTTP(connectionInfo.RenderingEngine); newProtocol = new ProtocolHTTP(connectionInfo, connectionInfo.RenderingEngine);
break; break;
case ProtocolType.HTTPS: case ProtocolType.HTTPS:
newProtocol = new ProtocolHTTPS(connectionInfo.RenderingEngine); newProtocol = new ProtocolHTTPS(connectionInfo, connectionInfo.RenderingEngine);
break; break;
case ProtocolType.ICA: case ProtocolType.ICA:
newProtocol = new IcaProtocol(); newProtocol = new IcaProtocol(connectionInfo);
((IcaProtocol) newProtocol).tmrReconnect.Elapsed += ((IcaProtocol) newProtocol).tmrReconnect_Elapsed; ((IcaProtocol) newProtocol).tmrReconnect.Elapsed += ((IcaProtocol) newProtocol).tmrReconnect_Elapsed;
break; break;
case ProtocolType.IntApp: case ProtocolType.IntApp:
newProtocol = new IntegratedProgram(); newProtocol = new IntegratedProgram(connectionInfo);
if (connectionInfo.ExtApp == "") if (connectionInfo.ExtApp == "")
{ {
throw (new Exception(Language.strNoExtAppDefined)); throw (new Exception(Language.strNoExtAppDefined));

View File

@@ -36,6 +36,11 @@ namespace mRemoteNG.Connection.Protocol
#endregion #endregion
public PuttyBase(ConnectionInfo connectionInfo)
: base(connectionInfo)
{
}
#region Private Events & Handlers #region Private Events & Handlers
private void ProcessExited(object sender, EventArgs e) private void ProcessExited(object sender, EventArgs e)
{ {
@@ -61,9 +66,9 @@ namespace mRemoteNG.Connection.Protocol
var arguments = new CommandLineArguments {EscapeForShell = false}; var arguments = new CommandLineArguments {EscapeForShell = false};
arguments.Add("-load", InterfaceControl.Info.PuttySession); arguments.Add("-load", Info.PuttySession);
if (!(InterfaceControl.Info is PuttySessionInfo)) if (!(Info is PuttySessionInfo))
{ {
arguments.Add("-" + PuttyProtocol); arguments.Add("-" + PuttyProtocol);
@@ -72,9 +77,9 @@ namespace mRemoteNG.Connection.Protocol
var username = ""; var username = "";
var password = ""; var password = "";
if (!string.IsNullOrEmpty(InterfaceControl.Info?.Username)) if (!string.IsNullOrEmpty(Info?.Username))
{ {
username = InterfaceControl.Info.Username; username = Info.Username;
} }
else else
{ {
@@ -90,9 +95,9 @@ namespace mRemoteNG.Connection.Protocol
} }
} }
if (!string.IsNullOrEmpty(InterfaceControl.Info?.Password)) if (!string.IsNullOrEmpty(Info?.Password))
{ {
password = InterfaceControl.Info.Password; password = Info.Password;
} }
else else
{ {
@@ -118,8 +123,8 @@ namespace mRemoteNG.Connection.Protocol
} }
} }
arguments.Add("-P", InterfaceControl.Info.Port.ToString()); arguments.Add("-P", Info.Port.ToString());
arguments.Add(InterfaceControl.Info.Hostname); arguments.Add(Info.Hostname);
} }
if (_isPuttyNg) if (_isPuttyNg)

View File

@@ -2,8 +2,9 @@ namespace mRemoteNG.Connection.Protocol.RAW
{ {
public class RawProtocol : PuttyBase public class RawProtocol : PuttyBase
{ {
public RawProtocol() public RawProtocol(ConnectionInfo connectionInfo)
{ : base(connectionInfo)
{
PuttyProtocol = Putty_Protocol.raw; PuttyProtocol = Putty_Protocol.raw;
} }

View File

@@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
public class RdpProtocol10 : RdpProtocol9 public class RdpProtocol10 : RdpProtocol9
{ {
public RdpProtocol10() public RdpProtocol10(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
Control = new AxMsRdpClient10NotSafeForScripting(); Control = new AxMsRdpClient10NotSafeForScripting();
RdpVersionEnum = RdpVersionEnum.Rdc10; RdpVersionEnum = RdpVersionEnum.Rdc10;

View File

@@ -20,7 +20,6 @@ namespace mRemoteNG.Connection.Protocol.RDP
private readonly FrmMain _frmMain = FrmMain.Default; private readonly FrmMain _frmMain = FrmMain.Default;
protected MsRdpClient6NotSafeForScripting RdpClient; protected MsRdpClient6NotSafeForScripting RdpClient;
protected bool LoginComplete; protected bool LoginComplete;
protected ConnectionInfo ConnectionInfo;
#region Properties #region Properties
public virtual bool SmartSize public virtual bool SmartSize
@@ -82,7 +81,8 @@ namespace mRemoteNG.Connection.Protocol.RDP
#endregion #endregion
public RdpProtocol6() public RdpProtocol6(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
Control = new AxMsRdpClient6NotSafeForScripting(); Control = new AxMsRdpClient6NotSafeForScripting();
Connecting += OnConnectingDebugMessage; Connecting += OnConnectingDebugMessage;
@@ -97,7 +97,6 @@ namespace mRemoteNG.Connection.Protocol.RDP
try try
{ {
Control.CreateControl(); Control.CreateControl();
ConnectionInfo = InterfaceControl.Info;
try try
{ {
@@ -117,14 +116,14 @@ namespace mRemoteNG.Connection.Protocol.RDP
_rdpVersion = new Version(RdpClient.Version); _rdpVersion = new Version(RdpClient.Version);
RdpClient.Server = ConnectionInfo.Hostname; RdpClient.Server = Info.Hostname;
SetCredentials(); SetCredentials();
SetResolution(); SetResolution();
RdpClient.FullScreenTitle = ConnectionInfo.Name; RdpClient.FullScreenTitle = Info.Name;
_alertOnIdleDisconnect = ConnectionInfo.RDPAlertIdleTimeout; _alertOnIdleDisconnect = Info.RDPAlertIdleTimeout;
RdpClient.AdvancedSettings2.MinutesToIdleTimeout = ConnectionInfo.RDPMinutesToIdleTimeout; RdpClient.AdvancedSettings2.MinutesToIdleTimeout = Info.RDPMinutesToIdleTimeout;
//not user changeable //not user changeable
RdpClient.AdvancedSettings2.GrabFocusOnConnect = true; RdpClient.AdvancedSettings2.GrabFocusOnConnect = true;
@@ -136,21 +135,21 @@ namespace mRemoteNG.Connection.Protocol.RDP
RdpClient.AdvancedSettings2.overallConnectionTimeout = Settings.Default.ConRDPOverallConnectionTimeout; RdpClient.AdvancedSettings2.overallConnectionTimeout = Settings.Default.ConRDPOverallConnectionTimeout;
RdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(ConnectionInfo.CacheBitmaps); RdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(Info.CacheBitmaps);
if (_rdpVersion >= RdpVersion.RDC61) if (_rdpVersion >= RdpVersion.RDC61)
{ {
RdpClient.AdvancedSettings7.EnableCredSspSupport = ConnectionInfo.UseCredSsp; RdpClient.AdvancedSettings7.EnableCredSspSupport = Info.UseCredSsp;
} }
SetUseConsoleSession(); SetUseConsoleSession();
SetPort(); SetPort();
RedirectKeys = ConnectionInfo.RedirectKeys; RedirectKeys = Info.RedirectKeys;
SetRedirection(); SetRedirection();
SetAuthenticationLevel(); SetAuthenticationLevel();
SetLoadBalanceInfo(); SetLoadBalanceInfo();
SetRdGateway(); SetRdGateway();
RdpClient.ColorDepth = (int)ConnectionInfo.Colors; RdpClient.ColorDepth = (int)Info.Colors;
SetPerformanceFlags(); SetPerformanceFlags();
@@ -257,32 +256,32 @@ namespace mRemoteNG.Connection.Protocol.RDP
} }
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strRdpGatewayIsSupported, true); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strRdpGatewayIsSupported, true);
if (ConnectionInfo.RDGatewayUsageMethod != RDGatewayUsageMethod.Never) if (Info.RDGatewayUsageMethod != RDGatewayUsageMethod.Never)
{ {
RdpClient.TransportSettings.GatewayUsageMethod = (uint)ConnectionInfo.RDGatewayUsageMethod; RdpClient.TransportSettings.GatewayUsageMethod = (uint)Info.RDGatewayUsageMethod;
RdpClient.TransportSettings.GatewayHostname = ConnectionInfo.RDGatewayHostname; RdpClient.TransportSettings.GatewayHostname = Info.RDGatewayHostname;
RdpClient.TransportSettings.GatewayProfileUsageMethod = 1; // TSC_PROXY_PROFILE_MODE_EXPLICIT RdpClient.TransportSettings.GatewayProfileUsageMethod = 1; // TSC_PROXY_PROFILE_MODE_EXPLICIT
if (ConnectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard) if (Info.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard)
{ {
RdpClient.TransportSettings.GatewayCredsSource = 1; // TSC_PROXY_CREDS_MODE_SMARTCARD RdpClient.TransportSettings.GatewayCredsSource = 1; // TSC_PROXY_CREDS_MODE_SMARTCARD
} }
if (_rdpVersion >= RdpVersion.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials) if (_rdpVersion >= RdpVersion.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials)
{ {
if (ConnectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.Yes) if (Info.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.Yes)
{ {
RdpClient.TransportSettings2.GatewayUsername = ConnectionInfo.Username; RdpClient.TransportSettings2.GatewayUsername = Info.Username;
RdpClient.TransportSettings2.GatewayPassword = ConnectionInfo.Password; RdpClient.TransportSettings2.GatewayPassword = Info.Password;
RdpClient.TransportSettings2.GatewayDomain = ConnectionInfo?.Domain; RdpClient.TransportSettings2.GatewayDomain = Info?.Domain;
} }
else if (ConnectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard) else if (Info.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard)
{ {
RdpClient.TransportSettings2.GatewayCredSharing = 0; RdpClient.TransportSettings2.GatewayCredSharing = 0;
} }
else else
{ {
RdpClient.TransportSettings2.GatewayUsername = ConnectionInfo.RDGatewayUsername; RdpClient.TransportSettings2.GatewayUsername = Info.RDGatewayUsername;
RdpClient.TransportSettings2.GatewayPassword = ConnectionInfo.RDGatewayPassword; RdpClient.TransportSettings2.GatewayPassword = Info.RDGatewayPassword;
RdpClient.TransportSettings2.GatewayDomain = ConnectionInfo.RDGatewayDomain; RdpClient.TransportSettings2.GatewayDomain = Info.RDGatewayDomain;
RdpClient.TransportSettings2.GatewayCredSharing = 0; RdpClient.TransportSettings2.GatewayCredSharing = 0;
} }
} }
@@ -310,7 +309,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
} }
else else
{ {
value = ConnectionInfo.UseConsoleSession; value = Info.UseConsoleSession;
} }
if (_rdpVersion >= RdpVersion.RDC61) if (_rdpVersion >= RdpVersion.RDC61)
@@ -341,9 +340,9 @@ namespace mRemoteNG.Connection.Protocol.RDP
return; return;
} }
var userName = ConnectionInfo?.Username ?? ""; var userName = Info?.Username ?? "";
var password = ConnectionInfo?.Password ?? ""; var password = Info?.Password ?? "";
var domain = ConnectionInfo?.Domain ?? ""; var domain = Info?.Domain ?? "";
if (string.IsNullOrEmpty(userName)) if (string.IsNullOrEmpty(userName))
{ {
@@ -412,19 +411,19 @@ namespace mRemoteNG.Connection.Protocol.RDP
return; return;
} }
if ((InterfaceControl.Info.Resolution == RdpResolutions.FitToWindow) || (InterfaceControl.Info.Resolution == RdpResolutions.SmartSize)) if ((Info.Resolution == RdpResolutions.FitToWindow) || (Info.Resolution == RdpResolutions.SmartSize))
{ {
RdpClient.DesktopWidth = InterfaceControl.Size.Width; RdpClient.DesktopWidth = InterfaceControl.Size.Width;
RdpClient.DesktopHeight = InterfaceControl.Size.Height; RdpClient.DesktopHeight = InterfaceControl.Size.Height;
if (InterfaceControl.Info.Resolution == RdpResolutions.SmartSize) if (Info.Resolution == RdpResolutions.SmartSize)
{ {
RdpClient.AdvancedSettings2.SmartSizing = true; RdpClient.AdvancedSettings2.SmartSizing = true;
} }
} }
else if (InterfaceControl.Info.Resolution == RdpResolutions.Fullscreen) else if (Info.Resolution == RdpResolutions.Fullscreen)
{ {
RdpClient.FullScreen = true; RdpClient.FullScreen = true;
RdpClient.DesktopWidth = Screen.FromControl(_frmMain).Bounds.Width; RdpClient.DesktopWidth = Screen.FromControl(_frmMain).Bounds.Width;
@@ -432,7 +431,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
} }
else else
{ {
var resolution = ConnectionInfo.Resolution.GetResolutionRectangle(); var resolution = Info.Resolution.GetResolutionRectangle();
RdpClient.DesktopWidth = resolution.Width; RdpClient.DesktopWidth = resolution.Width;
RdpClient.DesktopHeight = resolution.Height; RdpClient.DesktopHeight = resolution.Height;
} }
@@ -447,9 +446,9 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
try try
{ {
if (ConnectionInfo.Port != (int)Defaults.Port) if (Info.Port != (int)Defaults.Port)
{ {
RdpClient.AdvancedSettings2.RDPPort = ConnectionInfo.Port; RdpClient.AdvancedSettings2.RDPPort = Info.Port;
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -462,11 +461,11 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
try try
{ {
RdpClient.AdvancedSettings2.RedirectDrives = ConnectionInfo.RedirectDiskDrives; RdpClient.AdvancedSettings2.RedirectDrives = Info.RedirectDiskDrives;
RdpClient.AdvancedSettings2.RedirectPorts = ConnectionInfo.RedirectPorts; RdpClient.AdvancedSettings2.RedirectPorts = Info.RedirectPorts;
RdpClient.AdvancedSettings2.RedirectPrinters = ConnectionInfo.RedirectPrinters; RdpClient.AdvancedSettings2.RedirectPrinters = Info.RedirectPrinters;
RdpClient.AdvancedSettings2.RedirectSmartCards = ConnectionInfo.RedirectSmartCards; RdpClient.AdvancedSettings2.RedirectSmartCards = Info.RedirectSmartCards;
RdpClient.SecuredSettings2.AudioRedirectionMode = (int)ConnectionInfo.RedirectSound; RdpClient.SecuredSettings2.AudioRedirectionMode = (int)Info.RedirectSound;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -479,22 +478,22 @@ namespace mRemoteNG.Connection.Protocol.RDP
try try
{ {
var pFlags = 0; var pFlags = 0;
if (ConnectionInfo.DisplayThemes == false) if (Info.DisplayThemes == false)
{ {
pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableThemes); pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableThemes);
} }
if (ConnectionInfo.DisplayWallpaper == false) if (Info.DisplayWallpaper == false)
{ {
pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableWallpaper); pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableWallpaper);
} }
if (ConnectionInfo.EnableFontSmoothing) if (Info.EnableFontSmoothing)
{ {
pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableFontSmoothing); pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableFontSmoothing);
} }
if (ConnectionInfo.EnableDesktopComposition) if (Info.EnableDesktopComposition)
{ {
pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableDesktopComposition); pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableDesktopComposition);
} }
@@ -511,7 +510,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
try try
{ {
RdpClient.AdvancedSettings5.AuthenticationLevel = (uint)ConnectionInfo.RDPAuthenticationLevel; RdpClient.AdvancedSettings5.AuthenticationLevel = (uint)Info.RDPAuthenticationLevel;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -521,15 +520,15 @@ namespace mRemoteNG.Connection.Protocol.RDP
private void SetLoadBalanceInfo() private void SetLoadBalanceInfo()
{ {
if (string.IsNullOrEmpty(ConnectionInfo.LoadBalanceInfo)) if (string.IsNullOrEmpty(Info.LoadBalanceInfo))
{ {
return; return;
} }
try try
{ {
RdpClient.AdvancedSettings2.LoadBalanceInfo = LoadBalanceInfoUseUtf8 RdpClient.AdvancedSettings2.LoadBalanceInfo = LoadBalanceInfoUseUtf8
? new AzureLoadBalanceInfoEncoder().Encode(ConnectionInfo.LoadBalanceInfo) ? new AzureLoadBalanceInfoEncoder().Encode(Info.LoadBalanceInfo)
: ConnectionInfo.LoadBalanceInfo; : Info.LoadBalanceInfo;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -558,7 +557,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
private void OnConnectingDebugMessage(object sender, EventArgs args) private void OnConnectingDebugMessage(object sender, EventArgs args)
{ {
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg,
$"Connection requested RDP version: '{ConnectionInfo.RdpProtocolVersion}'. Using RDP provider: '{sender.GetType().Name}'"); $"Connection requested RDP version: '{Info.RdpProtocolVersion}'. Using RDP provider: '{sender.GetType().Name}'");
} }
#endregion #endregion
@@ -569,7 +568,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
if (_alertOnIdleDisconnect) if (_alertOnIdleDisconnect)
{ {
string message = "The " + ConnectionInfo.Name + " session was disconnected due to inactivity"; string message = "The " + Info.Name + " session was disconnected due to inactivity";
const string caption = "Session Disconnected"; const string caption = "Session Disconnected";
MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
@@ -641,7 +640,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
#region Reconnect Stuff #region Reconnect Stuff
public void tmrReconnect_Elapsed(object sender, System.Timers.ElapsedEventArgs e) public void tmrReconnect_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
var srvReady = PortScanner.IsPortOpen(ConnectionInfo.Hostname, Convert.ToString(ConnectionInfo.Port)); var srvReady = PortScanner.IsPortOpen(Info.Hostname, Convert.ToString(Info.Port));
ReconnectGroup.ServerReady = srvReady; ReconnectGroup.ServerReady = srvReady;

View File

@@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
public class RdpProtocol7 : RdpProtocol6 public class RdpProtocol7 : RdpProtocol6
{ {
public RdpProtocol7() public RdpProtocol7(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
Control = new AxMsRdpClient7NotSafeForScripting(); Control = new AxMsRdpClient7NotSafeForScripting();
RdpVersionEnum = RdpVersionEnum.Rdc7; RdpVersionEnum = RdpVersionEnum.Rdc7;

View File

@@ -39,8 +39,9 @@ namespace mRemoteNG.Connection.Protocol.RDP
} }
} }
public RdpProtocol8() public RdpProtocol8(ConnectionInfo connectionInfo)
{ : base(connectionInfo)
{
Control = new AxMsRdpClient8NotSafeForScripting(); Control = new AxMsRdpClient8NotSafeForScripting();
RdpVersionEnum = RdpVersionEnum.Rdc8; RdpVersionEnum = RdpVersionEnum.Rdc8;
} }
@@ -50,7 +51,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
base.Initialize(); base.Initialize();
try try
{ {
_rdpClient.AdvancedSettings8.AudioQualityMode = (uint)ConnectionInfo.SoundQuality; _rdpClient.AdvancedSettings8.AudioQualityMode = (uint)Info.SoundQuality;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -95,10 +96,10 @@ namespace mRemoteNG.Connection.Protocol.RDP
if (!LoginComplete) if (!LoginComplete)
return; return;
if (!InterfaceControl.Info.AutomaticResize) if (!Info.AutomaticResize)
return; return;
if (!(InterfaceControl.Info.Resolution == RdpResolutions.FitToWindow | InterfaceControl.Info.Resolution == RdpResolutions.Fullscreen)) if (!(Info.Resolution == RdpResolutions.FitToWindow | Info.Resolution == RdpResolutions.Fullscreen))
return; return;
if (SmartSize) if (SmartSize)

View File

@@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
public class RdpProtocol9 : RdpProtocol8 public class RdpProtocol9 : RdpProtocol8
{ {
public RdpProtocol9() public RdpProtocol9(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
Control = new AxMsRdpClient9NotSafeForScripting(); Control = new AxMsRdpClient9NotSafeForScripting();
RdpVersionEnum = RdpVersionEnum.Rdc9; RdpVersionEnum = RdpVersionEnum.Rdc9;

View File

@@ -4,10 +4,10 @@
{ {
public ProtocolBase CreateProtocol(ConnectionInfo connectionInfo) public ProtocolBase CreateProtocol(ConnectionInfo connectionInfo)
{ {
return CreateProtocol(connectionInfo.RdpProtocolVersion); return CreateProtocol(connectionInfo.RdpProtocolVersion, connectionInfo);
} }
public ProtocolBase CreateProtocol(RdpVersionEnum version) public ProtocolBase CreateProtocol(RdpVersionEnum version, ConnectionInfo connectionInfo)
{ {
RdpProtocol6 newProtocol = null; RdpProtocol6 newProtocol = null;
@@ -15,19 +15,19 @@
switch (version) switch (version)
{ {
case RdpVersionEnum.Rdc6: case RdpVersionEnum.Rdc6:
newProtocol = new RdpProtocol6(); newProtocol = new RdpProtocol6(connectionInfo);
break; break;
case RdpVersionEnum.Rdc7: case RdpVersionEnum.Rdc7:
newProtocol = new RdpProtocol7(); newProtocol = new RdpProtocol7(connectionInfo);
break; break;
case RdpVersionEnum.Rdc8: case RdpVersionEnum.Rdc8:
newProtocol = new RdpProtocol8(); newProtocol = new RdpProtocol8(connectionInfo);
break; break;
case RdpVersionEnum.Rdc9: case RdpVersionEnum.Rdc9:
newProtocol = new RdpProtocol9(); newProtocol = new RdpProtocol9(connectionInfo);
break; break;
case RdpVersionEnum.Rdc10: case RdpVersionEnum.Rdc10:
newProtocol = new RdpProtocol10(); newProtocol = new RdpProtocol10(connectionInfo);
break; break;
} }

View File

@@ -13,11 +13,12 @@ namespace mRemoteNG.Connection.Protocol.RDP
public List<RdpVersionEnum> GetSupportedRdpVersions() public List<RdpVersionEnum> GetSupportedRdpVersions()
{ {
var supportedVersions = new List<RdpVersionEnum>(); var supportedVersions = new List<RdpVersionEnum>();
var connectionInfo = new ConnectionInfo();
var rdpFactory = new RdpProtocolFactory(); var rdpFactory = new RdpProtocolFactory();
foreach (var version in RdpVersionEnum.Rdc6.GetAll()) foreach (var version in RdpVersionEnum.Rdc6.GetAll())
{ {
var protocol = rdpFactory.CreateProtocol(version); var protocol = rdpFactory.CreateProtocol(version, connectionInfo);
if (RdpClientIsSupported(protocol)) if (RdpClientIsSupported(protocol))
supportedVersions.Add(version); supportedVersions.Add(version);
} }
@@ -29,7 +30,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
try try
{ {
rdpProtocol.Initialize(); return rdpProtocol.Initialize();
} }
catch (Exception) catch (Exception)
{ {
@@ -39,8 +40,6 @@ namespace mRemoteNG.Connection.Protocol.RDP
{ {
rdpProtocol.Close(); rdpProtocol.Close();
} }
return true;
} }
} }
} }

View File

@@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Rlogin
{ {
public class ProtocolRlogin : PuttyBase public class ProtocolRlogin : PuttyBase
{ {
public ProtocolRlogin(ConnectionInfo connectionInfo)
public ProtocolRlogin() : base(connectionInfo)
{ {
this.PuttyProtocol = Putty_Protocol.rlogin; PuttyProtocol = Putty_Protocol.rlogin;
} }
public enum Defaults public enum Defaults

View File

@@ -4,11 +4,11 @@ namespace mRemoteNG.Connection.Protocol.SSH
{ {
public class ProtocolSSH1 : PuttyBase public class ProtocolSSH1 : PuttyBase
{ {
public ProtocolSSH1(ConnectionInfo connectionInfo)
public ProtocolSSH1() : base(connectionInfo)
{ {
this.PuttyProtocol = Putty_Protocol.ssh; PuttyProtocol = Putty_Protocol.ssh;
this.PuttySSHVersion = Putty_SSHVersion.ssh1; PuttySSHVersion = Putty_SSHVersion.ssh1;
} }
public enum Defaults public enum Defaults

View File

@@ -2,11 +2,11 @@ namespace mRemoteNG.Connection.Protocol.SSH
{ {
public class ProtocolSSH2 : PuttyBase public class ProtocolSSH2 : PuttyBase
{ {
public ProtocolSSH2(ConnectionInfo connectionInfo)
public ProtocolSSH2() : base(connectionInfo)
{ {
this.PuttyProtocol = Putty_Protocol.ssh; PuttyProtocol = Putty_Protocol.ssh;
this.PuttySSHVersion = Putty_SSHVersion.ssh2; PuttySSHVersion = Putty_SSHVersion.ssh2;
} }
public enum Defaults public enum Defaults

View File

@@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Serial
{ {
public class ProtocolSerial : PuttyBase public class ProtocolSerial : PuttyBase
{ {
public ProtocolSerial(ConnectionInfo connectionInfo)
public ProtocolSerial() : base(connectionInfo)
{ {
this.PuttyProtocol = Putty_Protocol.serial; PuttyProtocol = Putty_Protocol.serial;
} }
public enum Defaults public enum Defaults

View File

@@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Telnet
{ {
public class ProtocolTelnet : PuttyBase public class ProtocolTelnet : PuttyBase
{ {
public ProtocolTelnet(ConnectionInfo connectionInfo)
public ProtocolTelnet() : base(connectionInfo)
{ {
this.PuttyProtocol = Putty_Protocol.telnet; PuttyProtocol = Putty_Protocol.telnet;
} }
public enum Defaults public enum Defaults

View File

@@ -10,7 +10,8 @@ namespace mRemoteNG.Connection.Protocol.VNC
{ {
public class ProtocolVNC : ProtocolBase public class ProtocolVNC : ProtocolBase
{ {
#region Properties private VncSharp.RemoteDesktop _VNC;
public bool SmartSize public bool SmartSize
{ {
get { return _VNC.Scaled; } get { return _VNC.Scaled; }
@@ -22,16 +23,11 @@ namespace mRemoteNG.Connection.Protocol.VNC
get { return _VNC.ViewOnly; } get { return _VNC.ViewOnly; }
set { _VNC.ViewOnly = value; } set { _VNC.ViewOnly = value; }
} }
#endregion
#region Private Declarations
private VncSharp.RemoteDesktop _VNC;
private ConnectionInfo Info;
#endregion
#region Public Methods #region Public Methods
public ProtocolVNC() public ProtocolVNC(ConnectionInfo connectionInfo)
: base(connectionInfo)
{ {
Control = new VncSharp.RemoteDesktop(); Control = new VncSharp.RemoteDesktop();
} }
@@ -44,7 +40,7 @@ namespace mRemoteNG.Connection.Protocol.VNC
{ {
_VNC = (VncSharp.RemoteDesktop)Control; _VNC = (VncSharp.RemoteDesktop)Control;
Info = InterfaceControl.Info; Info = InterfaceControl.Protocol.Info;
_VNC.VncPort = Info.Port; _VNC.VncPort = Info.Port;

View File

@@ -437,7 +437,7 @@ namespace mRemoteNG.UI.Menu
foreach (var i in icList) foreach (var i in icList)
{ {
i.Protocol.Close(); i.Protocol.Close();
ConnectionInitiator.OpenConnection(i.Info, ConnectionInfo.Force.DoNotJump); ConnectionInitiator.OpenConnection(i.Protocol.Info, ConnectionInfo.Force.DoNotJump);
} }
// throw it on the garbage collector // throw it on the garbage collector

View File

@@ -2,6 +2,8 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using AxMSTSCLib; using AxMSTSCLib;
using AxWFICALib; using AxWFICALib;
@@ -458,42 +460,26 @@ namespace mRemoteNG.UI.Window
{ {
pnlCheck1.Visible = true; pnlCheck1.Visible = true;
try var tester = new RdpSupportTester();
var supportedRdpVersions = tester.GetSupportedRdpVersions();
if (supportedRdpVersions.Any())
{ {
using (var rdpClient = new AxMsRdpClient8NotSafeForScripting()) pbCheck1.Image = Resources.Good_Symbol;
{ lblCheck1.ForeColor = Color.DarkOliveGreen;
rdpClient.CreateControl(); lblCheck1.Text = "RDP (Remote Desktop) " + Language.strCcCheckSucceeded;
txtCheck1.Text = string.Format(Language.strCcRDPOK, supportedRdpVersions.Aggregate(new StringBuilder(), (builder, enum1) => builder.Append(enum1+",")));
while (!rdpClient.Created) Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "RDP installed", true);
{ return;
Thread.Sleep(10);
System.Windows.Forms.Application.DoEvents();
}
if (!(new Version(rdpClient.Version) >= RdpVersion.RDC80))
{
throw new Exception(
$"Found RDC Client version {rdpClient.Version} but version {RdpVersion.RDC80} or higher is required.");
}
pbCheck1.Image = Resources.Good_Symbol;
lblCheck1.ForeColor = Color.DarkOliveGreen;
lblCheck1.Text = "RDP (Remote Desktop) " + Language.strCcCheckSucceeded;
txtCheck1.Text = string.Format(Language.strCcRDPOK, rdpClient.Version);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "RDP installed", true);
}
} }
catch (Exception ex)
{
pbCheck1.Image = Resources.Bad_Symbol;
lblCheck1.ForeColor = Color.Firebrick;
lblCheck1.Text = "RDP (Remote Desktop) " + Language.strCcCheckFailed;
txtCheck1.Text = string.Format(Language.strCcRDPFailed, GeneralAppInfo.UrlForum);
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, pbCheck1.Image = Resources.Bad_Symbol;
"RDP " + Language.strCcNotInstalledProperly, true); lblCheck1.ForeColor = Color.Firebrick;
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, ex.Message, true); lblCheck1.Text = "RDP (Remote Desktop) " + Language.strCcCheckFailed;
} txtCheck1.Text = string.Format(Language.strCcRDPFailed, GeneralAppInfo.UrlForum);
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg,
"RDP " + Language.strCcNotInstalledProperly, true);
} }
private void CheckVnc() private void CheckVnc()

View File

@@ -160,7 +160,7 @@ namespace mRemoteNG.UI.Window
else else
{ {
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
FrmMain.Default.SelectedConnection = interfaceControl?.Info; FrmMain.Default.SelectedConnection = interfaceControl?.Protocol.Info;
} }
} }
#endregion #endregion
@@ -178,7 +178,7 @@ namespace mRemoteNG.UI.Window
if(ThemeManager.getInstance().ThemingActive) if(ThemeManager.getInstance().ThemingActive)
{ {
base.ApplyTheme(); base.ApplyTheme();
this.vsToolStripExtender = new WeifenLuo.WinFormsUI.Docking.VisualStudioToolStripExtender(this.components); vsToolStripExtender = new VisualStudioToolStripExtender(components);
vsToolStripExtender.DefaultRenderer = _toolStripProfessionalRenderer; vsToolStripExtender.DefaultRenderer = _toolStripProfessionalRenderer;
vsToolStripExtender.SetStyle(cmenTab, ThemeManager.getInstance().ActiveTheme.Version, ThemeManager.getInstance().ActiveTheme.Theme); vsToolStripExtender.SetStyle(cmenTab, ThemeManager.getInstance().ActiveTheme.Version, ThemeManager.getInstance().ActiveTheme.Theme);
TabController.BackColor = ThemeManager.getInstance().ActiveTheme.ExtendedPalette.getColor("Tab_Item_Background"); TabController.BackColor = ThemeManager.getInstance().ActiveTheme.ExtendedPalette.getColor("Tab_Item_Background");
@@ -377,7 +377,7 @@ namespace mRemoteNG.UI.Window
var interfaceControl = (InterfaceControl)TabController.SelectedTab?.Tag; var interfaceControl = (InterfaceControl)TabController.SelectedTab?.Tag;
if (interfaceControl == null) return; if (interfaceControl == null) return;
if (interfaceControl.Info.Protocol == ProtocolType.RDP) if (interfaceControl.Protocol.Info.Protocol == ProtocolType.RDP)
{ {
var rdp = (RdpProtocol6)interfaceControl.Protocol; var rdp = (RdpProtocol6)interfaceControl.Protocol;
cmenTabFullscreen.Visible = true; cmenTabFullscreen.Visible = true;
@@ -391,7 +391,7 @@ namespace mRemoteNG.UI.Window
cmenTabSmartSize.Visible = false; cmenTabSmartSize.Visible = false;
} }
if (interfaceControl.Info.Protocol == ProtocolType.VNC) if (interfaceControl.Protocol.Info.Protocol == ProtocolType.VNC)
{ {
var vnc = (ProtocolVNC)interfaceControl.Protocol; var vnc = (ProtocolVNC)interfaceControl.Protocol;
cmenTabSendSpecialKeys.Visible = true; cmenTabSendSpecialKeys.Visible = true;
@@ -412,7 +412,7 @@ namespace mRemoteNG.UI.Window
cmenTabTransferFile.Visible = false; cmenTabTransferFile.Visible = false;
} }
if (interfaceControl.Info.Protocol == ProtocolType.SSH1 | interfaceControl.Info.Protocol == ProtocolType.SSH2) if (interfaceControl.Protocol.Info.Protocol == ProtocolType.SSH1 | interfaceControl.Protocol.Info.Protocol == ProtocolType.SSH2)
{ {
cmenTabTransferFile.Visible = true; cmenTabTransferFile.Visible = true;
} }
@@ -468,9 +468,9 @@ namespace mRemoteNG.UI.Window
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
if (interfaceControl == null) return; if (interfaceControl == null) return;
if (interfaceControl.Info.Protocol == ProtocolType.SSH1 | interfaceControl.Info.Protocol == ProtocolType.SSH2) if (interfaceControl.Protocol.Info.Protocol == ProtocolType.SSH1 | interfaceControl.Protocol.Info.Protocol == ProtocolType.SSH2)
SshTransferFile(); SshTransferFile();
else if (interfaceControl.Info.Protocol == ProtocolType.VNC) else if (interfaceControl.Protocol.Info.Protocol == ProtocolType.VNC)
VncTransferFile(); VncTransferFile();
} }
catch (Exception ex) catch (Exception ex)
@@ -487,7 +487,7 @@ namespace mRemoteNG.UI.Window
if (interfaceControl == null) return; if (interfaceControl == null) return;
Windows.Show(WindowType.SSHTransfer); Windows.Show(WindowType.SSHTransfer);
var connectionInfo = interfaceControl.Info; var connectionInfo = interfaceControl.Protocol.Info;
Windows.SshtransferForm.Hostname = connectionInfo.Hostname; Windows.SshtransferForm.Hostname = connectionInfo.Hostname;
Windows.SshtransferForm.Username = connectionInfo.Username; Windows.SshtransferForm.Username = connectionInfo.Username;
@@ -640,7 +640,7 @@ namespace mRemoteNG.UI.Window
try try
{ {
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
externalTool.Start(interfaceControl?.Info); externalTool.Start(interfaceControl?.Protocol.Info);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -667,7 +667,7 @@ namespace mRemoteNG.UI.Window
{ {
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
if (interfaceControl == null) return; if (interfaceControl == null) return;
_connectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump); _connectionInitiator.OpenConnection(interfaceControl.Protocol.Info, ConnectionInfo.Force.DoNotJump);
_ignoreChangeSelectedTabClick = false; _ignoreChangeSelectedTabClick = false;
} }
catch (Exception ex) catch (Exception ex)
@@ -683,7 +683,7 @@ namespace mRemoteNG.UI.Window
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
if (interfaceControl == null) return; if (interfaceControl == null) return;
interfaceControl.Protocol.Close(); interfaceControl.Protocol.Close();
_connectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump); _connectionInitiator.OpenConnection(interfaceControl.Protocol.Info, ConnectionInfo.Force.DoNotJump);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -844,7 +844,7 @@ namespace mRemoteNG.UI.Window
try try
{ {
var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
if (interfaceControl?.Info.Protocol == ProtocolType.VNC) if (interfaceControl?.Protocol.Info.Protocol == ProtocolType.VNC)
((ProtocolVNC)interfaceControl.Protocol).RefreshScreen(); ((ProtocolVNC)interfaceControl.Protocol).RefreshScreen();
} }
catch (Exception ex) catch (Exception ex)
@@ -868,7 +868,7 @@ namespace mRemoteNG.UI.Window
if (tabClientRectangle.Contains(MousePosition)) if (tabClientRectangle.Contains(MousePosition))
{ {
var interfaceControl = selectedTab.Tag as InterfaceControl; var interfaceControl = selectedTab.Tag as InterfaceControl;
if (interfaceControl?.Info?.Protocol == ProtocolType.RDP) if (interfaceControl?.Protocol.Info?.Protocol == ProtocolType.RDP)
{ {
interfaceControl.Protocol.Focus(); interfaceControl.Protocol.Focus();
return; // Do not pass to base class return; // Do not pass to base class