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

Allow opening multiple logs in the same view #121

Merged
merged 8 commits into from
May 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void SetActiveDatabases(IEnumerable<string> databaseNames)
LoadDatabases();
}

public DisplayEventModel Resolve(EventRecord eventRecord)
public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
{
while (!_ready)
{
Expand All @@ -185,7 +185,7 @@ public DisplayEventModel Resolve(EventRecord eventRecord)
_providerDetails.TryGetValue(eventRecord.ProviderName, out ProviderDetails? providerDetails);
if (providerDetails != null)
{
lastResult = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails);
lastResult = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails, OwningLogName);
}
}
else
Expand All @@ -195,7 +195,7 @@ public DisplayEventModel Resolve(EventRecord eventRecord)
var providerDetails = dbContext.ProviderDetails.FirstOrDefault(p => p.ProviderName == eventRecord.ProviderName);
if (providerDetails != null)
{
lastResult = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails);
lastResult = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails, OwningLogName);

if (lastResult?.Description != null)
{
Expand All @@ -222,7 +222,8 @@ public DisplayEventModel Resolve(EventRecord eventRecord)
eventRecord.Qualifiers,
eventRecord.Keywords,
eventRecord.LogName,
null);
null,
OwningLogName);
}

if (lastResult.Description == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EventReaderEventResolver : IEventResolver

public event EventHandler<string>? StatusChanged;

public DisplayEventModel Resolve(EventRecord eventRecord)
public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
{
var desc = eventRecord.FormatDescription();
var xml = eventRecord.ToXml();
Expand All @@ -36,8 +36,8 @@ public DisplayEventModel Resolve(EventRecord eventRecord)
eventRecord.Qualifiers,
eventRecord.Keywords,
eventRecord.LogName,
null
);
null,
OwningLogName);
}

private static T TryGetValue<T>(Func<T> func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics.Eventing.Reader;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;

namespace EventLogExpert.Library.EventResolvers;

Expand Down Expand Up @@ -93,7 +92,7 @@ protected EventResolverBase(Action<string> tracer)
/// </param>
/// <param name="providerDetails"></param>
/// <returns></returns>
protected DisplayEventModel ResolveFromProviderDetails(EventRecord eventRecord, IList<EventProperty> eventProperties, ProviderDetails providerDetails)
protected DisplayEventModel ResolveFromProviderDetails(EventRecord eventRecord, IList<EventProperty> eventProperties, ProviderDetails providerDetails, string owningLogName)
{
string? description = null;
string? xml = null;
Expand Down Expand Up @@ -193,6 +192,7 @@ protected DisplayEventModel ResolveFromProviderDetails(EventRecord eventRecord,
eventRecord.Qualifiers,
eventRecord.Keywords,
eventRecord.LogName,
template);
template,
owningLogName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace EventLogExpert.Library.EventResolvers
/// </summary>
public interface IEventResolver
{
public DisplayEventModel Resolve(EventRecord eventRecord);
public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName);

public string Status { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LocalProviderEventResolver : EventResolverBase, IEventResolver

public LocalProviderEventResolver(Action<string> tracer) : base(tracer) { }

public DisplayEventModel Resolve(EventRecord eventRecord)
public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLogName)
{
if (!_providerDetails.ContainsKey(eventRecord.ProviderName))
{
Expand All @@ -50,14 +50,15 @@ public DisplayEventModel Resolve(EventRecord eventRecord)
eventRecord.Qualifiers,
eventRecord.Keywords,
eventRecord.LogName,
null);
null,
OwningLogName);
}

// 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.
var eventProperties = eventRecord.Properties;

var result = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails);
var result = ResolveFromProviderDetails(eventRecord, eventProperties, providerDetails, OwningLogName);

if (result.Description == null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/EventLogExpert.Library/Models/DisplayEventModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public record DisplayEventModel(
IList<EventProperty> Properties,
int? Qualifiers,
long? Keywords,
string LogName,
string? Template)
string LogName, // This is the log name from the event reader
string? Template,
string OwningLog) // This is the name of the log file or the live log, which we use internally
{
public string Xml
{
Expand Down
12 changes: 6 additions & 6 deletions src/EventLogExpert.Test/EventResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ internal UnitTestEventResolver(List<ProviderDetails> providerDetailsList) : base
_providerDetailsList = providerDetailsList;
}

public DisplayEventModel Resolve(EventRecord eventRecord)
public DisplayEventModel Resolve(EventRecord eventRecord, string OwningLog)
{
return ResolveFromProviderDetails(eventRecord, eventRecord.Properties, _providerDetailsList[0]);
return ResolveFromProviderDetails(eventRecord, eventRecord.Properties, _providerDetailsList[0], OwningLog);
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public void CanResolveMSExchangeRepl4114()
};

var resolver = new UnitTestEventResolver(new List<ProviderDetails> { providerDetails });
var result = resolver.Resolve(eventRecord.Object);
var result = resolver.Resolve(eventRecord.Object, "Test");

var expectedDescription = "Database redundancy health check passed.\r\nDatabase copy: SERVER1\r\nRedundancy count: 4\r\nIsSuppressed: False\r\n\r\nErrors:\r\nLots of copy status text";
Assert.Equal(expectedDescription, result.Description);
Expand All @@ -120,7 +120,7 @@ public void PerfTest()
EventRecord er;
while (null != (er = eventLogReader.ReadEvent()))
{
resolver.Resolve(er);
resolver.Resolve(er, "Test");
}

sw.Stop();
Expand Down Expand Up @@ -148,7 +148,7 @@ public void PerfTest2()
sw.Restart();
foreach (var record in eventRecords)
{
resolver.Resolve(record);
resolver.Resolve(record, "Test");
}

sw.Stop();
Expand Down Expand Up @@ -186,7 +186,7 @@ public void Test1()

foreach (var r in resolvers)
{
var resolved = r.Resolve(er);
var resolved = r.Resolve(er, "Test");

uniqueDescriptions.Add(resolved.Description
.Replace("\r", "") // I can't figure out the logic of FormatMessage() for when it leaves
Expand Down
12 changes: 10 additions & 2 deletions src/EventLogExpert/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
// // Licensed under the MIT License.

using EventLogExpert.Library.EventResolvers;
using EventLogExpert.Store.EventLog;
using EventLogExpert.Store.Settings;
using Fluxor;
using static EventLogExpert.Store.EventLog.EventLogState;
using IDispatcher = Fluxor.IDispatcher;

namespace EventLogExpert;

public partial class App : Application
{
public App(IDispatcher fluxorDispatcher, IEventResolver resolver)
public App(IDispatcher fluxorDispatcher, IEventResolver resolver,
IStateSelection<EventLogState, IEnumerable<LogSpecifier>> activeLogsState,
IStateSelection<EventLogState, bool> continuouslyUpdateState,
IStateSelection<SettingsState, bool> showLogState,
IStateSelection<SettingsState,bool> showComputerState)
{
InitializeComponent();

MainPage = new NavigationPage(new MainPage(fluxorDispatcher, resolver));
MainPage = new NavigationPage(new MainPage(fluxorDispatcher, resolver, activeLogsState, continuouslyUpdateState, showLogState, showComputerState));
}

protected override Window CreateWindow(IActivationState? activationState)
Expand Down
2 changes: 1 addition & 1 deletion src/EventLogExpert/Components/DetailsPane.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void CopyEvent()
{
StringBuilder stringToCopy = new();

stringToCopy.AppendLine($"Log Name: {EventLogState.Value.ActiveLog.Name}");
stringToCopy.AppendLine($"Log Name: {Event?.LogName}");
stringToCopy.AppendLine($"Source: {Event?.Source}");
stringToCopy.AppendLine($"Date: {Event?.TimeCreated.ConvertTimeZone(SettingsState.Value.TimeZone)}");
stringToCopy.AppendLine($"Event ID: {Event?.Id}");
Expand Down
16 changes: 16 additions & 0 deletions src/EventLogExpert/Components/EventTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<table id="eventTable">
<thead>
<tr>
@if (SettingsState.Value.ShowLogName)
{
<th id="logname">Log Name</th>
}
@if (SettingsState.Value.ShowComputerName)
{
<th id="computername">Computer</th>
}
<th id="level">Level</th>
<th id="time">
Date and Time
Expand All @@ -24,6 +32,14 @@
<tbody>
<Virtualize Items="@GetFilteredEvents()" Context="evt">
<tr class="@GetCss(evt)" @key="evt.RecordId" @onfocus="() => SelectEvent(evt)" tabindex="0">
@if (SettingsState.Value.ShowLogName)
{
<td>@evt.OwningLog</td>
}
@if (SettingsState.Value.ShowComputerName)
{
<td>@evt.ComputerName</td>
}
<td>@evt.Level</td>
<td>@evt.TimeCreated.ConvertTimeZone(SettingsState.Value.TimeZone)</td>
<td>@evt.Source</td>
Expand Down
20 changes: 20 additions & 0 deletions src/EventLogExpert/Components/EventTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using EventLogExpert.Library.Models;
using EventLogExpert.Store.EventLog;
using EventLogExpert.Store.Settings;
using Fluxor;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Linq.Dynamic.Core;
Expand All @@ -17,11 +19,29 @@ public partial class EventTable

[Inject] private IJSRuntime JSRuntime { get; set; } = null!;

[Inject] private IStateSelection<SettingsState, bool> showLogState { get; init; } = null!;

[Inject] private IStateSelection<SettingsState, bool> showComputerState { get; init; } = null!;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("enableColumnResize");

showLogState.Select(s => s.ShowLogName);
showLogState.SelectedValueChanged += async (sender, showLogName) =>
{
await JSRuntime.InvokeVoidAsync("deleteColumnResize");
await JSRuntime.InvokeVoidAsync("enableColumnResize");
};

showComputerState.Select(s => s.ShowComputerName);
showComputerState.SelectedValueChanged += async (sender, showComputer) =>
{
await JSRuntime.InvokeVoidAsync("deleteColumnResize");
await JSRuntime.InvokeVoidAsync("enableColumnResize");
};
}

await base.OnAfterRenderAsync(firstRender);
Expand Down
4 changes: 4 additions & 0 deletions src/EventLogExpert/Components/EventTable.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ th, td {

.table-row { cursor: pointer; }

#logname { width: 100px; }

#computername { width: 100px; }

#level { width: 100px; }

#time { width: 165px; }
Expand Down
1 change: 0 additions & 1 deletion src/EventLogExpert/Components/FilterPane.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@using EventLogExpert.Shared.Components
@inherits FluxorComponent

@inject IState<AvailableFilterState> AvailableFilterState
@inject IState<EventLogState> EventLogState
@inject IState<FilterPaneState> FilterPaneState
@inject IState<SettingsState> SettingsState
Expand Down
14 changes: 6 additions & 8 deletions src/EventLogExpert/Components/StatusBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
@inject IState<StatusBarState> StatusBarState

<div class="status-bar">
@if (EventLogState.Value.Events.Count < 1 || EventLogState.Value.ActiveLog.LogType == EventLogExpert.Store.EventLog.EventLogState.LogType.File)
@if (EventLogState.Value.EventsLoading > 0)
{
<span>Events Loaded: @StatusBarState.Value.EventsLoaded</span>
}
else
{
<span>Events Loaded: @EventLogState.Value.Events.Count</span>
<span>Loading Progress: @EventLogState.Value.EventsLoading</span>
}

<span>Events Loaded: @EventLogState.Value.Events.Count</span>

@if (EventLogState.Value.ContinuouslyUpdate)
{
<span>Continuously Updating</span>
}
else
{
<span>New Events: @EventLogState.Value.NewEventBuffer.Events.Count</span>
@if (EventLogState.Value.NewEventBuffer.IsBufferFull)
<span>New Events: @EventLogState.Value.NewEventBuffer.Count</span>
@if (EventLogState.Value.NewEventBufferIsFull)
{
<span>Buffer Full</span>
}
Expand Down
25 changes: 19 additions & 6 deletions src/EventLogExpert/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@

<ContentPage.MenuBarItems>
<MenuBarItem Text="File">
<MenuFlyoutItem Text="Open File" Clicked="OpenFile_Clicked" />
<MenuFlyoutSubItem Text="Open Live Event Log">
<MenuFlyoutItem Text="Application" Clicked="OpenLiveLog_Clicked" />
<MenuFlyoutItem Text="System" Clicked="OpenLiveLog_Clicked" />
<MenuFlyoutSubItem Text="Other Logs" x:Name="OtherLogsFlyoutSubitem" />
<MenuFlyoutSubItem Text="Open">
<MenuFlyoutItem Text="File" Clicked="OpenFile_Clicked" />
<MenuFlyoutSubItem Text="Live Event Log">
<MenuFlyoutItem Text="Application" Clicked="OpenLiveLog_Clicked" />
<MenuFlyoutItem Text="System" Clicked="OpenLiveLog_Clicked" />
<MenuFlyoutSubItem Text="Other Logs" x:Name="OpenOtherLogsFlyoutSubitem" />
</MenuFlyoutSubItem>
</MenuFlyoutSubItem>
<MenuFlyoutSubItem Text="Add Another Log To This View">
<MenuFlyoutItem Text="File" Clicked="AddFile_Clicked" />
<MenuFlyoutSubItem Text="Live Event Log">
<MenuFlyoutItem Text="Application" Clicked="AddLiveLog_Clicked" />
<MenuFlyoutItem Text="System" Clicked="AddLiveLog_Clicked" />
<MenuFlyoutSubItem Text="Other Logs" x:Name="AddOtherLogsFlyoutSubitem" />
</MenuFlyoutSubItem>
</MenuFlyoutSubItem>
<MenuFlyoutItem Text="Close All Open Logs" x:Name="CloseAllOpenLogs" Clicked="CloseAll_Clicked" />
</MenuBarItem>
<MenuBarItem Text="View">
<MenuFlyoutItem Text="Load New Events" Clicked="LoadNewEvents_Clicked" />
<MenuFlyoutItem Text="Continuously Update" Clicked="ContinuouslyUpdate_Clicked" />
<MenuFlyoutItem Text="Continuously Update" Clicked="ContinuouslyUpdate_Clicked" x:Name="ContinuouslyUpdateMenuItem" />
<MenuFlyoutItem Text="Show Log Name Column" Clicked="ShowLogName_Clicked" x:Name="ShowLogNameMenuItem" />
<MenuFlyoutItem Text="Show Computer Name Column" Clicked="ShowComputerName_Clicked" x:Name="ShowComputerNameMenuItem" />
</MenuBarItem>
<MenuBarItem Text="Tools">
<MenuFlyoutItem Text="Settings" Clicked="OpenSettingsModal_Clicked" />
Expand Down
Loading