made some references to the connection service non static

This commit is contained in:
David Sparer
2018-03-03 17:34:45 -06:00
parent f00dad3c96
commit e7afe5ea93
10 changed files with 76 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading;
using mRemoteNG.App;
using mRemoteNG.Config.Putty;
using mRemoteNG.Config.Settings;
using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol;
@@ -67,11 +68,12 @@ namespace mRemoteNGTests.Connection.Protocol
connectionTreeWindow.ConnectionTreeContextMenu = connectionTreeContextMenu;
var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow);
var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent());
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()));
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance));
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), shutdown);
Func<NotificationAreaIcon> notificationAreaIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, _connectionInitiator, shutdown);
Func<ExternalToolsWindow> externalToolsWindowBuilder = () => new ExternalToolsWindow(_connectionInitiator, _externalToolsService);
var windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow, updateWindowBuilder, notificationAreaIconBuilder, externalToolsWindowBuilder);
var windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow,
sshTransferWindow, updateWindowBuilder, notificationAreaIconBuilder, externalToolsWindowBuilder, Runtime.ConnectionsService);
var connectionWindow = new ConnectionWindow(new DockContent(), _connectionInitiator, windows, _externalToolsService);
var connectionInfo = new ConnectionInfo {ExtApp = extAppName};
return new InterfaceControl(connectionWindow, sut, connectionInfo);

View File

@@ -1,4 +1,6 @@
using mRemoteNG.App;
using System;
using mRemoteNG.App;
using mRemoteNG.Config.Putty;
using mRemoteNG.Config.Settings;
using mRemoteNG.Connection;
using mRemoteNG.Tools;
@@ -21,8 +23,9 @@ namespace mRemoteNGTests.UI.Forms
public void Setup()
{
var connectionInitiator = Substitute.For<IConnectionInitiator>();
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()));
_optionsForm = new frmOptions(connectionInitiator, type => {}, () => new NotificationAreaIcon(FrmMain.Default, connectionInitiator, shutdown));
var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance));
Func<NotificationAreaIcon> notificationIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, connectionInitiator, shutdown);
_optionsForm = new frmOptions(connectionInitiator, type => {}, notificationIconBuilder, Runtime.ConnectionsService);
_optionsForm.Show();
}

View File

@@ -1,18 +1,27 @@
using System.IO;
using mRemoteNG.Config.Connections;
using mRemoteNG.Connection;
using mRemoteNG.Tools;
namespace mRemoteNG.App.Initialization
{
public class CredsAndConsSetup
{
public void LoadCredsAndCons()
{
private readonly ConnectionsService _connectionsService;
public CredsAndConsSetup(ConnectionsService connectionsService)
{
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
}
public void LoadCredsAndCons()
{
new SaveConnectionsOnEdit(Runtime.ConnectionsService);
new SaveConnectionsOnEdit(_connectionsService);
if (Settings.Default.FirstStart && !Settings.Default.LoadConsFromCustomLocation && !File.Exists(Runtime.ConnectionsService.GetStartupConnectionFileName()))
Runtime.ConnectionsService.NewConnectionsFile(Runtime.ConnectionsService.GetStartupConnectionFileName());
if (Settings.Default.FirstStart && !Settings.Default.LoadConsFromCustomLocation && !File.Exists(_connectionsService.GetStartupConnectionFileName()))
_connectionsService.NewConnectionsFile(_connectionsService.GetStartupConnectionFileName());
Runtime.ConnectionsService.LoadConnections();
_connectionsService.LoadConnections();
}
}
}

View File

@@ -1,4 +1,3 @@
using mRemoteNG.Config.Putty;
using mRemoteNG.Connection;
using mRemoteNG.Messages;
using mRemoteNG.Tools;
@@ -21,6 +20,6 @@ namespace mRemoteNG.App
public static MessageCollector MessageCollector { get; } = new MessageCollector();
public static NotificationAreaIcon NotificationAreaIcon { get; set; }
public static ConnectionsService ConnectionsService { get; } = new ConnectionsService(PuttySessionsManager.Instance);
public static ConnectionsService ConnectionsService { get; set; }
}
}

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Windows.Forms;
using mRemoteNG.Config.Putty;
using mRemoteNG.Config.Settings;
using mRemoteNG.Connection;
using mRemoteNG.UI.Controls;
using mRemoteNG.UI.Forms;
// ReSharper disable ArrangeAccessorOwnerBody
@@ -13,11 +14,13 @@ namespace mRemoteNG.App
public class Shutdown
{
private readonly SettingsSaver _settingsSaver;
private readonly ConnectionsService _connectionsService;
private static string _updateFilePath;
public Shutdown(SettingsSaver settingsSaver)
public Shutdown(SettingsSaver settingsSaver, ConnectionsService connectionsService)
{
_settingsSaver = settingsSaver.ThrowIfNull(nameof(settingsSaver));
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
}
private static bool UpdatePending
@@ -62,7 +65,7 @@ namespace mRemoteNG.App
private void SaveConnections()
{
if (Settings.Default.SaveConsOnExit)
Runtime.ConnectionsService.SaveConnections();
_connectionsService.SaveConnections();
}
private void SaveSettings(Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, FrmMain frmMain)

View File

@@ -23,11 +23,13 @@ namespace mRemoteNG.App
private readonly ConnectionIconLoader _connectionIconLoader;
private readonly FrmMain _frmMain;
private readonly Windows _windows;
private readonly ConnectionsService _connectionsService;
public Startup(FrmMain frmMain, Windows windows)
public Startup(FrmMain frmMain, Windows windows, ConnectionsService connectionsService)
{
_frmMain = frmMain.ThrowIfNull(nameof(frmMain));
_frmMain = frmMain.ThrowIfNull(nameof(frmMain));
_windows = windows.ThrowIfNull(nameof(windows));
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
_appUpdate = new AppUpdater();
_connectionIconLoader = new ConnectionIconLoader(GeneralAppInfo.HomePath + "\\Icons\\");
}
@@ -56,8 +58,8 @@ namespace mRemoteNG.App
messageCollector.AddMessage(MessageClass.DebugMsg, "Determining if we need a database syncronizer");
if (!Settings.Default.UseSQLServer) return;
messageCollector.AddMessage(MessageClass.DebugMsg, "Creating database syncronizer");
Runtime.ConnectionsService.RemoteConnectionsSyncronizer = new RemoteConnectionsSyncronizer(new SqlConnectionsUpdateChecker());
Runtime.ConnectionsService.RemoteConnectionsSyncronizer.Enable();
_connectionsService.RemoteConnectionsSyncronizer = new RemoteConnectionsSyncronizer(new SqlConnectionsUpdateChecker());
_connectionsService.RemoteConnectionsSyncronizer.Enable();
}
public void CheckForUpdate()

View File

@@ -23,6 +23,7 @@ namespace mRemoteNG.App
private readonly Func<UpdateWindow> _updateWindowBuilder;
private readonly Func<NotificationAreaIcon> _notificationAreaIconBuilder;
private readonly Func<ExternalToolsWindow> _externalToolsWindowBuilder;
private readonly ConnectionsService _connectionsService;
internal ConnectionTreeWindow TreeForm { get; }
internal ConfigWindow ConfigForm { get; }
@@ -39,7 +40,8 @@ namespace mRemoteNG.App
SSHTransferWindow sshtransferForm,
Func<UpdateWindow> updateWindowBuilder,
Func<NotificationAreaIcon> notificationAreaIconBuilder,
Func<ExternalToolsWindow> externalToolsWindowBuilder)
Func<ExternalToolsWindow> externalToolsWindowBuilder,
ConnectionsService connectionsService)
{
_connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator));
TreeForm = treeForm.ThrowIfNull(nameof(treeForm));
@@ -50,6 +52,7 @@ namespace mRemoteNG.App
_updateWindowBuilder = updateWindowBuilder;
_notificationAreaIconBuilder = notificationAreaIconBuilder;
_externalToolsWindowBuilder = externalToolsWindowBuilder;
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
}
public void Show(WindowType windowType)
@@ -71,7 +74,7 @@ namespace mRemoteNG.App
_adimportForm.Show(dockPanel);
break;
case WindowType.Options:
using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder))
using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder, _connectionsService))
{
optionsForm.ShowDialog(dockPanel);
}

View File

@@ -3,16 +3,20 @@ using mRemoteNG.App;
using mRemoteNG.Config.Connections;
using mRemoteNG.Config.Connections.Multiuser;
using mRemoteNG.Config.DatabaseConnectors;
using mRemoteNG.Connection;
using mRemoteNG.Security.SymmetricEncryption;
using mRemoteNG.Tools;
namespace mRemoteNG.UI.Forms.OptionsPages
{
public partial class SqlServerPage
{
private readonly SqlDatabaseConnectionTester _databaseConnectionTester;
private readonly ConnectionsService _connectionsService;
public SqlServerPage()
public SqlServerPage(ConnectionsService connectionsService)
{
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
InitializeComponent();
base.ApplyTheme();
_databaseConnectionTester = new SqlDatabaseConnectionTester();
@@ -75,18 +79,18 @@ namespace mRemoteNG.UI.Forms.OptionsPages
Settings.Default.Save();
}
private static void ReinitializeSqlUpdater()
private void ReinitializeSqlUpdater()
{
Runtime.ConnectionsService.RemoteConnectionsSyncronizer?.Dispose();
Runtime.ConnectionsService.RemoteConnectionsSyncronizer = new RemoteConnectionsSyncronizer(new SqlConnectionsUpdateChecker());
Runtime.ConnectionsService.RemoteConnectionsSyncronizer.Enable();
_connectionsService.RemoteConnectionsSyncronizer?.Dispose();
_connectionsService.RemoteConnectionsSyncronizer = new RemoteConnectionsSyncronizer(new SqlConnectionsUpdateChecker());
_connectionsService.RemoteConnectionsSyncronizer.Enable();
}
private void DisableSql()
{
Runtime.ConnectionsService.RemoteConnectionsSyncronizer?.Dispose();
Runtime.ConnectionsService.RemoteConnectionsSyncronizer = null;
Runtime.ConnectionsService.LoadConnections(true);
_connectionsService.RemoteConnectionsSyncronizer?.Dispose();
_connectionsService.RemoteConnectionsSyncronizer = null;
_connectionsService.LoadConnections(true);
}
private void chkUseSQLServer_CheckedChanged(object sender, EventArgs e)

View File

@@ -50,7 +50,6 @@ namespace mRemoteNG.UI.Forms
private ConnectionInfo _selectedConnection;
private readonly IList<IMessageWriter> _messageWriters = new List<IMessageWriter>();
private readonly ThemeManager _themeManager;
private readonly Runtime _runtime;
private readonly ConnectionInitiator _connectionInitiator;
private readonly PanelAdder _panelAdder;
private readonly WebHelper _webHelper;
@@ -63,6 +62,7 @@ namespace mRemoteNG.UI.Forms
private readonly Shutdown _shutdown;
private readonly ICredentialRepositoryList _credentialRepositoryList;
private readonly Func<NotificationAreaIcon> _notificationAreaIconBuilder;
private readonly ConnectionsService _connectionsService;
internal FullscreenHandler Fullscreen { get; set; }
@@ -71,11 +71,12 @@ namespace mRemoteNG.UI.Forms
private FrmMain()
{
_runtime = new Runtime();
_windowList = new WindowList();
_credentialRepositoryList = new CredentialRepositoryList();
var externalToolsService = new ExternalToolsService();
ExternalToolsTypeConverter.ExternalToolsService = externalToolsService;
_connectionsService = new ConnectionsService(PuttySessionsManager.Instance);
ExternalToolsTypeConverter.ExternalToolsService = externalToolsService;
_export = new Export(_credentialRepositoryList);
_connectionInitiator = new ConnectionInitiator(_windowList, externalToolsService);
_webHelper = new WebHelper(_connectionInitiator);
@@ -90,16 +91,16 @@ namespace mRemoteNG.UI.Forms
var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow);
var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent());
_settingsSaver = new SettingsSaver(externalToolsService);
_shutdown = new Shutdown(_settingsSaver);
_shutdown = new Shutdown(_settingsSaver, _connectionsService);
Func<UpdateWindow> updateWindowBuilder = () => new UpdateWindow(new DockContent(), _shutdown);
_notificationAreaIconBuilder = () => new NotificationAreaIcon(this, _connectionInitiator, _shutdown);
Func<ExternalToolsWindow> externalToolsWindowBuilder = () => new ExternalToolsWindow(_connectionInitiator, externalToolsService);
_windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder, externalToolsWindowBuilder);
_windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder, externalToolsWindowBuilder, _connectionsService);
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);
_startup = new Startup(this, _windows, _connectionsService);
connectionTreeContextMenu.ShowWindowAction = _windows.Show;
InitializeComponent();
@@ -215,8 +216,8 @@ namespace mRemoteNG.UI.Forms
if (Settings.Default.ResetPanels)
SetDefaultLayout();
Runtime.ConnectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
var credsAndConsSetup = new CredsAndConsSetup();
_connectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
var credsAndConsSetup = new CredsAndConsSetup(_connectionsService);
credsAndConsSetup.LoadCredsAndCons();
_windows.TreeForm.Focus();
@@ -334,7 +335,7 @@ namespace mRemoteNG.UI.Forms
if (CTaskDialog.CommandButtonResult != 1) return;
using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, Language.strTabUpdates))
using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, _connectionsService, Language.strTabUpdates))
{
optionsForm.ShowDialog(this);
}
@@ -403,7 +404,7 @@ namespace mRemoteNG.UI.Forms
private void tmrAutoSave_Tick(object sender, EventArgs e)
{
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Doing AutoSave");
Runtime.ConnectionsService.SaveConnectionsAsync();
_connectionsService.SaveConnectionsAsync();
}
#endregion
@@ -556,21 +557,21 @@ namespace mRemoteNG.UI.Forms
var titleBuilder = new StringBuilder(Application.ProductName);
const string separator = " - ";
if (Runtime.ConnectionsService.IsConnectionsFileLoaded)
if (_connectionsService.IsConnectionsFileLoaded)
{
if (Runtime.ConnectionsService.UsingDatabase)
if (_connectionsService.UsingDatabase)
{
titleBuilder.Append(separator);
titleBuilder.Append(Language.strSQLServer.TrimEnd(':'));
}
else
{
if (!string.IsNullOrEmpty(Runtime.ConnectionsService.ConnectionFileName))
if (!string.IsNullOrEmpty(_connectionsService.ConnectionFileName))
{
titleBuilder.Append(separator);
titleBuilder.Append(Settings.Default.ShowCompleteConsPathInTitle
? Runtime.ConnectionsService.ConnectionFileName
: Path.GetFileName(Runtime.ConnectionsService.ConnectionFileName));
? _connectionsService.ConnectionFileName
: Path.GetFileName(_connectionsService.ConnectionFileName));
}
}
}

View File

@@ -17,17 +17,19 @@ namespace mRemoteNG.UI.Forms
private readonly IConnectionInitiator _connectionInitiator;
private readonly Action<WindowType> _showWindowAction;
private readonly Func<NotificationAreaIcon> _notificationAreaIconBuilder;
private readonly ConnectionsService _connectionsService;
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder)
: this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, Language.strStartupExit)
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, string pageName)
public frmOptions(IConnectionInitiator connectionInitiator, Action<WindowType> showWindowAction, Func<NotificationAreaIcon> notificationAreaIconBuilder, ConnectionsService connectionsService, string pageName)
{
_connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator));
_showWindowAction = showWindowAction.ThrowIfNull(nameof(showWindowAction));
_notificationAreaIconBuilder = notificationAreaIconBuilder;
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
_pageName = pageName.ThrowIfNull(nameof(pageName));
InitializeComponent();
}
@@ -73,7 +75,7 @@ namespace mRemoteNG.UI.Forms
{typeof(NotificationsPage).Name, new NotificationsPage()},
{typeof(ConnectionsPage).Name, new ConnectionsPage()},
{typeof(CredentialsPage).Name, new CredentialsPage()},
{typeof(SqlServerPage).Name, new SqlServerPage()},
{typeof(SqlServerPage).Name, new SqlServerPage(_connectionsService)},
{typeof(UpdatesPage).Name, new UpdatesPage(_showWindowAction)},
{typeof(ThemePage).Name, new ThemePage()},
{typeof(SecurityPage).Name, new SecurityPage()},