Skip to content

Commit

Permalink
Refactored DetailsPane and removed XML caching since formating will b…
Browse files Browse the repository at this point in the history
…e done on DetailsPane
  • Loading branch information
jschick04 authored and bill-long committed Mar 7, 2024
1 parent 027247a commit a020617
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EventProviderDatabaseEventResolver : EventResolverBase, IEventResol

private bool disposedValue;

public EventProviderDatabaseEventResolver(IDatabaseCollectionProvider dbCollection) : this(dbCollection, (s,log) => { }) { }
public EventProviderDatabaseEventResolver(IDatabaseCollectionProvider dbCollection) : this(dbCollection, (s, log) => { }) { }

public EventProviderDatabaseEventResolver(IDatabaseCollectionProvider dbCollection, Action<string, LogLevel> tracer) : base(tracer)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ private static IEnumerable<string> SortDatabases(IEnumerable<string> databasePat

public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
{
DisplayEventModel lastResult = null!;
DisplayEventModel? lastResult = null;

// The Properties getter is expensive, so we only call the getter once,
// and we pass this value separately from the eventRecord so it can be reused.
Expand Down Expand Up @@ -177,6 +177,7 @@ public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
{
_tracer($"Resolved {eventRecord.ProviderName} provider from database {dbContext.Name}.", LogLevel.Information);
_providerDetails.TryAdd(eventRecord.ProviderName, providerDetails);

return lastResult;
}
}
Expand Down Expand Up @@ -211,12 +212,12 @@ public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
eventRecord.ThreadId,
eventRecord.LogName,
OwningLogName,
eventRecord);
eventRecord.ToXml());
}

if (lastResult.Description == null)
{
lastResult = lastResult with { Description = ""};
lastResult = lastResult with { Description = "" };
}

return lastResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
eventRecord.ThreadId,
eventRecord.LogName,
OwningLogName,
eventRecord);
eventRecord.ToXml());
}

private static T TryGetValue<T>(Func<T> func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ protected DisplayEventModel ResolveFromProviderDetails(
eventRecord.ThreadId,
eventRecord.LogName!,
owningLogName,
eventRecord);
eventRecord.ToXml());
}

[GeneratedRegex("%+[0-9]+")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
eventRecord.ThreadId,
eventRecord.LogName,
OwningLogName,
eventRecord);
eventRecord.ToXml());
}

// The Properties getter is expensive, so we only call the getter once,
Expand Down
43 changes: 1 addition & 42 deletions src/EventLogExpert.Eventing/Models/DisplayEventModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using System.Diagnostics.Eventing.Reader;
using System.Xml.Linq;

namespace EventLogExpert.Eventing.Models;

public sealed record DisplayEventModel(
Expand All @@ -22,42 +19,4 @@ public sealed record DisplayEventModel(
int? ThreadId,
string LogName, // This is the log name from the event reader
string OwningLog, // This is the name of the log file or the live log, which we use internally
EventRecord EventRecord)
{
private EventRecord? EventRecord { get; set; } = EventRecord;

public string Xml
{
get
{
if (_cachedXml is not null) { return _cachedXml; }

lock (this)
{
if (_cachedXml is not null) { return _cachedXml; }

if (EventRecord is null)
{
return "Unable to get XML. EventRecord is null.";
}

var unformattedXml = EventRecord.ToXml();

try
{
_cachedXml = XElement.Parse(unformattedXml).ToString();
}
catch
{
_cachedXml = unformattedXml;
}

EventRecord = null;

return _cachedXml;
}
}
}

private string? _cachedXml;
}
string Xml);
21 changes: 0 additions & 21 deletions src/EventLogExpert.UI/Store/EventLog/EventLogEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,6 @@ await Task.Run(() =>
{
logWatcherService.AddLog(action.LogName, lastEvent?.Bookmark);
}

sw.Restart();

await Task.Run(() =>
{
for (int i = 0; i < events.Count; i++)
{
action.Token.ThrowIfCancellationRequested();

if (sw.ElapsedMilliseconds > 1000)
{
sw.Restart();
dispatcher.Dispatch(new StatusBarAction.SetXmlLoading(activityId, i));
}

_ = events[i].Xml;
}
},
action.Token);

dispatcher.Dispatch(new StatusBarAction.SetXmlLoading(activityId, 0));
}
catch (TaskCanceledException)
{
Expand Down
74 changes: 38 additions & 36 deletions src/EventLogExpert.UI/Store/LoggingMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using EventLogExpert.Eventing.Helpers;
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Eventing.Helpers;
using EventLogExpert.UI.Store.EventLog;
using EventLogExpert.UI.Store.EventTable;
using EventLogExpert.UI.Store.FilterCache;
Expand All @@ -23,56 +26,55 @@ public override void BeforeDispatch(object action)
{
switch (action)
{
case EventLogAction.LoadEvents loadEventsAction :
case EventLogAction.LoadEvents loadEventsAction:
debugLogger.Trace($"Action: {action.GetType()} with {loadEventsAction.Events.Count} events.");
break;
case EventLogAction.AddEvent addEventsAction :
case EventLogAction.AddEvent addEventsAction:
debugLogger.Trace($"Action: {action.GetType()} with {addEventsAction.NewEvent.Source} event ID {addEventsAction.NewEvent.Id}.");
break;
case EventLogAction.OpenLog openLogAction :
case EventLogAction.OpenLog openLogAction:
debugLogger.Trace($"Action: {action.GetType()} with {openLogAction.LogName} log type {openLogAction.LogType}.");
break;
case EventLogAction.AddEventBuffered :
case EventLogAction.AddEventSuccess :
case EventLogAction.SetFilters :
case EventTableAction.AddTable :
case EventTableAction.LoadColumnsCompleted :
case EventTableAction.UpdateDisplayedEvents :
case FilterCacheAction.AddFavoriteFilterCompleted :
case FilterCacheAction.AddRecentFilterCompleted :
case FilterCacheAction.ImportFavorites :
case FilterCacheAction.LoadFiltersCompleted :
case FilterCacheAction.RemoveFavoriteFilterCompleted :
case FilterGroupAction.AddGroup :
case FilterGroupAction.ImportGroups :
case FilterGroupAction.LoadGroupsSuccess :
case FilterGroupAction.SetFilter :
case FilterGroupAction.SetGroup :
case FilterGroupAction.UpdateDisplayGroups :
case FilterPaneAction.AddAdvancedFilter :
case FilterPaneAction.AddBasicFilter :
case FilterPaneAction.AddCachedFilter :
case FilterPaneAction.ApplyFilterGroup :
case FilterPaneAction.SetAdvancedFilter :
case FilterPaneAction.SetBasicFilter :
case FilterPaneAction.SetCachedFilter :
case FilterPaneAction.SetFilterDateRange :
case SettingsAction.LoadDatabasesCompleted :
case SettingsAction.LoadSettingsCompleted :
case EventLogAction.AddEventBuffered:
case EventLogAction.AddEventSuccess:
case EventLogAction.SetFilters:
case EventTableAction.AddTable:
case EventTableAction.LoadColumnsCompleted:
case EventTableAction.UpdateDisplayedEvents:
case FilterCacheAction.AddFavoriteFilterCompleted:
case FilterCacheAction.AddRecentFilterCompleted:
case FilterCacheAction.ImportFavorites:
case FilterCacheAction.LoadFiltersCompleted:
case FilterCacheAction.RemoveFavoriteFilterCompleted:
case FilterGroupAction.AddGroup:
case FilterGroupAction.ImportGroups:
case FilterGroupAction.LoadGroupsSuccess:
case FilterGroupAction.SetFilter:
case FilterGroupAction.SetGroup:
case FilterGroupAction.UpdateDisplayGroups:
case FilterPaneAction.AddAdvancedFilter:
case FilterPaneAction.AddBasicFilter:
case FilterPaneAction.AddCachedFilter:
case FilterPaneAction.ApplyFilterGroup:
case FilterPaneAction.SetAdvancedFilter:
case FilterPaneAction.SetBasicFilter:
case FilterPaneAction.SetCachedFilter:
case FilterPaneAction.SetFilterDateRange:
case SettingsAction.LoadDatabasesCompleted:
case SettingsAction.LoadSettingsCompleted:
case SettingsAction.Save:
case SettingsAction.SaveCompleted :
case SettingsAction.SaveCompleted:
debugLogger.Trace($"Action: {action.GetType()}.");
break;
case EventLogAction.SelectEvent selectEventAction :
case EventLogAction.SelectEvent selectEventAction:
debugLogger.Trace($"Action: {nameof(EventLogAction.SelectEvent)} selected " +
$"{selectEventAction.SelectedEvent?.Source} event ID {selectEventAction.SelectedEvent?.Id}.");

break;
case StatusBarAction.SetEventsLoading :
case StatusBarAction.SetXmlLoading :
case StatusBarAction.SetEventsLoading:
debugLogger.Trace($"Action: {action.GetType()} {JsonSerializer.Serialize(action, _serializerOptions)}", LogLevel.Debug);
break;
default :
default:
try
{
debugLogger.Trace($"Action: {action.GetType()} {JsonSerializer.Serialize(action, _serializerOptions)}");
Expand Down
2 changes: 0 additions & 2 deletions src/EventLogExpert.UI/Store/StatusBar/StatusBarAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ public sealed record CloseAll;
public sealed record SetEventsLoading(Guid ActivityId, int Count);

public sealed record SetResolverStatus(string ResolverStatus);

public sealed record SetXmlLoading(Guid ActivityId, int Count);
}
11 changes: 0 additions & 11 deletions src/EventLogExpert.UI/Store/StatusBar/StatusBarReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public static StatusBarState ReduceCloseAll(StatusBarState state, StatusBarActio
updatedState = updatedState with { EventsLoading = updatedState.EventsLoading.Remove(action.ActivityId) };
}

if (state.XmlLoading.ContainsKey(action.ActivityId))
{
updatedState = updatedState with { XmlLoading = updatedState.XmlLoading.Remove(action.ActivityId) };
}

return updatedState;
}

Expand All @@ -43,12 +38,6 @@ public static StatusBarState
ReduceSetResolverStatus(StatusBarState state, StatusBarAction.SetResolverStatus action) =>
new() { ResolverStatus = action.ResolverStatus };

[ReducerMethod]
public static StatusBarState ReduceSetXmlLoading(StatusBarState state, StatusBarAction.SetXmlLoading action)
{
return state with { XmlLoading = CommonLoadingReducer(state.XmlLoading, action.ActivityId, action.Count) };
}

private static ImmutableDictionary<Guid, int> CommonLoadingReducer(
ImmutableDictionary<Guid, int> loadingEntries,
Guid activityId,
Expand Down
2 changes: 0 additions & 2 deletions src/EventLogExpert.UI/Store/StatusBar/StatusBarState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ public sealed record StatusBarState
public ImmutableDictionary<Guid, int> EventsLoading { get; init; } = ImmutableDictionary<Guid, int>.Empty;

public string ResolverStatus { get; init; } = string.Empty;

public ImmutableDictionary<Guid, int> XmlLoading { get; init; } = ImmutableDictionary<Guid, int>.Empty;
}
33 changes: 13 additions & 20 deletions src/EventLogExpert/Components/DetailsPane.razor
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
@using EventLogExpert.UI.Store.EventLog
@using EventLogExpert.UI.Store.Settings
@using System.Xml.Linq
@inherits FluxorComponent

@inject IState<EventLogState> EventLogState
@inject IState<SettingsState> SettingsState

<div id="details-pane" data-toggle="@IsVisible" hidden="@(EventLogState.Value.SelectedEvent is null)">
<div data-toggle="@IsVisible" hidden="@(SelectedEvent is null)" id="details-pane">
<div id="details-resizer"></div>

<div id="details-header" class="flex-space-between" @onclick="ToggleMenu">
<div class="flex-space-between" id="details-header" @onclick="ToggleMenu">
<div>Details</div>

<span class="menu-toggle" data-rotate="@IsVisible">
<i class="bi bi-caret-up"></i>
</span>
</div>

@if (Event is not null)
@if (SelectedEvent is not null)
{
<div class="details-group" data-toggle="@_isXmlVisible.ToString().ToLower()">
<div class="d-flex flex-row">
@if (EventLogState.Value.ActiveLogs.Count > 1)
{
<div>Log Name: @Event.LogName</div>
}
<div>Source: @Event.Source</div>
<div>Event Id: @Event.Id</div>
<div>Level: @Event.Level</div>
@if (Event.KeywordsDisplayNames.Any())
<div>Log Name: @SelectedEvent.LogName</div>
<div>Source: @SelectedEvent.Source</div>
<div>Event Id: @SelectedEvent.Id</div>
<div>Level: @SelectedEvent.Level</div>
@if (SelectedEvent.KeywordsDisplayNames.Any())
{
<div>
@Event.KeywordsDisplayNames.GetEventKeywords()
@SelectedEvent.KeywordsDisplayNames.GetEventKeywords()
</div>
}
<div>Date and Time: @Event.TimeCreated.ConvertTimeZone(SettingsState.Value.Config.TimeZoneInfo)</div>
<div>Date and Time: @SelectedEvent.TimeCreated.ConvertTimeZone(SettingsState.Value.Config.TimeZoneInfo)</div>
</div>

<div>Description:</div>
<p class="details-description">@Event.Description</p>
<p class="details-description">@SelectedEvent.Description</p>
</div>

<div class="details-row-xml" @onclick="ToggleXml">
Expand All @@ -50,6 +43,6 @@
</span>
</div>

<p class="details-xml" data-toggle="@_isXmlVisible.ToString().ToLower()">@Event.Xml</p>
<p class="details-xml" data-toggle="@_isXmlVisible.ToString().ToLower()">@XElement.Parse(SelectedEvent.Xml)</p>
}
</div>
Loading

0 comments on commit a020617

Please sign in to comment.