mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
added a safety check to the previous session opener to only open sessions that aren't already open
This commit is contained in:
@@ -32,7 +32,6 @@ namespace mRemoteNG.App
|
||||
}
|
||||
}
|
||||
|
||||
private static string SettingsPath { get; } = SettingsFileInfo.SettingsPath;
|
||||
public static WindowList WindowList { get; set; }
|
||||
public static MessageCollector MessageCollector { get; } = new MessageCollector();
|
||||
public static NotificationAreaIcon NotificationAreaIcon { get; set; }
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Config.Connections.Multiuser;
|
||||
using mRemoteNG.Config.DatabaseConnectors;
|
||||
using mRemoteNG.Messages;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading;
|
||||
using mRemoteNG.Config.Connections.Multiuser;
|
||||
using mRemoteNG.Config.DatabaseConnectors;
|
||||
|
||||
namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
private readonly SqlDatabaseConnector _sqlConnector;
|
||||
private readonly SqlCommand _sqlQuery;
|
||||
private DateTime _lastUpdateTime;
|
||||
private DateTime LastUpdateTime => Runtime.ConnectionsService.LastSqlUpdate;
|
||||
private DateTime _lastDatabaseUpdateTime;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
_sqlConnector = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings();
|
||||
_sqlQuery = new SqlCommand("SELECT * FROM tblUpdate", _sqlConnector.SqlConnection);
|
||||
_lastUpdateTime = default(DateTime);
|
||||
_lastDatabaseUpdateTime = default(DateTime);
|
||||
}
|
||||
|
||||
@@ -58,14 +57,14 @@ namespace mRemoteNG.Config.Connections
|
||||
private bool DatabaseIsMoreUpToDateThanUs()
|
||||
{
|
||||
var lastUpdateInDb = GetLastUpdateTimeFromDbResponse();
|
||||
var IAmTheLastoneUpdated = CheckIfIAmTheLastOneUpdated(lastUpdateInDb);
|
||||
return (lastUpdateInDb > _lastUpdateTime && !IAmTheLastoneUpdated);
|
||||
var amTheLastoneUpdated = CheckIfIAmTheLastOneUpdated(lastUpdateInDb);
|
||||
return (lastUpdateInDb > LastUpdateTime && !amTheLastoneUpdated);
|
||||
}
|
||||
|
||||
private bool CheckIfIAmTheLastOneUpdated(DateTime lastUpdateInDb)
|
||||
{
|
||||
DateTime LastSqlUpdateWithoutMilliseconds = new DateTime(Runtime.ConnectionsService.LastSqlUpdate.Ticks - (Runtime.ConnectionsService.LastSqlUpdate.Ticks % TimeSpan.TicksPerSecond), Runtime.ConnectionsService.LastSqlUpdate.Kind);
|
||||
return lastUpdateInDb == LastSqlUpdateWithoutMilliseconds;
|
||||
DateTime lastSqlUpdateWithoutMilliseconds = new DateTime(LastUpdateTime.Ticks - (LastUpdateTime.Ticks % TimeSpan.TicksPerSecond), LastUpdateTime.Kind);
|
||||
return lastUpdateInDb == lastSqlUpdateWithoutMilliseconds;
|
||||
}
|
||||
|
||||
private DateTime GetLastUpdateTimeFromDbResponse()
|
||||
@@ -106,8 +105,8 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
var args = new ConnectionsUpdateAvailableEventArgs(_sqlConnector, _lastDatabaseUpdateTime);
|
||||
ConnectionsUpdateAvailable?.Invoke(this, args);
|
||||
if(args.Handled)
|
||||
_lastUpdateTime = _lastDatabaseUpdateTime;
|
||||
//if(args.Handled)
|
||||
// LastUpdateTime = _lastDatabaseUpdateTime;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Connection.Protocol.RDP;
|
||||
using mRemoteNG.Container;
|
||||
@@ -8,14 +6,23 @@ using mRemoteNG.Messages;
|
||||
using mRemoteNG.UI.Forms;
|
||||
using mRemoteNG.UI.Panels;
|
||||
using mRemoteNG.UI.Window;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using TabPage = Crownwood.Magic.Controls.TabPage;
|
||||
|
||||
|
||||
namespace mRemoteNG.Connection
|
||||
{
|
||||
public class ConnectionInitiator : IConnectionInitiator
|
||||
public class ConnectionInitiator : IConnectionInitiator
|
||||
{
|
||||
private readonly PanelAdder _panelAdder = new PanelAdder();
|
||||
private readonly List<string> _activeConnections = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// List of unique IDs of the currently active connections
|
||||
/// </summary>
|
||||
public IEnumerable<string> ActiveConnections => _activeConnections;
|
||||
|
||||
public void OpenConnection(ContainerInfo containerInfo, ConnectionInfo.Force force = ConnectionInfo.Force.None)
|
||||
{
|
||||
@@ -118,6 +125,7 @@ namespace mRemoteNG.Connection
|
||||
}
|
||||
|
||||
connectionInfo.OpenConnections.Add(newProtocol);
|
||||
_activeConnections.Add(connectionInfo.ConstantID);
|
||||
FrmMain.Default.SelectedConnection = connectionInfo;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -210,7 +218,7 @@ namespace mRemoteNG.Connection
|
||||
newProtocol.Closed += ((ConnectionWindow)connectionForm).Prot_Event_Closed;
|
||||
}
|
||||
|
||||
private static void SetConnectionEventHandlers(ProtocolBase newProtocol)
|
||||
private void SetConnectionEventHandlers(ProtocolBase newProtocol)
|
||||
{
|
||||
newProtocol.Disconnected += Prot_Event_Disconnected;
|
||||
newProtocol.Connected += Prot_Event_Connected;
|
||||
@@ -251,7 +259,7 @@ namespace mRemoteNG.Connection
|
||||
}
|
||||
}
|
||||
|
||||
private static void Prot_Event_Closed(object sender)
|
||||
private void Prot_Event_Closed(object sender)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -267,6 +275,8 @@ namespace mRemoteNG.Connection
|
||||
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strConnenctionClosedByUser, connDetail, prot.InterfaceControl.Info.Protocol, Environment.UserName));
|
||||
prot.InterfaceControl.Info.OpenConnections.Remove(prot);
|
||||
if (_activeConnections.Contains(prot.InterfaceControl.Info.ConstantID))
|
||||
_activeConnections.Remove(prot.InterfaceControl.Info.ConstantID);
|
||||
|
||||
if (prot.InterfaceControl.Info.PostExtApp == "") return;
|
||||
var extA = Runtime.ExternalToolsService.GetExtAppByName(prot.InterfaceControl.Info.PostExtApp);
|
||||
|
||||
@@ -116,6 +116,9 @@ namespace mRemoteNG.Connection
|
||||
? new SqlConnectionsLoader(_localConnectionPropertiesSerializer, _localConnectionPropertiesDataProvider).Load()
|
||||
: new XmlConnectionsLoader(connectionFileName).Load();
|
||||
|
||||
if (useDatabase)
|
||||
LastSqlUpdate = DateTime.Now;
|
||||
|
||||
if (newConnectionTreeModel == null)
|
||||
{
|
||||
DialogFactory.ShowLoadConnectionsFailedDialog(connectionFileName, "Decrypting connection file failed", IsConnectionsFileLoaded);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using mRemoteNG.Container;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mRemoteNG.Connection
|
||||
{
|
||||
public interface IConnectionInitiator
|
||||
{
|
||||
IEnumerable<string> ActiveConnections { get; }
|
||||
|
||||
void OpenConnection(ConnectionInfo connectionInfo);
|
||||
|
||||
void OpenConnection(ContainerInfo containerInfo, ConnectionInfo.Force force = ConnectionInfo.Force.None);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.UI.Controls;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace mRemoteNG.Tree
|
||||
@@ -21,7 +21,12 @@ namespace mRemoteNG.Tree
|
||||
public void Execute(IConnectionTree connectionTree)
|
||||
{
|
||||
var connectionInfoList = connectionTree.GetRootConnectionNode().GetRecursiveChildList().Where(node => !(node is ContainerInfo));
|
||||
var previouslyOpenedConnections = connectionInfoList.Where(item => item.PleaseConnect);
|
||||
var previouslyOpenedConnections = connectionInfoList
|
||||
.Where(item =>
|
||||
item.PleaseConnect &&
|
||||
// ignore items that have already connected
|
||||
!_connectionInitiator.ActiveConnections.Contains(item.ConstantID));
|
||||
|
||||
foreach (var connectionInfo in previouslyOpenedConnections)
|
||||
{
|
||||
_connectionInitiator.OpenConnection(connectionInfo);
|
||||
|
||||
Reference in New Issue
Block a user