From 836389942fd14fdce7209665f304777c5192ca9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 13 Mar 2023 18:13:42 +0100 Subject: [PATCH] Fixed bug where network status log would be sent repeatedly when not connected and added threshold for value change. --- .../Requests/NetworkAdapterRequest.cs | 2 +- SafeExamBrowser.Server/ServerProxy.cs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) 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);