refactored xml credential loading to a new class

This commit is contained in:
David Sparer
2017-05-07 11:57:15 -06:00
parent 9ba081f241
commit 83156bf28e
3 changed files with 45 additions and 10 deletions

View File

@@ -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;
}
}
}

View 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;
}
}
}

View File

@@ -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" />