From c471f621b2be134559619cc4d54db134b73d7889 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 5 Oct 2016 12:37:05 -0600 Subject: [PATCH] #141 ConnectionInfo now listens to collection changed events from the ProtocolList and raises a PropertyChanged event for OpenConnections when the list contents changes. --- .../Connection/ConnectionInfoTests.cs | 19 +++++++++++++++++++ mRemoteV1/Connection/ConnectionInfo.cs | 17 +++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/mRemoteNGTests/Connection/ConnectionInfoTests.cs b/mRemoteNGTests/Connection/ConnectionInfoTests.cs index b3f80c68..6db4eed9 100644 --- a/mRemoteNGTests/Connection/ConnectionInfoTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInfoTests.cs @@ -1,4 +1,5 @@ using mRemoteNG.Connection; +using mRemoteNG.Connection.Protocol.SSH; using mRemoteNG.Container; using NUnit.Framework; @@ -53,5 +54,23 @@ namespace mRemoteNGTests.Connection _connectionInfo.CopyFrom(secondConnection); Assert.That(_connectionInfo.Domain, Is.EqualTo(secondConnection.Domain)); } + + [Test] + public void PropertyChangedEventRaisedWhenOpenConnectionsChanges() + { + var eventWasCalled = false; + _connectionInfo.PropertyChanged += (sender, args) => eventWasCalled = true; + _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + Assert.That(eventWasCalled); + } + + [Test] + public void PropertyChangedEventArgsAreCorrectWhenOpenConnectionsChanges() + { + var nameOfModifiedProperty = ""; + _connectionInfo.PropertyChanged += (sender, args) => nameOfModifiedProperty = args.PropertyName; + _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + Assert.That(nameOfModifiedProperty, Is.EqualTo("OpenConnections")); + } } } \ No newline at end of file diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 4d711876..75b4d331 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -30,7 +30,7 @@ namespace mRemoteNG.Connection public ConnectionInfoInheritance Inheritance { get; set; } [Browsable(false)] - public ProtocolList OpenConnections { get; set; } + public ProtocolList OpenConnections { get; protected set; } [Browsable(false)] public bool IsContainer { get; set; } @@ -83,14 +83,13 @@ namespace mRemoteNG.Connection newConnectionInfo.CopyFrom(this); newConnectionInfo.ConstantID = MiscTools.CreateConstantID(); newConnectionInfo.SetParent(Parent); - newConnectionInfo.OpenConnections = new ProtocolList(); newConnectionInfo.Inheritance = Inheritance.Clone(); return newConnectionInfo; } - public void CopyFrom(ConnectionInfo sourceConnectionInfo) + public void CopyFrom(AbstractConnectionInfoData sourceConnectionInfo) { - var properties = typeof(ConnectionInfo).GetProperties(); + var properties = typeof(AbstractConnectionInfoData).GetProperties(); foreach (var property in properties) { var remotePropertyValue = property.GetValue(sourceConnectionInfo, null); @@ -319,9 +318,15 @@ namespace mRemoteNG.Connection private void SetNonBrowsablePropertiesDefaults() { Inheritance = new ConnectionInfoInheritance(this); - OpenConnections = new ProtocolList(); + SetNewOpenConnectionList(); PositionID = 0; } + + protected void SetNewOpenConnectionList() + { + OpenConnections = new ProtocolList(); + OpenConnections.CollectionChanged += (sender, args) => RaisePropertyChangedEvent(this, new PropertyChangedEventArgs("OpenConnections")); + } #endregion - } + } } \ No newline at end of file