diff --git a/SafeExamBrowser.Server/Requests/NetworkAdapterRequest.cs b/SafeExamBrowser.Server/Requests/NetworkAdapterRequest.cs index 6e7fe1a9..707af4b7 100644 --- a/SafeExamBrowser.Server/Requests/NetworkAdapterRequest.cs +++ b/SafeExamBrowser.Server/Requests/NetworkAdapterRequest.cs @@ -32,7 +32,7 @@ namespace SafeExamBrowser.Server.Requests { var json = new JObject { - ["text"] = network != default ? $" {network.Name}: {network.Status}, {network.SignalStrength}%" : " not connected", + ["text"] = $" {(network != default ? $"{network.Name}: {network.Status}, {network.SignalStrength}%" : "not connected")}", ["timestamp"] = DateTime.Now.ToUnixTimestamp(), ["type"] = LogLevel.Info.ToLogType() }; diff --git a/SafeExamBrowser.Server/ServerProxy.cs b/SafeExamBrowser.Server/ServerProxy.cs index 58369c77..45173efe 100644 --- a/SafeExamBrowser.Server/ServerProxy.cs +++ b/SafeExamBrowser.Server/ServerProxy.cs @@ -432,17 +432,18 @@ namespace SafeExamBrowser.Server { try { - var connected = status.IsOnline; var value = Convert.ToInt32(status.BatteryCharge * 100); + var statusChanged = powerSupplyConnected != status.IsOnline; + var valueChanged = powerSupplyValue != value; - if (powerSupplyConnected != connected || powerSupplyValue != value) + if (statusChanged || valueChanged) { var request = new PowerSupplyRequest(api, httpClient, logger, parser, settings); var success = request.TryExecute(status, powerSupplyConnected, powerSupplyValue, out var message); if (success) { - powerSupplyConnected = connected; + powerSupplyConnected = status.IsOnline; powerSupplyValue = value; } else @@ -464,8 +465,10 @@ namespace SafeExamBrowser.Server try { var network = networkAdapter.GetWirelessNetworks().FirstOrDefault(n => n.Status == ConnectionStatus.Connected); + var statusChanged = network == default && wirelessNetworkValue != NOT_CONNECTED; + var valueChanged = network != default && Math.Abs(network.SignalStrength - wirelessNetworkValue) >= 5; - if (network?.SignalStrength != wirelessNetworkValue) + if (statusChanged || valueChanged) { var request = new NetworkAdapterRequest(api, httpClient, logger, parser, settings); var success = request.TryExecute(network, out var message);