Skip to content

Commit

Permalink
Move available value states into EventLogState
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-long committed May 25, 2023
1 parent 6dc2d96 commit f7f5c19
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 97 deletions.
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
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
8 changes: 4 additions & 4 deletions src/EventLogExpert/Shared/Components/FilterRow.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IState<AvailableFilterState> AvailableFilterPaneState
@inject IState<EventLogState> EventLogState

<div class="filter-row">
@if (Value.IsEditing)
Expand Down Expand Up @@ -27,7 +27,7 @@
case FilterType.EventId :
<FilterSelect CssClass="input-filter-id" TInput="int"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.EventIdsAll.OrderBy(id => id)" />
Items="EventLogState.Value.EventIds.OrderBy(id => id)" />
break;
case FilterType.Level :
<FilterSelect CssClass="input-filter-severity" TInput="SeverityLevel"
Expand All @@ -36,12 +36,12 @@
case FilterType.Source :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.EventProviderNamesAll.OrderBy(n => n)" />
Items="EventLogState.Value.EventProviderNames.OrderBy(n => n)" />
break;
case FilterType.Task :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.TaskNamesAll.OrderBy(n => n)" />
Items="EventLogState.Value.TaskNames.OrderBy(n => n)" />
break;
case FilterType.Description :
default :
Expand Down
8 changes: 4 additions & 4 deletions src/EventLogExpert/Shared/Components/SubFilterRow.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IState<AvailableFilterState> AvailableFilterPaneState
@inject IState<EventLogState> EventLogState

<div class="subfilter-row">
<div>
Expand All @@ -17,7 +17,7 @@
case FilterType.EventId :
<FilterSelect CssClass="input-filter-id" TInput="int"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.EventIdsAll.OrderBy(id => id)" />
Items="EventLogState.Value.EventIds.OrderBy(id => id)" />
break;
case FilterType.Level :
<FilterSelect CssClass="input-filter-severity" TInput="SeverityLevel"
Expand All @@ -26,12 +26,12 @@
case FilterType.Source :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.EventProviderNamesAll.OrderBy(n => n)" />
Items="EventLogState.Value.EventProviderNames.OrderBy(n => n)" />
break;
case FilterType.Task :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="AvailableFilterPaneState.Value.TaskNamesAll.OrderBy(n => n)" />
Items="EventLogState.Value.TaskNames.OrderBy(n => n)" />
break;
case FilterType.Description :
default :
Expand Down
72 changes: 64 additions & 8 deletions src/EventLogExpert/Store/EventLog/EventLogReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public static EventLogState ReduceAddEvent(EventLogState state, EventLogAction.A
return state;
}

var newEvent = new List<DisplayEventModel>
{
action.NewEvent
};
var newEvent = new[] { action.NewEvent };

var newState = state;

Expand All @@ -43,6 +40,24 @@ public static EventLogState ReduceAddEvent(EventLogState state, EventLogAction.A
newState = newState with { NewEventBuffer = updatedBuffer, NewEventBufferIsFull = full };
}

if (!state.EventIds.Contains(action.NewEvent.Id))
{
newState = newState with { EventIds = (new[] {action.NewEvent.Id})
.Concat(state.EventIds).ToList().AsReadOnly() };
}

if (!state.EventProviderNames.Contains(action.NewEvent.Source))
{
newState = newState with { EventProviderNames = (new[] {action.NewEvent.Source})
.Concat(state.EventProviderNames).ToList().AsReadOnly() };
}

if (!state.TaskNames.Contains(action.NewEvent.TaskCategory))
{
newState = newState with { TaskNames = (new[] { action.NewEvent.TaskCategory })
.Concat(state.TaskNames).ToList().AsReadOnly() };
}

return newState;
}

Expand All @@ -53,7 +68,13 @@ public static EventLogState ReduceLoadEvents(EventLogState state, EventLogAction
{
Events = action.Events.Concat(state.Events)
.OrderByDescending(e => e.TimeCreated)
.ToList().AsReadOnly()
.ToList().AsReadOnly(),
EventIds = action.AllEventIds.Concat(state.EventIds)
.Distinct().OrderBy(n => n).ToList().AsReadOnly(),
EventProviderNames = action.AllProviderNames.Concat(state.EventProviderNames)
.Distinct().OrderBy(n => n).ToList().AsReadOnly(),
TaskNames = action.AllTaskNames.Concat(state.TaskNames)
.Distinct().OrderBy(n => n).ToList().AsReadOnly()
};
}

Expand Down Expand Up @@ -88,11 +109,15 @@ public static EventLogState ReduceCloseLog(EventLogState state, EventLogAction.C
{
ActiveLogs = new List<LogSpecifier>().AsReadOnly(),
Events = new List<DisplayEventModel>().AsReadOnly(),
NewEventBuffer = new List<DisplayEventModel>().AsReadOnly()
NewEventBuffer = new List<DisplayEventModel>().AsReadOnly(),
NewEventBufferIsFull = false,
EventIds = new List<int>().AsReadOnly(),
EventProviderNames = new List<string>().AsReadOnly(),
TaskNames = new List<string>().AsReadOnly()
};
}

return state with
var newState = state with
{
ActiveLogs = state.ActiveLogs
.Where(l => l.Name != action.LogName)
Expand All @@ -104,6 +129,12 @@ public static EventLogState ReduceCloseLog(EventLogState state, EventLogAction.C
.Where(e => e.OwningLog != action.LogName)
.ToList().AsReadOnly()
};

newState = RecalculateAvailableValueCollections(newState);

newState = newState with { NewEventBufferIsFull = newState.NewEventBuffer.Count >= MaxNewEvents ? true : false };

return newState;
}

[ReducerMethod]
Expand All @@ -113,7 +144,11 @@ public static EventLogState ReduceCloseAll(EventLogState state, EventLogAction.C
{
ActiveLogs = new List<LogSpecifier>().AsReadOnly(),
Events = new List<DisplayEventModel>().AsReadOnly(),
NewEventBuffer = new List<DisplayEventModel>().AsReadOnly()
NewEventBuffer = new List<DisplayEventModel>().AsReadOnly(),
NewEventBufferIsFull = false,
EventIds = new List<int>().AsReadOnly(),
EventProviderNames = new List<string>().AsReadOnly(),
TaskNames = new List<string>().AsReadOnly()
};
}

Expand Down Expand Up @@ -147,4 +182,25 @@ public static EventLogState ReduceSetContinouslyUpdate(EventLogState state, Even
[ReducerMethod]
public static EventLogState ReduceSetEventsLoading(EventLogState state, EventLogAction.SetEventsLoading action) =>
state with { EventsLoading = action.Count };

private static EventLogState RecalculateAvailableValueCollections(EventLogState state)
{
var eventIds = new HashSet<int>();
var providerNames = new HashSet<string>();
var taskNames = new HashSet<string>();

foreach (var e in state.Events)
{
eventIds.Add(e.Id);
providerNames.Add(e.Source);
taskNames.Add(e.TaskCategory);
}

return state with
{
EventIds = eventIds.ToList().AsReadOnly(),
EventProviderNames = providerNames.ToList().AsReadOnly(),
TaskNames = taskNames.ToList().AsReadOnly()
};
}
}
6 changes: 6 additions & 0 deletions src/EventLogExpert/Store/EventLog/EventLogState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public enum LogType { Live, File }

public ReadOnlyCollection<LogSpecifier> ActiveLogs { get; init; } = new List<LogSpecifier>().AsReadOnly();

public ReadOnlyCollection<int> EventIds { get; init; } = new List<int>().AsReadOnly();

public ReadOnlyCollection<string> EventProviderNames { get; init; } = new List<string>().AsReadOnly();

public ReadOnlyCollection<string> TaskNames { get; init;} = new List<string>().AsReadOnly();

public bool ContinuouslyUpdate { get; init; } = false;

public ReadOnlyCollection<DisplayEventModel> Events { get; init; } = new List<DisplayEventModel>().AsReadOnly();
Expand Down
20 changes: 0 additions & 20 deletions src/EventLogExpert/Store/FilterPane/AvailableFilterState.cs

This file was deleted.

2 changes: 0 additions & 2 deletions src/EventLogExpert/Store/FilterPane/FilterPaneAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace EventLogExpert.Store.FilterPane;

public record FilterPaneAction
{
public record AddAvailableFilters(string FilterText);

public record AddFilter;

public record RemoveFilter(FilterModel FilterModel);
Expand Down
52 changes: 0 additions & 52 deletions src/EventLogExpert/Store/FilterPane/FilterPaneReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,13 @@
// // Licensed under the MIT License.

using EventLogExpert.Library.Models;
using EventLogExpert.Store.EventLog;
using Fluxor;
using System.Collections.Immutable;
using IDispatcher = Fluxor.IDispatcher;

namespace EventLogExpert.Store.FilterPane;

public class FilterPaneReducers
{
private readonly IDispatcher _dispatcher;

public FilterPaneReducers(IDispatcher dispatcher) => _dispatcher = dispatcher;

[ReducerMethod]
public static AvailableFilterState ReduceAddEvent(AvailableFilterState state, EventLogAction.AddEvent action)
{
var ev = action.NewEvent;

var newState = state;

// These lookups against EventIdsAll, etc, could be slow if
// we have a lot of values. Consider whether we should change these to
// ImmutableHashSets.
if (!state.EventIdsAll.Contains(ev.Id))
{
var newId = new List<int> { ev.Id };
var allIds = newId.Concat(state.EventIdsAll).ToImmutableList();
newState = state with { EventIdsAll = allIds };
}

if (!state.EventProviderNamesAll.Contains(ev.Source))
{
var newProvider = new List<string> { ev.Source };
var allProviders = newProvider.Concat(state.EventProviderNamesAll).ToImmutableList();
newState = state with { EventProviderNamesAll = allProviders };
}

if (!state.TaskNamesAll.Contains(ev.TaskCategory))
{
var newTask = new List<string> { ev.TaskCategory };
var allTasks = newTask.Concat(state.TaskNamesAll).ToImmutableList();
newState = state with { TaskNamesAll = allTasks };
}

return newState;
}

[ReducerMethod(typeof(FilterPaneAction.AddFilter))]
public static FilterPaneState ReduceAddFilterAction(FilterPaneState state)
{
Expand All @@ -64,9 +24,6 @@ public static FilterPaneState ReduceAddFilterAction(FilterPaneState state)
return state with { CurrentFilters = updatedList };
}

[ReducerMethod(typeof(FilterPaneAction.AddAvailableFilters))]
public static AvailableFilterState ReduceAddRecentFilter(AvailableFilterState state) => state;

[ReducerMethod]
public static FilterPaneState ReduceAddSubFilterAction(FilterPaneState state, FilterPaneAction.AddSubFilter action)
{
Expand All @@ -80,15 +37,6 @@ public static FilterPaneState ReduceAddSubFilterAction(FilterPaneState state, Fi
return state with { CurrentFilters = updatedList };
}

[ReducerMethod]
public static AvailableFilterState ReduceLoadEventsAction(AvailableFilterState state,
EventLogAction.LoadEvents action) => state with
{
EventIdsAll = action.AllEventIds,
EventProviderNamesAll = action.AllProviderNames,
TaskNamesAll = action.AllTaskNames
};

[ReducerMethod]
public static FilterPaneState ReduceRemoveFilterAction(FilterPaneState state, FilterPaneAction.RemoveFilter action)
{
Expand Down

0 comments on commit f7f5c19

Please sign in to comment.