diff --git a/mRemoteV1/App/Import.cs b/mRemoteV1/App/Import.cs
index 2638508a2..02eecf405 100644
--- a/mRemoteV1/App/Import.cs
+++ b/mRemoteV1/App/Import.cs
@@ -10,7 +10,7 @@ using mRemoteNG.Tools;
namespace mRemoteNG.App
{
- public class Import
+ public static class Import
{
private enum FileType
{
@@ -23,7 +23,7 @@ namespace mRemoteNG.App
}
#region Public Methods
- public static void ImportFromFile(ContainerInfo importDestinationContainer, bool alwaysUseSelectedTreeNode = false)
+ public static void ImportFromFile(ContainerInfo importDestinationContainer)
{
try
{
@@ -51,6 +51,7 @@ namespace mRemoteNG.App
try
{
IConnectionImporter importer;
+ // ReSharper disable once SwitchStatementMissingSomeCases
switch (DetermineFileType(fileName))
{
case FileType.mRemoteXml:
@@ -91,8 +92,7 @@ namespace mRemoteNG.App
{
try
{
- var importer = new ActiveDirectoryImporter();
- importer.Import(ldapPath, importDestinationContainer);
+ ActiveDirectoryImporter.Import(ldapPath, importDestinationContainer);
Runtime.SaveConnectionsAsync();
}
catch (Exception ex)
@@ -120,8 +120,9 @@ namespace mRemoteNG.App
private static FileType DetermineFileType(string fileName)
{
// TODO: Use the file contents to determine the file type instead of trusting the extension
- var fileExtension = Convert.ToString(Path.GetExtension(fileName).ToLowerInvariant());
- switch (fileExtension)
+ var extension = Path.GetExtension(fileName);
+ if (extension == null) return FileType.Unknown;
+ switch (extension.ToLowerInvariant())
{
case ".xml":
return FileType.mRemoteXml;
diff --git a/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs b/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs
index 39be73d71..da9172292 100644
--- a/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs
+++ b/mRemoteV1/Config/Import/ActiveDirectoryImporter.cs
@@ -16,7 +16,7 @@ namespace mRemoteNG.Config.Import
Import(ldapPathAsString, destinationContainer);
}
- public void Import(string ldapPath, ContainerInfo destinationContainer)
+ public static void Import(string ldapPath, ContainerInfo destinationContainer)
{
try
{
diff --git a/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs b/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs
index 417eed3e0..a7ff47c06 100644
--- a/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs
+++ b/mRemoteV1/Config/Serializers/ActiveDirectoryDeserializer.cs
@@ -2,6 +2,7 @@
using System.DirectoryServices;
using System.Text.RegularExpressions;
using mRemoteNG.App;
+using mRemoteNG.Config.Import;
using mRemoteNG.Connection;
using mRemoteNG.Container;
using mRemoteNG.Tree;
@@ -45,19 +46,27 @@ namespace mRemoteNG.Config.Serializers
{
try
{
- const string ldapFilter = "(objectClass=computer)";
+ const string ldapFilter = "(|(objectClass=computer)(objectClass=organizationalUnit))";
using (var ldapSearcher = new DirectorySearcher())
{
ldapSearcher.SearchRoot = new DirectoryEntry(ldapPath);
ldapSearcher.Filter = ldapFilter;
ldapSearcher.SearchScope = SearchScope.OneLevel;
- ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn" });
+ ldapSearcher.PropertiesToLoad.AddRange(new[] { "securityEquals", "cn", "objectClass" });
var ldapResults = ldapSearcher.FindAll();
foreach (SearchResult ldapResult in ldapResults)
{
using (var directoryEntry = ldapResult.GetDirectoryEntry())
+ {
+ if (directoryEntry.Properties["objectClass"].Contains("organizationalUnit"))
+ {
+ ActiveDirectoryImporter.Import(ldapResult.Path, parentContainer);
+ continue;
+ }
+
DeserializeConnection(directoryEntry, parentContainer);
+ }
}
}
}
diff --git a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs
index 0f8a9d1be..1597396d6 100644
--- a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs
+++ b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.Designer.cs
@@ -7,87 +7,100 @@ namespace mRemoteNG.UI.Window
#region Windows Form Designer generated code
private void InitializeComponent()
{
- this.btnImport = new System.Windows.Forms.Button();
- this.Load += new System.EventHandler(ADImport_Load);
- this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
- this.txtDomain = new System.Windows.Forms.TextBox();
- this.txtDomain.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(mRemoteNG.UI.Window.ActiveDirectoryImportWindow.txtDomain_PreviewKeyDown);
- this.txtDomain.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDomain_KeyDown);
- this.lblDomain = new System.Windows.Forms.Label();
- this.btnChangeDomain = new System.Windows.Forms.Button();
- this.btnChangeDomain.Click += new System.EventHandler(this.btnChangeDomain_Click);
- this.ActiveDirectoryTree = new ADTree.ADtree();
- this.ActiveDirectoryTree.ADPathChanged += new ADTree.ADtree.ADPathChangedEventHandler(this.ActiveDirectoryTree_ADPathChanged);
- this.SuspendLayout();
- //
- //btnImport
- //
- this.btnImport.Anchor = (System.Windows.Forms.AnchorStyles) (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
- this.btnImport.Location = new System.Drawing.Point(443, 338);
- this.btnImport.Name = "btnImport";
- this.btnImport.Size = new System.Drawing.Size(75, 23);
- this.btnImport.TabIndex = 4;
- this.btnImport.Text = "&Import";
- this.btnImport.UseVisualStyleBackColor = true;
- //
- //txtDomain
- //
- this.txtDomain.Anchor = (System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right);
- this.txtDomain.Location = new System.Drawing.Point(12, 25);
- this.txtDomain.Name = "txtDomain";
- this.txtDomain.Size = new System.Drawing.Size(425, 20);
- this.txtDomain.TabIndex = 1;
- //
- //lblDomain
- //
- this.lblDomain.AutoSize = true;
- this.lblDomain.Location = new System.Drawing.Point(9, 9);
- this.lblDomain.Name = "lblDomain";
- this.lblDomain.Size = new System.Drawing.Size(46, 13);
- this.lblDomain.TabIndex = 0;
- this.lblDomain.Text = "Domain:";
- //
- //btnChangeDomain
- //
- this.btnChangeDomain.Anchor = (System.Windows.Forms.AnchorStyles) (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
- this.btnChangeDomain.Location = new System.Drawing.Point(443, 23);
- this.btnChangeDomain.Name = "btnChangeDomain";
- this.btnChangeDomain.Size = new System.Drawing.Size(75, 23);
- this.btnChangeDomain.TabIndex = 2;
- this.btnChangeDomain.Text = "Change";
- this.btnChangeDomain.UseVisualStyleBackColor = true;
- //
- //ActiveDirectoryTree
- //
- this.ActiveDirectoryTree.ADPath = null;
- this.ActiveDirectoryTree.Anchor = (System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right);
- this.ActiveDirectoryTree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.ActiveDirectoryTree.Location = new System.Drawing.Point(12, 52);
- this.ActiveDirectoryTree.Name = "ActiveDirectoryTree";
- this.ActiveDirectoryTree.SelectedNode = null;
- this.ActiveDirectoryTree.Size = new System.Drawing.Size(506, 280);
- this.ActiveDirectoryTree.TabIndex = 3;
- //
- //ADImport
- //
- this.AcceptButton = this.btnImport;
- this.ClientSize = new System.Drawing.Size(530, 373);
- this.Controls.Add(this.ActiveDirectoryTree);
- this.Controls.Add(this.lblDomain);
- this.Controls.Add(this.txtDomain);
- this.Controls.Add(this.btnChangeDomain);
- this.Controls.Add(this.btnImport);
- this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, System.Convert.ToByte(0));
- this.Icon = Resources.ActiveDirectory_Icon;
- this.Name = "ActiveDirectoryImport";
- this.TabText = "Active Directory Import";
- this.Text = "Active Directory Import";
- this.ResumeLayout(false);
- this.PerformLayout();
-
+ this.btnImport = new System.Windows.Forms.Button();
+ this.txtDomain = new System.Windows.Forms.TextBox();
+ this.lblDomain = new System.Windows.Forms.Label();
+ this.btnChangeDomain = new System.Windows.Forms.Button();
+ this.ActiveDirectoryTree = new ADTree.ADtree();
+ this.btnClose = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // btnImport
+ //
+ this.btnImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.btnImport.Location = new System.Drawing.Point(362, 338);
+ this.btnImport.Name = "btnImport";
+ this.btnImport.Size = new System.Drawing.Size(75, 23);
+ this.btnImport.TabIndex = 4;
+ this.btnImport.Text = "&Import";
+ this.btnImport.UseVisualStyleBackColor = true;
+ this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
+ //
+ // txtDomain
+ //
+ this.txtDomain.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.txtDomain.Location = new System.Drawing.Point(12, 25);
+ this.txtDomain.Name = "txtDomain";
+ this.txtDomain.Size = new System.Drawing.Size(425, 22);
+ this.txtDomain.TabIndex = 1;
+ this.txtDomain.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDomain_KeyDown);
+ //
+ // lblDomain
+ //
+ this.lblDomain.AutoSize = true;
+ this.lblDomain.Location = new System.Drawing.Point(9, 9);
+ this.lblDomain.Name = "lblDomain";
+ this.lblDomain.Size = new System.Drawing.Size(50, 13);
+ this.lblDomain.TabIndex = 0;
+ this.lblDomain.Text = "Domain:";
+ //
+ // btnChangeDomain
+ //
+ this.btnChangeDomain.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.btnChangeDomain.Location = new System.Drawing.Point(443, 23);
+ this.btnChangeDomain.Name = "btnChangeDomain";
+ this.btnChangeDomain.Size = new System.Drawing.Size(75, 23);
+ this.btnChangeDomain.TabIndex = 2;
+ this.btnChangeDomain.Text = "Change";
+ this.btnChangeDomain.UseVisualStyleBackColor = true;
+ this.btnChangeDomain.Click += new System.EventHandler(this.btnChangeDomain_Click);
+ //
+ // ActiveDirectoryTree
+ //
+ this.ActiveDirectoryTree.ADPath = null;
+ this.ActiveDirectoryTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.ActiveDirectoryTree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.ActiveDirectoryTree.Domain = "tant-a01";
+ this.ActiveDirectoryTree.Location = new System.Drawing.Point(12, 52);
+ this.ActiveDirectoryTree.Name = "ActiveDirectoryTree";
+ this.ActiveDirectoryTree.SelectedNode = null;
+ this.ActiveDirectoryTree.Size = new System.Drawing.Size(506, 280);
+ this.ActiveDirectoryTree.TabIndex = 3;
+ this.ActiveDirectoryTree.ADPathChanged += new ADTree.ADtree.ADPathChangedEventHandler(this.ActiveDirectoryTree_ADPathChanged);
+ //
+ // btnClose
+ //
+ this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.btnClose.Location = new System.Drawing.Point(444, 337);
+ this.btnClose.Name = "btnClose";
+ this.btnClose.Size = new System.Drawing.Size(75, 23);
+ this.btnClose.TabIndex = 5;
+ this.btnClose.Text = "Close";
+ this.btnClose.UseVisualStyleBackColor = true;
+ this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
+ //
+ // ActiveDirectoryImportWindow
+ //
+ this.AcceptButton = this.btnImport;
+ this.ClientSize = new System.Drawing.Size(530, 373);
+ this.Controls.Add(this.btnClose);
+ this.Controls.Add(this.ActiveDirectoryTree);
+ this.Controls.Add(this.lblDomain);
+ this.Controls.Add(this.txtDomain);
+ this.Controls.Add(this.btnChangeDomain);
+ this.Controls.Add(this.btnImport);
+ this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.Icon = global::mRemoteNG.Resources.ActiveDirectory_Icon;
+ this.Name = "ActiveDirectoryImportWindow";
+ this.TabText = "Active Directory Import";
+ this.Text = "Active Directory Import";
+ this.Load += new System.EventHandler(this.ADImport_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
}
private System.Windows.Forms.Button btnImport;
private System.Windows.Forms.TextBox txtDomain;
@@ -95,5 +108,7 @@ namespace mRemoteNG.UI.Window
private System.Windows.Forms.Button btnChangeDomain;
private ADTree.ADtree ActiveDirectoryTree;
#endregion
- }
+
+ private System.Windows.Forms.Button btnClose;
+ }
}
diff --git a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs
index 2ced90b14..d5ab43022 100644
--- a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs
+++ b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.cs
@@ -22,14 +22,15 @@ namespace mRemoteNG.UI.Window
#region Private Methods
#region Event Handlers
- public void ADImport_Load(object sender, EventArgs e)
+
+ private void ADImport_Load(object sender, EventArgs e)
{
ApplyLanguage();
txtDomain.Text = ActiveDirectoryTree.Domain;
EnableDisableImportButton();
}
-
- public void btnImport_Click(object sender, EventArgs e)
+
+ private void btnImport_Click(object sender, EventArgs e)
{
var selectedNode = Windows.TreeForm.SelectedNode;
ContainerInfo importDestination;
@@ -38,31 +39,27 @@ namespace mRemoteNG.UI.Window
else
importDestination = Runtime.ConnectionTreeModel.RootNodes.First();
Import.ImportFromActiveDirectory(ActiveDirectoryTree.ADPath, importDestination);
- DialogResult = DialogResult.OK;
- Close();
}
-
- public static void txtDomain_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
+
+ private static void txtDomain_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Enter)
e.IsInputKey = true;
}
-
- public void txtDomain_KeyDown(object sender, KeyEventArgs e)
+
+ private void txtDomain_KeyDown(object sender, KeyEventArgs e)
{
- if (e.KeyCode == Keys.Enter)
- {
- ChangeDomain();
- e.SuppressKeyPress = true;
- }
+ if (e.KeyCode != Keys.Enter) return;
+ ChangeDomain();
+ e.SuppressKeyPress = true;
}
-
- public void btnChangeDomain_Click(object sender, EventArgs e)
+
+ private void btnChangeDomain_Click(object sender, EventArgs e)
{
ChangeDomain();
}
-
- public void ActiveDirectoryTree_ADPathChanged(object sender)
+
+ private void ActiveDirectoryTree_ADPathChanged(object sender)
{
EnableDisableImportButton();
}
@@ -86,5 +83,10 @@ namespace mRemoteNG.UI.Window
btnImport.Enabled = !string.IsNullOrEmpty(ActiveDirectoryTree.ADPath);
}
#endregion
- }
+
+ private void btnClose_Click(object sender, EventArgs e)
+ {
+ Close();
+ }
+ }
}
\ No newline at end of file
diff --git a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.resx b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.resx
index 19dc0dd8b..d58980a38 100644
--- a/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.resx
+++ b/mRemoteV1/UI/Window/ActiveDirectoryImportWindow.resx
@@ -112,9 +112,9 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
\ No newline at end of file
diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs
index 8cfa452c9..4b5d5f055 100644
--- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs
+++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs
@@ -92,7 +92,7 @@ namespace mRemoteNG.UI.Window
dropSink.CanDropBetween = true;
}
- private object ConnectionImageGetter(object rowObject)
+ private static object ConnectionImageGetter(object rowObject)
{
if (rowObject is RootPuttySessionsNodeInfo) return "PuttySessions";
if (rowObject is RootNodeInfo) return "Root";
@@ -194,7 +194,7 @@ namespace mRemoteNG.UI.Window
_contextMenu.ImportFileClicked += (sender, args) =>
{
var selectedNodeAsContainer = SelectedNode as ContainerInfo ?? SelectedNode.Parent;
- Import.ImportFromFile(selectedNodeAsContainer, true);
+ Import.ImportFromFile(selectedNodeAsContainer);
};
_contextMenu.ImportActiveDirectoryClicked += (sender, args) => Windows.Show(WindowType.ActiveDirectoryImport);
_contextMenu.ImportPortScanClicked += (sender, args) => Windows.Show(WindowType.PortScan);
@@ -316,7 +316,7 @@ namespace mRemoteNG.UI.Window
}
#endregion
- public void ExpandPreviouslyOpenedFolders()
+ private void ExpandPreviouslyOpenedFolders()
{
var containerList = ConnectionTreeModel.GetRecursiveChildList(GetRootConnectionNode()).OfType();
var previouslyExpandedNodes = containerList.Where(container => container.IsExpanded);
@@ -324,7 +324,7 @@ namespace mRemoteNG.UI.Window
olvConnections.InvokeRebuildAll(true);
}
- public void OpenConnectionsFromLastSession()
+ private void OpenConnectionsFromLastSession()
{
if (!Settings.Default.OpenConsFromLastSession || Settings.Default.NoReconnect) return;
var connectionInfoList = GetRootConnectionNode().GetRecursiveChildList().Where(node => !(node is ContainerInfo));
@@ -389,7 +389,7 @@ namespace mRemoteNG.UI.Window
return PromptUser(messagePrompt);
}
- private bool PromptUser(string promptMessage)
+ private static bool PromptUser(string promptMessage)
{
var msgBoxResponse = MessageBox.Show(promptMessage, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
return (msgBoxResponse == DialogResult.Yes);
@@ -477,13 +477,14 @@ namespace mRemoteNG.UI.Window
private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
var senderAsContainerInfo = sender as ContainerInfo;
+ // ReSharper disable once SwitchStatementMissingSomeCases
switch (args?.Action)
{
case NotifyCollectionChangedAction.Add:
var childList = senderAsContainerInfo?.Children;
ConnectionInfo otherChild = null;
if (childList?.Count > 1)
- try { otherChild = childList.First(child => !args.NewItems.Contains(child)); } catch { }
+ otherChild = childList.First(child => !args.NewItems.Contains(child));
RefreshTreeObject(otherChild ?? senderAsContainerInfo);
break;
case NotifyCollectionChangedAction.Remove:
@@ -509,13 +510,7 @@ namespace mRemoteNG.UI.Window
private void RefreshTreeObjects(IList modelObjects)
{
- try
- {
- olvConnections.RefreshObjects(modelObjects);
- }
- catch (Exception)
- {
- }
+ olvConnections.RefreshObjects(modelObjects);
}
#endregion
@@ -725,12 +720,15 @@ namespace mRemoteNG.UI.Window
private void ExpandParentsRecursive(ConnectionInfo connectionInfo)
{
- if (connectionInfo?.Parent == null) return;
- olvConnections.Expand(connectionInfo.Parent);
- ExpandParentsRecursive(connectionInfo.Parent);
- }
+ while (true)
+ {
+ if (connectionInfo?.Parent == null) return;
+ olvConnections.Expand(connectionInfo.Parent);
+ connectionInfo = connectionInfo.Parent;
+ }
+ }
- private void tvConnections_KeyPress(object sender, KeyPressEventArgs e)
+ private void tvConnections_KeyPress(object sender, KeyPressEventArgs e)
{
try
{