From f7f5c190be7647975432eecf793e934de3ea3626 Mon Sep 17 00:00:00 2001 From: Bill Long Date: Thu, 25 May 2023 13:53:41 -0500 Subject: [PATCH] Move available value states into EventLogState --- src/EventLogExpert.Test/EventResolverTests.cs | 12 ++-- .../Components/FilterPane.razor | 1 - .../Shared/Components/FilterRow.razor | 8 +-- .../Shared/Components/SubFilterRow.razor | 8 +-- .../Store/EventLog/EventLogReducers.cs | 72 ++++++++++++++++--- .../Store/EventLog/EventLogState.cs | 6 ++ .../Store/FilterPane/AvailableFilterState.cs | 20 ------ .../Store/FilterPane/FilterPaneAction.cs | 2 - .../Store/FilterPane/FilterPaneReducers.cs | 52 -------------- 9 files changed, 84 insertions(+), 97 deletions(-) delete mode 100644 src/EventLogExpert/Store/FilterPane/AvailableFilterState.cs diff --git a/src/EventLogExpert.Test/EventResolverTests.cs b/src/EventLogExpert.Test/EventResolverTests.cs index c6fb8384..b13a53b8 100644 --- a/src/EventLogExpert.Test/EventResolverTests.cs +++ b/src/EventLogExpert.Test/EventResolverTests.cs @@ -28,9 +28,9 @@ internal UnitTestEventResolver(List 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); } } @@ -103,7 +103,7 @@ public void CanResolveMSExchangeRepl4114() }; var resolver = new UnitTestEventResolver(new List { 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); @@ -120,7 +120,7 @@ public void PerfTest() EventRecord er; while (null != (er = eventLogReader.ReadEvent())) { - resolver.Resolve(er); + resolver.Resolve(er, "Test"); } sw.Stop(); @@ -148,7 +148,7 @@ public void PerfTest2() sw.Restart(); foreach (var record in eventRecords) { - resolver.Resolve(record); + resolver.Resolve(record, "Test"); } sw.Stop(); @@ -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 diff --git a/src/EventLogExpert/Components/FilterPane.razor b/src/EventLogExpert/Components/FilterPane.razor index 2cceedba..1fb0608e 100644 --- a/src/EventLogExpert/Components/FilterPane.razor +++ b/src/EventLogExpert/Components/FilterPane.razor @@ -1,7 +1,6 @@ @using EventLogExpert.Shared.Components @inherits FluxorComponent -@inject IState AvailableFilterState @inject IState EventLogState @inject IState FilterPaneState @inject IState SettingsState diff --git a/src/EventLogExpert/Shared/Components/FilterRow.razor b/src/EventLogExpert/Shared/Components/FilterRow.razor index a5b4cd54..c14fa832 100644 --- a/src/EventLogExpert/Shared/Components/FilterRow.razor +++ b/src/EventLogExpert/Shared/Components/FilterRow.razor @@ -1,4 +1,4 @@ -@inject IState AvailableFilterPaneState +@inject IState EventLogState
@if (Value.IsEditing) @@ -27,7 +27,7 @@ case FilterType.EventId : + Items="EventLogState.Value.EventIds.OrderBy(id => id)" /> break; case FilterType.Level : + Items="EventLogState.Value.EventProviderNames.OrderBy(n => n)" /> break; case FilterType.Task : + Items="EventLogState.Value.TaskNames.OrderBy(n => n)" /> break; case FilterType.Description : default : diff --git a/src/EventLogExpert/Shared/Components/SubFilterRow.razor b/src/EventLogExpert/Shared/Components/SubFilterRow.razor index 923bca1c..45025910 100644 --- a/src/EventLogExpert/Shared/Components/SubFilterRow.razor +++ b/src/EventLogExpert/Shared/Components/SubFilterRow.razor @@ -1,4 +1,4 @@ -@inject IState AvailableFilterPaneState +@inject IState EventLogState
@@ -17,7 +17,7 @@ case FilterType.EventId : + Items="EventLogState.Value.EventIds.OrderBy(id => id)" /> break; case FilterType.Level : + Items="EventLogState.Value.EventProviderNames.OrderBy(n => n)" /> break; case FilterType.Task : + Items="EventLogState.Value.TaskNames.OrderBy(n => n)" /> break; case FilterType.Description : default : diff --git a/src/EventLogExpert/Store/EventLog/EventLogReducers.cs b/src/EventLogExpert/Store/EventLog/EventLogReducers.cs index b533db74..76e7af62 100644 --- a/src/EventLogExpert/Store/EventLog/EventLogReducers.cs +++ b/src/EventLogExpert/Store/EventLog/EventLogReducers.cs @@ -25,10 +25,7 @@ public static EventLogState ReduceAddEvent(EventLogState state, EventLogAction.A return state; } - var newEvent = new List - { - action.NewEvent - }; + var newEvent = new[] { action.NewEvent }; var newState = state; @@ -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; } @@ -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() }; } @@ -88,11 +109,15 @@ public static EventLogState ReduceCloseLog(EventLogState state, EventLogAction.C { ActiveLogs = new List().AsReadOnly(), Events = new List().AsReadOnly(), - NewEventBuffer = new List().AsReadOnly() + NewEventBuffer = new List().AsReadOnly(), + NewEventBufferIsFull = false, + EventIds = new List().AsReadOnly(), + EventProviderNames = new List().AsReadOnly(), + TaskNames = new List().AsReadOnly() }; } - return state with + var newState = state with { ActiveLogs = state.ActiveLogs .Where(l => l.Name != action.LogName) @@ -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] @@ -113,7 +144,11 @@ public static EventLogState ReduceCloseAll(EventLogState state, EventLogAction.C { ActiveLogs = new List().AsReadOnly(), Events = new List().AsReadOnly(), - NewEventBuffer = new List().AsReadOnly() + NewEventBuffer = new List().AsReadOnly(), + NewEventBufferIsFull = false, + EventIds = new List().AsReadOnly(), + EventProviderNames = new List().AsReadOnly(), + TaskNames = new List().AsReadOnly() }; } @@ -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(); + var providerNames = new HashSet(); + var taskNames = new HashSet(); + + 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() + }; + } } diff --git a/src/EventLogExpert/Store/EventLog/EventLogState.cs b/src/EventLogExpert/Store/EventLog/EventLogState.cs index 9f0fc5e1..c5e786e6 100644 --- a/src/EventLogExpert/Store/EventLog/EventLogState.cs +++ b/src/EventLogExpert/Store/EventLog/EventLogState.cs @@ -18,6 +18,12 @@ public enum LogType { Live, File } public ReadOnlyCollection ActiveLogs { get; init; } = new List().AsReadOnly(); + public ReadOnlyCollection EventIds { get; init; } = new List().AsReadOnly(); + + public ReadOnlyCollection EventProviderNames { get; init; } = new List().AsReadOnly(); + + public ReadOnlyCollection TaskNames { get; init;} = new List().AsReadOnly(); + public bool ContinuouslyUpdate { get; init; } = false; public ReadOnlyCollection Events { get; init; } = new List().AsReadOnly(); diff --git a/src/EventLogExpert/Store/FilterPane/AvailableFilterState.cs b/src/EventLogExpert/Store/FilterPane/AvailableFilterState.cs deleted file mode 100644 index 6cb11791..00000000 --- a/src/EventLogExpert/Store/FilterPane/AvailableFilterState.cs +++ /dev/null @@ -1,20 +0,0 @@ -// // Copyright (c) Microsoft Corporation. -// // Licensed under the MIT License. - -using Fluxor; -using System.Collections.Immutable; - -namespace EventLogExpert.Store.FilterPane; - -[FeatureState] -public record AvailableFilterState -{ - // Temporarily disabling this until filtering is back in place - //public ImmutableList RecentFilters { get; } = ImmutableList.Empty; - - public IEnumerable EventIdsAll { get; init; } = ImmutableList.Empty; - - public IEnumerable EventProviderNamesAll { get; init; } = ImmutableList.Empty; - - public IEnumerable TaskNamesAll { get; init; } = ImmutableList.Empty; -} diff --git a/src/EventLogExpert/Store/FilterPane/FilterPaneAction.cs b/src/EventLogExpert/Store/FilterPane/FilterPaneAction.cs index b4677fdb..b6beeba0 100644 --- a/src/EventLogExpert/Store/FilterPane/FilterPaneAction.cs +++ b/src/EventLogExpert/Store/FilterPane/FilterPaneAction.cs @@ -7,8 +7,6 @@ namespace EventLogExpert.Store.FilterPane; public record FilterPaneAction { - public record AddAvailableFilters(string FilterText); - public record AddFilter; public record RemoveFilter(FilterModel FilterModel); diff --git a/src/EventLogExpert/Store/FilterPane/FilterPaneReducers.cs b/src/EventLogExpert/Store/FilterPane/FilterPaneReducers.cs index 1276f1e3..c2afbbcb 100644 --- a/src/EventLogExpert/Store/FilterPane/FilterPaneReducers.cs +++ b/src/EventLogExpert/Store/FilterPane/FilterPaneReducers.cs @@ -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 { ev.Id }; - var allIds = newId.Concat(state.EventIdsAll).ToImmutableList(); - newState = state with { EventIdsAll = allIds }; - } - - if (!state.EventProviderNamesAll.Contains(ev.Source)) - { - var newProvider = new List { ev.Source }; - var allProviders = newProvider.Concat(state.EventProviderNamesAll).ToImmutableList(); - newState = state with { EventProviderNamesAll = allProviders }; - } - - if (!state.TaskNamesAll.Contains(ev.TaskCategory)) - { - var newTask = new List { 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) { @@ -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) { @@ -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) {