Skip to content

Commit

Permalink
Updated display pane logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 committed Jan 14, 2025
1 parent eb78dbc commit 3069514
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
18 changes: 10 additions & 8 deletions src/EventLogExpert.Eventing/Models/DisplayEventModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public sealed record DisplayEventModel(
string OwningLog /*This is the name of the log file or the live log, which we use internally*/,
PathType PathType)
{
private string _xml = string.Empty;

public Guid? ActivityId { get; init; }

public string ComputerName { get; init; } = string.Empty;
Expand Down Expand Up @@ -40,34 +42,34 @@ public sealed record DisplayEventModel(

public SecurityIdentifier? UserId { get; init; }

public string Xml { get; set; } = string.Empty;
public string Xml { get => _xml; init => _xml = value; }

public async Task<string> ResolveXml()
public async Task ResolveXml()
{
if (!string.IsNullOrEmpty(Xml)) { return Xml; }
if (!string.IsNullOrEmpty(Xml)) { return; }

return Xml = await Task.Run(() =>
await Task.Run(() =>
{
using EvtHandle handle = EventMethods.EvtQuery(
EventLogSession.GlobalSession.Handle,
OwningLog,
$"*[System[EventRecordID='{RecordId}']]",
PathType);

if (handle.IsInvalid) { return Xml = string.Empty; }
if (handle.IsInvalid) { return; }

var buffer = new IntPtr[1];
int count = 0;

bool success = EventMethods.EvtNext(handle, buffer.Length, buffer, 0, 0, ref count);

if (!success) { return string.Empty; }
if (!success) { return; }

using EvtHandle eventHandle = new(buffer[0]);

if (eventHandle.IsInvalid) { return string.Empty; }
if (eventHandle.IsInvalid) { return; }

return Xml = EventMethods.RenderEventXml(eventHandle) ?? string.Empty;
_xml = EventMethods.RenderEventXml(eventHandle) ?? string.Empty;
}
);
}
Expand Down
7 changes: 2 additions & 5 deletions src/EventLogExpert/Components/DetailsPane.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ protected override void OnInitialized()
{
SelectedEvent = selectedEvents.LastOrDefault();

if (SelectedEvent is null || (_hasOpened && !Settings.ShowDisplayPaneOnSelectionChange))
{
return;
}
if (SelectedEvent is null) { return; }

await SelectedEvent.ResolveXml();

_isVisible = true;
if (!_hasOpened || Settings.ShowDisplayPaneOnSelectionChange) { _isVisible = true; }

StateHasChanged();
};
Expand Down

0 comments on commit 3069514

Please sign in to comment.