From 5bd43afcd3265da71dd74aea44822f80eb868fb4 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sun, 11 Feb 2018 20:35:14 -0600 Subject: [PATCH] refactored relationship between protocol objects and interfacecontrol --- .../Connection/ConnectionInfoTests.cs | 4 +- .../Protocol/IntegratedProgramTests.cs | 21 ++-- .../Connection/Protocol/ProtocolListTests.cs | 7 +- mRemoteV1/Connection/ConnectionInitiator.cs | 37 +++---- mRemoteV1/Connection/InterfaceControl.cs | 5 +- .../Protocol/Http/Connection.Protocol.HTTP.cs | 3 +- .../Http/Connection.Protocol.HTTPBase.cs | 29 +++--- .../Http/Connection.Protocol.HTTPS.cs | 4 +- .../Connection/Protocol/ICA/IcaProtocol.cs | 31 +++--- .../Connection/Protocol/IntegratedProgram.cs | 17 ++-- mRemoteV1/Connection/Protocol/ProtocolBase.cs | 14 ++- .../Connection/Protocol/ProtocolFactory.cs | 20 ++-- mRemoteV1/Connection/Protocol/PuttyBase.cs | 21 ++-- .../Connection/Protocol/RAW/RawProtocol.cs | 5 +- .../Connection/Protocol/RDP/RdpProtocol10.cs | 3 +- .../Connection/Protocol/RDP/RdpProtocol6.cs | 97 +++++++++---------- .../Connection/Protocol/RDP/RdpProtocol7.cs | 3 +- .../Connection/Protocol/RDP/RdpProtocol8.cs | 11 ++- .../Connection/Protocol/RDP/RdpProtocol9.cs | 3 +- .../Protocol/RDP/RdpProtocolFactory.cs | 14 +-- .../Protocol/RDP/RdpSupportTester.cs | 7 +- .../Rlogin/Connection.Protocol.Rlogin.cs | 8 +- .../Protocol/SSH/Connection.Protocol.SSH1.cs | 8 +- .../Protocol/SSH/Connection.Protocol.SSH2.cs | 10 +- .../Serial/Connection.Protocol.Serial.cs | 8 +- .../Telnet/Connection.Protocol.Telnet.cs | 8 +- .../Protocol/VNC/Connection.Protocol.VNC.cs | 14 +-- mRemoteV1/UI/Menu/MainFileMenu.cs | 2 +- mRemoteV1/UI/Window/ComponentsCheckWindow.cs | 52 ++++------ mRemoteV1/UI/Window/ConnectionWindow.cs | 26 ++--- 30 files changed, 246 insertions(+), 246 deletions(-) diff --git a/mRemoteNGTests/Connection/ConnectionInfoTests.cs b/mRemoteNGTests/Connection/ConnectionInfoTests.cs index 5475bdb63..d183441bf 100644 --- a/mRemoteNGTests/Connection/ConnectionInfoTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInfoTests.cs @@ -81,7 +81,7 @@ namespace mRemoteNGTests.Connection { var eventWasCalled = false; _connectionInfo.PropertyChanged += (sender, args) => eventWasCalled = true; - _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + _connectionInfo.OpenConnections.Add(new ProtocolSSH2(_connectionInfo)); Assert.That(eventWasCalled); } @@ -90,7 +90,7 @@ namespace mRemoteNGTests.Connection { var nameOfModifiedProperty = ""; _connectionInfo.PropertyChanged += (sender, args) => nameOfModifiedProperty = args.PropertyName; - _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + _connectionInfo.OpenConnections.Add(new ProtocolSSH2(_connectionInfo)); Assert.That(nameOfModifiedProperty, Is.EqualTo("OpenConnections")); } diff --git a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs index 1dc68ae45..a424b2504 100644 --- a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs +++ b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs @@ -1,5 +1,4 @@ -using System.Collections.ObjectModel; -using mRemoteNG.App; +using mRemoteNG.App; using mRemoteNG.Connection; using mRemoteNG.Connection.Protocol; using mRemoteNG.Tools; @@ -12,7 +11,7 @@ namespace mRemoteNGTests.Connection.Protocol { public class IntegratedProgramTests { - private readonly ExternalTool _extTool = new ExternalTool + private readonly ExternalTool _extTool = new ExternalTool { DisplayName = "notepad", FileName = @"%windir%\system32\notepad.exe", @@ -20,13 +19,13 @@ namespace mRemoteNGTests.Connection.Protocol TryIntegrate = true }; - [Test] public void CanStartExternalApp() { SetExternalToolList(_extTool); - var sut = new IntegratedProgram(); - sut.InterfaceControl = BuildInterfaceControl("notepad", sut); + var connectionInfo = new ConnectionInfo { ExtApp = _extTool.DisplayName }; + var sut = new IntegratedProgram(connectionInfo); + sut.InterfaceControl = BuildInterfaceControl(sut); sut.Initialize(); var appStarted = sut.Connect(); sut.Disconnect(); @@ -37,8 +36,9 @@ namespace mRemoteNGTests.Connection.Protocol public void ConnectingToExternalAppThatDoesntExistDoesNothing() { SetExternalToolList(_extTool); - var sut = new IntegratedProgram(); - sut.InterfaceControl = BuildInterfaceControl("doesntExist", sut); + var connectionInfo = new ConnectionInfo { ExtApp = "doesntExist" }; + var sut = new IntegratedProgram(connectionInfo); + sut.InterfaceControl = BuildInterfaceControl(sut); var appInitialized = sut.Initialize(); Assert.That(appInitialized, Is.False); } @@ -48,11 +48,10 @@ namespace mRemoteNGTests.Connection.Protocol Runtime.ExternalToolsService.ExternalTools = new FullyObservableCollection {externalTool}; } - private InterfaceControl BuildInterfaceControl(string extAppName, ProtocolBase sut) + private InterfaceControl BuildInterfaceControl(ProtocolBase sut) { var connectionWindow = new ConnectionWindow(new DockContent()); - var connectionInfo = new ConnectionInfo {ExtApp = extAppName}; - return new InterfaceControl(connectionWindow, sut, connectionInfo); + return new InterfaceControl(connectionWindow, sut); } } } \ No newline at end of file diff --git a/mRemoteNGTests/Connection/Protocol/ProtocolListTests.cs b/mRemoteNGTests/Connection/Protocol/ProtocolListTests.cs index 7ca68e713..030e18109 100644 --- a/mRemoteNGTests/Connection/Protocol/ProtocolListTests.cs +++ b/mRemoteNGTests/Connection/Protocol/ProtocolListTests.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Specialized; +using mRemoteNG.Connection; using mRemoteNG.Connection.Protocol; using mRemoteNG.Connection.Protocol.SSH; using mRemoteNG.Connection.Protocol.Telnet; @@ -21,9 +22,9 @@ namespace mRemoteNGTests.Connection.Protocol public void Setup() { _protocolList = new ProtocolList(); - _protocol1 = new ProtocolTelnet(); - _protocol2 = new ProtocolSSH2(); - _protocol3 = new ProtocolVNC(); + _protocol1 = new ProtocolTelnet(new ConnectionInfo()); + _protocol2 = new ProtocolSSH2(new ConnectionInfo()); + _protocol3 = new ProtocolVNC(new ConnectionInfo()); } [TearDown] diff --git a/mRemoteV1/Connection/ConnectionInitiator.cs b/mRemoteV1/Connection/ConnectionInitiator.cs index d7f8d2af9..717c0939e 100644 --- a/mRemoteV1/Connection/ConnectionInitiator.cs +++ b/mRemoteV1/Connection/ConnectionInitiator.cs @@ -100,7 +100,7 @@ namespace mRemoteNG.Connection var connectionContainer = SetConnectionContainer(connectionInfo, connectionForm); SetConnectionFormEventHandlers(newProtocol, connectionForm); SetConnectionEventHandlers(newProtocol); - BuildConnectionInterfaceController(connectionInfo, newProtocol, connectionContainer); + BuildConnectionInterfaceController(newProtocol, connectionContainer); newProtocol.Force = force; @@ -144,7 +144,7 @@ namespace mRemoteNG.Connection { var ic = t.Controls[0] as InterfaceControl; if (ic == null) continue; - if (ic.Info == connectionInfo) + if (ic.Protocol.Info == connectionInfo) { return ic; } @@ -213,9 +213,9 @@ namespace mRemoteNG.Connection 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 @@ -233,7 +233,7 @@ namespace mRemoteNG.Connection Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strProtocolEventDisconnected, disconnectedMessage), true); 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 desc = disconnectedMessage.Replace("\r\n", " "); @@ -253,19 +253,20 @@ namespace mRemoteNG.Connection var prot = (ProtocolBase)sender; Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnenctionCloseEvent, true); string connDetail; - if (prot.InterfaceControl.Info.Hostname == "" && prot.InterfaceControl.Info.Protocol == ProtocolType.IntApp) - connDetail = prot.InterfaceControl.Info.ExtApp; - else if (prot.InterfaceControl.Info.Hostname != "") - connDetail = prot.InterfaceControl.Info.Hostname; + if (prot.Info.Hostname == "" && prot.Info.Protocol == ProtocolType.IntApp) + connDetail = prot.Info.ExtApp; + else if (prot.Info.Hostname != "") + connDetail = prot.Info.Hostname; else connDetail = "UNKNOWN"; - Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strConnenctionClosedByUser, connDetail, prot.InterfaceControl.Info.Protocol, Environment.UserName)); - prot.InterfaceControl.Info.OpenConnections.Remove(prot); + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, + string.Format(Language.strConnenctionClosedByUser, connDetail, prot.Info.Protocol, Environment.UserName)); + prot.Info.OpenConnections.Remove(prot); - if (prot.InterfaceControl.Info.PostExtApp == "") return; - var extA = Runtime.ExternalToolsService.GetExtAppByName(prot.InterfaceControl.Info.PostExtApp); - extA?.Start(prot.InterfaceControl.Info); + if (prot.Info.PostExtApp == "") return; + var extA = Runtime.ExternalToolsService.GetExtAppByName(prot.Info.PostExtApp); + extA?.Start(prot.Info); } catch (Exception ex) { @@ -277,7 +278,8 @@ namespace mRemoteNG.Connection { var prot = (ProtocolBase)sender; 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) @@ -287,11 +289,12 @@ namespace mRemoteNG.Connection Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventErrorOccured, true); var prot = (ProtocolBase)sender; - if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return; + if (prot.Info.Protocol != ProtocolType.RDP) return; var errorMessageAsInt = Convert.ToInt32(errorMessage); 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) { diff --git a/mRemoteV1/Connection/InterfaceControl.cs b/mRemoteV1/Connection/InterfaceControl.cs index 185d5023e..5034f0952 100644 --- a/mRemoteV1/Connection/InterfaceControl.cs +++ b/mRemoteV1/Connection/InterfaceControl.cs @@ -10,15 +10,12 @@ namespace mRemoteNG.Connection public sealed partial class InterfaceControl { public ProtocolBase Protocol { get; set; } - public ConnectionInfo Info { get; set; } - - public InterfaceControl(Control parent, ProtocolBase protocol, ConnectionInfo info) + public InterfaceControl(Control parent, ProtocolBase protocol) { try { Protocol = protocol; - Info = info; Parent = parent; Location = new Point(0, 0); Size = Parent.Size; diff --git a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTP.cs b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTP.cs index cbdaca2fd..070621bd0 100644 --- a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTP.cs +++ b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTP.cs @@ -3,7 +3,8 @@ namespace mRemoteNG.Connection.Protocol.Http public class ProtocolHTTP : HTTPBase { - public ProtocolHTTP(RenderingEngine RenderingEngine) : base(RenderingEngine) + public ProtocolHTTP(ConnectionInfo connectionInfo, RenderingEngine renderingEngine) + : base(connectionInfo, renderingEngine) { httpOrS = "http"; defaultPort = (int)Defaults.Port; diff --git a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs index 75206bacb..7e5ed1de1 100644 --- a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs +++ b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs @@ -9,20 +9,19 @@ namespace mRemoteNG.Connection.Protocol.Http { public class HTTPBase : ProtocolBase { - #region Private Properties private Control wBrowser; + private string tabTitle; protected string httpOrS; protected int defaultPort; - private string tabTitle; - #endregion #region Public Methods - protected HTTPBase(RenderingEngine RenderingEngine) - { + protected HTTPBase(ConnectionInfo connectionInfo, RenderingEngine renderingEngine) + : base(connectionInfo) + { try { - if (RenderingEngine == RenderingEngine.Gecko) + if (renderingEngine == RenderingEngine.Gecko) { if(!Xpcom.IsInitialized) Xpcom.Initialize("Firefox"); @@ -58,7 +57,7 @@ namespace mRemoteNG.Connection.Protocol.Http { wBrowser = Control; - if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) + if (Info.RenderingEngine == RenderingEngine.Gecko) { var GeckoBrowser = (GeckoWebBrowser) wBrowser; if (GeckoBrowser != null) @@ -96,7 +95,7 @@ namespace mRemoteNG.Connection.Protocol.Http { try { - var strHost = InterfaceControl.Info.Hostname; + var strHost = Info.Hostname; /* * Commenting out since this codes doesn't actually do anything at this time... * 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; } */ - if (InterfaceControl.Info.Port != defaultPort) + if (Info.Port != defaultPort) { if (strHost.EndsWith("/")) { @@ -120,13 +119,13 @@ namespace mRemoteNG.Connection.Protocol.Http 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 { - ((WebBrowser)wBrowser).Navigate(strHost + ":" + InterfaceControl.Info.Port); + ((WebBrowser)wBrowser).Navigate(strHost + ":" + Info.Port); } } else @@ -136,7 +135,7 @@ namespace mRemoteNG.Connection.Protocol.Http strHost = httpOrS + "://" + strHost; } - if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) + if (Info.RenderingEngine == RenderingEngine.Gecko) { ((GeckoWebBrowser)wBrowser).Navigate(strHost); } @@ -181,7 +180,7 @@ namespace mRemoteNG.Connection.Protocol.Http if (tabP == null) return; string shortTitle; - if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) + if (Info.RenderingEngine == RenderingEngine.Gecko) { if (((GeckoWebBrowser) wBrowser).DocumentTitle.Length >= 15) { @@ -229,7 +228,7 @@ namespace mRemoteNG.Connection.Protocol.Http if (tabP == null) return; string shortTitle; - if (InterfaceControl.Info.RenderingEngine == RenderingEngine.Gecko) + if (Info.RenderingEngine == RenderingEngine.Gecko) { if (((GeckoWebBrowser)wBrowser).DocumentTitle.Length >= 15) { diff --git a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPS.cs b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPS.cs index 08f28a927..66f4b837c 100644 --- a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPS.cs +++ b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPS.cs @@ -2,8 +2,8 @@ namespace mRemoteNG.Connection.Protocol.Http { public class ProtocolHTTPS : HTTPBase { - - public ProtocolHTTPS(RenderingEngine RenderingEngine) : base(RenderingEngine) + public ProtocolHTTPS(ConnectionInfo connectionInfo, RenderingEngine renderingEngine) + : base(connectionInfo, renderingEngine) { httpOrS = "https"; defaultPort = (int)Defaults.Port; diff --git a/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs b/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs index dbe48be5e..7cc3b2964 100644 --- a/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs +++ b/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs @@ -16,11 +16,11 @@ namespace mRemoteNG.Connection.Protocol.ICA public class IcaProtocol : ProtocolBase { private AxICAClient _icaClient; - private ConnectionInfo _info; private readonly FrmMain _frmMain = FrmMain.Default; #region Public Methods - public IcaProtocol() + public IcaProtocol(ConnectionInfo connectionInfo) + : base(connectionInfo) { try { @@ -39,7 +39,6 @@ namespace mRemoteNG.Connection.Protocol.ICA try { _icaClient = (AxICAClient)Control; - _info = InterfaceControl.Info; _icaClient.CreateControl(); while (!_icaClient.Created) @@ -48,7 +47,7 @@ namespace mRemoteNG.Connection.Protocol.ICA Application.DoEvents(); } - _icaClient.Address = _info.Hostname; + _icaClient.Address = Info.Hostname; SetCredentials(); SetResolution(); SetColors(); @@ -78,8 +77,8 @@ namespace mRemoteNG.Connection.Protocol.ICA _icaClient.Hotkey11Shift = null; _icaClient.Hotkey11Char = null; - _icaClient.PersistentCacheEnabled = _info.CacheBitmaps; - _icaClient.Title = _info.Name; + _icaClient.PersistentCacheEnabled = Info.CacheBitmaps; + _icaClient.Title = Info.Name; return true; } catch (Exception ex) @@ -117,9 +116,9 @@ namespace mRemoteNG.Connection.Protocol.ICA return; } - var user = _info?.Username ?? ""; - var pass = _info?.Password ?? ""; - var dom = _info?.Domain ?? ""; + var user = Info?.Username ?? ""; + var pass = Info?.Password ?? ""; + var dom = Info?.Domain ?? ""; if (string.IsNullOrEmpty(user)) { @@ -187,22 +186,22 @@ namespace mRemoteNG.Connection.Protocol.ICA return; } - if (InterfaceControl.Info.Resolution == RdpResolutions.FitToWindow) + if (Info.Resolution == RdpResolutions.FitToWindow) { _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); } - 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.FullScreenWindow(); } else { - var resolution = _info.Resolution.GetResolutionRectangle(); + var resolution = Info.Resolution.GetResolutionRectangle(); _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, resolution.Width, resolution.Height, 0); } } @@ -215,7 +214,7 @@ namespace mRemoteNG.Connection.Protocol.ICA private void SetColors() { // ReSharper disable once SwitchStatementMissingSomeCases - switch (_info.Colors) + switch (Info.Colors) { case RdpColors.Colors256: _icaClient.SetProp("DesiredColor", "2"); @@ -235,7 +234,7 @@ namespace mRemoteNG.Connection.Protocol.ICA private void SetSecurity() { // ReSharper disable once SwitchStatementMissingSomeCases - switch (_info.ICAEncryptionStrength) + switch (Info.ICAEncryptionStrength) { case EncryptionStrength.Encr128BitLogonOnly: _icaClient.Encrypt = true; @@ -312,7 +311,7 @@ namespace mRemoteNG.Connection.Protocol.ICA #region Reconnect Stuff 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; diff --git a/mRemoteV1/Connection/Protocol/IntegratedProgram.cs b/mRemoteV1/Connection/Protocol/IntegratedProgram.cs index 32129ceee..03a57cb8f 100644 --- a/mRemoteV1/Connection/Protocol/IntegratedProgram.cs +++ b/mRemoteV1/Connection/Protocol/IntegratedProgram.cs @@ -11,27 +11,30 @@ namespace mRemoteNG.Connection.Protocol { public class IntegratedProgram : ProtocolBase { - #region Private Fields private ExternalTool _externalTool; private IntPtr _handle; private Process _process; - #endregion + + public IntegratedProgram(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + } #region Public Methods public override bool Initialize() { - if (InterfaceControl.Info == null) + if (Info == null) return base.Initialize(); - _externalTool = Runtime.ExternalToolsService.GetExtAppByName(InterfaceControl.Info.ExtApp); + _externalTool = Runtime.ExternalToolsService.GetExtAppByName(Info.ExtApp); 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; } - _externalTool.ConnectionInfo = InterfaceControl.Info; + _externalTool.ConnectionInfo = Info; return base.Initialize(); } @@ -44,7 +47,7 @@ namespace mRemoteNG.Connection.Protocol 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 * _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... diff --git a/mRemoteV1/Connection/Protocol/ProtocolBase.cs b/mRemoteV1/Connection/Protocol/ProtocolBase.cs index 2e6a6296d..1a0a98814 100644 --- a/mRemoteV1/Connection/Protocol/ProtocolBase.cs +++ b/mRemoteV1/Connection/Protocol/ProtocolBase.cs @@ -41,6 +41,7 @@ namespace mRemoteNG.Connection.Protocol protected Control Control { get; set; } + public ConnectionInfo Info { get; set; } #endregion public ConnectionInfo.Force Force { get; set; } @@ -49,12 +50,19 @@ namespace mRemoteNG.Connection.Protocol protected ReconnectGroup ReconnectGroup; #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; } - protected ProtocolBase() + protected ProtocolBase(ConnectionInfo connectionInfo) + : this(connectionInfo, "") { } @@ -108,7 +116,7 @@ namespace mRemoteNG.Connection.Protocol public virtual bool Connect() { - if (InterfaceControl.Info.Protocol == ProtocolType.RDP) return false; + if (Info.Protocol == ProtocolType.RDP) return false; RaiseConnectionConnectedEvent(this); return true; } diff --git a/mRemoteV1/Connection/Protocol/ProtocolFactory.cs b/mRemoteV1/Connection/Protocol/ProtocolFactory.cs index 9bddde8f2..7042e14dd 100644 --- a/mRemoteV1/Connection/Protocol/ProtocolFactory.cs +++ b/mRemoteV1/Connection/Protocol/ProtocolFactory.cs @@ -22,35 +22,35 @@ namespace mRemoteNG.Connection.Protocol newProtocol = new RdpProtocolFactory().CreateProtocol(connectionInfo); break; case ProtocolType.VNC: - newProtocol = new ProtocolVNC(); + newProtocol = new ProtocolVNC(connectionInfo); break; case ProtocolType.SSH1: - newProtocol = new ProtocolSSH1(); + newProtocol = new ProtocolSSH1(connectionInfo); break; case ProtocolType.SSH2: - newProtocol = new ProtocolSSH2(); + newProtocol = new ProtocolSSH2(connectionInfo); break; case ProtocolType.Telnet: - newProtocol = new ProtocolTelnet(); + newProtocol = new ProtocolTelnet(connectionInfo); break; case ProtocolType.Rlogin: - newProtocol = new ProtocolRlogin(); + newProtocol = new ProtocolRlogin(connectionInfo); break; case ProtocolType.RAW: - newProtocol = new RawProtocol(); + newProtocol = new RawProtocol(connectionInfo); break; case ProtocolType.HTTP: - newProtocol = new ProtocolHTTP(connectionInfo.RenderingEngine); + newProtocol = new ProtocolHTTP(connectionInfo, connectionInfo.RenderingEngine); break; case ProtocolType.HTTPS: - newProtocol = new ProtocolHTTPS(connectionInfo.RenderingEngine); + newProtocol = new ProtocolHTTPS(connectionInfo, connectionInfo.RenderingEngine); break; case ProtocolType.ICA: - newProtocol = new IcaProtocol(); + newProtocol = new IcaProtocol(connectionInfo); ((IcaProtocol) newProtocol).tmrReconnect.Elapsed += ((IcaProtocol) newProtocol).tmrReconnect_Elapsed; break; case ProtocolType.IntApp: - newProtocol = new IntegratedProgram(); + newProtocol = new IntegratedProgram(connectionInfo); if (connectionInfo.ExtApp == "") { throw (new Exception(Language.strNoExtAppDefined)); diff --git a/mRemoteV1/Connection/Protocol/PuttyBase.cs b/mRemoteV1/Connection/Protocol/PuttyBase.cs index 3c83d00ae..e9de7037d 100644 --- a/mRemoteV1/Connection/Protocol/PuttyBase.cs +++ b/mRemoteV1/Connection/Protocol/PuttyBase.cs @@ -36,6 +36,11 @@ namespace mRemoteNG.Connection.Protocol #endregion + public PuttyBase(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + } + #region Private Events & Handlers private void ProcessExited(object sender, EventArgs e) { @@ -61,9 +66,9 @@ namespace mRemoteNG.Connection.Protocol 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); @@ -72,9 +77,9 @@ namespace mRemoteNG.Connection.Protocol var username = ""; var password = ""; - if (!string.IsNullOrEmpty(InterfaceControl.Info?.Username)) + if (!string.IsNullOrEmpty(Info?.Username)) { - username = InterfaceControl.Info.Username; + username = Info.Username; } 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 { @@ -118,8 +123,8 @@ namespace mRemoteNG.Connection.Protocol } } - arguments.Add("-P", InterfaceControl.Info.Port.ToString()); - arguments.Add(InterfaceControl.Info.Hostname); + arguments.Add("-P", Info.Port.ToString()); + arguments.Add(Info.Hostname); } if (_isPuttyNg) diff --git a/mRemoteV1/Connection/Protocol/RAW/RawProtocol.cs b/mRemoteV1/Connection/Protocol/RAW/RawProtocol.cs index 4e9643e35..f8afbcb47 100644 --- a/mRemoteV1/Connection/Protocol/RAW/RawProtocol.cs +++ b/mRemoteV1/Connection/Protocol/RAW/RawProtocol.cs @@ -2,8 +2,9 @@ namespace mRemoteNG.Connection.Protocol.RAW { public class RawProtocol : PuttyBase { - public RawProtocol() - { + public RawProtocol(ConnectionInfo connectionInfo) + : base(connectionInfo) + { PuttyProtocol = Putty_Protocol.raw; } diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol10.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol10.cs index 9e8f78d98..7f297672a 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol10.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol10.cs @@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP { public class RdpProtocol10 : RdpProtocol9 { - public RdpProtocol10() + public RdpProtocol10(ConnectionInfo connectionInfo) + : base(connectionInfo) { Control = new AxMsRdpClient10NotSafeForScripting(); RdpVersionEnum = RdpVersionEnum.Rdc10; diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol6.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol6.cs index b6a86bb46..2c4969225 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol6.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol6.cs @@ -20,7 +20,6 @@ namespace mRemoteNG.Connection.Protocol.RDP private readonly FrmMain _frmMain = FrmMain.Default; protected MsRdpClient6NotSafeForScripting RdpClient; protected bool LoginComplete; - protected ConnectionInfo ConnectionInfo; #region Properties public virtual bool SmartSize @@ -82,7 +81,8 @@ namespace mRemoteNG.Connection.Protocol.RDP #endregion - public RdpProtocol6() + public RdpProtocol6(ConnectionInfo connectionInfo) + : base(connectionInfo) { Control = new AxMsRdpClient6NotSafeForScripting(); Connecting += OnConnectingDebugMessage; @@ -97,7 +97,6 @@ namespace mRemoteNG.Connection.Protocol.RDP try { Control.CreateControl(); - ConnectionInfo = InterfaceControl.Info; try { @@ -117,14 +116,14 @@ namespace mRemoteNG.Connection.Protocol.RDP _rdpVersion = new Version(RdpClient.Version); - RdpClient.Server = ConnectionInfo.Hostname; + RdpClient.Server = Info.Hostname; SetCredentials(); SetResolution(); - RdpClient.FullScreenTitle = ConnectionInfo.Name; + RdpClient.FullScreenTitle = Info.Name; - _alertOnIdleDisconnect = ConnectionInfo.RDPAlertIdleTimeout; - RdpClient.AdvancedSettings2.MinutesToIdleTimeout = ConnectionInfo.RDPMinutesToIdleTimeout; + _alertOnIdleDisconnect = Info.RDPAlertIdleTimeout; + RdpClient.AdvancedSettings2.MinutesToIdleTimeout = Info.RDPMinutesToIdleTimeout; //not user changeable RdpClient.AdvancedSettings2.GrabFocusOnConnect = true; @@ -136,21 +135,21 @@ namespace mRemoteNG.Connection.Protocol.RDP RdpClient.AdvancedSettings2.overallConnectionTimeout = Settings.Default.ConRDPOverallConnectionTimeout; - RdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(ConnectionInfo.CacheBitmaps); + RdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(Info.CacheBitmaps); if (_rdpVersion >= RdpVersion.RDC61) { - RdpClient.AdvancedSettings7.EnableCredSspSupport = ConnectionInfo.UseCredSsp; + RdpClient.AdvancedSettings7.EnableCredSspSupport = Info.UseCredSsp; } SetUseConsoleSession(); SetPort(); - RedirectKeys = ConnectionInfo.RedirectKeys; + RedirectKeys = Info.RedirectKeys; SetRedirection(); SetAuthenticationLevel(); SetLoadBalanceInfo(); SetRdGateway(); - RdpClient.ColorDepth = (int)ConnectionInfo.Colors; + RdpClient.ColorDepth = (int)Info.Colors; SetPerformanceFlags(); @@ -257,32 +256,32 @@ namespace mRemoteNG.Connection.Protocol.RDP } 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.GatewayHostname = ConnectionInfo.RDGatewayHostname; + RdpClient.TransportSettings.GatewayUsageMethod = (uint)Info.RDGatewayUsageMethod; + RdpClient.TransportSettings.GatewayHostname = Info.RDGatewayHostname; 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 } 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.GatewayPassword = ConnectionInfo.Password; - RdpClient.TransportSettings2.GatewayDomain = ConnectionInfo?.Domain; + RdpClient.TransportSettings2.GatewayUsername = Info.Username; + RdpClient.TransportSettings2.GatewayPassword = Info.Password; + RdpClient.TransportSettings2.GatewayDomain = Info?.Domain; } - else if (ConnectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard) + else if (Info.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.SmartCard) { RdpClient.TransportSettings2.GatewayCredSharing = 0; } else { - RdpClient.TransportSettings2.GatewayUsername = ConnectionInfo.RDGatewayUsername; - RdpClient.TransportSettings2.GatewayPassword = ConnectionInfo.RDGatewayPassword; - RdpClient.TransportSettings2.GatewayDomain = ConnectionInfo.RDGatewayDomain; + RdpClient.TransportSettings2.GatewayUsername = Info.RDGatewayUsername; + RdpClient.TransportSettings2.GatewayPassword = Info.RDGatewayPassword; + RdpClient.TransportSettings2.GatewayDomain = Info.RDGatewayDomain; RdpClient.TransportSettings2.GatewayCredSharing = 0; } } @@ -310,7 +309,7 @@ namespace mRemoteNG.Connection.Protocol.RDP } else { - value = ConnectionInfo.UseConsoleSession; + value = Info.UseConsoleSession; } if (_rdpVersion >= RdpVersion.RDC61) @@ -341,9 +340,9 @@ namespace mRemoteNG.Connection.Protocol.RDP return; } - var userName = ConnectionInfo?.Username ?? ""; - var password = ConnectionInfo?.Password ?? ""; - var domain = ConnectionInfo?.Domain ?? ""; + var userName = Info?.Username ?? ""; + var password = Info?.Password ?? ""; + var domain = Info?.Domain ?? ""; if (string.IsNullOrEmpty(userName)) { @@ -412,19 +411,19 @@ namespace mRemoteNG.Connection.Protocol.RDP 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.DesktopHeight = InterfaceControl.Size.Height; - if (InterfaceControl.Info.Resolution == RdpResolutions.SmartSize) + if (Info.Resolution == RdpResolutions.SmartSize) { RdpClient.AdvancedSettings2.SmartSizing = true; } } - else if (InterfaceControl.Info.Resolution == RdpResolutions.Fullscreen) + else if (Info.Resolution == RdpResolutions.Fullscreen) { RdpClient.FullScreen = true; RdpClient.DesktopWidth = Screen.FromControl(_frmMain).Bounds.Width; @@ -432,7 +431,7 @@ namespace mRemoteNG.Connection.Protocol.RDP } else { - var resolution = ConnectionInfo.Resolution.GetResolutionRectangle(); + var resolution = Info.Resolution.GetResolutionRectangle(); RdpClient.DesktopWidth = resolution.Width; RdpClient.DesktopHeight = resolution.Height; } @@ -447,9 +446,9 @@ namespace mRemoteNG.Connection.Protocol.RDP { 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) @@ -462,11 +461,11 @@ namespace mRemoteNG.Connection.Protocol.RDP { try { - RdpClient.AdvancedSettings2.RedirectDrives = ConnectionInfo.RedirectDiskDrives; - RdpClient.AdvancedSettings2.RedirectPorts = ConnectionInfo.RedirectPorts; - RdpClient.AdvancedSettings2.RedirectPrinters = ConnectionInfo.RedirectPrinters; - RdpClient.AdvancedSettings2.RedirectSmartCards = ConnectionInfo.RedirectSmartCards; - RdpClient.SecuredSettings2.AudioRedirectionMode = (int)ConnectionInfo.RedirectSound; + RdpClient.AdvancedSettings2.RedirectDrives = Info.RedirectDiskDrives; + RdpClient.AdvancedSettings2.RedirectPorts = Info.RedirectPorts; + RdpClient.AdvancedSettings2.RedirectPrinters = Info.RedirectPrinters; + RdpClient.AdvancedSettings2.RedirectSmartCards = Info.RedirectSmartCards; + RdpClient.SecuredSettings2.AudioRedirectionMode = (int)Info.RedirectSound; } catch (Exception ex) { @@ -479,22 +478,22 @@ namespace mRemoteNG.Connection.Protocol.RDP try { var pFlags = 0; - if (ConnectionInfo.DisplayThemes == false) + if (Info.DisplayThemes == false) { pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableThemes); } - if (ConnectionInfo.DisplayWallpaper == false) + if (Info.DisplayWallpaper == false) { pFlags += Convert.ToInt32(RdpPerformanceFlags.DisableWallpaper); } - if (ConnectionInfo.EnableFontSmoothing) + if (Info.EnableFontSmoothing) { pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableFontSmoothing); } - if (ConnectionInfo.EnableDesktopComposition) + if (Info.EnableDesktopComposition) { pFlags += Convert.ToInt32(RdpPerformanceFlags.EnableDesktopComposition); } @@ -511,7 +510,7 @@ namespace mRemoteNG.Connection.Protocol.RDP { try { - RdpClient.AdvancedSettings5.AuthenticationLevel = (uint)ConnectionInfo.RDPAuthenticationLevel; + RdpClient.AdvancedSettings5.AuthenticationLevel = (uint)Info.RDPAuthenticationLevel; } catch (Exception ex) { @@ -521,15 +520,15 @@ namespace mRemoteNG.Connection.Protocol.RDP private void SetLoadBalanceInfo() { - if (string.IsNullOrEmpty(ConnectionInfo.LoadBalanceInfo)) + if (string.IsNullOrEmpty(Info.LoadBalanceInfo)) { return; } try { RdpClient.AdvancedSettings2.LoadBalanceInfo = LoadBalanceInfoUseUtf8 - ? new AzureLoadBalanceInfoEncoder().Encode(ConnectionInfo.LoadBalanceInfo) - : ConnectionInfo.LoadBalanceInfo; + ? new AzureLoadBalanceInfoEncoder().Encode(Info.LoadBalanceInfo) + : Info.LoadBalanceInfo; } catch (Exception ex) { @@ -558,7 +557,7 @@ namespace mRemoteNG.Connection.Protocol.RDP private void OnConnectingDebugMessage(object sender, EventArgs args) { 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 @@ -569,7 +568,7 @@ namespace mRemoteNG.Connection.Protocol.RDP 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"; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } @@ -641,7 +640,7 @@ 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)); + var srvReady = PortScanner.IsPortOpen(Info.Hostname, Convert.ToString(Info.Port)); ReconnectGroup.ServerReady = srvReady; diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol7.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol7.cs index 05d3c8e80..b4943a310 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol7.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol7.cs @@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP { public class RdpProtocol7 : RdpProtocol6 { - public RdpProtocol7() + public RdpProtocol7(ConnectionInfo connectionInfo) + : base(connectionInfo) { Control = new AxMsRdpClient7NotSafeForScripting(); RdpVersionEnum = RdpVersionEnum.Rdc7; diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol8.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol8.cs index 8d75ca598..ff952884c 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol8.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol8.cs @@ -39,8 +39,9 @@ namespace mRemoteNG.Connection.Protocol.RDP } } - public RdpProtocol8() - { + public RdpProtocol8(ConnectionInfo connectionInfo) + : base(connectionInfo) + { Control = new AxMsRdpClient8NotSafeForScripting(); RdpVersionEnum = RdpVersionEnum.Rdc8; } @@ -50,7 +51,7 @@ namespace mRemoteNG.Connection.Protocol.RDP base.Initialize(); try { - _rdpClient.AdvancedSettings8.AudioQualityMode = (uint)ConnectionInfo.SoundQuality; + _rdpClient.AdvancedSettings8.AudioQualityMode = (uint)Info.SoundQuality; } catch (Exception ex) { @@ -95,10 +96,10 @@ namespace mRemoteNG.Connection.Protocol.RDP if (!LoginComplete) return; - if (!InterfaceControl.Info.AutomaticResize) + if (!Info.AutomaticResize) return; - if (!(InterfaceControl.Info.Resolution == RdpResolutions.FitToWindow | InterfaceControl.Info.Resolution == RdpResolutions.Fullscreen)) + if (!(Info.Resolution == RdpResolutions.FitToWindow | Info.Resolution == RdpResolutions.Fullscreen)) return; if (SmartSize) diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol9.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol9.cs index a41b38128..f0e9c749a 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol9.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol9.cs @@ -5,7 +5,8 @@ namespace mRemoteNG.Connection.Protocol.RDP { public class RdpProtocol9 : RdpProtocol8 { - public RdpProtocol9() + public RdpProtocol9(ConnectionInfo connectionInfo) + : base(connectionInfo) { Control = new AxMsRdpClient9NotSafeForScripting(); RdpVersionEnum = RdpVersionEnum.Rdc9; diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocolFactory.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocolFactory.cs index 7bdb77e1c..5fd500f3e 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocolFactory.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocolFactory.cs @@ -4,10 +4,10 @@ { 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; @@ -15,19 +15,19 @@ switch (version) { case RdpVersionEnum.Rdc6: - newProtocol = new RdpProtocol6(); + newProtocol = new RdpProtocol6(connectionInfo); break; case RdpVersionEnum.Rdc7: - newProtocol = new RdpProtocol7(); + newProtocol = new RdpProtocol7(connectionInfo); break; case RdpVersionEnum.Rdc8: - newProtocol = new RdpProtocol8(); + newProtocol = new RdpProtocol8(connectionInfo); break; case RdpVersionEnum.Rdc9: - newProtocol = new RdpProtocol9(); + newProtocol = new RdpProtocol9(connectionInfo); break; case RdpVersionEnum.Rdc10: - newProtocol = new RdpProtocol10(); + newProtocol = new RdpProtocol10(connectionInfo); break; } diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpSupportTester.cs b/mRemoteV1/Connection/Protocol/RDP/RdpSupportTester.cs index 5fc633adf..9a1feb1cd 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpSupportTester.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpSupportTester.cs @@ -13,11 +13,12 @@ namespace mRemoteNG.Connection.Protocol.RDP public List GetSupportedRdpVersions() { var supportedVersions = new List(); + var connectionInfo = new ConnectionInfo(); var rdpFactory = new RdpProtocolFactory(); foreach (var version in RdpVersionEnum.Rdc6.GetAll()) { - var protocol = rdpFactory.CreateProtocol(version); + var protocol = rdpFactory.CreateProtocol(version, connectionInfo); if (RdpClientIsSupported(protocol)) supportedVersions.Add(version); } @@ -29,7 +30,7 @@ namespace mRemoteNG.Connection.Protocol.RDP { try { - rdpProtocol.Initialize(); + return rdpProtocol.Initialize(); } catch (Exception) { @@ -39,8 +40,6 @@ namespace mRemoteNG.Connection.Protocol.RDP { rdpProtocol.Close(); } - - return true; } } } diff --git a/mRemoteV1/Connection/Protocol/Rlogin/Connection.Protocol.Rlogin.cs b/mRemoteV1/Connection/Protocol/Rlogin/Connection.Protocol.Rlogin.cs index 6a8b187b3..af650d95e 100644 --- a/mRemoteV1/Connection/Protocol/Rlogin/Connection.Protocol.Rlogin.cs +++ b/mRemoteV1/Connection/Protocol/Rlogin/Connection.Protocol.Rlogin.cs @@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Rlogin { public class ProtocolRlogin : PuttyBase { - - public ProtocolRlogin() - { - this.PuttyProtocol = Putty_Protocol.rlogin; + public ProtocolRlogin(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + PuttyProtocol = Putty_Protocol.rlogin; } public enum Defaults diff --git a/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH1.cs b/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH1.cs index 53d59a282..548d5e49e 100644 --- a/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH1.cs +++ b/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH1.cs @@ -4,11 +4,11 @@ namespace mRemoteNG.Connection.Protocol.SSH { public class ProtocolSSH1 : PuttyBase { - - public ProtocolSSH1() + public ProtocolSSH1(ConnectionInfo connectionInfo) + : base(connectionInfo) { - this.PuttyProtocol = Putty_Protocol.ssh; - this.PuttySSHVersion = Putty_SSHVersion.ssh1; + PuttyProtocol = Putty_Protocol.ssh; + PuttySSHVersion = Putty_SSHVersion.ssh1; } public enum Defaults diff --git a/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH2.cs b/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH2.cs index 2fa12b4f7..642c648f6 100644 --- a/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH2.cs +++ b/mRemoteV1/Connection/Protocol/SSH/Connection.Protocol.SSH2.cs @@ -2,11 +2,11 @@ namespace mRemoteNG.Connection.Protocol.SSH { public class ProtocolSSH2 : PuttyBase { - - public ProtocolSSH2() - { - this.PuttyProtocol = Putty_Protocol.ssh; - this.PuttySSHVersion = Putty_SSHVersion.ssh2; + public ProtocolSSH2(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + PuttyProtocol = Putty_Protocol.ssh; + PuttySSHVersion = Putty_SSHVersion.ssh2; } public enum Defaults diff --git a/mRemoteV1/Connection/Protocol/Serial/Connection.Protocol.Serial.cs b/mRemoteV1/Connection/Protocol/Serial/Connection.Protocol.Serial.cs index 9e8d2ffd9..ed81e4ce4 100644 --- a/mRemoteV1/Connection/Protocol/Serial/Connection.Protocol.Serial.cs +++ b/mRemoteV1/Connection/Protocol/Serial/Connection.Protocol.Serial.cs @@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Serial { public class ProtocolSerial : PuttyBase { - - public ProtocolSerial() - { - this.PuttyProtocol = Putty_Protocol.serial; + public ProtocolSerial(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + PuttyProtocol = Putty_Protocol.serial; } public enum Defaults diff --git a/mRemoteV1/Connection/Protocol/Telnet/Connection.Protocol.Telnet.cs b/mRemoteV1/Connection/Protocol/Telnet/Connection.Protocol.Telnet.cs index 7fc93cbfd..ef3196c60 100644 --- a/mRemoteV1/Connection/Protocol/Telnet/Connection.Protocol.Telnet.cs +++ b/mRemoteV1/Connection/Protocol/Telnet/Connection.Protocol.Telnet.cs @@ -2,10 +2,10 @@ namespace mRemoteNG.Connection.Protocol.Telnet { public class ProtocolTelnet : PuttyBase { - - public ProtocolTelnet() - { - this.PuttyProtocol = Putty_Protocol.telnet; + public ProtocolTelnet(ConnectionInfo connectionInfo) + : base(connectionInfo) + { + PuttyProtocol = Putty_Protocol.telnet; } public enum Defaults diff --git a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs index 8098a4990..6cfae7b87 100644 --- a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs +++ b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs @@ -10,7 +10,8 @@ namespace mRemoteNG.Connection.Protocol.VNC { public class ProtocolVNC : ProtocolBase { - #region Properties + private VncSharp.RemoteDesktop _VNC; + public bool SmartSize { get { return _VNC.Scaled; } @@ -22,16 +23,11 @@ namespace mRemoteNG.Connection.Protocol.VNC get { return _VNC.ViewOnly; } set { _VNC.ViewOnly = value; } } - - #endregion - #region Private Declarations - private VncSharp.RemoteDesktop _VNC; - private ConnectionInfo Info; - #endregion #region Public Methods - public ProtocolVNC() + public ProtocolVNC(ConnectionInfo connectionInfo) + : base(connectionInfo) { Control = new VncSharp.RemoteDesktop(); } @@ -44,7 +40,7 @@ namespace mRemoteNG.Connection.Protocol.VNC { _VNC = (VncSharp.RemoteDesktop)Control; - Info = InterfaceControl.Info; + Info = InterfaceControl.Protocol.Info; _VNC.VncPort = Info.Port; diff --git a/mRemoteV1/UI/Menu/MainFileMenu.cs b/mRemoteV1/UI/Menu/MainFileMenu.cs index 9a95be158..f529549be 100644 --- a/mRemoteV1/UI/Menu/MainFileMenu.cs +++ b/mRemoteV1/UI/Menu/MainFileMenu.cs @@ -437,7 +437,7 @@ namespace mRemoteNG.UI.Menu foreach (var i in icList) { i.Protocol.Close(); - ConnectionInitiator.OpenConnection(i.Info, ConnectionInfo.Force.DoNotJump); + ConnectionInitiator.OpenConnection(i.Protocol.Info, ConnectionInfo.Force.DoNotJump); } // throw it on the garbage collector diff --git a/mRemoteV1/UI/Window/ComponentsCheckWindow.cs b/mRemoteV1/UI/Window/ComponentsCheckWindow.cs index ed2306b99..ade47a3c2 100644 --- a/mRemoteV1/UI/Window/ComponentsCheckWindow.cs +++ b/mRemoteV1/UI/Window/ComponentsCheckWindow.cs @@ -2,6 +2,8 @@ using System; using System.Diagnostics; using System.Drawing; using System.IO; +using System.Linq; +using System.Text; using System.Threading; using AxMSTSCLib; using AxWFICALib; @@ -458,42 +460,26 @@ namespace mRemoteNG.UI.Window { pnlCheck1.Visible = true; - try + var tester = new RdpSupportTester(); + var supportedRdpVersions = tester.GetSupportedRdpVersions(); + + if (supportedRdpVersions.Any()) { - using (var rdpClient = new AxMsRdpClient8NotSafeForScripting()) - { - rdpClient.CreateControl(); - - while (!rdpClient.Created) - { - 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); - } + pbCheck1.Image = Resources.Good_Symbol; + lblCheck1.ForeColor = Color.DarkOliveGreen; + lblCheck1.Text = "RDP (Remote Desktop) " + Language.strCcCheckSucceeded; + txtCheck1.Text = string.Format(Language.strCcRDPOK, supportedRdpVersions.Aggregate(new StringBuilder(), (builder, enum1) => builder.Append(enum1+","))); + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "RDP installed", true); + return; } - 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, - "RDP " + Language.strCcNotInstalledProperly, true); - Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, ex.Message, true); - } + 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, + "RDP " + Language.strCcNotInstalledProperly, true); } private void CheckVnc() diff --git a/mRemoteV1/UI/Window/ConnectionWindow.cs b/mRemoteV1/UI/Window/ConnectionWindow.cs index 4ccc30467..9d1ed95ba 100644 --- a/mRemoteV1/UI/Window/ConnectionWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionWindow.cs @@ -160,7 +160,7 @@ namespace mRemoteNG.UI.Window else { var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; - FrmMain.Default.SelectedConnection = interfaceControl?.Info; + FrmMain.Default.SelectedConnection = interfaceControl?.Protocol.Info; } } #endregion @@ -178,7 +178,7 @@ namespace mRemoteNG.UI.Window if(ThemeManager.getInstance().ThemingActive) { base.ApplyTheme(); - this.vsToolStripExtender = new WeifenLuo.WinFormsUI.Docking.VisualStudioToolStripExtender(this.components); + vsToolStripExtender = new VisualStudioToolStripExtender(components); vsToolStripExtender.DefaultRenderer = _toolStripProfessionalRenderer; vsToolStripExtender.SetStyle(cmenTab, ThemeManager.getInstance().ActiveTheme.Version, ThemeManager.getInstance().ActiveTheme.Theme); TabController.BackColor = ThemeManager.getInstance().ActiveTheme.ExtendedPalette.getColor("Tab_Item_Background"); @@ -377,7 +377,7 @@ namespace mRemoteNG.UI.Window var interfaceControl = (InterfaceControl)TabController.SelectedTab?.Tag; if (interfaceControl == null) return; - if (interfaceControl.Info.Protocol == ProtocolType.RDP) + if (interfaceControl.Protocol.Info.Protocol == ProtocolType.RDP) { var rdp = (RdpProtocol6)interfaceControl.Protocol; cmenTabFullscreen.Visible = true; @@ -391,7 +391,7 @@ namespace mRemoteNG.UI.Window cmenTabSmartSize.Visible = false; } - if (interfaceControl.Info.Protocol == ProtocolType.VNC) + if (interfaceControl.Protocol.Info.Protocol == ProtocolType.VNC) { var vnc = (ProtocolVNC)interfaceControl.Protocol; cmenTabSendSpecialKeys.Visible = true; @@ -412,7 +412,7 @@ namespace mRemoteNG.UI.Window 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; } @@ -468,9 +468,9 @@ namespace mRemoteNG.UI.Window var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; 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(); - else if (interfaceControl.Info.Protocol == ProtocolType.VNC) + else if (interfaceControl.Protocol.Info.Protocol == ProtocolType.VNC) VncTransferFile(); } catch (Exception ex) @@ -487,7 +487,7 @@ namespace mRemoteNG.UI.Window if (interfaceControl == null) return; Windows.Show(WindowType.SSHTransfer); - var connectionInfo = interfaceControl.Info; + var connectionInfo = interfaceControl.Protocol.Info; Windows.SshtransferForm.Hostname = connectionInfo.Hostname; Windows.SshtransferForm.Username = connectionInfo.Username; @@ -640,7 +640,7 @@ namespace mRemoteNG.UI.Window try { var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; - externalTool.Start(interfaceControl?.Info); + externalTool.Start(interfaceControl?.Protocol.Info); } catch (Exception ex) { @@ -667,7 +667,7 @@ namespace mRemoteNG.UI.Window { var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; if (interfaceControl == null) return; - _connectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump); + _connectionInitiator.OpenConnection(interfaceControl.Protocol.Info, ConnectionInfo.Force.DoNotJump); _ignoreChangeSelectedTabClick = false; } catch (Exception ex) @@ -683,7 +683,7 @@ namespace mRemoteNG.UI.Window var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; if (interfaceControl == null) return; interfaceControl.Protocol.Close(); - _connectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump); + _connectionInitiator.OpenConnection(interfaceControl.Protocol.Info, ConnectionInfo.Force.DoNotJump); } catch (Exception ex) { @@ -844,7 +844,7 @@ namespace mRemoteNG.UI.Window try { var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl; - if (interfaceControl?.Info.Protocol == ProtocolType.VNC) + if (interfaceControl?.Protocol.Info.Protocol == ProtocolType.VNC) ((ProtocolVNC)interfaceControl.Protocol).RefreshScreen(); } catch (Exception ex) @@ -868,7 +868,7 @@ namespace mRemoteNG.UI.Window if (tabClientRectangle.Contains(MousePosition)) { var interfaceControl = selectedTab.Tag as InterfaceControl; - if (interfaceControl?.Info?.Protocol == ProtocolType.RDP) + if (interfaceControl?.Protocol.Info?.Protocol == ProtocolType.RDP) { interfaceControl.Protocol.Focus(); return; // Do not pass to base class