about summary refs log tree commit diff
path: root/ModerationClient/Services/ClientContainer.cs
blob: ebdbab6326c2ca17e3810276d609b3afaca7a02c (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
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace ModerationClient.Services;

public class ClientContainer(ILogger<ClientContainer> logger, MatrixAuthenticationService authService, CommandLineConfiguration cfg) {
    private readonly CommandLineConfiguration _cfg = cfg;

    private bool _isRunning;
    
    public void EnsureRunning()
    {
        if (_isRunning) return;
        _isRunning = true;
        _ = Task.Run(Run).ContinueWith(t => {
            if (t.IsFaulted)
            {
                logger.LogError(t.Exception, "Error in client container task");
            }
            return _isRunning = false;
        });
    }
    
    private async Task Run()
    {
        Console.WriteLine("Running client view model loop...");
        ArgumentNullException.ThrowIfNull(authService.Homeserver, nameof(authService.Homeserver));
        
    }
}