Skip to content

Commit

Permalink
Merge pull request #166 from Blazam-App/Beta-Dev
Browse files Browse the repository at this point in the history
Fix for memory leak in AD virtual list view
  • Loading branch information
jacobsen9026 authored Nov 20, 2023
2 parents 7c3bb58 + 259093e commit 66a35af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>0.8.5</AssemblyVersion>
<Version>2023.11.20.1820</Version>
<Version>2023.11.20.1939</Version>

<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
Expand Down
15 changes: 0 additions & 15 deletions BLAZAM/Pages/Computers/ViewComputer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,10 @@
await InvokeAsync(StateHasChanged);
if (Computer != null)
{

Task.Run(() =>
{
var services = Computer.Services;

RefreshEntryComponents();

});




Computer.OnOnlineChanged += ((online) =>
{
RefreshEntryComponents();
});



}
LoadingData = false;
await RefreshEntryComponents();
Expand Down
14 changes: 11 additions & 3 deletions BLAZAMActiveDirectory/Adapters/ADComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BLAZAM.ActiveDirectory.Interfaces;
using BLAZAM.Database.Models;
using System.Net.Sockets;
using System.DirectoryServices;

namespace BLAZAM.ActiveDirectory.Adapters
{
Expand All @@ -26,7 +27,7 @@ private WmiConnection? wmiConnection
private bool? online;
public ADComputer()
{
MonitorOnlineStatus();

}

public string? OperatingSystem
Expand Down Expand Up @@ -59,7 +60,7 @@ public virtual bool? IsOnline
}
}
public List<ComputerService> Services => wmiConnection.Services;
public ComputerMemory Memory =>wmiConnection?.Memory ?? new();
public ComputerMemory Memory => wmiConnection?.Memory ?? new();
public int Processor => wmiConnection.Processor;
public double MemoryUsedPercent => wmiConnection.Memory.PercentUsed;
public List<IADComputerDrive> GetDrives()
Expand Down Expand Up @@ -168,7 +169,7 @@ await Task.Run(() =>
} while (x < retries);
}
catch(SocketException ex)
catch (SocketException ex)
{
}
Expand All @@ -187,6 +188,13 @@ await Task.Run(() =>

}

public override async Task Parse(SearchResult result, IActiveDirectoryContext directory)
{
await base.Parse(result, directory);
if (!this.IsDeleted)
MonitorOnlineStatus();
}

public override void Dispose()
{
base.Dispose();
Expand Down
14 changes: 10 additions & 4 deletions BLAZAMActiveDirectory/Searchers/ADSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.ComponentModel;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,7 +62,9 @@ public class ADSearch : SearchBase
/// to confirm search is completed and no more results are coming.</para>
/// </summary>
public AppEvent<IEnumerable<IDirectoryEntryAdapter>> ResultsCollected { get; set; }


int PageSize = 40;

public ActiveDirectoryObjectType? ObjectTypeFilter { get; set; }
public bool? EnabledOnly { get; set; }
public int MaxResults { get; set; } = 50;
Expand Down Expand Up @@ -106,7 +109,7 @@ public async Task<List<IDirectoryEntryAdapter>> SearchAsync()
{
SearchRoot ??= ActiveDirectoryContext.Instance.GetDirectoryEntry(DatabaseCache.ActiveDirectorySettings?.ApplicationBaseDN);
var pageOffset = 1;
var pageSize = 40;

searcher = new DirectorySearcher(SearchRoot)
{
//TODO Ensure bbroken
Expand Down Expand Up @@ -214,7 +217,7 @@ public async Task<List<IDirectoryEntryAdapter>> SearchAsync()

SearchTime = DateTime.Now - startTime;

PerformSearch<TObject, TInterface>(startTime, searcher, pageSize);
PerformSearch<TObject, TInterface>(startTime, searcher, PageSize);

if (cancellationToken?.IsCancellationRequested == true) return new();

Expand Down Expand Up @@ -298,7 +301,7 @@ private DateTime NewMethod()
// throw new ApplicationException("The searcher lost it's VirtualListView in the middle of searching!");
lastResults = searcher.FindAll();
AddResults<TObject, TInterface>(lastResults);
if (lastResults.Count < pageSize)
if (searcher.VirtualListView==null || lastResults.Count < pageSize)
moreResults = false;
SearchTime = DateTime.Now - startTime;

Expand All @@ -319,7 +322,10 @@ private void PrepareSearcher(DirectorySearcher searcher)
searcher.PropertiesToLoad.Add("name");
}
if (SearchDeleted)
{
searcher.Tombstone = true;
searcher.VirtualListView = new DirectoryVirtualListView(0, PageSize - 1, 1);
}
//searcher.Asynchronous = true;
searcher.SizeLimit = MaxResults;
searcher.Filter = searcher.Filter?.Substring(0, searcher.Filter.Length - 1) + FilterQuery + ")";
Expand Down

0 comments on commit 66a35af

Please sign in to comment.