mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Putty sessions now being shown in connection tree again
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Config.DataProviders;
|
||||
using mRemoteNG.Config.Putty;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.UI;
|
||||
@@ -65,8 +66,9 @@ namespace mRemoteNG.Config.Connections
|
||||
frmMain.Default.AreWeUsingSqlServerForSavingConnections = UseDatabase;
|
||||
frmMain.Default.ConnectionsFileName = ConnectionFileName;
|
||||
|
||||
if (!import)
|
||||
Putty.PuttySessionsManager.AddSessionsToTree(Windows.treeForm.tvConnections);
|
||||
if (import) return;
|
||||
PuttySessionsManager.AddSessionsToTree(Windows.treeForm.tvConnections);
|
||||
Runtime.ConnectionTreeModel.RootNodes.AddRange(PuttySessionsManager.RootPuttySessionsNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.Tree;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Root.PuttySessions;
|
||||
|
||||
@@ -10,50 +9,27 @@ namespace mRemoteNG.Config.Putty
|
||||
{
|
||||
public abstract class AbstractPuttySessionsProvider
|
||||
{
|
||||
#region Public Methods
|
||||
private TreeNode _rootTreeNode;
|
||||
public TreeNode RootTreeNode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rootTreeNode == null)
|
||||
{
|
||||
_rootTreeNode = CreateRootTreeNode();
|
||||
}
|
||||
return _rootTreeNode;
|
||||
}
|
||||
}
|
||||
|
||||
private RootPuttySessionsNodeInfo _rootInfo;
|
||||
public RootPuttySessionsNodeInfo RootInfo => _rootInfo ?? (_rootInfo = CreateRootInfo());
|
||||
public RootPuttySessionsNodeInfo RootInfo { get; } = new RootPuttySessionsNodeInfo();
|
||||
|
||||
#region Public Methods
|
||||
public abstract string[] GetSessionNames(bool raw = false);
|
||||
public abstract PuttySessionInfo GetSession(string sessionName);
|
||||
|
||||
public virtual IEnumerable<PuttySessionInfo> GetSessions()
|
||||
{
|
||||
var sessionList = new List<PuttySessionInfo>();
|
||||
foreach (var sessionName in GetSessionNames(true))
|
||||
{
|
||||
var sessionInfo = GetSession(sessionName);
|
||||
if (string.IsNullOrEmpty(sessionInfo?.Hostname))
|
||||
{
|
||||
if (string.IsNullOrEmpty(sessionInfo?.Hostname) || RootInfo.Children.Any(child => child.Name == sessionInfo.Name))
|
||||
continue;
|
||||
}
|
||||
sessionList.Add(sessionInfo);
|
||||
RootInfo.AddChild(sessionInfo);
|
||||
}
|
||||
return sessionList;
|
||||
return RootInfo.Children.OfType<PuttySessionInfo>();
|
||||
}
|
||||
|
||||
public virtual void StartWatcher()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void StartWatcher() { }
|
||||
|
||||
public virtual void StopWatcher()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void StopWatcher() { }
|
||||
#endregion
|
||||
|
||||
#region Public Events
|
||||
@@ -80,61 +56,10 @@ namespace mRemoteNG.Config.Putty
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
private delegate TreeNode CreateRootTreeNodeDelegate();
|
||||
protected virtual TreeNode CreateRootTreeNode()
|
||||
{
|
||||
TreeView treeView = ConnectionTree.TreeView;
|
||||
if (treeView == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (treeView.InvokeRequired)
|
||||
{
|
||||
return (TreeNode)treeView.Invoke(new CreateRootTreeNodeDelegate(CreateRootTreeNode));
|
||||
}
|
||||
|
||||
TreeNode newTreeNode = new TreeNode();
|
||||
RootInfo.TreeNode = newTreeNode;
|
||||
|
||||
newTreeNode.Name = _rootInfo.Name;
|
||||
newTreeNode.Text = _rootInfo.Name;
|
||||
newTreeNode.Tag = _rootInfo;
|
||||
newTreeNode.ImageIndex = (int)TreeImageType.PuttySessions;
|
||||
newTreeNode.SelectedImageIndex = (int)TreeImageType.PuttySessions;
|
||||
|
||||
return newTreeNode;
|
||||
}
|
||||
|
||||
protected virtual RootPuttySessionsNodeInfo CreateRootInfo()
|
||||
{
|
||||
var newRootInfo = new RootPuttySessionsNodeInfo();
|
||||
|
||||
if (string.IsNullOrEmpty(Convert.ToString(mRemoteNG.Settings.Default.PuttySavedSessionsName)))
|
||||
{
|
||||
newRootInfo.Name = Language.strPuttySavedSessionsRootName;
|
||||
}
|
||||
else
|
||||
{
|
||||
newRootInfo.Name = Convert.ToString(mRemoteNG.Settings.Default.PuttySavedSessionsName);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Convert.ToString(mRemoteNG.Settings.Default.PuttySavedSessionsPanel)))
|
||||
{
|
||||
newRootInfo.Panel = Language.strGeneral;
|
||||
}
|
||||
else
|
||||
{
|
||||
newRootInfo.Panel = Convert.ToString(mRemoteNG.Settings.Default.PuttySavedSessionsPanel);
|
||||
}
|
||||
|
||||
return newRootInfo;
|
||||
}
|
||||
|
||||
protected virtual void OnSessionChanged(SessionChangedEventArgs e)
|
||||
{
|
||||
SessionChangedEvent?.Invoke(this, new SessionChangedEventArgs());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Root.PuttySessions;
|
||||
|
||||
|
||||
namespace mRemoteNG.Config.Putty
|
||||
@@ -17,122 +16,77 @@ namespace mRemoteNG.Config.Putty
|
||||
get
|
||||
{
|
||||
if (_providers == null || _providers.Count == 0)
|
||||
{
|
||||
AddProviders();
|
||||
}
|
||||
return _providers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PuttySessionsManager()
|
||||
{
|
||||
|
||||
}
|
||||
public static List<RootPuttySessionsNodeInfo> RootPuttySessionsNodes { get; } = new List<RootPuttySessionsNodeInfo>();
|
||||
|
||||
#region Public Methods
|
||||
private delegate void AddSessionsToTreeDelegate(TreeView treeView);
|
||||
public static void AddSessionsToTree(TreeView treeView)
|
||||
{
|
||||
if (treeView == null)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
if (treeView.InvokeRequired)
|
||||
{
|
||||
treeView.Invoke(new AddSessionsToTreeDelegate(AddSessionsToTree));
|
||||
return ;
|
||||
}
|
||||
|
||||
foreach (var provider in Providers)
|
||||
{
|
||||
var rootTreeNode = provider.RootTreeNode;
|
||||
var inUpdate = false;
|
||||
|
||||
var savedSessions = new List<ConnectionInfo>(provider.GetSessions());
|
||||
if (!IsProviderEnabled(provider) || savedSessions == null || savedSessions.Count == 0)
|
||||
{
|
||||
if (rootTreeNode != null && treeView.Nodes.Contains(rootTreeNode))
|
||||
{
|
||||
treeView.BeginUpdate();
|
||||
treeView.Nodes.Remove(rootTreeNode);
|
||||
treeView.EndUpdate();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!treeView.Nodes.Contains(rootTreeNode))
|
||||
{
|
||||
if (!inUpdate)
|
||||
{
|
||||
treeView.BeginUpdate();
|
||||
inUpdate = true;
|
||||
}
|
||||
treeView.Nodes.Add(rootTreeNode);
|
||||
}
|
||||
|
||||
var newTreeNodes = new List<TreeNode>();
|
||||
foreach (PuttySessionInfo sessionInfo in savedSessions)
|
||||
{
|
||||
TreeNode treeNode;
|
||||
bool isNewNode;
|
||||
if (rootTreeNode.Nodes.ContainsKey(sessionInfo.Name))
|
||||
{
|
||||
treeNode = rootTreeNode.Nodes[sessionInfo.Name];
|
||||
isNewNode = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
treeNode = ConnectionTreeNode.AddNode(TreeNodeType.PuttySession, sessionInfo.Name);
|
||||
if (treeNode == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
treeNode.Name = treeNode.Text;
|
||||
treeNode.ImageIndex = (int)TreeImageType.ConnectionClosed;
|
||||
treeNode.SelectedImageIndex = (int)TreeImageType.ConnectionClosed;
|
||||
isNewNode = true;
|
||||
}
|
||||
|
||||
sessionInfo.RootRootPuttySessionsInfo = provider.RootInfo;
|
||||
sessionInfo.TreeNode = treeNode;
|
||||
//sessionInfo.IInheritable.TurnOffInheritanceCompletely();
|
||||
|
||||
treeNode.Tag = sessionInfo;
|
||||
|
||||
if (isNewNode)
|
||||
{
|
||||
newTreeNodes.Add(treeNode);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (TreeNode treeNode in rootTreeNode.Nodes)
|
||||
{
|
||||
if (savedSessions.Contains((ConnectionInfo) treeNode.Tag)) continue;
|
||||
if (!inUpdate)
|
||||
{
|
||||
treeView.BeginUpdate();
|
||||
inUpdate = true;
|
||||
}
|
||||
rootTreeNode.Nodes.Remove(treeNode);
|
||||
}
|
||||
|
||||
if (newTreeNodes.Count != 0)
|
||||
{
|
||||
if (!inUpdate)
|
||||
{
|
||||
treeView.BeginUpdate();
|
||||
inUpdate = true;
|
||||
}
|
||||
rootTreeNode.Nodes.AddRange(newTreeNodes.ToArray());
|
||||
}
|
||||
|
||||
if (!inUpdate) continue;
|
||||
ConnectionTree.Sort(rootTreeNode, SortOrder.Ascending);
|
||||
rootTreeNode.Expand();
|
||||
treeView.EndUpdate();
|
||||
AddSessionsToTreeForProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddSessionsToTreeForProvider(AbstractPuttySessionsProvider provider)
|
||||
{
|
||||
var rootTreeNode = provider.RootInfo;
|
||||
provider.GetSessions();
|
||||
//var savedSessions = new List<PuttySessionInfo>(provider.GetSessions());
|
||||
//if (!IsProviderEnabled(provider) || savedSessions == null || savedSessions.Count == 0)
|
||||
//{
|
||||
// if (rootTreeNode != null && treeView.Nodes.Contains(rootTreeNode))
|
||||
// {
|
||||
// treeView.BeginUpdate();
|
||||
// treeView.Nodes.Remove(rootTreeNode);
|
||||
// treeView.EndUpdate();
|
||||
// }
|
||||
// continue;
|
||||
//}
|
||||
|
||||
//var newTreeNodes = new List<TreeNode>();
|
||||
//foreach (var sessionInfo in savedSessions)
|
||||
//{
|
||||
// TreeNode treeNode;
|
||||
// bool isNewNode;
|
||||
// if (rootTreeNode.Nodes.ContainsKey(sessionInfo.Name))
|
||||
// {
|
||||
// treeNode = rootTreeNode.Nodes[sessionInfo.Name];
|
||||
// isNewNode = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// treeNode = ConnectionTreeNode.AddNode(TreeNodeType.PuttySession, sessionInfo.Name);
|
||||
// if (treeNode == null)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// treeNode.Name = treeNode.Text;
|
||||
// treeNode.ImageIndex = (int)TreeImageType.ConnectionClosed;
|
||||
// treeNode.SelectedImageIndex = (int)TreeImageType.ConnectionClosed;
|
||||
// isNewNode = true;
|
||||
// }
|
||||
|
||||
// sessionInfo.RootRootPuttySessionsInfo = provider.RootInfo;
|
||||
// sessionInfo.TreeNode = treeNode;
|
||||
// //sessionInfo.IInheritable.TurnOffInheritanceCompletely();
|
||||
|
||||
// treeNode.Tag = sessionInfo;
|
||||
|
||||
// if (isNewNode)
|
||||
// {
|
||||
// newTreeNodes.Add(treeNode);
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!RootPuttySessionsNodes.Contains(rootTreeNode))
|
||||
RootPuttySessionsNodes.Add(rootTreeNode);
|
||||
rootTreeNode.SortRecursive();
|
||||
}
|
||||
|
||||
public static void StartWatcher()
|
||||
{
|
||||
@@ -159,8 +113,7 @@ namespace mRemoteNG.Config.Putty
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
public void AddProvider(AbstractPuttySessionsProvider provider)
|
||||
public static void AddProvider(AbstractPuttySessionsProvider provider)
|
||||
{
|
||||
_providers.Add(provider);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using mRemoteNG.Connection;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Tools;
|
||||
|
||||
@@ -7,41 +7,29 @@ namespace mRemoteNG.Tree.Root
|
||||
{
|
||||
[DefaultProperty("Name")]
|
||||
public class RootNodeInfo : ContainerInfo
|
||||
{
|
||||
private string _name;
|
||||
{
|
||||
private string _name;
|
||||
|
||||
|
||||
public RootNodeInfo(RootNodeType rootType)
|
||||
public RootNodeInfo(RootNodeType rootType)
|
||||
{
|
||||
_name = Language.strConnections;
|
||||
_name = Language.strConnections;
|
||||
Type = rootType;
|
||||
}
|
||||
|
||||
|
||||
#region Public Properties
|
||||
[LocalizedAttributes.LocalizedCategory("strCategoryDisplay"),
|
||||
Browsable(true),
|
||||
LocalizedAttributes.LocalizedDefaultValue("strConnections"),
|
||||
LocalizedAttributes.LocalizedDisplayName("strPropertyNameName"),
|
||||
LocalizedAttributes.LocalizedDescription("strPropertyDescriptionName")]
|
||||
public override string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
if (_name == value)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
_name = value;
|
||||
if (TreeNode != null)
|
||||
{
|
||||
TreeNode.Name = value;
|
||||
TreeNode.Text = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedAttributes.LocalizedCategory("strCategoryDisplay"),
|
||||
[LocalizedAttributes.LocalizedCategory("strCategoryDisplay"),
|
||||
Browsable(true),
|
||||
LocalizedAttributes.LocalizedDefaultValue("strConnections"),
|
||||
LocalizedAttributes.LocalizedDisplayName("strPropertyNameName"),
|
||||
LocalizedAttributes.LocalizedDescription("strPropertyDescriptionName")]
|
||||
public override string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
[LocalizedAttributes.LocalizedCategory("strCategoryDisplay"),
|
||||
Browsable(true),
|
||||
LocalizedAttributes.LocalizedDisplayName("strPasswordProtect"),
|
||||
TypeConverter(typeof(Tools.MiscTools.YesNoTypeConverter))]
|
||||
|
||||
@@ -12,9 +12,12 @@ namespace mRemoteNG.Root.PuttySessions
|
||||
|
||||
|
||||
public RootPuttySessionsNodeInfo() : base(RootNodeType.PuttySessions)
|
||||
{
|
||||
_name = Language.strPuttySavedSessionsRootName;
|
||||
_panel = Language.strGeneral;
|
||||
{
|
||||
_name = Language.strPuttySavedSessionsRootName;
|
||||
_panel =
|
||||
string.IsNullOrEmpty(Settings.Default.PuttySavedSessionsPanel)
|
||||
? Language.strGeneral
|
||||
: Settings.Default.PuttySavedSessionsPanel;
|
||||
}
|
||||
|
||||
#region Public Properties
|
||||
@@ -24,16 +27,8 @@ namespace mRemoteNG.Root.PuttySessions
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
if (_name == value)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
_name = value;
|
||||
if (TreeNode != null)
|
||||
{
|
||||
TreeNode.Text = value;
|
||||
}
|
||||
Settings.Default.PuttySavedSessionsName = value;
|
||||
//Settings.Default.PuttySavedSessionsName = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +40,6 @@ namespace mRemoteNG.Root.PuttySessions
|
||||
get { return _panel; }
|
||||
set
|
||||
{
|
||||
if (_panel == value)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
_panel = value;
|
||||
Settings.Default.PuttySavedSessionsPanel = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user