mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
modified a few more classes to reduce reliance on Runtime
This commit is contained in:
@@ -66,7 +66,7 @@ namespace mRemoteNGTests.Connection.Protocol
|
||||
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 connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), _connectionInitiator, connectionsService);
|
||||
var connectionTree = connectionTreeWindow.ConnectionTree;
|
||||
var export = new Export(new CredentialRepositoryList(), connectionsService);
|
||||
var connectionTreeContextMenu = new ConnectionContextMenu(connectionTree, _connectionInitiator, sshTransferWindow, export, _externalToolsService, import);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace mRemoteNGTests.UI.Window
|
||||
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};
|
||||
_connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), connectionInitiator, connectionsService) {ConnectionTreeContextMenu = connectionContextMenu};
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -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; set; } = new ConnectionsService(PuttySessionsManager.Instance, new Import());
|
||||
public static ConnectionsService ConnectionsService { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.App.Info;
|
||||
using mRemoteNG.Config.DatabaseConnectors;
|
||||
using mRemoteNG.Config.DataProviders;
|
||||
using mRemoteNG.Config.Serializers;
|
||||
using mRemoteNG.Config.Serializers.Versioning;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Messages;
|
||||
using mRemoteNG.Security;
|
||||
@@ -21,14 +21,15 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
public class SqlConnectionsSaver : ISaver<ConnectionTreeModel>
|
||||
{
|
||||
private SecureString _password = Runtime.ConnectionsService.EncryptionKey;
|
||||
private readonly ConnectionsService _connectionsService;
|
||||
private readonly SaveFilter _saveFilter;
|
||||
|
||||
public SqlConnectionsSaver(SaveFilter saveFilter)
|
||||
public SqlConnectionsSaver(SaveFilter saveFilter, ConnectionsService connectionsService)
|
||||
{
|
||||
if (saveFilter == null)
|
||||
throw new ArgumentNullException(nameof(saveFilter));
|
||||
_saveFilter = saveFilter;
|
||||
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
|
||||
}
|
||||
|
||||
public void Save(ConnectionTreeModel connectionTreeModel)
|
||||
@@ -67,17 +68,17 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
if (rootTreeNode.Password)
|
||||
{
|
||||
_password = rootTreeNode.PasswordString.ConvertToSecureString();
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsProtected", _password);
|
||||
_connectionsService.EncryptionKey = rootTreeNode.PasswordString.ConvertToSecureString();
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsProtected", _connectionsService.EncryptionKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _connectionsService.EncryptionKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
|
||||
strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _connectionsService.EncryptionKey);
|
||||
}
|
||||
|
||||
var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace mRemoteNG.Connection
|
||||
|
||||
var previouslyUsingDatabase = UsingDatabase;
|
||||
if (useDatabase)
|
||||
new SqlConnectionsSaver(saveFilter).Save(connectionTreeModel);
|
||||
new SqlConnectionsSaver(saveFilter, this).Save(connectionTreeModel);
|
||||
else
|
||||
new XmlConnectionsSaver(connectionFileName, saveFilter).Save(connectionTreeModel);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace mRemoteNG.UI.Controls
|
||||
private WeifenLuo.WinFormsUI.Docking.VisualStudioToolStripExtender vsToolStripExtender;
|
||||
|
||||
public IConnectionInitiator ConnectionInitiator { get; set; }
|
||||
public ConnectionsService ConnectionsService { get; set; }
|
||||
|
||||
public QuickConnectToolStrip()
|
||||
{
|
||||
@@ -167,7 +168,7 @@ namespace mRemoteNG.UI.Controls
|
||||
{
|
||||
try
|
||||
{
|
||||
var connectionInfo = Runtime.ConnectionsService.CreateQuickConnect(_cmbQuickConnect.Text.Trim(), Converter.StringToProtocol(Settings.Default.QuickConnectProtocol));
|
||||
var connectionInfo = ConnectionsService.CreateQuickConnect(_cmbQuickConnect.Text.Trim(), Converter.StringToProtocol(Settings.Default.QuickConnectProtocol));
|
||||
if (connectionInfo == null)
|
||||
{
|
||||
_cmbQuickConnect.Focus();
|
||||
@@ -214,7 +215,7 @@ namespace mRemoteNG.UI.Controls
|
||||
};
|
||||
|
||||
// ReSharper disable once CoVariantArrayConversion
|
||||
ToolStripItem[] rootMenuItems = menuItemsConverter.CreateToolStripDropDownItems(Runtime.ConnectionsService.ConnectionTreeModel).ToArray();
|
||||
ToolStripItem[] rootMenuItems = menuItemsConverter.CreateToolStripDropDownItems(ConnectionsService.ConnectionTreeModel).ToArray();
|
||||
_btnConnections.DropDownItems.AddRange(rootMenuItems);
|
||||
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace mRemoteNG.UI.Forms
|
||||
var externalToolsService = new ExternalToolsService();
|
||||
_import = new Import();
|
||||
_connectionsService = new ConnectionsService(PuttySessionsManager.Instance, _import);
|
||||
Runtime.ConnectionsService = _connectionsService;
|
||||
_import.ConnectionsService = _connectionsService;
|
||||
_appUpdater = new AppUpdater(() => _connectionsService.EncryptionKey);
|
||||
ExternalToolsTypeConverter.ExternalToolsService = externalToolsService;
|
||||
@@ -87,7 +88,7 @@ namespace mRemoteNG.UI.Forms
|
||||
_webHelper = new WebHelper(_connectionInitiator);
|
||||
var configWindow = new ConfigWindow(new DockContent());
|
||||
var sshTransferWindow = new SSHTransferWindow();
|
||||
var connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), _connectionInitiator);
|
||||
var connectionTreeWindow = new ConnectionTreeWindow(new DockContent(), _connectionInitiator, _connectionsService);
|
||||
var connectionTree = connectionTreeWindow.ConnectionTree;
|
||||
connectionTree.SelectedNodeChanged += configWindow.HandleConnectionTreeSelectionChanged;
|
||||
var connectionTreeContextMenu = new ConnectionContextMenu(connectionTree, _connectionInitiator, sshTransferWindow, _export, externalToolsService, _import);
|
||||
@@ -118,6 +119,7 @@ namespace mRemoteNG.UI.Forms
|
||||
_externalToolsToolStrip.ExternalToolsService = externalToolsService;
|
||||
_externalToolsToolStrip.GetSelectedConnectionFunc = () => SelectedConnection;
|
||||
_quickConnectToolStrip.ConnectionInitiator = _connectionInitiator;
|
||||
_quickConnectToolStrip.ConnectionsService = _connectionsService;
|
||||
CredentialRecordTypeConverter.CredentialRepositoryList = _credentialRepositoryList;
|
||||
CredentialRecordListAdaptor.CredentialRepositoryList = _credentialRepositoryList;
|
||||
|
||||
@@ -277,6 +279,7 @@ namespace mRemoteNG.UI.Forms
|
||||
mainFileMenu1.Export = _export;
|
||||
mainFileMenu1.Shutdown = _shutdown;
|
||||
mainFileMenu1.Import = _import;
|
||||
mainFileMenu1.ConnectionsService = _connectionsService;
|
||||
|
||||
viewMenu1.TsExternalTools = _externalToolsToolStrip;
|
||||
viewMenu1.TsQuickConnect = _quickConnectToolStrip;
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace mRemoteNG.UI.Menu
|
||||
public Export Export { get; set; }
|
||||
public Shutdown Shutdown { get; set; }
|
||||
public Import Import { get; set; }
|
||||
public ConnectionsService ConnectionsService { get; set; }
|
||||
|
||||
public MainFileMenu()
|
||||
{
|
||||
@@ -351,31 +352,31 @@ namespace mRemoteNG.UI.Menu
|
||||
return;
|
||||
}
|
||||
|
||||
Runtime.ConnectionsService.NewConnectionsFile(saveFileDialog.FileName);
|
||||
ConnectionsService.NewConnectionsFile(saveFileDialog.FileName);
|
||||
}
|
||||
|
||||
private void mMenFileLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Runtime.ConnectionsService.IsConnectionsFileLoaded)
|
||||
if (ConnectionsService.IsConnectionsFileLoaded)
|
||||
{
|
||||
var msgBoxResult = MessageBox.Show(Language.strSaveConnectionsFileBeforeOpeningAnother, Language.strSave, MessageBoxButtons.YesNoCancel);
|
||||
// ReSharper disable once SwitchStatementMissingSomeCases
|
||||
switch (msgBoxResult)
|
||||
{
|
||||
case DialogResult.Yes:
|
||||
Runtime.ConnectionsService.SaveConnections();
|
||||
ConnectionsService.SaveConnections();
|
||||
break;
|
||||
case DialogResult.Cancel:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Runtime.ConnectionsService.LoadConnections(true);
|
||||
ConnectionsService.LoadConnections(true);
|
||||
}
|
||||
|
||||
private void mMenFileSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
Runtime.ConnectionsService.SaveConnectionsAsync();
|
||||
ConnectionsService.SaveConnectionsAsync();
|
||||
}
|
||||
|
||||
private void mMenFileSaveAs_Click(object sender, EventArgs e)
|
||||
@@ -391,9 +392,9 @@ namespace mRemoteNG.UI.Menu
|
||||
if (saveFileDialog.ShowDialog(FrmMain.Default) != DialogResult.OK) return;
|
||||
var newFileName = saveFileDialog.FileName;
|
||||
|
||||
Runtime.ConnectionsService.SaveConnections(Runtime.ConnectionsService.ConnectionTreeModel, false, new SaveFilter(), newFileName);
|
||||
ConnectionsService.SaveConnections(ConnectionsService.ConnectionTreeModel, false, new SaveFilter(), newFileName);
|
||||
|
||||
if (newFileName == Runtime.ConnectionsService.GetDefaultStartupConnectionFileName())
|
||||
if (newFileName == ConnectionsService.GetDefaultStartupConnectionFileName())
|
||||
{
|
||||
Settings.Default.LoadConsFromCustomLocation = false;
|
||||
}
|
||||
@@ -457,7 +458,7 @@ namespace mRemoteNG.UI.Menu
|
||||
var selectedNode = TreeWindow.SelectedNode;
|
||||
ContainerInfo importDestination;
|
||||
if (selectedNode == null)
|
||||
importDestination = Runtime.ConnectionsService.ConnectionTreeModel.RootNodes.First();
|
||||
importDestination = ConnectionsService.ConnectionTreeModel.RootNodes.First();
|
||||
else
|
||||
importDestination = selectedNode as ContainerInfo ?? selectedNode.Parent;
|
||||
Import.ImportFromFile(importDestination);
|
||||
@@ -475,7 +476,7 @@ namespace mRemoteNG.UI.Menu
|
||||
|
||||
private void mMenFileExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
Export.ExportToFile(Windows.TreeForm.SelectedNode, Runtime.ConnectionsService.ConnectionTreeModel);
|
||||
Export.ExportToFile(Windows.TreeForm.SelectedNode, ConnectionsService.ConnectionTreeModel);
|
||||
}
|
||||
|
||||
private void mMenFileExit_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace mRemoteNG.UI.Window
|
||||
public partial class ConnectionTreeWindow
|
||||
{
|
||||
private readonly IConnectionInitiator _connectionInitiator;
|
||||
private readonly ConnectionsService _connectionsService;
|
||||
private ThemeManager _themeManager;
|
||||
private readonly ConnectionTreeSearchTextFilter _connectionTreeSearchTextFilter = new ConnectionTreeSearchTextFilter();
|
||||
|
||||
@@ -34,9 +35,10 @@ namespace mRemoteNG.UI.Window
|
||||
set { olvConnections = value; }
|
||||
}
|
||||
|
||||
public ConnectionTreeWindow(DockContent panel, IConnectionInitiator connectionInitiator)
|
||||
public ConnectionTreeWindow(DockContent panel, IConnectionInitiator connectionInitiator, ConnectionsService connectionsService)
|
||||
{
|
||||
WindowType = WindowType.Tree;
|
||||
_connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService));
|
||||
WindowType = WindowType.Tree;
|
||||
DockPnl = panel.ThrowIfNull(nameof(panel));
|
||||
_connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator));
|
||||
InitializeComponent();
|
||||
@@ -105,7 +107,7 @@ namespace mRemoteNG.UI.Window
|
||||
SetTreePostSetupActions();
|
||||
SetConnectionTreeDoubleClickHandlers();
|
||||
SetConnectionTreeSingleClickHandlers();
|
||||
Runtime.ConnectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
|
||||
_connectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
|
||||
}
|
||||
|
||||
private void SetTreePostSetupActions()
|
||||
|
||||
Reference in New Issue
Block a user