mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Refactored code for exporting connections in visionapp remote desktop 2008 csv format
This commit is contained in:
@@ -74,13 +74,13 @@ namespace mRemoteNG.Config.Connections
|
||||
SaveToSQL();
|
||||
break;
|
||||
case Format.mRCSV:
|
||||
SaveToCsv();
|
||||
SaveToMremotengFormattedCsv();
|
||||
break;
|
||||
case Format.vRDvRE:
|
||||
SaveToVRE();
|
||||
break;
|
||||
case Format.vRDCSV:
|
||||
SaveTovRDCSV();
|
||||
SaveToRemoteDesktop2008FormattedCsv();
|
||||
break;
|
||||
default:
|
||||
SaveToXml();
|
||||
@@ -573,7 +573,7 @@ namespace mRemoteNG.Config.Connections
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToCsv()
|
||||
private void SaveToMremotengFormattedCsv()
|
||||
{
|
||||
var csvConnectionsSerializer = new CsvConnectionsSerializerMremotengFormat { SaveSecurity = SaveSecurity };
|
||||
var dataProvider = new FileDataProvider(ConnectionFileName);
|
||||
@@ -582,60 +582,13 @@ namespace mRemoteNG.Config.Connections
|
||||
}
|
||||
|
||||
#region vRD CSV
|
||||
|
||||
private StreamWriter csvWr;
|
||||
private void SaveTovRDCSV()
|
||||
{
|
||||
if (Runtime.IsConnectionsFileLoaded == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var tN = (TreeNode)RootTreeNode.Clone();
|
||||
var tNC = tN.Nodes;
|
||||
csvWr = new StreamWriter(ConnectionFileName);
|
||||
SaveNodevRDCSV(tNC);
|
||||
csvWr.Close();
|
||||
}
|
||||
|
||||
private void SaveNodevRDCSV(TreeNodeCollection tNC)
|
||||
{
|
||||
foreach (TreeNode node in tNC)
|
||||
{
|
||||
if (ConnectionTreeNode.GetNodeType(node) == TreeNodeType.Connection)
|
||||
{
|
||||
ConnectionInfo curConI = (ConnectionInfo)node.Tag;
|
||||
|
||||
if (curConI.Protocol == ProtocolType.RDP)
|
||||
{
|
||||
WritevRDCSVLine(curConI);
|
||||
}
|
||||
}
|
||||
else if (ConnectionTreeNode.GetNodeType(node) == TreeNodeType.Container)
|
||||
{
|
||||
SaveNodevRDCSV(node.Nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WritevRDCSVLine(ConnectionInfo con)
|
||||
{
|
||||
string nodePath = con.TreeNode.FullPath;
|
||||
|
||||
int firstSlash = nodePath.IndexOf("\\", StringComparison.Ordinal);
|
||||
nodePath = nodePath.Remove(0, firstSlash + 1);
|
||||
int lastSlash = nodePath.LastIndexOf("\\", StringComparison.Ordinal);
|
||||
|
||||
if (lastSlash > 0)
|
||||
{
|
||||
nodePath = nodePath.Remove(lastSlash);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodePath = "";
|
||||
}
|
||||
|
||||
csvWr.WriteLine(con.Name + ";" + con.Hostname + ";" + con.MacAddress + ";;" + Convert.ToString(con.Port) + ";" + Convert.ToString(con.UseConsoleSession) + ";" + nodePath);
|
||||
}
|
||||
private void SaveToRemoteDesktop2008FormattedCsv()
|
||||
{
|
||||
var csvSerializer = new CsvConnectionsSerializerRemoteDesktop2008Format();
|
||||
var dataProvider = new FileDataProvider(ConnectionFileName);
|
||||
var csvContent = csvSerializer.Serialize(ConnectionTreeModel);
|
||||
dataProvider.Save(csvContent);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region vRD VRE
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Tree;
|
||||
using mRemoteNG.Tree.Root;
|
||||
|
||||
|
||||
namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
public class CsvConnectionsSerializerRemoteDesktop2008Format : ISerializer
|
||||
{
|
||||
private string _csv = "";
|
||||
|
||||
public string Serialize(ConnectionTreeModel connectionTreeModel)
|
||||
{
|
||||
var rootNode = (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
|
||||
return SerializeToCsv(rootNode);
|
||||
}
|
||||
|
||||
private string SerializeToCsv(RootNodeInfo rootNodeInfo)
|
||||
{
|
||||
if (Runtime.IsConnectionsFileLoaded == false)
|
||||
return "";
|
||||
|
||||
_csv = "";
|
||||
SerializeNodesRecursive(rootNodeInfo);
|
||||
return _csv;
|
||||
}
|
||||
|
||||
private void SerializeNodesRecursive(ContainerInfo containerInfo)
|
||||
{
|
||||
foreach (var child in containerInfo.Children)
|
||||
{
|
||||
if (child is ContainerInfo)
|
||||
SerializeNodesRecursive((ContainerInfo)child);
|
||||
else if (child.Protocol == ProtocolType.RDP)
|
||||
SerializeConnectionInfo(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void SerializeConnectionInfo(ConnectionInfo con)
|
||||
{
|
||||
var nodePath = con.TreeNode.FullPath;
|
||||
|
||||
var firstSlash = nodePath.IndexOf("\\", StringComparison.Ordinal);
|
||||
nodePath = nodePath.Remove(0, firstSlash + 1);
|
||||
var lastSlash = nodePath.LastIndexOf("\\", StringComparison.Ordinal);
|
||||
|
||||
nodePath = lastSlash > 0 ? nodePath.Remove(lastSlash) : "";
|
||||
|
||||
_csv += con.Name + ";" + con.Hostname + ";" + con.MacAddress + ";;" + con.Port + ";" + con.UseConsoleSession + ";" + nodePath + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,7 @@
|
||||
<Compile Include="App\Update\UpdateInfo.cs" />
|
||||
<Compile Include="App\Windows.cs" />
|
||||
<Compile Include="Config\Connections\CsvConnectionsSerializerMremotengFormat.cs" />
|
||||
<Compile Include="Config\Connections\CsvConnectionsSerializerRemoteDesktop2008Format.cs" />
|
||||
<Compile Include="Config\DataProviders\FileDataProviderWithBackup.cs" />
|
||||
<Compile Include="Config\Connections\ConnectionsDecryptor.cs" />
|
||||
<Compile Include="Config\Connections\ConnectionsLoader.cs" />
|
||||
|
||||
Reference in New Issue
Block a user