Skip to content

Commit

Permalink
Optimize revoked Tickets
Browse files Browse the repository at this point in the history
Fix Performance Issues
  • Loading branch information
TheR00st3r committed Nov 14, 2024
1 parent 89c3808 commit 21febfc
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 92 deletions.
6 changes: 6 additions & 0 deletions EventulaEntranceClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Pages\NewFolder1\" />
<Folder Include="Pages\NewFolder2\" />
<Folder Include="Pages\NewFolder3\" />
<Folder Include="Pages\NewFolder\" />
</ItemGroup>
</Project>
108 changes: 59 additions & 49 deletions Pages/Management.razor
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
@page "/management"
@using EventulaEntranceClient.Pages.Components
@using static Microsoft.AspNetCore.Components.Web.RenderMode

@rendermode InteractiveServer
@implements IDisposable

<div class="@AnimationClass" onmousemove="@(() => ResetTimerInterval())" onkeypress="@(() => ResetTimerInterval())">

<audio id="newParticipantSound" src="/audio/mixkit-elevator-tone-2863.wav" />
<audio id="revokedParticipantSound" src="/audio/mixkit-arcade-space-shooter-dead-notification-272.wav" />

<div class="row">
<div class="col-8 col-md-9 col-lg-10">
<div class="row">
@foreach (var signInPlace in ParticipantSignInPlaces)
{
<div class="col-12 col-lg-6 col-xl-4 mb-3">
<ParticipantSignInPlaceComponent SignInPlace="@signInPlace"></ParticipantSignInPlaceComponent>
</div>
}
</div>
</div>
<div class="col-4 col-md-3 col-lg-2">
<div class="d-grid gap-1">
<button type="button" class="btn btn-outline-primary btn-sm" onclick="@(() => GoBack())">
<i class="oi oi-arrow-left text-primary"></i> Go back
</button>
@if (@IsRunningElectron)
{
<button type="button" class="btn btn-outline-primary btn-sm" onclick="@(() => CloseApp())">
<i class="oi oi-circle-x text-primary"></i> Close app
</button>
}
</div>
<hr />
<video id="videoFeed" width="1920" height="1080" />
<div>@LastTicketNr</div>
<hr />
<div class="d-grid gap-1">
@foreach (var participant in Participants)
{
<button class="btn btn-outline-primary" type="button" onclick="@(() => AddToSignInPlace(participant))">
<div class="d-flex justify-content-start">
<div class="flex-shrink-0">
<img class="card-img" src="@participant.User.Avatar" alt="@participant.User.Steamname" width="64" height="64">
</div>
<div class="flex-grow-1 text-start m-2">
<p class="m-0 text-break">@participant.User.Firstname @participant.User.Surname</p>
<p class="m-0 text-muted text-break">@@@participant.User.Steamname</p>
</div>
</div>
</button>
}
</div>
</div>
</div>
<audio id="newParticipantSound" src="/audio/mixkit-elevator-tone-2863.wav" />
<audio id="revokedParticipantSound" src="/audio/mixkit-arcade-space-shooter-dead-notification-272.wav" />

<div class="row">
<div class="col-8 col-md-9 col-lg-10">
<div class="row">
@foreach (var signInPlace in ParticipantSignInPlaces)
{
<div class="col-12 col-lg-6 col-xl-4 mb-3">
<ParticipantSignInPlaceComponent SignInPlace="@signInPlace"></ParticipantSignInPlaceComponent>
</div>
}
</div>
</div>
<div class="col-4 col-md-3 col-lg-2">
<div class="d-grid gap-1">
<button type="button" class="btn btn-outline-primary btn-sm" onclick="@(() => GoBack())">
<i class="oi oi-arrow-left text-primary"></i> Go back
</button>
@if (@IsRunningElectron)
{
<button type="button" class="btn btn-outline-primary btn-sm" onclick="@(() => CloseApp())">
<i class="oi oi-circle-x text-primary"></i> Close app
</button>
}
</div>
<hr />
<video id="videoFeed" width="1920" height="1080" />
<div>@LastTicketNr</div>
<hr />
<div class="d-grid gap-1">
@foreach (var participant in Participants)
{
<button class="btn btn-outline-primary @(participant.Revoked != 0 ? "btn-outline-danger": string.Empty)" type="button" @onclick="()=>AddToSignInPlace(participant)">
<div class="d-flex justify-content-start">

@if (participant.Revoked != 0)
{
<div class="position-absolute align-self-center"><p class="m-0 fs-3 p-2 rounded-4 rotate-30" style="color: var(--bs-btn-hover-color);border: 2px var(--bs-btn-hover-color) solid;background: var(--bs-btn-color);">Revoked!</p></div>
}

<div class="flex-shrink-0">
<img class="card-img" src="@participant.User.Avatar" alt="@participant.User.Steamname" width="64" height="64">
</div>

<div class="flex-grow-1 text-start m-2">

<p class="m-0 text-break">@participant.User.Firstname @participant.User.Surname</p>
<p class="m-0 text-muted text-break">@@@participant.User.Steamname</p>
</div>
</div>
</button>
}
</div>
</div>
</div>
</div>

<footer class="fixed-bottom text-center footer">
<a href="settings/?ac=@AccessCode">Settings</a>
<a href="settings/?ac=@AccessCode">Settings</a>
</footer>
49 changes: 25 additions & 24 deletions Pages/Management.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected override void OnInitialized()
_InactiveTimer.Elapsed += UserInactive;
_InactiveTimer.AutoReset = false;

_BackgroundTrigger.Trigger += Trigger;
_BackgroundTrigger.SubscribeTrigger(Trigger);
_UiNotifyService.NewParticipant += OnNewParticipant;
_ParticipantSignInPlacesCount = _SettingsService.RetrieveSignInPlaceCount();
ParticipantSignInPlaces = new List<ParticipantSignInPlace>(_ParticipantSignInPlacesCount);
Expand Down Expand Up @@ -139,12 +139,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
}

IsRunningElectron = await _JSRuntime.InvokeAsync<bool>("isElectron").ConfigureAwait(false);

await InvokeAsync(StateHasChanged);
}
}

private async void Trigger(object sender, EventArgs eventArgs)
private async Task Trigger()
{
try
{
Expand Down Expand Up @@ -178,28 +177,19 @@ public async Task ProcessImage(string imageString)
var qrCode = _BarcodeService.BarcodeTextFromImage(imageData);
_Logger.LogInformation(string.IsNullOrEmpty(qrCode) ? "QR Code not found" : $"QR Code found {qrCode}");

if (!_LastTicket.Equals(qrCode, StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(qrCode) || string.Equals(_LastTicket, qrCode, StringComparison.OrdinalIgnoreCase))
{
_LastTicket = qrCode;
LastTicketNr = string.IsNullOrEmpty(qrCode) ? _NoTicketFound : qrCode;
await InvokeAsync(StateHasChanged);
return;
}

if (!string.IsNullOrEmpty(qrCode))
_LastTicket = qrCode;
LastTicketNr = string.IsNullOrEmpty(qrCode) ? _NoTicketFound : $"Ticket Nr.: {qrCode.Split('/')[^1]}";
await InvokeAsync(StateHasChanged);

var ticketRequest = await _EventulaApiService.RequestTicket(qrCode).ConfigureAwait(false);
if (ticketRequest?.Participant != null)
{
var ticketRequest = await _EventulaApiService.RequestTicket(qrCode).ConfigureAwait(false);
if (ticketRequest?.Participant != null)
{
if (ticketRequest.Participant.Revoked != 0)
{
// Todo Add Participant but disallow them to sign in
await _JSRuntime.InvokeAsync<string>("PlayAudio", "revokedParticipantSound");
}
else
{
await AddParticipantAsync(ticketRequest.Participant).ConfigureAwait(false);
}
}
await AddParticipantAsync(ticketRequest.Participant).ConfigureAwait(false);
}
}

Expand All @@ -210,6 +200,16 @@ public async Task AddToSignInPlace(Participant participant)
return;
}

// Reset last ticket to be able to scan again
_LastTicket = null;

if (participant.Revoked != 0)
{
Participants.Remove(participant);
_DataStore.Delete(participant);
return;
}

var openPlace = FindEmptySignInPlace();

if (openPlace == null)
Expand Down Expand Up @@ -248,7 +248,8 @@ private async Task AddParticipantAsync(Participant participant)
_DataStore.AddOrUpdate(participant);
Participants.Add(participant);

await _JSRuntime.InvokeAsync<string>("PlayAudio", "newParticipantSound");
await _JSRuntime.InvokeAsync<string>("PlayAudio", participant.Revoked != 0 ? "revokedParticipantSound" : "newParticipantSound");

AnimationClass = "glow-shadow";
await InvokeAsync(StateHasChanged);
await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false);
Expand All @@ -265,7 +266,7 @@ private async Task AddParticipantAsync(Participant participant)
}
else
{
var participantInSignInPlace = ParticipantSignInPlaces.FirstOrDefault(x => x.Participant == oldParticipant);
var participantInSignInPlace = ParticipantSignInPlaces.Find(x => x.Participant == oldParticipant);
if (participantInSignInPlace != null)
{
participantInSignInPlace.Participant = participant;
Expand All @@ -292,7 +293,7 @@ private void UserInactive(Object source, ElapsedEventArgs e)
#region IDisposable
void IDisposable.Dispose()
{
_BackgroundTrigger.Trigger -= Trigger;
_BackgroundTrigger.Unsubscribe(Trigger);
}
#endregion

Expand Down
23 changes: 19 additions & 4 deletions Services/BackgroundTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public class BackgroundTrigger
{
private readonly ILogger<BackgroundTrigger> _Logger;
CancellationTokenSource _Cts;
readonly CancellationTokenSource _Cts;
private Func<Task> _Trigger;

public BackgroundTrigger(ILogger<BackgroundTrigger> logger)
{
Expand All @@ -18,17 +19,31 @@ public void Stop()
_Cts.Cancel();
}

public event EventHandler Trigger;
public void SubscribeTrigger(Func<Task> trigger)
{
_Trigger = trigger;
}

public void Unsubscribe(Func<Task> trigger)
{
if (_Trigger == trigger)
{
_Trigger = null;
}
}

private async Task CaptureFrameTimer(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
try
{
Trigger?.Invoke(this, new EventArgs());
if (_Trigger != null)
{
await _Trigger();
}

await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
await Task.Delay(TimeSpan.FromMilliseconds(500), cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
37 changes: 24 additions & 13 deletions Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class SettingsService
private const int _SettingsIdentifier = 1337;
private readonly IDataStore _DataStore;
private readonly ILogger<SettingsService> _Logger;
private Settings _CurrentSettings;

public SettingsService(IDataStore dataStore, ILogger<SettingsService> logger)
{
Expand All @@ -16,7 +17,7 @@ public bool SaveSettings(string token, string eventulaApiBaseAddress, bool enabl
{
try
{
_DataStore.AddOrUpdate(new Settings()
_CurrentSettings = new Settings()
{
Id = _SettingsIdentifier,
Token = token,
Expand All @@ -29,8 +30,8 @@ public bool SaveSettings(string token, string eventulaApiBaseAddress, bool enabl
SignInPlaceCount = signInPlaceCount,
AdminPin = adminPin,
UserPin = userPin

}) ;
};
_DataStore.AddOrUpdate(_CurrentSettings) ;

return true;
}
Expand All @@ -41,44 +42,54 @@ public bool SaveSettings(string token, string eventulaApiBaseAddress, bool enabl
}
}

public Settings LoadSettings()
{
if(_CurrentSettings == null)
{
_CurrentSettings = _DataStore.LoadById<Settings>(_SettingsIdentifier);
}

return _CurrentSettings;
}

public string RetrieveToken()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.Token;
return LoadSettings()?.Token;
}
public string RetrieveEventulaApiBaseAddress()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.EventulaApiBaseAddress;
return LoadSettings()?.EventulaApiBaseAddress;
}
public bool RetrieveEnableCovidTest()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.EnableCovidTest ?? true;
return LoadSettings()?.EnableCovidTest ?? true;
}
public bool RetrieveEnableTwoGVerification()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.EnableTwoGVerification ?? true;
return LoadSettings()?.EnableTwoGVerification ?? true;
}
public bool RetrieveEnableTermsChecked()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.EnableTermsChecked ?? true;
return LoadSettings()?.EnableTermsChecked ?? true;
}
public int RetrieveTestTimeInMinutes()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.TestTimeInMinutes ?? 15;
return LoadSettings()?.TestTimeInMinutes ?? 15;
}
public int RetrieveSignInPlaceCount()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.SignInPlaceCount ?? 12;
return LoadSettings()?.SignInPlaceCount ?? 12;
}
public string RetrieveCustomBackgroundImage()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.CustomBackgroundImage;
return LoadSettings()?.CustomBackgroundImage;
}
public string RetrieveAdminPin()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.AdminPin;
return LoadSettings()?.AdminPin;
}
public string RetrieveUserPin()
{
return _DataStore.LoadById<Settings>(_SettingsIdentifier)?.UserPin;
return LoadSettings()?.UserPin;
}
}
7 changes: 6 additions & 1 deletion wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ video {
100% {
box-shadow: 0 0 50px rgba(50, 160, 50, 1);
}
}
}


.rotate-30 {
transform: rotate(30deg);
}
2 changes: 1 addition & 1 deletion wwwroot/js/webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function getFrame(src, dest) {
let video = document.getElementById(src);
var canvas = document.createElement("canvas");
let canvas = document.createElement("canvas");

canvas.width = 1920;
canvas.height = 1080;
Expand Down

0 comments on commit 21febfc

Please sign in to comment.