Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for memory leak in Session List view #255

Merged
merged 21 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 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.9</AssemblyVersion>
<Version>2024.02.27.2343</Version>
<Version>2024.03.15.1259</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
Expand All @@ -28,6 +28,8 @@
<None Remove="static\img\default_logo4.png" />
</ItemGroup>






Expand Down
16 changes: 10 additions & 6 deletions BLAZAM/Pages/Benchmark.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@inject IAppDatabaseFactory factory
@inject IActiveDirectoryContextFactory directoryFactory
@inherits AppComponentBase
@page "/benchmark"

@inject IActiveDirectoryContext Dir

<h3>Benchmark</h3>
<p>Number of cycles</p>
Expand All @@ -16,17 +17,17 @@
<p>User Bench</p>
<p>email: @userBench?.SamAccountName</p>
@code {
#nullable disable warnings
#nullable disable warnings
ActiveDirectoryContext ad;
bool Running = false;
int runCount;
int runCount = 1;
int cycle;
double elapsed;
double elapsed2;
IADUser userBench;
protected override void OnInitialized()
{
// ad = new ActiveDirectory(factory, true);
// ad = new ActiveDirectory(factory, true);
}
async Task Benchmark1()
{
Expand All @@ -39,8 +40,9 @@
for (cycle = 0; cycle < runCount; cycle++)
{
DateTime start = DateTime.Now;
var dir = Directory as ActiveDirectoryContext;


var user = dir.Authenticate(new() { Username = "johnsoncontrols", Password = "bburg123" });
runs[cycle] = (DateTime.Now - start).TotalSeconds;
InvokeAsync(StateHasChanged);

Expand Down Expand Up @@ -79,7 +81,9 @@

DateTime start = DateTime.Now;

Dir.Users.FindUsersByString("cja");
var dir = Directory as ActiveDirectoryContext;
var user = dir.Authenticate_Alt(new() { Username = "johnsoncontrols", Password = "bburg123" });

runs[cycle] = (DateTime.Now - start).TotalSeconds;

InvokeAsync(StateHasChanged);
Expand Down
50 changes: 29 additions & 21 deletions BLAZAM/Pages/Configure/Audit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,35 @@
</MudTabPanel>
<MudTabPanel>
<ChildContent>
<MudDataGrid Virtualize=true
Height="600px"
ColumnResizeMode="ResizeMode.Container"
FixedHeader=true
Hideable=true
Items="@systemAuditEntries.OrderByDescending(ae=>ae.Timestamp)"
Filterable="false"
SortMode="@SortMode.Multiple"
Groupable="false">
<Columns>
<PropertyColumn Property="x => x.Timestamp.ToLocalTime()" />
<PropertyColumn Property="x => x.Username" />
<PropertyColumn Property="x => x.IpAddress" />
<PropertyColumn Property="x => x.Target" />

<PropertyColumn Property="x => x.Target" />
<PropertyColumn Property="x => x.BeforeAction" />
<PropertyColumn Property="x => x.AfterAction" />

</Columns>
</MudDataGrid>
@if(ApplicationInfo.InDemoMode && CurrentUser.Username == "Demo")
{
<MudText>Disabled in demo</MudText>
}
else
{
<MudDataGrid Virtualize=true
Height="600px"
ColumnResizeMode="ResizeMode.Container"
FixedHeader=true
Hideable=true
Items="@systemAuditEntries.OrderByDescending(ae=>ae.Timestamp)"
Filterable="false"
SortMode="@SortMode.Multiple"
Groupable="false">
<Columns>
<PropertyColumn Property="x => x.Timestamp.ToLocalTime()" />
<PropertyColumn Property="x => x.Username" />
<PropertyColumn Property="x => x.IpAddress" />
<PropertyColumn Property="x => x.Target" />

<PropertyColumn Property="x => x.Target" />
<PropertyColumn Property="x => x.BeforeAction" />
<PropertyColumn Property="x => x.AfterAction" />

</Columns>
</MudDataGrid>
}




Expand Down
28 changes: 21 additions & 7 deletions BLAZAM/Pages/Groups/ConfirmNewGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
@Group.ADSPath

</MudCard>
<MudButton Color=Color.Success OnClick="CommitChanges">Create...</MudButton>
<MudButton Disabled=@disableCreateGroupButton Color=Color.Success OnClick="CommitChanges">Create...</MudButton>
}
@code {

#nullable disable warnings
#nullable disable warnings


private bool disableCreateGroupButton = false;

[Parameter]
public EventCallback<IADGroup> Confirmed { get; set; }
Expand All @@ -23,12 +23,26 @@

async Task CommitChanges()
{
if (await MessageService.Confirm("Are you sure you want to create this OU?", "Create OU"))
if (await MessageService.Confirm("Are you sure you want to create this group?", "Create group"))
{
await Group.CommitChangesAsync();
SnackBarService.Success("Group created");
disableCreateGroupButton = true;
await InvokeAsync(StateHasChanged);
IJob createGroupJob = new Job(AppLocalization["Create User"]);
createGroupJob.StopOnFailedStep = true;
createGroupJob.ShowJobDetailsDialog(MessageService);
var result = await Group.CommitChangesAsync(createGroupJob);

disableCreateGroupButton = false;
InvokeAsync(StateHasChanged);
if (result.FailedSteps.Count == 0)
{

SnackBarService.Success("Group created");

}
await AuditLogger.Group.Created(Group);
var commitJob = Group.CommitChanges();
await Confirmed.InvokeAsync(Group);
Nav.NavigateTo("/groups/create",true);
}
}
}
8 changes: 8 additions & 0 deletions BLAZAM/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@

@if (ApplicationInfo.InDebugMode)
{
<MudContextMenu Text="Test Context Menu">
<MenuContents>

<MudMenuItem>Test Item</MudMenuItem>
<MudMenuItem>Test Item</MudMenuItem>
<MudMenuItem>Test Item</MudMenuItem>
</MenuContents>
</MudContextMenu><br/>
<MudButton Variant="Variant.Filled" OnClick="testJob">Run Test Job</MudButton>
}

Expand Down
19 changes: 16 additions & 3 deletions BLAZAM/Pages/Users/ConfirmNewUser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,15 @@ InDirectoryTemplate(ActiveDirectoryFields.PhysicalDeliveryOffice)

</Row>

@if (!confirmed)
{
<MudButton Disabled=@disableCreateUserButton Color="Color.Success" OnClick="ConfirmUser">Create User</MudButton>

}else{
<MudButton Color="Color.Primary" OnClick="@(()=>{Nav.NavigateTo(User.SearchUri);})">Go To User</MudButton>
<MudButton Color="Color.Success" OnClick="@(()=>{Nav.NavigateTo("/create/user");})">Create Another</MudButton>

<MudButton Disabled=@disableCreateUserButton Color="Color.Success" OnClick="ConfirmUser">Create User</MudButton>
}
<MudButton StartIcon="@Icons.Material.Filled.Print" Color="Color.Info" OnClick="Print">Print</MudButton>

@code {
Expand All @@ -173,7 +180,7 @@ InDirectoryTemplate(ActiveDirectoryFields.PhysicalDeliveryOffice)
if (DirectoryTemplate == null) return true;
return DirectoryTemplate?.FieldValues.Any(f => f.Field.FieldName == field.FieldName) == true;
}

bool confirmed = false;
bool disableCreateUserButton=false;
/// <summary>
/// Triggered when the user confirms the creation of this
Expand All @@ -196,8 +203,14 @@ InDirectoryTemplate(ActiveDirectoryFields.PhysicalDeliveryOffice)
InvokeAsync(StateHasChanged);
if (result.FailedSteps.Count == 0)
{

var newUser = Directory.Users.FindUsersByContainerName(User.CanonicalName, false, true);
if (newUser != null)
{
User = newUser;
}
SnackBarService.Success("User has been created");
confirmed = true;
Confirmed.InvokeAsync();
//Nav.NavigateTo("/search/" + User.SamAccountName);

}
Expand Down
33 changes: 19 additions & 14 deletions BLAZAM/Pages/Users/CreateUser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
{
<MudPaper Width="300px">
<MudText>@AppLocalization["There are no templates available"]</MudText>
<AuthorizeView Roles="@UserRoles.SuperAdmin">
<MudLink OnClick="@(()=>{Nav.NavigateTo("/templates");})">Create One</MudLink>
<AuthorizeView Roles="@UserRoles.SuperAdmin">
<MudLink OnClick="@(()=>{Nav.NavigateTo("/templates");})">Create One</MudLink>

</AuthorizeView>
</MudPaper>
</AuthorizeView>
</MudPaper>
}
<MudButton Color=Color.Secondary OnClick="@(()=>{custom=true; newUser=null; SelectedTemplate=null; SelectedStep=4;})">Custom</MudButton>

Expand All @@ -51,7 +51,7 @@


<NewUserNameEntry @bind-NewUserName=@newUserName OnNext="CreateTemplateUser" OnBack="@(()=>{SelectedStep=0;})" />



</ChildContent>
Expand Down Expand Up @@ -110,7 +110,7 @@
</TabContent>
<ChildContent>
@*TODO: The following binding cause the next button to not update when validation is reached, updates are controlled from
this element
this element
*@
<ViewUser DirectoryEntry="@newUser" @bind-ConfirmPassword=@customConfirmPassword @bind-Password=customPassword />
<MudButton Color=Color.Primary OnClick="@(()=>{SelectedStep=4;})">Back</MudButton>
Expand Down Expand Up @@ -204,8 +204,12 @@ newUser.StagePasswordChange(customConfirmPassword.ToSecureString());
{
if (newUser == null)
{
newUser = selectedOU.CreateUser(customUserDisplayName.Trim());
newUser.DisplayName = customUserDisplayName;
if (customUserDisplayName == null) SnackBarService.Error(AppLocalization["No display name was set"]);
else
{
newUser = selectedOU.CreateUser(customUserDisplayName.Trim());
newUser.DisplayName = customUserDisplayName;
}
}
else
{
Expand Down Expand Up @@ -240,22 +244,22 @@ newUser.StagePasswordChange(customConfirmPassword.ToSecureString());
{
try
{
if (fieldValue.Field != null)
if (fieldValue.Field != null && fieldValue.Value != null)
if (fieldValue.Field.FieldName.ToLower() == "homedirectory")
newUser.HomeDirectory = SelectedTemplate.ReplaceVariables(fieldValue.Value, newUserName);
else
newUser.NewEntryProperties[fieldValue.Field.FieldName] = SelectedTemplate.ReplaceVariables(fieldValue.Value, newUserName);
else if (fieldValue.CustomField != null)
else if (fieldValue.CustomField != null && fieldValue.Value != null)
newUser.NewEntryProperties[fieldValue.CustomField.FieldName] = SelectedTemplate.ReplaceVariables(fieldValue.Value, newUserName);
}
catch (Exception ex)
{
Loggers.ActiveDirectryLogger.Error("Could not set value for " + fieldValue.Field?.FieldName + ": " + fieldValue.Value.ToString() + " {@Error}", ex);
Loggers.ActiveDirectryLogger.Error("Could not set value for " + fieldValue.Field?.FieldName + ": " + fieldValue.Value?.ToString() + " {@Error}", ex);
}

}
var conflictingEntry = Directory.Users.FindUserByUsername(newUser.SamAccountName,false);
if (conflictingEntry != null)
var conflictingEntry = Directory.Users.FindUserByUsername(newUser.SamAccountName, false);
if (conflictingEntry != null && conflictingEntry.SamAccountName?.Equals(newUser.SamAccountName, StringComparison.InvariantCultureIgnoreCase) == true)
{
newUser = null;
SnackBarService.Warning("An account with that name already exists! " + conflictingEntry.SamAccountName);
Expand All @@ -278,7 +282,8 @@ newUser.StagePasswordChange(customConfirmPassword.ToSecureString());
SelectedStep = 6;

}
}catch(Exception ex)
}
catch (Exception ex)
{

Loggers.ActiveDirectryLogger.Error("Error while creating template user {@Error}", ex);
Expand Down
Loading
Loading