From ab5cc7a9dc710e69b53cb08070afc818d09cf028 Mon Sep 17 00:00:00 2001 From: Jerker Dahlblom Date: Fri, 20 Oct 2023 19:05:18 +0300 Subject: [PATCH] Limit decimals now possible in Test Range --- .../Communication/TCPClientHandler.cs | 1 - src/client/DCSInsight/DCSInsight.csproj | 2 +- src/client/DCSInsight/Misc/Extensions.cs | 1 - .../DCSInsight/Misc/ResultComparator.cs | 20 +++++++++++ src/client/DCSInsight/Misc/TextBoxParam.cs | 7 +--- .../DCSInsight/Windows/WindowRangeTest.xaml | 14 ++++++-- .../Windows/WindowRangeTest.xaml.cs | 35 +++++++++++++++---- 7 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/client/DCSInsight/Communication/TCPClientHandler.cs b/src/client/DCSInsight/Communication/TCPClientHandler.cs index dff1a1c..480983d 100644 --- a/src/client/DCSInsight/Communication/TCPClientHandler.cs +++ b/src/client/DCSInsight/Communication/TCPClientHandler.cs @@ -6,7 +6,6 @@ using System; using System.Collections.Generic; using System.Net; -using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Threading; diff --git a/src/client/DCSInsight/DCSInsight.csproj b/src/client/DCSInsight/DCSInsight.csproj index e2a1211..4546402 100644 --- a/src/client/DCSInsight/DCSInsight.csproj +++ b/src/client/DCSInsight/DCSInsight.csproj @@ -6,7 +6,7 @@ true dcs-insight 1.0.0 - 1.7.3 + 1.7.4 Images\Magnifier_icon.ico diff --git a/src/client/DCSInsight/Misc/Extensions.cs b/src/client/DCSInsight/Misc/Extensions.cs index 9c81bab..8c716ab 100644 --- a/src/client/DCSInsight/Misc/Extensions.cs +++ b/src/client/DCSInsight/Misc/Extensions.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.IO; using Newtonsoft.Json; namespace DCSInsight.Misc diff --git a/src/client/DCSInsight/Misc/ResultComparator.cs b/src/client/DCSInsight/Misc/ResultComparator.cs index b294906..eb0d6fc 100644 --- a/src/client/DCSInsight/Misc/ResultComparator.cs +++ b/src/client/DCSInsight/Misc/ResultComparator.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Globalization; using System.Text; using DCSInsight.JSON; @@ -9,6 +10,9 @@ internal class ResultComparator { private readonly DCSAPI _dcsApi; private readonly object _lockObject = new(); + private static NumberFormatInfo _numberFormatInfoDecimals = NumberFormatInfo.InvariantInfo; + private static bool _limitDecimals; + private static int _decimalPlaces; public ResultComparator(DCSAPI dcsApi) { @@ -57,6 +61,11 @@ public bool SetResult(DCSAPI dcsApi) throw new Exception("SetResult() : This is not the matching DCSAPI."); } + if (_limitDecimals && double.TryParse(dcsApi.Result, NumberStyles.AllowDecimalPoint | NumberStyles.Float, _numberFormatInfoDecimals, out _)) + { + dcsApi.Result = Math.Round(decimal.Parse(dcsApi.Result, NumberStyles.AllowDecimalPoint | NumberStyles.Float, _numberFormatInfoDecimals), _decimalPlaces).ToString(CultureInfo.InvariantCulture); + } + if (dcsApi.Result != _dcsApi.Result) { _dcsApi.Result = dcsApi.Result; @@ -88,5 +97,16 @@ public string GetResultString() return currentTestString.ToString(); } } + + public static void SetDecimals(bool limitDecimals, int decimalPlaces) + { + _limitDecimals = limitDecimals; + _decimalPlaces = decimalPlaces; + _numberFormatInfoDecimals = new NumberFormatInfo + { + NumberDecimalSeparator = ".", + NumberDecimalDigits = decimalPlaces + }; + } } } diff --git a/src/client/DCSInsight/Misc/TextBoxParam.cs b/src/client/DCSInsight/Misc/TextBoxParam.cs index de1e229..c4ed6f9 100644 --- a/src/client/DCSInsight/Misc/TextBoxParam.cs +++ b/src/client/DCSInsight/Misc/TextBoxParam.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Controls; +using System.Windows.Controls; namespace DCSInsight.Misc { diff --git a/src/client/DCSInsight/Windows/WindowRangeTest.xaml b/src/client/DCSInsight/Windows/WindowRangeTest.xaml index 2463a90..443ebdc 100644 --- a/src/client/DCSInsight/Windows/WindowRangeTest.xaml +++ b/src/client/DCSInsight/Windows/WindowRangeTest.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:DCSInsight.Windows" xmlns:userControls="clr-namespace:DCSInsight.UserControls" mc:Ignorable="d" - Title="Range Test API Calls" MaxHeight="600" MinHeight="200" Width="850" Closing="WindowRangeTest_OnClosing" WindowStartupLocation="CenterScreen" Loaded="WindowRangeTest_OnLoaded"> + Title="Range Test API Calls" MaxHeight="600" MinHeight="200" Width="1000" Closing="WindowRangeTest_OnClosing" WindowStartupLocation="CenterScreen" Loaded="WindowRangeTest_OnLoaded"> @@ -27,10 +27,20 @@ -