mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
refactored xml credential loading to a new class
This commit is contained in:
@@ -30,10 +30,8 @@ namespace mRemoteNG.Config.Connections
|
||||
}
|
||||
else
|
||||
{
|
||||
var dataProvider = new FileDataProvider(ConnectionFileName);
|
||||
var xmlString = dataProvider.Load();
|
||||
var deserializer = new XmlConnectionsDeserializer(credentialRecords, PromptForPassword);
|
||||
connectionTreeModel = deserializer.Deserialize(xmlString);
|
||||
var xmlLoader = new XmlConnectionsLoader(ConnectionFileName, credentialRecords);
|
||||
connectionTreeModel = xmlLoader.Load();
|
||||
}
|
||||
|
||||
if (connectionTreeModel != null)
|
||||
@@ -47,11 +45,5 @@ namespace mRemoteNG.Config.Connections
|
||||
|
||||
return connectionTreeModel;
|
||||
}
|
||||
|
||||
private SecureString PromptForPassword()
|
||||
{
|
||||
var password = MiscTools.PasswordDialog("", false);
|
||||
return password;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
mRemoteV1/Config/Connections/XmlConnectionsLoader.cs
Normal file
42
mRemoteV1/Config/Connections/XmlConnectionsLoader.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using mRemoteNG.Config.DataProviders;
|
||||
using mRemoteNG.Config.Serializers;
|
||||
using mRemoteNG.Credential;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
|
||||
namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
public class XmlConnectionsLoader
|
||||
{
|
||||
private readonly string _connectionFilePath;
|
||||
private readonly IEnumerable<ICredentialRecord> _credentialRecords;
|
||||
|
||||
public XmlConnectionsLoader(string connectionFilePath, IEnumerable<ICredentialRecord> credentialRecords)
|
||||
{
|
||||
if (string.IsNullOrEmpty(connectionFilePath))
|
||||
throw new ArgumentException($"{nameof(connectionFilePath)} cannot be null or empty");
|
||||
if (credentialRecords == null)
|
||||
throw new ArgumentNullException(nameof(credentialRecords));
|
||||
|
||||
_connectionFilePath = connectionFilePath;
|
||||
_credentialRecords = credentialRecords;
|
||||
}
|
||||
|
||||
public ConnectionTreeModel Load()
|
||||
{
|
||||
var dataProvider = new FileDataProvider(_connectionFilePath);
|
||||
var xmlString = dataProvider.Load();
|
||||
var deserializer = new XmlConnectionsDeserializer(_credentialRecords, PromptForPassword);
|
||||
return deserializer.Deserialize(xmlString);
|
||||
}
|
||||
|
||||
private SecureString PromptForPassword()
|
||||
{
|
||||
var password = MiscTools.PasswordDialog("", false);
|
||||
return password;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@
|
||||
<Compile Include="Config\Connections\Multiuser\ConnectionsUpdateAvailableEventArgs.cs" />
|
||||
<Compile Include="Config\Connections\Multiuser\RemoteConnectionsSyncronizer.cs" />
|
||||
<Compile Include="Config\Connections\SqlConnectionsLoader.cs" />
|
||||
<Compile Include="Config\Connections\XmlConnectionsLoader.cs" />
|
||||
<Compile Include="Config\CredentialHarvester.cs" />
|
||||
<Compile Include="Config\CredentialRecordLoader.cs" />
|
||||
<Compile Include="Config\CredentialRecordSaver.cs" />
|
||||
|
||||
Reference in New Issue
Block a user