modified some classes to request ConnectionsService as a ctor arg

This commit is contained in:
David Sparer
2018-03-04 11:34:48 -06:00
parent 5903481c87
commit 8159165968
11 changed files with 61 additions and 46 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Security;
using System.Threading;
using mRemoteNG.App;
using mRemoteNG.App.Update;
using mRemoteNG.Config.Putty;
using mRemoteNG.Config.Settings;
using mRemoteNG.Connection;
@@ -61,23 +63,26 @@ namespace mRemoteNGTests.Connection.Protocol
private InterfaceControl BuildInterfaceControl(string extAppName, ProtocolBase sut)
{
var import = new Import();
var connectionsService = new ConnectionsService(PuttySessionsManager.Instance, import);
var configWindow = new ConfigWindow(new DockContent());
var sshTransferWindow = new SSHTransferWindow();
var connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), _connectionInitiator);
var connectionTree = connectionTreeWindow.ConnectionTree;
var export = new Export(new CredentialRepositoryList());
var export = new Export(new CredentialRepositoryList(), connectionsService);
var connectionTreeContextMenu = new ConnectionContextMenu(connectionTree, _connectionInitiator, sshTransferWindow, export, _externalToolsService, import);
connectionTreeWindow.ConnectionTreeContextMenu = connectionTreeContextMenu;
var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow);
var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent());
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import));
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), shutdown);
var appUpdater = new AppUpdater(() => connectionsService.EncryptionKey);
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), shutdown, appUpdater);
Func<NotificationAreaIcon> notificationAreaIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, _connectionInitiator, shutdown);
Func<ExternalToolsWindow> externalToolsWindowBuilder = () => new ExternalToolsWindow(_connectionInitiator, _externalToolsService);
Func<PortScanWindow> portScanWindowBuilder = () => new PortScanWindow(() => connectionTreeWindow.SelectedNode, import);
Func<ActiveDirectoryImportWindow> activeDirectoryImportWindowBuilder = () => new ActiveDirectoryImportWindow(() => connectionTreeWindow.SelectedNode, import);
var windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow,
sshTransferWindow, updateWindowBuilder, notificationAreaIconBuilder, externalToolsWindowBuilder, Runtime.ConnectionsService, portScanWindowBuilder, activeDirectoryImportWindowBuilder);
sshTransferWindow, updateWindowBuilder, notificationAreaIconBuilder, externalToolsWindowBuilder,
connectionsService, portScanWindowBuilder, activeDirectoryImportWindowBuilder, appUpdater);
var connectionWindow = new ConnectionWindow(new DockContent(), _connectionInitiator, windows, _externalToolsService);
var connectionInfo = new ConnectionInfo {ExtApp = extAppName};
return new InterfaceControl(connectionWindow, sut, connectionInfo);

View File

@@ -1,5 +1,7 @@
using System;
using System.Security;
using mRemoteNG.App;
using mRemoteNG.App.Update;
using mRemoteNG.Config.Putty;
using mRemoteNG.Config.Settings;
using mRemoteNG.Connection;
@@ -26,7 +28,9 @@ namespace mRemoteNGTests.UI.Forms
var import = new Import();
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import));
Func<NotificationAreaIcon> notificationIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, connectionInitiator, shutdown);
_optionsForm = new frmOptions(connectionInitiator, type => {}, notificationIconBuilder, Runtime.ConnectionsService);
var connectionsService = new ConnectionsService(PuttySessionsManager.Instance, import);
var appUpdater = new AppUpdater(() => connectionsService.EncryptionKey);
_optionsForm = new frmOptions(connectionInitiator, type => {}, notificationIconBuilder, connectionsService, appUpdater);
_optionsForm.Show();
}

View File

@@ -1,5 +1,6 @@
using System.Threading;
using mRemoteNG.App;
using mRemoteNG.Config.Putty;
using mRemoteNG.Connection;
using mRemoteNG.Credential.Repositories;
using mRemoteNG.Tools;
@@ -23,7 +24,9 @@ namespace mRemoteNGTests.UI.Window
var sshTransferWindow = new SSHTransferWindow();
var externalToolsService = new ExternalToolsService();
var import = new Import();
var connectionContextMenu = new ConnectionContextMenu(connectionTree, connectionInitiator, sshTransferWindow, new Export(new CredentialRepositoryList()), externalToolsService, import);
var connectionsService = new ConnectionsService(PuttySessionsManager.Instance, import);
var export = new Export(new CredentialRepositoryList(), connectionsService);
var connectionContextMenu = new ConnectionContextMenu(connectionTree, connectionInitiator, sshTransferWindow, export, externalToolsService, import);
_connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), connectionInitiator) {ConnectionTreeContextMenu = connectionContextMenu};
}

View File

@@ -21,11 +21,13 @@ namespace mRemoteNG.App
{
public class Export
{
private readonly ConnectionsService _connectionsService;
private readonly ICredentialRepositoryList _credentialRepositoryList;
public Export(ICredentialRepositoryList credentialRepositoryList)
public Export(ICredentialRepositoryList credentialRepositoryList, ConnectionsService connectionsService)
{
_credentialRepositoryList = credentialRepositoryList.ThrowIfNull(nameof(credentialRepositoryList));
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
}
public void ExportToFile(ConnectionInfo selectedNode, ConnectionTreeModel connectionTreeModel)
@@ -110,7 +112,7 @@ namespace mRemoteNG.App
}
finally
{
Runtime.ConnectionsService.RemoteConnectionsSyncronizer?.Enable();
_connectionsService.RemoteConnectionsSyncronizer?.Enable();
}
}
}

View File

@@ -19,18 +19,18 @@ namespace mRemoteNG.App
{
public class Startup
{
private AppUpdater _appUpdate;
private readonly AppUpdater _appUpdate;
private readonly ConnectionIconLoader _connectionIconLoader;
private readonly FrmMain _frmMain;
private readonly Windows _windows;
private readonly ConnectionsService _connectionsService;
public Startup(FrmMain frmMain, Windows windows, ConnectionsService connectionsService)
public Startup(FrmMain frmMain, Windows windows, ConnectionsService connectionsService, AppUpdater appUpdate)
{
_frmMain = frmMain.ThrowIfNull(nameof(frmMain));
_windows = windows.ThrowIfNull(nameof(windows));
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
_appUpdate = new AppUpdater();
_appUpdate = appUpdate.ThrowIfNull(nameof(appUpdate));
_connectionIconLoader = new ConnectionIconLoader(GeneralAppInfo.HomePath + "\\Icons\\");
}
@@ -64,11 +64,7 @@ namespace mRemoteNG.App
public void CheckForUpdate()
{
if (_appUpdate == null)
{
_appUpdate = new AppUpdater();
}
else if (_appUpdate.IsGetUpdateInfoRunning)
if (_appUpdate.IsGetUpdateInfoRunning)
{
return;
}

View File

@@ -4,6 +4,7 @@ using System.Net;
using System.ComponentModel;
using System.Threading;
using System.Reflection;
using System.Security;
using mRemoteNG.App.Info;
using mRemoteNG.Security.SymmetricEncryption;
using System.Security.Cryptography;
@@ -22,6 +23,7 @@ namespace mRemoteNG.App.Update
private WebProxy _webProxy;
private Thread _getUpdateInfoThread;
private Thread _getChangeLogThread;
private readonly Func<SecureString> _encryptionKeyRetrievalFunc;
#region Public Properties
@@ -48,8 +50,9 @@ namespace mRemoteNG.App.Update
#region Public Methods
public AppUpdater()
public AppUpdater(Func<SecureString> encryptionKeyRetrievalFunc)
{
_encryptionKeyRetrievalFunc = encryptionKeyRetrievalFunc;
SetProxySettings();
}
@@ -61,7 +64,7 @@ namespace mRemoteNG.App.Update
var useAuthentication = Settings.Default.UpdateProxyUseAuthentication;
var username = Settings.Default.UpdateProxyAuthUser;
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
var password = cryptographyProvider.Decrypt(Settings.Default.UpdateProxyAuthPass, Runtime.ConnectionsService.EncryptionKey);
var password = cryptographyProvider.Decrypt(Settings.Default.UpdateProxyAuthPass, _encryptionKeyRetrievalFunc());
SetProxySettings(shouldWeUseProxy, proxyAddress, port, useAuthentication, username, password);
}

View File

@@ -1,4 +1,5 @@
using System;
using mRemoteNG.App.Update;
using mRemoteNG.Connection;
using mRemoteNG.Messages;
using mRemoteNG.Tools;
@@ -25,6 +26,7 @@ namespace mRemoteNG.App
private readonly Func<PortScanWindow> _portScanWindowBuilder;
private readonly Func<ActiveDirectoryImportWindow> _activeDirectoryImportWindowBuilder;
private readonly ConnectionsService _connectionsService;
private readonly AppUpdater _appUpdater;
internal ConnectionTreeWindow TreeForm { get; }
internal ConfigWindow ConfigForm { get; }
@@ -44,7 +46,8 @@ namespace mRemoteNG.App
Func<ExternalToolsWindow> externalToolsWindowBuilder,
ConnectionsService connectionsService,
Func<PortScanWindow> portScanWindowBuilder,
Func<ActiveDirectoryImportWindow> activeDirectoryImportWindowBuilder)
Func<ActiveDirectoryImportWindow> activeDirectoryImportWindowBuilder,
AppUpdater appUpdater)
{
_connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator));
TreeForm = treeForm.ThrowIfNull(nameof(treeForm));
@@ -57,6 +60,7 @@ namespace mRemoteNG.App
_externalToolsWindowBuilder = externalToolsWindowBuilder;
_portScanWindowBuilder = portScanWindowBuilder;
_activeDirectoryImportWindowBuilder = activeDirectoryImportWindowBuilder;
_appUpdater = appUpdater.ThrowIfNull(nameof(appUpdater));
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
}
@@ -79,7 +83,7 @@ namespace mRemoteNG.App
_adimportForm.Show(dockPanel);
break;
case WindowType.Options:
using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder, _connectionsService))
using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater))
{
optionsForm.ShowDialog(dockPanel);
}

View File

@@ -12,11 +12,12 @@ namespace mRemoteNG.UI.Forms.OptionsPages
{
public partial class UpdatesPage
{
private AppUpdater _appUpdate;
private readonly AppUpdater _appUpdate;
private readonly Action<WindowType> _showWindowAction;
public UpdatesPage(Action<WindowType> showWindowAction)
public UpdatesPage(AppUpdater appUpdate, Action<WindowType> showWindowAction)
{
_appUpdate = appUpdate;
_showWindowAction = showWindowAction.ThrowIfNull(nameof(showWindowAction));
InitializeComponent();
base.ApplyTheme();
@@ -188,15 +189,11 @@ namespace mRemoteNG.UI.Forms.OptionsPages
private void btnTestProxy_Click(object sender, EventArgs e)
{
if (_appUpdate != null)
if (_appUpdate.IsGetUpdateInfoRunning)
{
if (_appUpdate.IsGetUpdateInfoRunning)
{
return;
}
return;
}
_appUpdate = new AppUpdater();
//_appUpdate.Load += _appUpdate.Update_Load;
_appUpdate.SetProxySettings(chkUseProxyForAutomaticUpdates.Checked, txtProxyAddress.Text,
(int) numProxyPort.Value, chkUseProxyAuthentication.Checked, txtProxyUsername.Text,

View File

@@ -12,6 +12,7 @@ using Microsoft.Win32;
using mRemoteNG.App;
using mRemoteNG.App.Info;
using mRemoteNG.App.Initialization;
using mRemoteNG.App.Update;
using mRemoteNG.Config;
using mRemoteNG.Config.Connections;
using mRemoteNG.Config.Putty;
@@ -64,6 +65,7 @@ namespace mRemoteNG.UI.Forms
private readonly Func<NotificationAreaIcon> _notificationAreaIconBuilder;
private readonly ConnectionsService _connectionsService;
private readonly Import _import;
private readonly AppUpdater _appUpdater;
internal FullscreenHandler Fullscreen { get; set; }
@@ -77,9 +79,9 @@ namespace mRemoteNG.UI.Forms
var externalToolsService = new ExternalToolsService();
_import = new Import();
_connectionsService = new ConnectionsService(PuttySessionsManager.Instance, _import);
_appUpdater = new AppUpdater(() => _connectionsService.EncryptionKey);
ExternalToolsTypeConverter.ExternalToolsService = externalToolsService;
_export = new Export(_credentialRepositoryList);
_export = new Export(_credentialRepositoryList, _connectionsService);
_connectionInitiator = new ConnectionInitiator(_windowList, externalToolsService);
_webHelper = new WebHelper(_connectionInitiator);
var configWindow = new ConfigWindow(new DockContent());
@@ -94,18 +96,18 @@ namespace mRemoteNG.UI.Forms
var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent());
_settingsSaver = new SettingsSaver(externalToolsService);
_shutdown = new Shutdown(_settingsSaver, _connectionsService);
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), _shutdown);
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), _shutdown, _appUpdater);
_notificationAreaIconBuilder = () => new NotificationAreaIcon(this, _connectionInitiator, _shutdown);
Func<ExternalToolsWindow> externalToolsWindowBuilder = () => new ExternalToolsWindow(_connectionInitiator, externalToolsService);
Func<PortScanWindow> portScanWindowBuilder = () => new PortScanWindow(() => connectionTreeWindow.SelectedNode, _import);
Func<ActiveDirectoryImportWindow> activeDirectoryImportWindowBuilder = () => new ActiveDirectoryImportWindow(() => connectionTreeWindow.SelectedNode, _import);
_windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow,
sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder, externalToolsWindowBuilder, _connectionsService, portScanWindowBuilder, activeDirectoryImportWindowBuilder);
sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder, externalToolsWindowBuilder, _connectionsService, portScanWindowBuilder, activeDirectoryImportWindowBuilder, _appUpdater);
Func<ConnectionWindow> connectionWindowBuilder = () => new ConnectionWindow(new DockContent(), _connectionInitiator, _windows, externalToolsService);
_panelAdder = new PanelAdder(_windowList, connectionWindowBuilder);
_showFullPathInTitle = Settings.Default.ShowCompleteConsPathInTitle;
_connectionInitiator.Adder = _panelAdder;
_startup = new Startup(this, _windows, _connectionsService);
_startup = new Startup(this, _windows, _connectionsService, _appUpdater);
connectionTreeContextMenu.ShowWindowAction = _windows.Show;
InitializeComponent();
@@ -341,7 +343,7 @@ namespace mRemoteNG.UI.Forms
if (CTaskDialog.CommandButtonResult != 1) return;
using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, _connectionsService, Language.strTabUpdates))
using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater, Language.strTabUpdates))
{
optionsForm.ShowDialog(this);
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using mRemoteNG.App.Update;
using mRemoteNG.Connection;
using mRemoteNG.Tools;
using mRemoteNG.UI.Forms.OptionsPages;
@@ -18,18 +19,20 @@ namespace mRemoteNG.UI.Forms
private readonly Action<WindowType> _showWindowAction;
private readonly Func<NotificationAreaIcon> _notificationAreaIconBuilder;
private readonly ConnectionsService _connectionsService;
private readonly AppUpdater _appUpdater;
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder, ConnectionsService connectionsService)
: this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, connectionsService, Language.strStartupExit)
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder, ConnectionsService connectionsService, AppUpdater appUpdater)
: this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, connectionsService, appUpdater, Language.strStartupExit)
{
}
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder, ConnectionsService connectionsService, string pageName)
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder, ConnectionsService connectionsService, AppUpdater appUpdater, string pageName)
{
_connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator));
_showWindowAction = showWindowAction.ThrowIfNull(nameof(showWindowAction));
_notificationAreaIconBuilder = notificationAreaIconBuilder;
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
_appUpdater = appUpdater.ThrowIfNull(nameof(appUpdater));
_pageName = pageName.ThrowIfNull(nameof(pageName));
InitializeComponent();
}
@@ -76,7 +79,7 @@ namespace mRemoteNG.UI.Forms
{typeof(ConnectionsPage).Name, new ConnectionsPage()},
{typeof(CredentialsPage).Name, new CredentialsPage()},
{typeof(SqlServerPage).Name, new SqlServerPage(_connectionsService)},
{typeof(UpdatesPage).Name, new UpdatesPage(_showWindowAction)},
{typeof(UpdatesPage).Name, new UpdatesPage(_appUpdater, _showWindowAction)},
{typeof(ThemePage).Name, new ThemePage()},
{typeof(SecurityPage).Name, new SecurityPage()},
{typeof(AdvancedPage).Name, new AdvancedPage()}

View File

@@ -15,15 +15,16 @@ namespace mRemoteNG.UI.Window
{
public partial class UpdateWindow : BaseWindow
{
private AppUpdater _appUpdate;
private Shutdown _shutdown;
private readonly AppUpdater _appUpdate;
private readonly Shutdown _shutdown;
private bool _isUpdateDownloadHandlerDeclared;
public UpdateWindow(DockContent panel, Shutdown shutdown)
public UpdateWindow(DockContent panel, Shutdown shutdown, AppUpdater appUpdate)
{
WindowType = WindowType.Update;
DockPnl = panel;
_shutdown = shutdown.ThrowIfNull(nameof(shutdown));
_appUpdate = appUpdate.ThrowIfNull(nameof(appUpdate));
InitializeComponent();
FontOverrider.FontOverride(this);
}
@@ -85,12 +86,7 @@ namespace mRemoteNG.UI.Window
#region Private Methods
private void CheckForUpdate()
{
if (_appUpdate == null)
{
_appUpdate = new AppUpdater();
//_appUpdate.Load += _appUpdate.Update_Load;
}
else if (_appUpdate.IsGetUpdateInfoRunning)
if (_appUpdate.IsGetUpdateInfoRunning)
{
return;
}