Skip to content

Commit

Permalink
Removed redundant ordering when getting category values
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 committed Oct 24, 2024
1 parent fe3d04d commit 868b598
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
16 changes: 6 additions & 10 deletions src/EventLogExpert.UI/Models/EventLogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,23 @@ public readonly record struct EventLogData(
{
public EventLogId Id { get; } = EventLogId.Create();

/// <summary>Gets a distinct list of values for the specified category.</summary>
public IEnumerable<string> GetCategoryValues(FilterCategory category)
{
switch (category)
{
case FilterCategory.Id:
return Events.Select(e => e.Id.ToString())
.Distinct().Order();
return Events.Select(e => e.Id.ToString()).Distinct();
case FilterCategory.ActivityId:
return Events.Select(e => e.ActivityId?.ToString() ?? string.Empty)
.Distinct().Order();
return Events.Select(e => e.ActivityId?.ToString() ?? string.Empty).Distinct();
case FilterCategory.Level:
return Enum.GetNames<SeverityLevel>();
case FilterCategory.KeywordsDisplayNames:
return Events.SelectMany(e => e.KeywordsDisplayNames)
.Distinct().Order();
return Events.SelectMany(e => e.KeywordsDisplayNames).Distinct();
case FilterCategory.Source:
return Events.Select(e => e.Source)
.Distinct().Order();
return Events.Select(e => e.Source).Distinct();
case FilterCategory.TaskCategory:
return Events.Select(e => e.TaskCategory)
.Distinct().Order();
return Events.Select(e => e.TaskCategory).Distinct();
case FilterCategory.Xml:
case FilterCategory.Description:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ private List<string> Items
.SelectMany(log => log.GetCategoryValues(FilterCategory.ActivityId))
.Distinct().Order().ToList();
case FilterCategory.Level:
List<string> items = [];

foreach (SeverityLevel item in Enum.GetValues(typeof(SeverityLevel)))
{
items.Add(item.ToString());
}

return items;
return Enum.GetNames<SeverityLevel>().ToList();
case FilterCategory.KeywordsDisplayNames:
return EventLogState.Value.ActiveLogs.Values
.SelectMany(log => log.GetCategoryValues(FilterCategory.KeywordsDisplayNames))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ private List<string> Items
.SelectMany(log => log.GetCategoryValues(FilterCategory.ActivityId))
.Distinct().Order().ToList();
case FilterCategory.Level:
List<string> items = [];

foreach (SeverityLevel item in Enum.GetValues(typeof(SeverityLevel)))
{
items.Add(item.ToString());
}

return items;
return Enum.GetNames<SeverityLevel>().ToList();
case FilterCategory.KeywordsDisplayNames:
return EventLogState.Value.ActiveLogs.Values
.SelectMany(log => log.GetCategoryValues(FilterCategory.KeywordsDisplayNames))
Expand Down

0 comments on commit 868b598

Please sign in to comment.