Live Anzeige des Netzwerkstatus funktioniert

This commit is contained in:
2025-10-01 10:15:50 +02:00
parent 6248fad147
commit 52c4243efc
7 changed files with 62 additions and 20 deletions

View File

@@ -0,0 +1,6 @@
namespace Watcher.Services;
public interface INetworkCheckStore
{
String? NetworkStatus { get; set; }
}

View File

@@ -6,16 +6,13 @@ public class NetworkCheck : BackgroundService
{
private readonly ILogger<NetworkCheck> _logger;
public static String networkCheckResult
{
get { return networkCheckResult; }
set { networkCheckResult = value; }
private INetworkCheckStore _NetworkCheckStore;
}
public NetworkCheck(ILogger<NetworkCheck> logger)
public NetworkCheck(ILogger<NetworkCheck> logger, INetworkCheckStore NetworkCheckStore)
{
_logger = logger;
_NetworkCheckStore = NetworkCheckStore;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -44,11 +41,13 @@ public class NetworkCheck : BackgroundService
PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success)
{
_NetworkCheckStore.NetworkStatus = "online";
_logger.LogInformation("Ping successfull. Watcher is online.");
}
}
catch
{
_NetworkCheckStore.NetworkStatus = "offline";
_logger.LogError("Ping failed. Watcher appears to have no network connection.");
}

View File

@@ -0,0 +1,6 @@
namespace Watcher.Services;
public class NetworkCheckStore : INetworkCheckStore
{
public String? NetworkStatus { get; set; }
}