Skip to content

Commit

Permalink
trees sorted by ascending values
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Aug 30, 2024
1 parent 782b6dc commit d1a7e20
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
12 changes: 9 additions & 3 deletions src/PSADTree/Commands/GetADTreeGroupMemberCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,22 @@ private void EnumerateMembers(
{
foreach (Principal member in searchResult.GetSortedEnumerable(_comparer))
{
IDisposable? disposable = null;
try
{
if (member is { DistinguishedName: null })
{
disposable = member;
continue;
}

if (Group.IsPresent && member.StructuralObjectClass != "group")
if (member.StructuralObjectClass != "group")
{
continue;
disposable = member;
if (Group.IsPresent)
{
continue;
}
}

TreeObjectBase treeObject = ProcessPrincipal(
Expand All @@ -151,7 +157,7 @@ private void EnumerateMembers(
}
finally
{
member.Dispose();
disposable?.Dispose();
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/PSADTree/PSADTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
<DefineConstants>$(DefineConstants);CORE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0"
PrivateAssets="all" />
<PackageReference Include="System.Management.Automation" Version="7.2.0" PrivateAssets="all" />
<PackageReference Include="System.DirectoryServices" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="6.0.0"
PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" PrivateAssets="all" />
<Reference Include="System.DirectoryServices" PrivateAssets="all" />
<Reference Include="System.DirectoryServices.AccountManagement" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="System.Management.Automation" Version="7.2.0" PrivateAssets="all" />
<PackageReference Include="System.DirectoryServices" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="6.0.0" PrivateAssets="all" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/PSADTree/PSADTreeComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace PSADTree;

#pragma warning disable CS8767
internal sealed class PSADTreeComparer : IComparer<Principal>
{
public int Compare(Principal lhs, Principal rhs) =>
Expand Down
17 changes: 11 additions & 6 deletions src/PSADTree/TreeGroup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.DirectoryServices.AccountManagement;
using System.Text;

namespace PSADTree;

Expand All @@ -14,6 +16,8 @@ public sealed class TreeGroup : TreeObjectBase

private const string _vtReset = "\x1B[0m";

private static readonly StringBuilder s_sb = new();

private List<TreeObjectBase>? _childs;

public ReadOnlyCollection<TreeObjectBase> Childs => new(_childs ??= []);
Expand Down Expand Up @@ -46,12 +50,13 @@ internal TreeGroup(
internal void SetCircularNested()
{
IsCircular = true;
Hierarchy = string.Concat(
Hierarchy.Insert(
Hierarchy.IndexOf("─ ") + 2,
_vtBrightRed),
_isCircular,
_vtReset);
Hierarchy = s_sb
.Append(Hierarchy.Insert(Hierarchy.IndexOf("─ ") + 2, _vtBrightRed))
.Append(_isCircular)
.Append(_vtReset)
.ToString();

s_sb.Clear();
}

internal void SetProcessed() => Hierarchy = string.Concat(Hierarchy, _isProcessed);
Expand Down

0 comments on commit d1a7e20

Please sign in to comment.