Fixed bug where network status log would be sent repeatedly when not connected and added threshold for value change.

This commit is contained in:
Damian Büchel 2023-03-13 18:13:42 +01:00
parent 0cdffd891b
commit 836389942f
2 changed files with 8 additions and 5 deletions

View file

@ -32,7 +32,7 @@ namespace SafeExamBrowser.Server.Requests
{ {
var json = new JObject var json = new JObject
{ {
["text"] = network != default ? $"<wlan> {network.Name}: {network.Status}, {network.SignalStrength}%" : "<wlan> not connected", ["text"] = $"<wlan> {(network != default ? $"{network.Name}: {network.Status}, {network.SignalStrength}%" : "not connected")}",
["timestamp"] = DateTime.Now.ToUnixTimestamp(), ["timestamp"] = DateTime.Now.ToUnixTimestamp(),
["type"] = LogLevel.Info.ToLogType() ["type"] = LogLevel.Info.ToLogType()
}; };

View file

@ -432,17 +432,18 @@ namespace SafeExamBrowser.Server
{ {
try try
{ {
var connected = status.IsOnline;
var value = Convert.ToInt32(status.BatteryCharge * 100); 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 request = new PowerSupplyRequest(api, httpClient, logger, parser, settings);
var success = request.TryExecute(status, powerSupplyConnected, powerSupplyValue, out var message); var success = request.TryExecute(status, powerSupplyConnected, powerSupplyValue, out var message);
if (success) if (success)
{ {
powerSupplyConnected = connected; powerSupplyConnected = status.IsOnline;
powerSupplyValue = value; powerSupplyValue = value;
} }
else else
@ -464,8 +465,10 @@ namespace SafeExamBrowser.Server
try try
{ {
var network = networkAdapter.GetWirelessNetworks().FirstOrDefault(n => n.Status == ConnectionStatus.Connected); 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 request = new NetworkAdapterRequest(api, httpClient, logger, parser, settings);
var success = request.TryExecute(network, out var message); var success = request.TryExecute(network, out var message);