implemented save connections on edit

This commit is contained in:
David Sparer
2017-11-12 15:14:50 -06:00
parent 1d80b166b1
commit f583b741d4
11 changed files with 24 additions and 40 deletions

View File

@@ -79,7 +79,7 @@ namespace mRemoteNG.App
}
}
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
}
catch (Exception ex)
@@ -93,7 +93,7 @@ namespace mRemoteNG.App
try
{
ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer, importSubOU);
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
catch (Exception ex)
{
@@ -107,7 +107,7 @@ namespace mRemoteNG.App
{
var importer = new PortScanImporter(protocol);
importer.Import(hosts, importDestinationContainer);
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
catch (Exception ex)
{

View File

@@ -192,21 +192,6 @@ namespace mRemoteNG.App
}
}
}
public static void SaveConnectionsAsync()
{
var t = new Thread(SaveConnectionsBGd);
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private static readonly object SaveLock = new object();
private static void SaveConnectionsBGd()
{
Monitor.Enter(SaveLock);
ConnectionsService.SaveConnections();
Monitor.Exit(SaveLock);
}
#endregion
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using mRemoteNG.App;
using mRemoteNG.App.Info;
@@ -16,6 +17,7 @@ namespace mRemoteNG.Connection
{
public class ConnectionsService
{
private static readonly object SaveLock = new object();
private readonly PuttySessionsManager _puttySessionsManager;
public bool IsConnectionsFileLoaded { get; set; }
@@ -170,6 +172,20 @@ namespace mRemoteNG.Connection
}
}
public void SaveConnectionsAsync()
{
var t = new Thread(SaveConnectionsBGd);
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void SaveConnectionsBGd()
{
Monitor.Enter(SaveLock);
SaveConnections();
Monitor.Exit(SaveLock);
}
public string GetStartupConnectionFileName()
{
return Settings.Default.LoadConsFromCustomLocation == false ? GetDefaultStartupConnectionFileName() : Settings.Default.CustomConsPath;

View File

@@ -26,7 +26,6 @@ namespace mRemoteNG.Tree
var dropSource = (ConnectionInfo)e.SourceModels[0];
DropModel(dropSource, dropTarget, e.DropTargetLocation);
e.Handled = true;
Runtime.SaveConnectionsAsync();
}
public void DropModel(ConnectionInfo dropSource, ConnectionInfo dropTarget, DropTargetLocation dropTargetLocation)

View File

@@ -748,13 +748,11 @@ namespace mRemoteNG.UI.Controls
private void OnAddConnectionClicked(object sender, EventArgs e)
{
_connectionTree.AddConnection();
Runtime.SaveConnectionsAsync();
}
private void OnAddFolderClicked(object sender, EventArgs e)
{
_connectionTree.AddFolder();
Runtime.SaveConnectionsAsync();
}
private void OnSortAscendingClicked(object sender, EventArgs e)
@@ -770,13 +768,11 @@ namespace mRemoteNG.UI.Controls
private void OnMoveUpClicked(object sender, EventArgs e)
{
_connectionTree.SelectedNode.Parent.PromoteChild(_connectionTree.SelectedNode);
Runtime.SaveConnectionsAsync();
}
private void OnMoveDownClicked(object sender, EventArgs e)
{
_connectionTree.SelectedNode.Parent.DemoteChild(_connectionTree.SelectedNode);
Runtime.SaveConnectionsAsync();
}
private void OnExternalToolClicked(object sender, EventArgs e)

View File

@@ -280,7 +280,6 @@ namespace mRemoteNG.UI.Controls
var newNode = SelectedNode.Clone();
SelectedNode.Parent.AddChildBelow(newNode, SelectedNode);
newNode.Parent.SetChildBelow(newNode, SelectedNode);
Runtime.SaveConnectionsAsync();
}
public void RenameSelectedNode()
@@ -294,7 +293,6 @@ namespace mRemoteNG.UI.Controls
if (SelectedNode is RootNodeInfo || SelectedNode is PuttySessionInfo) return;
if (!NodeDeletionConfirmer.Confirm(SelectedNode)) return;
ConnectionTreeModel.DeleteNode(SelectedNode);
Runtime.SaveConnectionsAsync();
}
public void SortRecursive(ConnectionInfo sortTarget, ListSortDirection sortDirection)
@@ -307,8 +305,6 @@ namespace mRemoteNG.UI.Controls
sortTargetAsContainer.SortRecursive(sortDirection);
else
SelectedNode.Parent.SortRecursive(sortDirection);
Runtime.SaveConnectionsAsync();
}
private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
@@ -389,7 +385,6 @@ namespace mRemoteNG.UI.Controls
_nodeInEditMode = false;
_allowEdit = false;
Windows.ConfigForm.SelectedTreeNode = SelectedNode;
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)
{

View File

@@ -315,7 +315,7 @@ namespace mRemoteNG.UI.Forms
private void tmrAutoSave_Tick(object sender, EventArgs e)
{
Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Doing AutoSave");
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
#endregion

View File

@@ -331,13 +331,11 @@ namespace mRemoteNG.UI.Menu
private void mMenFileNewConnection_Click(object sender, EventArgs e)
{
TreeWindow.ConnectionTree.AddConnection();
Runtime.SaveConnectionsAsync();
}
private void mMenFileNewFolder_Click(object sender, EventArgs e)
{
TreeWindow.ConnectionTree.AddFolder();
Runtime.SaveConnectionsAsync();
}
private void mMenFileNew_Click(object sender, EventArgs e)
@@ -372,7 +370,7 @@ namespace mRemoteNG.UI.Menu
private void mMenFileSave_Click(object sender, EventArgs e)
{
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
private void mMenFileSaveAs_Click(object sender, EventArgs e)
@@ -405,19 +403,16 @@ namespace mRemoteNG.UI.Menu
private void mMenFileDelete_Click(object sender, EventArgs e)
{
TreeWindow.ConnectionTree.DeleteSelectedNode();
Runtime.SaveConnectionsAsync();
}
private void mMenFileRename_Click(object sender, EventArgs e)
{
TreeWindow.ConnectionTree.RenameSelectedNode();
Runtime.SaveConnectionsAsync();
}
private void mMenFileDuplicate_Click(object sender, EventArgs e)
{
TreeWindow.ConnectionTree.DuplicateSelectedNode();
Runtime.SaveConnectionsAsync();
}
private void mMenReconnectAll_Click(object sender, EventArgs e)

View File

@@ -701,7 +701,7 @@ namespace mRemoteNG.UI.Window
UpdateRootInfoNode(e);
UpdateInheritanceNode();
ShowHideGridItems();
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
catch (Exception ex)
{
@@ -1592,7 +1592,7 @@ namespace mRemoteNG.UI.Window
connectionInfo.Icon = iconName;
_pGrid.Refresh();
Runtime.SaveConnectionsAsync();
Runtime.ConnectionsService.SaveConnectionsAsync();
}
catch (Exception ex)
{

View File

@@ -160,13 +160,11 @@ namespace mRemoteNG.UI.Window
private void cMenTreeAddConnection_Click(object sender, EventArgs e)
{
olvConnections.AddConnection();
Runtime.SaveConnectionsAsync();
}
private void cMenTreeAddFolder_Click(object sender, EventArgs e)
{
olvConnections.AddFolder();
Runtime.SaveConnectionsAsync();
}
private void tvConnections_BeforeLabelEdit(object sender, LabelEditEventArgs e)
@@ -180,7 +178,6 @@ namespace mRemoteNG.UI.Window
{
_contextMenu.EnableShortcutKeys();
ConnectionTree.ConnectionTreeModel.RenameNode(SelectedNode, e.Label);
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)
{

View File

@@ -136,6 +136,7 @@
<Compile Include="Config\Connections\ConnectionsLoadedEventArgs.cs" />
<Compile Include="Config\Connections\ConnectionsSavedEventArgs.cs" />
<Compile Include="Config\Connections\CsvConnectionsSaver.cs" />
<Compile Include="Config\Connections\SaveConnectionsOnEdit.cs" />
<Compile Include="Config\Connections\SaveFormat.cs" />
<Compile Include="Config\Connections\Multiuser\ConnectionsUpdateCheckFinishedEventArgs.cs" />
<Compile Include="Config\Connections\Multiuser\IConnectionsUpdateChecker.cs" />