mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Added a convenience property and a way to remove sessions that triggers eventing
This commit is contained in:
@@ -10,6 +10,7 @@ namespace mRemoteNG.Config.Putty
|
||||
public abstract class AbstractPuttySessionsProvider
|
||||
{
|
||||
public virtual RootPuttySessionsNodeInfo RootInfo { get; } = new RootPuttySessionsNodeInfo();
|
||||
protected virtual List<PuttySessionInfo> Sessions => RootInfo.Children.OfType<PuttySessionInfo>().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<PuttySessionInfo>();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user