mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
make constant id readonly
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using mRemoteNG.Connection;
|
||||
using System;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Connection.Protocol.Http;
|
||||
using mRemoteNG.Connection.Protocol.ICA;
|
||||
@@ -9,10 +10,14 @@ using NUnit.Framework;
|
||||
|
||||
namespace mRemoteNGTests.Connection
|
||||
{
|
||||
public class AbstractConnectionInfoDataTests
|
||||
public class AbstractConnectionInfoDataTests
|
||||
{
|
||||
#pragma warning disable 618
|
||||
private class TestAbstractConnectionInfoData : AbstractConnectionRecord {}
|
||||
private class TestAbstractConnectionInfoData : AbstractConnectionRecord {
|
||||
public TestAbstractConnectionInfoData() : base(Guid.NewGuid().ToString())
|
||||
{
|
||||
}
|
||||
}
|
||||
#pragma warning restore 618
|
||||
private TestAbstractConnectionInfoData _testAbstractConnectionInfoData;
|
||||
|
||||
|
||||
@@ -27,22 +27,6 @@ namespace mRemoteNGTests.Connection
|
||||
_connectionInfo = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatingConnectionInfoWithParentSetsTheParentProperty()
|
||||
{
|
||||
var container = new ContainerInfo();
|
||||
var connectionInfo = new ConnectionInfo(container);
|
||||
Assert.That(connectionInfo.Parent, Is.EqualTo(container));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatingConnectionInfoWithParentAddsToTheParentsChildList()
|
||||
{
|
||||
var container = new ContainerInfo();
|
||||
var connectionInfo = new ConnectionInfo(container);
|
||||
Assert.That(container.Children, Does.Contain(connectionInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyCreatesMemberwiseCopy()
|
||||
{
|
||||
|
||||
@@ -204,7 +204,9 @@ namespace mRemoteNG.Config.Serializers
|
||||
private ConnectionInfo GetConnectionInfoFromXml(XmlNode xmlnode)
|
||||
{
|
||||
if (xmlnode.Attributes == null) return null;
|
||||
var connectionInfo = new ConnectionInfo();
|
||||
|
||||
var connectionId = xmlnode.Attributes["Id"]?.Value ?? Guid.NewGuid().ToString();
|
||||
var connectionInfo = new ConnectionInfo(connectionId);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -491,7 +493,6 @@ namespace mRemoteNG.Config.Serializers
|
||||
|
||||
if (_confVersion >= 2.6)
|
||||
{
|
||||
connectionInfo.ConstantID = xmlnode.Attributes["Id"]?.Value ?? connectionInfo.ConstantID;
|
||||
connectionInfo.SoundQuality = (RdpProtocol.RDPSoundQuality)MiscTools.StringToEnum(typeof(RdpProtocol.RDPSoundQuality), Convert.ToString(xmlnode.Attributes["SoundQuality"].Value));
|
||||
connectionInfo.Inheritance.SoundQuality = bool.Parse(xmlnode.Attributes["InheritSoundQuality"].Value);
|
||||
connectionInfo.RDPMinutesToIdleTimeout = Convert.ToInt32(xmlnode.Attributes["RDPMinutesToIdleTimeout"]?.Value ?? "0");
|
||||
|
||||
@@ -15,7 +15,7 @@ using mRemoteNG.Tree.Root;
|
||||
|
||||
namespace mRemoteNG.Config.Serializers
|
||||
{
|
||||
public class DataTableDeserializer : IDeserializer<DataTable, ConnectionTreeModel>
|
||||
public class DataTableDeserializer : IDeserializer<DataTable, ConnectionTreeModel>
|
||||
{
|
||||
public ConnectionTreeModel Deserialize(DataTable table)
|
||||
{
|
||||
@@ -46,14 +46,16 @@ namespace mRemoteNG.Config.Serializers
|
||||
|
||||
private ConnectionInfo DeserializeConnectionInfo(DataRow row)
|
||||
{
|
||||
var connectionInfo = new ConnectionInfo();
|
||||
var connectionId = row["ConstantID"] as string ?? Guid.NewGuid().ToString();
|
||||
var connectionInfo = new ConnectionInfo(connectionId);
|
||||
PopulateConnectionInfoFromDatarow(row, connectionInfo);
|
||||
return connectionInfo;
|
||||
}
|
||||
|
||||
private ContainerInfo DeserializeContainerInfo(DataRow row)
|
||||
{
|
||||
var containerInfo = new ContainerInfo();
|
||||
var containerId = row["ConstantID"] as string ?? Guid.NewGuid().ToString();
|
||||
var containerInfo = new ContainerInfo(containerId);
|
||||
PopulateConnectionInfoFromDatarow(row, containerInfo);
|
||||
return containerInfo;
|
||||
}
|
||||
@@ -61,7 +63,6 @@ namespace mRemoteNG.Config.Serializers
|
||||
private void PopulateConnectionInfoFromDatarow(DataRow dataRow, ConnectionInfo connectionInfo)
|
||||
{
|
||||
connectionInfo.Name = (string)dataRow["Name"];
|
||||
connectionInfo.ConstantID = (string)dataRow["ConstantID"];
|
||||
|
||||
// This throws a NPE - Parent is a connectionInfo object which will be null at this point.
|
||||
// The Parent object is linked properly later in CreateNodeHierarchy()
|
||||
@@ -187,7 +188,7 @@ namespace mRemoteNG.Config.Serializers
|
||||
private ConnectionTreeModel CreateNodeHierarchy(List<ConnectionInfo> connectionList, DataTable dataTable)
|
||||
{
|
||||
var connectionTreeModel = new ConnectionTreeModel();
|
||||
var rootNode = new RootNodeInfo(RootNodeType.Connection) {ConstantID = "0"};
|
||||
var rootNode = new RootNodeInfo(RootNodeType.Connection, "0");
|
||||
connectionTreeModel.AddRootNode(rootNode);
|
||||
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
|
||||
@@ -498,7 +498,7 @@ namespace mRemoteNG.Connection
|
||||
|
||||
#region Misc
|
||||
[Browsable(false)]
|
||||
public string ConstantID { get; set; }
|
||||
public string ConstantID { get; /*set;*/ }
|
||||
|
||||
[LocalizedAttributes.LocalizedCategory("strCategoryMiscellaneous", 7),
|
||||
LocalizedAttributes.LocalizedDisplayName("strPropertyNameExternalToolBefore"),
|
||||
@@ -658,6 +658,11 @@ namespace mRemoteNG.Connection
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
protected AbstractConnectionRecord(string uniqueId)
|
||||
{
|
||||
ConstantID = uniqueId.ThrowIfNullOrEmpty(nameof(uniqueId));
|
||||
}
|
||||
|
||||
protected virtual TPropertyType GetPropertyValue<TPropertyType>(string propertyName, TPropertyType value)
|
||||
{
|
||||
return (TPropertyType)GetType().GetProperty(propertyName).GetValue(this, null);
|
||||
|
||||
@@ -14,7 +14,6 @@ using mRemoteNG.Connection.Protocol.SSH;
|
||||
using mRemoteNG.Connection.Protocol.Telnet;
|
||||
using mRemoteNG.Connection.Protocol.VNC;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
using mRemoteNG.Tree.Root;
|
||||
|
||||
@@ -52,7 +51,14 @@ namespace mRemoteNG.Connection
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public ConnectionInfo()
|
||||
|
||||
public ConnectionInfo()
|
||||
: this(Guid.NewGuid().ToString())
|
||||
{
|
||||
}
|
||||
|
||||
public ConnectionInfo(string uniqueId)
|
||||
: base(uniqueId)
|
||||
{
|
||||
SetTreeDisplayDefaults();
|
||||
SetConnectionDefaults();
|
||||
@@ -65,12 +71,6 @@ namespace mRemoteNG.Connection
|
||||
SetNonBrowsablePropertiesDefaults();
|
||||
SetDefaults();
|
||||
}
|
||||
|
||||
public ConnectionInfo(ContainerInfo parent) : this()
|
||||
{
|
||||
IsContainer = true;
|
||||
parent.AddChild(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -78,7 +78,6 @@ namespace mRemoteNG.Connection
|
||||
{
|
||||
var newConnectionInfo = new ConnectionInfo();
|
||||
newConnectionInfo.CopyFrom(this);
|
||||
newConnectionInfo.ConstantID = MiscTools.CreateConstantID();
|
||||
newConnectionInfo.Inheritance = Inheritance.Clone();
|
||||
return newConnectionInfo;
|
||||
}
|
||||
@@ -317,7 +316,6 @@ namespace mRemoteNG.Connection
|
||||
|
||||
private void SetMiscDefaults()
|
||||
{
|
||||
ConstantID = MiscTools.CreateConstantID();
|
||||
PreExtApp = Settings.Default.ConDefaultPreExtApp;
|
||||
PostExtApp = Settings.Default.ConDefaultPostExtApp;
|
||||
MacAddress = Settings.Default.ConDefaultMacAddress;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using mRemoteNG.Connection;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
|
||||
namespace mRemoteNG.Container
|
||||
{
|
||||
[DefaultProperty("Name")]
|
||||
[DefaultProperty("Name")]
|
||||
public class ContainerInfo : ConnectionInfo, INotifyCollectionChanged
|
||||
{
|
||||
[Browsable(false)]
|
||||
@@ -20,12 +19,18 @@ namespace mRemoteNG.Container
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
|
||||
public ContainerInfo()
|
||||
public ContainerInfo(string uniqueId)
|
||||
: base(uniqueId)
|
||||
{
|
||||
SetDefaults();
|
||||
IsContainer = true;
|
||||
}
|
||||
|
||||
public ContainerInfo()
|
||||
: this(Guid.NewGuid().ToString())
|
||||
{
|
||||
}
|
||||
|
||||
public override TreeNodeType GetTreeNodeType()
|
||||
{
|
||||
return TreeNodeType.Container;
|
||||
@@ -178,7 +183,6 @@ namespace mRemoteNG.Container
|
||||
{
|
||||
var newContainer = new ContainerInfo();
|
||||
newContainer.CopyFrom(this);
|
||||
newContainer.ConstantID = MiscTools.CreateConstantID();
|
||||
newContainer.OpenConnections = new ProtocolList();
|
||||
newContainer.Inheritance = Inheritance.Clone();
|
||||
foreach (var child in Children.ToArray())
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using mRemoteNG.Tools;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Security;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Security;
|
||||
using mRemoteNG.Tools;
|
||||
|
||||
|
||||
namespace mRemoteNG.Tree.Root
|
||||
@@ -13,11 +12,17 @@ namespace mRemoteNG.Tree.Root
|
||||
private string _name;
|
||||
private string _customPassword = "";
|
||||
|
||||
public RootNodeInfo(RootNodeType rootType)
|
||||
public RootNodeInfo(RootNodeType rootType, string uniqueId)
|
||||
: base(uniqueId)
|
||||
{
|
||||
_name = Language.strConnections;
|
||||
Type = rootType;
|
||||
}
|
||||
|
||||
public RootNodeInfo(RootNodeType rootType)
|
||||
: this(rootType, Guid.NewGuid().ToString())
|
||||
{
|
||||
}
|
||||
|
||||
#region Public Properties
|
||||
|
||||
|
||||
Reference in New Issue
Block a user