mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-26 03:58:45 +08:00
Made ContainerInfo class inherit from ConnectionInfo class
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<TPropertyType>(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;
|
||||
}
|
||||
|
||||
@@ -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<ConnectionInfo> Children { get; set; } = new List<ConnectionInfo>();
|
||||
|
||||
[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
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace mRemoteNG.Container
|
||||
{
|
||||
foreach (ContainerInfo containerInfo in List)
|
||||
{
|
||||
if (containerInfo.ConnectionInfo.ConstantID == id)
|
||||
if (containerInfo.ConstantID == id)
|
||||
{
|
||||
return containerInfo;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user