From 83156bf28e9bbeb3f2d5be0a16070eae9febdc65 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sun, 7 May 2017 11:57:15 -0600 Subject: [PATCH] refactored xml credential loading to a new class --- .../Config/Connections/ConnectionsLoader.cs | 12 +----- .../Connections/XmlConnectionsLoader.cs | 42 +++++++++++++++++++ mRemoteV1/mRemoteV1.csproj | 1 + 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 mRemoteV1/Config/Connections/XmlConnectionsLoader.cs diff --git a/mRemoteV1/Config/Connections/ConnectionsLoader.cs b/mRemoteV1/Config/Connections/ConnectionsLoader.cs index 32c1a6da8..4847fe659 100644 --- a/mRemoteV1/Config/Connections/ConnectionsLoader.cs +++ b/mRemoteV1/Config/Connections/ConnectionsLoader.cs @@ -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; - } } } \ No newline at end of file diff --git a/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs new file mode 100644 index 000000000..d31e146e6 --- /dev/null +++ b/mRemoteV1/Config/Connections/XmlConnectionsLoader.cs @@ -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 _credentialRecords; + + public XmlConnectionsLoader(string connectionFilePath, IEnumerable 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; + } + } +} diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 73b5e25cf..5cf504562 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -138,6 +138,7 @@ +