diff --git a/mRemoteV1/Config/Putty/AbstractPuttySessionsProvider.cs b/mRemoteV1/Config/Putty/AbstractPuttySessionsProvider.cs index 3fb333f01..7ef17ab5a 100644 --- a/mRemoteV1/Config/Putty/AbstractPuttySessionsProvider.cs +++ b/mRemoteV1/Config/Putty/AbstractPuttySessionsProvider.cs @@ -10,6 +10,7 @@ namespace mRemoteNG.Config.Putty public abstract class AbstractPuttySessionsProvider { public virtual RootPuttySessionsNodeInfo RootInfo { get; } = new RootPuttySessionsNodeInfo(); + protected virtual List Sessions => RootInfo.Children.OfType().ToList(); #region Public Methods public abstract string[] GetSessionNames(bool raw = false); @@ -22,16 +23,23 @@ namespace mRemoteNG.Config.Putty var sessionInfo = GetSession(sessionName); AddSession(sessionInfo); } - return RootInfo.Children.OfType(); + return Sessions; } protected virtual void AddSession(PuttySessionInfo sessionInfo) { - if (string.IsNullOrEmpty(sessionInfo?.Name) || RootInfo.Children.Any(child => child.Name == sessionInfo.Name)) + if (string.IsNullOrEmpty(sessionInfo?.Name) || Sessions.Any(child => child.Name == sessionInfo.Name)) return; RootInfo.AddChild(sessionInfo); RaisePuttySessionCollectionChangedEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, sessionInfo)); } + + protected virtual void RemoveSession(PuttySessionInfo sessionInfo) + { + if (!Sessions.Contains(sessionInfo)) return; + RootInfo.RemoveChild(sessionInfo); + RaisePuttySessionCollectionChangedEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, sessionInfo)); + } public virtual void StartWatcher() { } @@ -40,14 +48,12 @@ namespace mRemoteNG.Config.Putty public delegate void PuttySessionChangedEventHandler(object sender, PuttySessionChangedEventArgs e); public event PuttySessionChangedEventHandler PuttySessionChanged; - protected virtual void RaiseSessionChangedEvent(PuttySessionChangedEventArgs args) { PuttySessionChanged?.Invoke(this, args); } public event NotifyCollectionChangedEventHandler PuttySessionsCollectionChanged; - protected void RaisePuttySessionCollectionChangedEvent(NotifyCollectionChangedEventArgs args) { PuttySessionsCollectionChanged?.Invoke(this, args);