diff --git a/mRemoteV1/Config/Connections/ConnectionsSaver.cs b/mRemoteV1/Config/Connections/ConnectionsSaver.cs index 3fa8a8ff4..e8074fdf5 100644 --- a/mRemoteV1/Config/Connections/ConnectionsSaver.cs +++ b/mRemoteV1/Config/Connections/ConnectionsSaver.cs @@ -248,7 +248,7 @@ namespace mRemoteNG.Config.Connections if (ConnectionTreeNode.GetNodeType(node) == TreeNodeType.Container) //container { _sqlQuery.CommandText += "\'" + ContainerList[node.Tag].IsExpanded + "\',"; //Expanded - curConI = ContainerList[node.Tag].ConnectionInfo; + curConI = ContainerList[node.Tag]; SaveConnectionFieldsSQL(curConI); _sqlQuery.CommandText = MiscTools.PrepareForDB(_sqlQuery.CommandText); @@ -512,7 +512,7 @@ namespace mRemoteNG.Config.Connections { if (with_1.Parent != null) { - _parentConstantId = Convert.ToString(with_1.Parent.ConnectionInfo.ConstantID); + _parentConstantId = Convert.ToString(with_1.Parent.ConstantID); } else { @@ -523,7 +523,7 @@ namespace mRemoteNG.Config.Connections { if (with_1.Parent.Parent != null) { - _parentConstantId = Convert.ToString(with_1.Parent.Parent.ConnectionInfo.ConstantID); + _parentConstantId = Convert.ToString(with_1.Parent.Parent.ConstantID); } else { @@ -652,7 +652,7 @@ namespace mRemoteNG.Config.Connections if (ConnectionTreeNode.GetNodeType(node) == TreeNodeType.Container) //container { _xmlTextWriter.WriteAttributeString("Expanded", "", Convert.ToString(ContainerList[node.Tag].TreeNode.IsExpanded)); - curConI = ContainerList[node.Tag].ConnectionInfo; + curConI = ContainerList[node.Tag]; SaveConnectionFields(curConI); SaveNode(node.Nodes); _xmlTextWriter.WriteEndElement(); diff --git a/mRemoteV1/Config/Connections/SqlConnectionsLoader.cs b/mRemoteV1/Config/Connections/SqlConnectionsLoader.cs index 0c58f7516..746693d3f 100644 --- a/mRemoteV1/Config/Connections/SqlConnectionsLoader.cs +++ b/mRemoteV1/Config/Connections/SqlConnectionsLoader.cs @@ -268,7 +268,7 @@ namespace mRemoteNG.Config.Connections var conI = GetConnectionInfoFromSql(); conI.Parent = contI; conI.IsContainer = true; - contI.ConnectionInfo = conI; + contI.CopyFrom(conI); if (DatabaseUpdate) { diff --git a/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs index a0d411f5b..c4a59a123 100644 --- a/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs +++ b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs @@ -162,7 +162,7 @@ namespace mRemoteNG.Config.Connections { var connectionInfo = GetConnectionInfoFromXml(xmlNode); connectionInfo.TreeNode = treeNode; - connectionInfo.Parent = _previousContainer; //NEW + connectionInfo.Parent = _previousContainer; ConnectionList.Add(connectionInfo); treeNode.Tag = connectionInfo; treeNode.ImageIndex = (int)TreeImageType.ConnectionClosed; @@ -172,24 +172,19 @@ namespace mRemoteNG.Config.Connections private void AddContainerToList(XmlNode xmlNode, TreeNode treeNode) { var containerInfo = new ContainerInfo(); - if (treeNode.Parent != null) - { - if (ConnectionTreeNode.GetNodeType(treeNode.Parent) == TreeNodeType.Container) - containerInfo.Parent = (ContainerInfo) treeNode.Parent.Tag; - } - _previousContainer = containerInfo; //NEW - containerInfo.TreeNode = treeNode; - containerInfo.Name = xmlNode.Attributes["Name"].Value; if (_confVersion >= 0.8) - { - containerInfo.IsExpanded = xmlNode.Attributes["Expanded"].Value == "True"; - } + containerInfo.IsExpanded = xmlNode.Attributes?["Expanded"].Value == "True"; + if (_confVersion >= 0.9) + containerInfo.CopyFrom(GetConnectionInfoFromXml(xmlNode)); - var connectionInfo = _confVersion >= 0.9 ? GetConnectionInfoFromXml(xmlNode) : new ConnectionInfo(); - connectionInfo.Parent = containerInfo; - connectionInfo.IsContainer = true; - containerInfo.ConnectionInfo = connectionInfo; + if (treeNode.Parent?.Tag is ContainerInfo) + containerInfo.Parent = (ContainerInfo) treeNode.Parent.Tag; + + containerInfo.TreeNode = treeNode; + containerInfo.Name = xmlNode.Attributes?["Name"].Value; + + _previousContainer = containerInfo; ContainerList.Add(containerInfo); treeNode.Tag = containerInfo; treeNode.ImageIndex = (int) TreeImageType.Container; diff --git a/mRemoteV1/Config/Import/ActiveDirectory.cs b/mRemoteV1/Config/Import/ActiveDirectory.cs index 9318fc47e..045da331b 100644 --- a/mRemoteV1/Config/Import/ActiveDirectory.cs +++ b/mRemoteV1/Config/Import/ActiveDirectory.cs @@ -19,7 +19,6 @@ namespace mRemoteNG.Config.Import var containerInfo = new ContainerInfo(); containerInfo.TreeNode = treeNode; - containerInfo.ConnectionInfo = new ConnectionInfo(containerInfo); var name = ""; var match = Regex.Match(ldapPath, "ou=([^,]*)", RegexOptions.IgnoreCase); @@ -41,7 +40,7 @@ namespace mRemoteNG.Config.Import } else { - containerInfo.ConnectionInfo.Inheritance.DisableInheritance(); + containerInfo.Inheritance.DisableInheritance(); } treeNode.Text = name; diff --git a/mRemoteV1/Config/Import/PuttyConnectionManager.cs b/mRemoteV1/Config/Import/PuttyConnectionManager.cs index d4ac496ce..da66322a0 100644 --- a/mRemoteV1/Config/Import/PuttyConnectionManager.cs +++ b/mRemoteV1/Config/Import/PuttyConnectionManager.cs @@ -68,7 +68,7 @@ namespace mRemoteNG.Config.Import ConnectionInfo connectionInfo = CreateConnectionInfo(name); connectionInfo.Parent = containerInfo; connectionInfo.IsContainer = true; - containerInfo.ConnectionInfo = connectionInfo; + containerInfo.CopyFrom(connectionInfo); // We can only inherit from a container node, not the root node or connection nodes if (ConnectionTreeNode.GetNodeType(parentTreeNode) == TreeNodeType.Container) diff --git a/mRemoteV1/Config/Import/RemoteDesktopConnectionManager.cs b/mRemoteV1/Config/Import/RemoteDesktopConnectionManager.cs index e1c9e3e0d..00ef91bf0 100644 --- a/mRemoteV1/Config/Import/RemoteDesktopConnectionManager.cs +++ b/mRemoteV1/Config/Import/RemoteDesktopConnectionManager.cs @@ -51,7 +51,7 @@ namespace mRemoteNG.Config.Import ConnectionInfo connectionInfo = ConnectionInfoFromXml(propertiesNode); connectionInfo.Parent = containerInfo; connectionInfo.IsContainer = true; - containerInfo.ConnectionInfo = connectionInfo; + containerInfo.CopyFrom(connectionInfo); // We can only inherit from a container node, not the root node or connection nodes if (ConnectionTreeNode.GetNodeType(parentTreeNode) == TreeNodeType.Container) diff --git a/mRemoteV1/Config/Import/mRemoteNG.cs b/mRemoteV1/Config/Import/mRemoteNG.cs index a35778823..25261a97b 100644 --- a/mRemoteV1/Config/Import/mRemoteNG.cs +++ b/mRemoteV1/Config/Import/mRemoteNG.cs @@ -29,7 +29,7 @@ namespace mRemoteNG.Config.Import connectionInfo.TreeNode = treeNode; connectionInfo.Parent = containerInfo; connectionInfo.IsContainer = true; - containerInfo.ConnectionInfo = connectionInfo; + containerInfo.CopyFrom(connectionInfo); // We can only inherit from a container node, not the root node or connection nodes if (ConnectionTreeNode.GetNodeType(parentTreeNode) == TreeNodeType.Container) diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index c98156d5a..4477dda23 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -2,7 +2,6 @@ using System; using System.Windows.Forms; using System.ComponentModel; using mRemoteNG.Tools; -using System.Reflection; using mRemoteNG.App; using mRemoteNG.Connection.Protocol.VNC; using mRemoteNG.Connection.Protocol.SSH; @@ -20,7 +19,7 @@ using mRemoteNG.Messages; namespace mRemoteNG.Connection { [DefaultProperty("Name")] - public class ConnectionInfo : Parent,IInheritable + public class ConnectionInfo : Parent, IInheritable { #region Private Properties // Private properties with public get/set @@ -672,13 +671,23 @@ namespace mRemoteNG.Connection #endregion #region Public Methods - public ConnectionInfo Copy() + public virtual ConnectionInfo Copy() { var newConnectionInfo = (ConnectionInfo)MemberwiseClone(); newConnectionInfo.ConstantID = MiscTools.CreateConstantID(); newConnectionInfo.OpenConnections = new ProtocolList(); return newConnectionInfo; } + + public void CopyFrom(ConnectionInfo sourceConnectionInfo) + { + var properties = typeof(ConnectionInfo).GetProperties(); + foreach (var property in properties) + { + var remotePropertyValue = property.GetValue(sourceConnectionInfo, null); + property.SetValue(this, remotePropertyValue, null); + } + } public void SetDefaults() { @@ -739,10 +748,9 @@ namespace mRemoteNG.Connection private TPropertyType GetInheritedPropertyValue(string propertyName) { - var parentConnectionInfo = IsContainer ? Parent.Parent.ConnectionInfo : Parent.ConnectionInfo; - var connectionInfoType = parentConnectionInfo.GetType(); + var connectionInfoType = Parent.GetType(); var parentPropertyInfo = connectionInfoType.GetProperty(propertyName); - var parentPropertyValue = (TPropertyType)parentPropertyInfo.GetValue(parentConnectionInfo, null); + var parentPropertyValue = (TPropertyType)parentPropertyInfo.GetValue(Parent, null); return parentPropertyValue; } diff --git a/mRemoteV1/Container/ContainerInfo.cs b/mRemoteV1/Container/ContainerInfo.cs index 5a76f521b..1c3f1591e 100644 --- a/mRemoteV1/Container/ContainerInfo.cs +++ b/mRemoteV1/Container/ContainerInfo.cs @@ -1,60 +1,20 @@ +using System.Collections.Generic; using mRemoteNG.Connection; -using mRemoteNG.Tools; using System.ComponentModel; -using System.Windows.Forms; namespace mRemoteNG.Container { [DefaultProperty("Name")] - public class ContainerInfo : Parent,IInheritable + public class ContainerInfo : ConnectionInfo { - #region Properties - [LocalizedAttributes.LocalizedCategory("strCategoryDisplay", 1), - Browsable(true), - ReadOnly(false), - Bindable(false), - DefaultValue(""), - DesignOnly(false), - LocalizedAttributes.LocalizedDisplayName("strPropertyNameName"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionName")] - public string Name - { - get { return ConnectionInfo.Name; } - set { ConnectionInfo.Name = value; } - } - - [Category(""), - Browsable(false), - ReadOnly(false), - Bindable(false), - DefaultValue(""), - DesignOnly(false)] - public TreeNode TreeNode { get; set; } + [Browsable(false)] + public List Children { get; set; } = new List(); - [Category(""), Browsable(false)] - public ContainerInfo Parent { get; set; } - - [Category(""), Browsable(false)] - public ConnectionInfoInheritance Inheritance - { - get { return ConnectionInfo.Inheritance; } - set { ConnectionInfo.Inheritance = value; } - } - - [Category(""), - Browsable(false), - ReadOnly(false), - Bindable(false), - DefaultValue(""), - DesignOnly(false)] + [Category(""), Browsable(false), ReadOnly(false), + Bindable(false), DefaultValue(""), DesignOnly(false)] public bool IsExpanded { get; set; } - - public ConnectionInfo ConnectionInfo { get; set; } = new ConnectionInfo(); - - #endregion - #region Methods - public ContainerInfo Copy() + public new ContainerInfo Copy() { return (ContainerInfo)MemberwiseClone(); } @@ -62,12 +22,12 @@ namespace mRemoteNG.Container public ContainerInfo() { SetDefaults(); + IsContainer = true; } public void SetDefaults() { IsExpanded = true; } - #endregion } } \ No newline at end of file diff --git a/mRemoteV1/Container/ContainerList.cs b/mRemoteV1/Container/ContainerList.cs index 5a7709977..ac021387d 100644 --- a/mRemoteV1/Container/ContainerList.cs +++ b/mRemoteV1/Container/ContainerList.cs @@ -44,7 +44,7 @@ namespace mRemoteNG.Container { foreach (ContainerInfo containerInfo in List) { - if (containerInfo.ConnectionInfo.ConstantID == id) + if (containerInfo.ConstantID == id) { return containerInfo; } diff --git a/mRemoteV1/Tree/ConnectionTree.cs b/mRemoteV1/Tree/ConnectionTree.cs index f827fa017..8d3a3cce0 100644 --- a/mRemoteV1/Tree/ConnectionTree.cs +++ b/mRemoteV1/Tree/ConnectionTree.cs @@ -133,7 +133,7 @@ namespace mRemoteNG.Tree { Container.ContainerInfo containerInfo = SelectedNode.Tag as Container.ContainerInfo; if (containerInfo != null) - ConnectionTreeNode.RenameNode(containerInfo.ConnectionInfo, newName); + ConnectionTreeNode.RenameNode(containerInfo, newName); } public static void SetNodeToolTip(MouseEventArgs e, ToolTip tTip) diff --git a/mRemoteV1/Tree/ConnectionTreeNode.cs b/mRemoteV1/Tree/ConnectionTreeNode.cs index 6bbc66b23..d623c6198 100644 --- a/mRemoteV1/Tree/ConnectionTreeNode.cs +++ b/mRemoteV1/Tree/ConnectionTreeNode.cs @@ -18,7 +18,7 @@ namespace mRemoteNG.Tree if (GetNodeType(node) == TreeNodeType.Connection) return (node.Tag as ConnectionInfo).ConstantID; else if (GetNodeType(node) == TreeNodeType.Container) - return (node.Tag as ContainerInfo).ConnectionInfo.ConstantID; + return (node.Tag as ContainerInfo).ConstantID; return null; } @@ -181,14 +181,14 @@ namespace mRemoteNG.Tree ContainerInfo oldContainerInfo = (ContainerInfo) oldTreeNode.Tag; ContainerInfo newContainerInfo = oldContainerInfo.Copy(); - ConnectionInfo newConnectionInfo = oldContainerInfo.ConnectionInfo.Copy(); - newContainerInfo.ConnectionInfo = newConnectionInfo; + ConnectionInfo newConnectionInfo = oldContainerInfo.Copy(); + newContainerInfo.CopyFrom(newConnectionInfo); TreeNode newTreeNode = new TreeNode(newContainerInfo.Name); newTreeNode.Tag = newContainerInfo; newTreeNode.ImageIndex = (int)TreeImageType.Container; newTreeNode.SelectedImageIndex = (int)TreeImageType.Container; - newContainerInfo.ConnectionInfo.Parent = newContainerInfo; + newContainerInfo.Parent = newContainerInfo; Runtime.ContainerList.Add(newContainerInfo); diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs index 902e1cbcc..52433cc6b 100644 --- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs @@ -159,7 +159,7 @@ namespace mRemoteNG.UI.Window } else if (ConnectionTreeNode.GetNodeType(e.Node) == TreeNodeType.Container) { - Windows.configForm.SetPropertyGridObject(((ContainerInfo) e.Node.Tag).ConnectionInfo); + Windows.configForm.SetPropertyGridObject((ContainerInfo) e.Node.Tag); } else if ((ConnectionTreeNode.GetNodeType(e.Node) == TreeNodeType.Root) || (ConnectionTreeNode.GetNodeType(e.Node) == TreeNodeType.PuttyRoot)) { @@ -709,8 +709,7 @@ namespace mRemoteNG.UI.Window parentNode = selectedNode; } - newContainerInfo.ConnectionInfo = new ConnectionInfo(newContainerInfo); - newContainerInfo.ConnectionInfo.Name = newNode.Text; + newContainerInfo.Name = newNode.Text; // We can only inherit from a container node, not the root node or connection nodes if (ConnectionTreeNode.GetNodeType(parentNode) == TreeNodeType.Container) @@ -719,7 +718,7 @@ namespace mRemoteNG.UI.Window } else { - newContainerInfo.ConnectionInfo.Inheritance.DisableInheritance(); + newContainerInfo.Inheritance.DisableInheritance(); } Runtime.ContainerList.Add(newContainerInfo);