Skip to content

Commit

Permalink
Created state for event table
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 authored and bill-long committed Dec 28, 2023
1 parent 48b0b60 commit 2405951
Show file tree
Hide file tree
Showing 25 changed files with 890 additions and 935 deletions.
6 changes: 6 additions & 0 deletions src/EventLogExpert.UI/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace EventLogExpert.UI;

public enum LogType
{
Live,
File
}

public enum FilterType
{
[EnumMember(Value = "Event ID")] Id,
Expand Down
64 changes: 64 additions & 0 deletions src/EventLogExpert.UI/FilterMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,77 @@

using EventLogExpert.Eventing.Models;
using EventLogExpert.UI.Models;
using System.Collections.Immutable;
using System.Linq.Dynamic.Core;
using System.Text;

namespace EventLogExpert.UI;

public static class FilterMethods
{
public static Dictionary<string, IEnumerable<DisplayEventModel>> FilterActiveLogs(
ImmutableDictionary<string, EventLogData> activeLogs,
EventFilter eventFilter)
{
Dictionary<string, IEnumerable<DisplayEventModel>> activeLogsFiltered = [];

foreach (var activeLog in activeLogs)
{
activeLogsFiltered.Add(activeLog.Key, GetFilteredEvents(activeLog.Value.Events, eventFilter));
}

return activeLogsFiltered;
}

public static IEnumerable<DisplayEventModel> GetFilteredEvents(IEnumerable<DisplayEventModel> events, EventFilter eventFilter)
{
List<Func<DisplayEventModel, bool>> filters = [];

if (eventFilter.DateFilter?.IsEnabled is true)
{
filters.Add(e =>
e.TimeCreated >= eventFilter.DateFilter.After &&
e.TimeCreated <= eventFilter.DateFilter.Before);
}

if (eventFilter.AdvancedFilter?.IsEnabled is true)
{
filters.Add(e => eventFilter.AdvancedFilter.Comparison(e));
}

if (!eventFilter.Filters.IsEmpty)
{
filters.Add(e => eventFilter.Filters
.All(filter => filter.Comparison(e)));
}

if (!eventFilter.CachedFilters.IsEmpty)
{
filters.Add(e => eventFilter.CachedFilters
.All(filter => filter.Comparison(e)));
}

return events.AsParallel()
.Where(e => filters
.All(filter => filter(e)));
}

public static bool HasFilteringChanged(EventFilter updated, EventFilter original) =>
updated.AdvancedFilter?.Equals(original.AdvancedFilter) is false ||
updated.DateFilter?.Equals(original.DateFilter) is false ||
updated.CachedFilters.Equals(original.CachedFilters) is false ||
updated.Filters.Equals(original.Filters) is false;

public static bool HasIsDescendingChanged(bool updated, bool original) => updated.Equals(original);

public static bool HasOrderByChanged(ColumnName? updated, ColumnName? original) => updated.Equals(original);

public static bool IsFilteringEnabled(EventFilter eventFilter) =>
eventFilter.AdvancedFilter?.IsEnabled is true ||
eventFilter.CachedFilters.IsEmpty is false ||
eventFilter.DateFilter?.IsEnabled is true ||
eventFilter.Filters.IsEmpty is false;

/// <summary>Sorts events by RecordId if no order is specified</summary>
public static IEnumerable<DisplayEventModel> SortEvents(
this IEnumerable<DisplayEventModel> events,
Expand Down
12 changes: 12 additions & 0 deletions src/EventLogExpert.UI/Models/EventFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using System.Collections.Immutable;

namespace EventLogExpert.UI.Models;

public sealed record EventFilter(
AdvancedFilterModel? AdvancedFilter,
FilterDateModel? DateFilter,
ImmutableList<AdvancedFilterModel> CachedFilters,
ImmutableList<FilterModel> Filters);
18 changes: 18 additions & 0 deletions src/EventLogExpert.UI/Models/EventLogData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Eventing.Models;
using System.Collections.Immutable;
using System.Collections.ObjectModel;

namespace EventLogExpert.UI.Models;

public sealed record EventLogData(
string Name,
LogType Type,
ReadOnlyCollection<DisplayEventModel> Events,
ImmutableHashSet<int> EventIds,
ImmutableHashSet<Guid?> EventActivityIds,
ImmutableHashSet<string> EventProviderNames,
ImmutableHashSet<string> TaskNames,
ImmutableHashSet<string> KeywordNames);
31 changes: 31 additions & 0 deletions src/EventLogExpert.UI/Models/EventTableModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Eventing.Models;
using Microsoft.AspNetCore.Components;
using System.Collections.ObjectModel;

namespace EventLogExpert.UI.Models;

public sealed record EventTableModel
{
public Guid Id { get; } = Guid.NewGuid();

public string? FileName { get; init; }

public string ComputerName => DisplayedEvents.FirstOrDefault()?.ComputerName ?? string.Empty;

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

public LogType LogType { get; init; }

// Yes this is mutable but HTML refs are only directly assigned to fields and properties
public ElementReference? ElementReference { get; set; }

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

public bool IsCombined { get; init; }

public bool IsLoading { get; init; }
}
53 changes: 24 additions & 29 deletions src/EventLogExpert.UI/Store/EventLog/EventLogAction.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Eventing.Helpers;
using EventLogExpert.Eventing.Models;
using static EventLogExpert.UI.Store.EventLog.EventLogState;
using EventLogExpert.UI.Models;
using System.Collections.Immutable;
using System.Collections.ObjectModel;

namespace EventLogExpert.UI.Store.EventLog;

public record EventLogAction
public sealed record EventLogAction
{
public record AddEvent(DisplayEventModel NewEvent, ITraceLogger TraceLogger) : EventLogAction;
public sealed record AddEvent(DisplayEventModel NewEvent);

public record LoadEvents(
public sealed record AddEventBuffered(ReadOnlyCollection<DisplayEventModel> UpdatedBuffer, bool IsFull);

public sealed record AddEventSuccess(ImmutableDictionary<string, EventLogData> ActiveLogs);

public sealed record CloseAll;

public sealed record CloseLog(string LogName);

public sealed record LoadEvents(
string LogName,
LogType Type,
List<DisplayEventModel> Events,
IEnumerable<int> AllEventIds,
IEnumerable<Guid?> AllActivityIds,
IEnumerable<string> AllProviderNames,
IEnumerable<string> AllTaskNames,
IEnumerable<string> AllKeywords,
ITraceLogger TraceLogger
) : EventLogAction;
IEnumerable<string> AllKeywords);

public record LoadNewEvents(ITraceLogger TraceLogger) : EventLogAction;
public sealed record LoadEventsSuccess(ImmutableDictionary<string, EventLogData> ActiveLogs);

public record OpenLog(string LogName, LogType LogType) : EventLogAction;
public sealed record LoadNewEvents;

public record CloseLog(string LogName) : EventLogAction;
public sealed record OpenLog(string LogName, LogType LogType);

public record CloseAll : EventLogAction;
public sealed record SelectEvent(DisplayEventModel? SelectedEvent);

public record SelectEvent(DisplayEventModel? SelectedEvent) : EventLogAction;
public sealed record SetContinouslyUpdate(bool ContinuouslyUpdate);

/// <summary>
/// This action only has meaning for the UI.
/// </summary>
/// <param name="LogName"></param>
public record SelectLog(string? LogName) : EventLogAction;

public record SetContinouslyUpdate(bool ContinuouslyUpdate, ITraceLogger TraceLogger) : EventLogAction;

/// <summary>
/// Used to indicate the progress of event logs being loaded.
/// </summary>
/// <summary>Used to indicate the progress of event logs being loaded.</summary>
/// <param name="ActivityId">
/// A unique id that distinguishes this loading activity from others, since log names such as
/// Application will be common and many file names will be the same.
/// </param>
/// <param name="Count"></param>
public record SetEventsLoading(Guid ActivityId, int Count) : EventLogAction;

public record SetFilters(EventFilter EventFilter, ITraceLogger TraceLogger) : EventLogAction;
public sealed record SetEventsLoading(Guid ActivityId, int Count);

public record SetOrderBy(ColumnName? OrderBy, ITraceLogger TraceLogger) : EventLogAction;
public sealed record SetFilters(EventFilter EventFilter);

public record ToggleSorting(ITraceLogger TraceLogger) : EventLogAction;
public sealed record SetFiltersSuccess(EventFilter EventFilter);
}
Loading

0 comments on commit 2405951

Please sign in to comment.