summary refs log tree commit diff
path: root/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-03 23:38:36 +0200
committerRory& <root@rory.gay>2025-06-03 23:38:50 +0200
commit7ed1b77457f5e41ec5f7ba8e102f13f69380608d (patch)
tree22cbb57a43dfae7cc4458c1e13b3b5ae20595815 /testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
parentPrepare for budgeting, move to native createdAt (diff)
downloadnodejs-final-assignment-7ed1b77457f5e41ec5f7ba8e102f13f69380608d.tar.xz
Implement budget handling
Diffstat (limited to 'testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs')
-rw-r--r--testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs38
1 files changed, 0 insertions, 38 deletions
diff --git a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs b/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
deleted file mode 100644

index a2e133f..0000000 --- a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs +++ /dev/null
@@ -1,38 +0,0 @@ -namespace SafeNSound.FakeUser; - -public class RandomAlarmService(UserStore userStore) : IHostedService { - private Task? _listenerTask; - private readonly CancellationTokenSource _cts = new(); - - public async Task StartAsync(CancellationToken cancellationToken) { - _listenerTask = Run(_cts.Token); - } - - private static readonly string[] validReasons = ["fall", "toilet"]; - - private async Task Run(CancellationToken cancellationToken) { - while (!cancellationToken.IsCancellationRequested) { - try { - var user = userStore.GetRandomUser(); - var currentAlarm = await user.Client!.GetAlarm(); - if (currentAlarm is null) { - await user.Client!.SetAlarm(new Sdk.AlarmDto { - Reason = Random.Shared.GetItems(validReasons, 1).First() - }); - } - else { - await user.Client!.DeleteAlarm(); - } - } - catch (Exception ex) { - Console.WriteLine($"Error setting/deleting alarm: {ex.Message}"); - } - - await Task.Delay(TimeSpan.FromMilliseconds(250), cancellationToken); - } - } - - public async Task StopAsync(CancellationToken cancellationToken) { - await _cts.CancelAsync(); - } -} \ No newline at end of file