mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-25 19:38:37 +08:00
Updated the ISerialize interface to require a Serialize(ConnectionInfo) method to support serializing a target connection/container
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Security;
|
||||
@@ -17,17 +16,15 @@ namespace mRemoteNG.Config.Serializers
|
||||
|
||||
public string Serialize(ConnectionTreeModel connectionTreeModel)
|
||||
{
|
||||
var rootNode = (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return SerializeToCsv(rootNode);
|
||||
var rootNode = connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return Serialize(rootNode);
|
||||
}
|
||||
|
||||
private string SerializeToCsv(RootNodeInfo rootNodeInfo)
|
||||
public string Serialize(ConnectionInfo serializationTarget)
|
||||
{
|
||||
if (Runtime.IsConnectionsFileLoaded == false)
|
||||
return "";
|
||||
_csv = "";
|
||||
WriteCsvHeader();
|
||||
SerializeNodesRecursive(rootNodeInfo);
|
||||
SerializeNodesRecursive(serializationTarget);
|
||||
return _csv;
|
||||
}
|
||||
|
||||
@@ -47,15 +44,21 @@ namespace mRemoteNG.Config.Serializers
|
||||
_csv += csvHeader;
|
||||
}
|
||||
|
||||
private void SerializeNodesRecursive(ContainerInfo containerInfo)
|
||||
private void SerializeNodesRecursive(ConnectionInfo node)
|
||||
{
|
||||
foreach (var child in containerInfo.Children)
|
||||
var nodeAsContainer = node as ContainerInfo;
|
||||
if (nodeAsContainer != null)
|
||||
{
|
||||
if (child is ContainerInfo)
|
||||
SerializeNodesRecursive((ContainerInfo)child);
|
||||
else
|
||||
SerializeConnectionInfo(child);
|
||||
foreach (var child in nodeAsContainer.Children)
|
||||
{
|
||||
if (child is ContainerInfo)
|
||||
SerializeNodesRecursive((ContainerInfo) child);
|
||||
else
|
||||
SerializeConnectionInfo(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
SerializeConnectionInfo(node);
|
||||
}
|
||||
|
||||
private void SerializeConnectionInfo(ConnectionInfo con)
|
||||
|
||||
@@ -15,29 +15,32 @@ namespace mRemoteNG.Config.Serializers
|
||||
|
||||
public string Serialize(ConnectionTreeModel connectionTreeModel)
|
||||
{
|
||||
var rootNode = (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return SerializeToCsv(rootNode);
|
||||
var rootNode = connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return Serialize(rootNode);
|
||||
}
|
||||
|
||||
private string SerializeToCsv(RootNodeInfo rootNodeInfo)
|
||||
public string Serialize(ConnectionInfo serializationTarget)
|
||||
{
|
||||
if (Runtime.IsConnectionsFileLoaded == false)
|
||||
return "";
|
||||
|
||||
_csv = "";
|
||||
SerializeNodesRecursive(rootNodeInfo);
|
||||
SerializeNodesRecursive(serializationTarget);
|
||||
return _csv;
|
||||
}
|
||||
|
||||
private void SerializeNodesRecursive(ContainerInfo containerInfo)
|
||||
private void SerializeNodesRecursive(ConnectionInfo node)
|
||||
{
|
||||
foreach (var child in containerInfo.Children)
|
||||
var nodeAsContainer = node as ContainerInfo;
|
||||
if (nodeAsContainer != null)
|
||||
{
|
||||
if (child is ContainerInfo)
|
||||
SerializeNodesRecursive((ContainerInfo)child);
|
||||
else if (child.Protocol == ProtocolType.RDP)
|
||||
SerializeConnectionInfo(child);
|
||||
foreach (var child in nodeAsContainer.Children)
|
||||
{
|
||||
if (child is ContainerInfo)
|
||||
SerializeNodesRecursive((ContainerInfo)child);
|
||||
else if (child.Protocol == ProtocolType.RDP)
|
||||
SerializeConnectionInfo(child);
|
||||
}
|
||||
}
|
||||
else if (node.Protocol == ProtocolType.RDP)
|
||||
SerializeConnectionInfo(node);
|
||||
}
|
||||
|
||||
private void SerializeConnectionInfo(ConnectionInfo con)
|
||||
|
||||
@@ -25,17 +25,17 @@ namespace mRemoteNG.Config.Serializers
|
||||
public DataTable Serialize(ConnectionTreeModel connectionTreeModel)
|
||||
{
|
||||
var rootNode = (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
SerializeToDataTable(rootNode);
|
||||
return _dataTable;
|
||||
return Serialize(rootNode);
|
||||
}
|
||||
|
||||
private void SerializeToDataTable(RootNodeInfo rootNodeInfo)
|
||||
public DataTable Serialize(ConnectionInfo serializationTarget)
|
||||
{
|
||||
_dataTable = new DataTable(TableName);
|
||||
CreateSchema();
|
||||
SetPrimaryKey();
|
||||
_currentNodeIndex = 0;
|
||||
SerializeNodesRecursive(rootNodeInfo);
|
||||
SerializeNodesRecursive(serializationTarget);
|
||||
return _dataTable;
|
||||
}
|
||||
|
||||
private void CreateSchema()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using mRemoteNG.Tree;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Tree;
|
||||
|
||||
namespace mRemoteNG.Config.Serializers
|
||||
{
|
||||
public interface ISerializer<TFormat>
|
||||
{
|
||||
TFormat Serialize(ConnectionTreeModel connectionTreeModel);
|
||||
|
||||
TFormat Serialize(ConnectionInfo serializationTarget);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@ namespace mRemoteNG.Config.Serializers
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Serialize(ConnectionInfo serializationTarget)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private bool VerifyDatabaseVersion(SqlConnection sqlConnection)
|
||||
{
|
||||
bool isVerified = false;
|
||||
|
||||
@@ -31,34 +31,20 @@ namespace mRemoteNG.Config.Serializers
|
||||
public string Serialize(ConnectionTreeModel connectionTreeModel)
|
||||
{
|
||||
var rootNode = (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return SerializeToXml(rootNode);
|
||||
return Serialize(rootNode);
|
||||
}
|
||||
|
||||
private string SerializeToXml(RootNodeInfo rootNodeInfo)
|
||||
public string Serialize(ConnectionInfo serializationTarget)
|
||||
{
|
||||
var xml = "";
|
||||
try
|
||||
{
|
||||
if (!Runtime.IsConnectionsFileLoaded)
|
||||
return "";
|
||||
|
||||
//TreeNode treeNode;
|
||||
//if (ConnectionTreeNode.GetNodeType(rootTreeNode) == TreeNodeType.Root)
|
||||
//{
|
||||
// treeNode = (TreeNode)rootTreeNode.Clone();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// treeNode = new TreeNode("mR|Export (" + MiscTools.DBDate(DateTime.Now) + ")");
|
||||
// treeNode.Nodes.Add(Convert.ToString(rootTreeNode.Clone()));
|
||||
//}
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
using (_xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8))
|
||||
{
|
||||
SetXmlTextWriterSettings();
|
||||
_xmlTextWriter.WriteStartDocument();
|
||||
SaveNodesRecursive(rootNodeInfo);
|
||||
SaveNodesRecursive(serializationTarget);
|
||||
_xmlTextWriter.Flush();
|
||||
|
||||
var streamReader = new StreamReader(memoryStream, Encoding.UTF8, true);
|
||||
@@ -79,28 +65,27 @@ namespace mRemoteNG.Config.Serializers
|
||||
_xmlTextWriter.Indentation = 4;
|
||||
}
|
||||
|
||||
private void SaveNodesRecursive(RootNodeInfo rootNodeInfo)
|
||||
{
|
||||
SerializeRootNodeInfo(rootNodeInfo);
|
||||
foreach (var child in rootNodeInfo.Children)
|
||||
SaveNodesRecursive(child);
|
||||
_xmlTextWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
private void SaveNodesRecursive(ConnectionInfo connectionInfo)
|
||||
private void SaveNodesRecursive(ConnectionInfo node)
|
||||
{
|
||||
try
|
||||
{
|
||||
var containerInfo = connectionInfo as ContainerInfo;
|
||||
if (containerInfo != null)
|
||||
var nodeAsRoot = node as RootNodeInfo;
|
||||
var nodeAsContainer = node as ContainerInfo;
|
||||
if (nodeAsRoot != null)
|
||||
{
|
||||
SerializeContainerInfo(containerInfo);
|
||||
foreach (var child in containerInfo.Children)
|
||||
SerializeRootNodeInfo(nodeAsRoot);
|
||||
foreach (var child in nodeAsRoot.Children)
|
||||
SaveNodesRecursive(child);
|
||||
}
|
||||
else if (nodeAsContainer != null)
|
||||
{
|
||||
SerializeContainerInfo(nodeAsContainer);
|
||||
foreach (var child in nodeAsContainer.Children)
|
||||
SaveNodesRecursive(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
SerializeConnectionInfo(connectionInfo);
|
||||
SerializeConnectionInfo(node);
|
||||
}
|
||||
_xmlTextWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user