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

Experimental/winforms #13

Merged
merged 5 commits into from
Aug 5, 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
7 changes: 7 additions & 0 deletions LightQueryProfiler.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LightQueryProfiler.Shared.U
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LightQueryProfiler.Highlight", "src\LightQueryProfiler.Highlight\LightQueryProfiler.Highlight.csproj", "{BFF93236-CB9F-4780-9B52-C0DB3286451F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightQueryProfiler.WinFormsApp", "src\LightQueryProfiler.WinFormsApp\LightQueryProfiler.WinFormsApp.csproj", "{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +45,10 @@ Global
{BFF93236-CB9F-4780-9B52-C0DB3286451F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFF93236-CB9F-4780-9B52-C0DB3286451F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFF93236-CB9F-4780-9B52-C0DB3286451F}.Release|Any CPU.Build.0 = Release|Any CPU
{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,6 +59,7 @@ Global
{50A4667C-2F4A-4DF8-A88F-E5BE71DA7CDB} = {51FC1EE8-5A57-4BD8-A682-0790A08C0FE7}
{50FB44D7-9878-447C-BA1B-829D2BC86B78} = {66D515C8-C16C-4429-A47D-DB296B7DC486}
{BFF93236-CB9F-4780-9B52-C0DB3286451F} = {51FC1EE8-5A57-4BD8-A682-0790A08C0FE7}
{BA5AD370-10BB-40D7-8FD5-F7055DBA9D29} = {51FC1EE8-5A57-4BD8-A682-0790A08C0FE7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E833AB64-9548-4BE4-ACB5-2059821BDCDB}
Expand Down
32 changes: 3 additions & 29 deletions src/LightQueryProfiler.Shared/Services/ProfilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class ProfilerService : IProfilerService
private const string TargetName = "ring_buffer";
private readonly IXEventRepository _xEventRepository;
private readonly IXEventService _xEventService;
private List<ProfilerEvent>? lastRead;

public ProfilerService(IXEventRepository xEventRepository, IXEventService xEventService)
{
Expand All @@ -20,42 +19,17 @@ public ProfilerService(IXEventRepository xEventRepository, IXEventService xEvent
public async Task<List<ProfilerEvent>> GetLastEventsAsync(string sessionName)
{
List<ProfilerEvent> readEvents = await ReadXEventsAsync(sessionName);

if (lastRead == null || lastRead.Count == 0)
{
lastRead = readEvents.Where(p => !p.GetEventKey().Contains("LightQueryProfiler")).ToList();
return lastRead;
}

List<ProfilerEvent> newEvents = new List<ProfilerEvent>();

foreach (ProfilerEvent readEvent in readEvents)
{
bool eventFound = false;
foreach (ProfilerEvent lr in lastRead)
{
// ignore duplicate events
if (string.Equals(readEvent.GetEventKey(), lr.GetEventKey(), StringComparison.OrdinalIgnoreCase) == true)
{
eventFound = true;
break;
}

// ignore events created by itself
if (readEvent.GetEventKey().Contains("LightQueryProfiler"))
{
eventFound = true;
break;
}
}

if (eventFound == false)
// ignore events created by itself
if (!readEvent.GetEventKey().Contains("LightQueryProfiler", StringComparison.OrdinalIgnoreCase))
{
newEvents.Add(readEvent);
}
}

lastRead = readEvents;

return newEvents;
}

Expand Down
22 changes: 9 additions & 13 deletions src/LightQueryProfiler.SharedWebUI/Pages/Profiler.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,25 @@ private RenderFragment CreateRowDetailComponent(Dictionary<string, Event> row) =
builder.CloseComponent();
};

private List<Dictionary<string, Event>> FilterRowsOut(List<Dictionary<string, Event>> rows)
private List<Dictionary<string, Event>> FilterRows(List<Dictionary<string, Event>> rows)
{
List<Dictionary<string, Event>> result = new List<Dictionary<string, Event>>();
string filterValue;
string? eventValue;

if (Filters != null && Filters.Count > 0)
if (Filters?.Count > 0 && rows?.Count > 0)
{
if (rows != null && rows.Count > 0)
foreach (Dictionary<string, Event> r in rows)
{
foreach (KeyValuePair<string, object> f in Filters)
{
foreach (Dictionary<string, Event> r in rows)
if (r.ContainsKey(f.Key))
{
if (r.ContainsKey(f.Key))
filterValue = (f.Value?.ToString() ?? string.Empty).Trim();
eventValue = r[f.Key].EventValue?.ToString();
if (eventValue?.Contains(filterValue, StringComparison.OrdinalIgnoreCase) == true)
{
filterValue = (f.Value?.ToString() ?? string.Empty).Trim();
eventValue = r[f.Key].EventValue?.ToString();
if (eventValue != null &&
eventValue.Contains(filterValue, StringComparison.OrdinalIgnoreCase))
{
result.Add(r);
}
result.Add(r);
}
}
}
Expand Down Expand Up @@ -246,7 +242,7 @@ private async Task GetLastEventsInternalAsync()

if (Filters != null && Filters.Count > 0)
{
List<Dictionary<string, Event>> filterRows = FilterRowsOut(newRows);
List<Dictionary<string, Event>> filterRows = FilterRows(newRows);
if (filterRows != null && filterRows.Count > 0)
{
Rows.AddRange(filterRows);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LightQueryProfiler.SharedWebUI\LightQueryProfiler.SharedWebUI.csproj" />
<ProjectReference Include="..\LightQueryProfiler.Shared\LightQueryProfiler.Shared.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/LightQueryProfiler.WinFormsApp/Models/AuthenticationMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace LightQueryProfiler.WinFormsApp.Models
{
public class AuthenticationMode
{
public int Value { get; private set; }
public string? Name { get; private set; }

public AuthenticationMode(string name, int value)
{
Name = name;
Value = value;
}
}
}
35 changes: 35 additions & 0 deletions src/LightQueryProfiler.WinFormsApp/Presenters/FiltersPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using LightQueryProfiler.Shared.Models;
using LightQueryProfiler.WinFormsApp.Views;

namespace LightQueryProfiler.WinFormsApp.Presenters
{
public class FiltersPresenter
{
private readonly IFiltersView view;

public FiltersPresenter(IFiltersView filtersView)
{
view = filtersView;
view.OnApply += OnApply;
view.OnClose += OnClose;
}

public EventFilter GetEventFilter() => view.EventFilter;

public void SetEventFilter(EventFilter eventFilter)
{
view.EventFilter = eventFilter;
}
private void OnApply(object? sender, EventArgs e)
{
view.Form.DialogResult = DialogResult.OK;
view.Form.Close();
}

private void OnClose(object? sender, EventArgs e)
{
view.Form.DialogResult = DialogResult.Cancel;
view.Form.Close();
}
}
}
Loading
Loading