summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Demo/Pages/Home.razor
blob: ae352141ea283280d159eeb2fa2df6fc199a8777 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@page "/"
@using System.Text.Json.Nodes
@implements IDisposable

<PageTitle>Home</PageTitle>

<h1>SafeNSound</h1>

<p>Welcome to SafeNSound! This application is purely a demonstration of the basic concepts in SafeNSound!</p>
<p>Here be dragons!</p>

<pre>
    @serverStatus?.ToJson(indent: true)
</pre>

@code {

    private bool running = true;
    private JsonObject? serverStatus { get; set; }

    protected override async Task OnInitializedAsync() {
        _ = PollServerStatus();
    }

    private async Task PollServerStatus() {
        while (running) {
            try {
                serverStatus = await App.UserClient.HttpClient.GetFromJsonAsync<JsonObject>("/status");
            }
            catch (Exception ex) {
                serverStatus = new JsonObject {
                    ["error"] = ex.Message
                };
            }
            StateHasChanged();
            await Task.Delay(1000);
        }
    }

    private void ReleaseUnmanagedResources() {
        running = false;
    }

    public void Dispose() {
        ReleaseUnmanagedResources();
        GC.SuppressFinalize(this);
    }

    ~Home() => ReleaseUnmanagedResources();
}