Live Anzeige des Netzwerkstatus funktioniert
This commit is contained in:
6
Watcher/Services/INetworkCheckStore.cs
Normal file
6
Watcher/Services/INetworkCheckStore.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public interface INetworkCheckStore
|
||||
{
|
||||
String? NetworkStatus { get; set; }
|
||||
}
|
@@ -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.");
|
||||
}
|
||||
|
||||
|
6
Watcher/Services/NetworkCheckStore.cs
Normal file
6
Watcher/Services/NetworkCheckStore.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public class NetworkCheckStore : INetworkCheckStore
|
||||
{
|
||||
public String? NetworkStatus { get; set; }
|
||||
}
|
Reference in New Issue
Block a user