Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit decimals now possible in Test Range #34

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/client/DCSInsight/Communication/TCPClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/client/DCSInsight/DCSInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<AssemblyName>dcs-insight</AssemblyName>
<Version>1.0.0</Version>
<AssemblyVersion>1.7.3</AssemblyVersion>
<AssemblyVersion>1.7.4</AssemblyVersion>
<ApplicationIcon>Images\Magnifier_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/client/DCSInsight/Misc/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using Newtonsoft.Json;

namespace DCSInsight.Misc
Expand Down
20 changes: 20 additions & 0 deletions src/client/DCSInsight/Misc/ResultComparator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using DCSInsight.JSON;

Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
}
}
}
7 changes: 1 addition & 6 deletions src/client/DCSInsight/Misc/TextBoxParam.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
14 changes: 12 additions & 2 deletions src/client/DCSInsight/Windows/WindowRangeTest.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand All @@ -27,10 +27,20 @@
<Label VerticalAlignment="Center" Margin="0,0,0,0" >
<CheckBox Name="CheckBoxLoop" VerticalAlignment="Center" IsChecked="False" Checked="CheckBoxLoop_OnChecked" Unchecked="CheckBoxLoop_OnUnchecked"/>
</Label>
<Label VerticalAlignment="Center" Content="Show changes only" Margin="10,0,0,0" />
<Label VerticalAlignment="Center" Content="Changes only" Margin="10,0,0,0" />
<Label VerticalAlignment="Center" Margin="0,0,0,0" >
<CheckBox Name="CheckBoxShowChangesOnly" VerticalAlignment="Center" IsChecked="False" Checked="CheckBoxShowChangesOnly_OnChecked" Unchecked="CheckBoxShowChangesOnly_OnUnchecked"/>
</Label>
<Label VerticalAlignment="Center" Content="Decimals" Margin="0,0,0,0" />
<ComboBox Name="ComboBoxDecimals" SelectedValuePath="Content" IsReadOnly="True" SelectedIndex="0" SelectionChanged="ComboBoxDecimals_OnSelectionChanged">
<ComboBoxItem>*</ComboBoxItem>
<ComboBoxItem>0</ComboBoxItem>
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
</ComboBox>
<CheckBox Name="CheckBoxTop" Content="On Top" BorderBrush="Gray" Margin="20,0,0,0" Checked="CheckBoxTop_OnChecked" Unchecked="CheckBoxTop_OnUnchecked"></CheckBox>
<Button Width="20" Content="?" Margin="10,0,0,0" BorderBrush="Black" FontSize="14" Name="ButtonInformation" Click="ButtonInformation_OnClick"></Button>
</ToolBar>
Expand Down
35 changes: 28 additions & 7 deletions src/client/DCSInsight/Windows/WindowRangeTest.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using DCSInsight.Events;
using DCSInsight.Interfaces;
using DCSInsight.JSON;
Expand Down Expand Up @@ -98,7 +94,7 @@ public void ErrorMessage(ErrorEventArgs args)
{
if (!_isConnected || !_isRunning) return;

Dispatcher?.BeginInvoke((Action)(() => TextBoxResults.Text += args.Message));
Dispatcher?.BeginInvoke((Action)(() => AddResultText(args.Message)));
AutoResetEvent1.Set();
}
catch (Exception ex)
Expand Down Expand Up @@ -146,7 +142,7 @@ public void DataReceived(DataEventArgs args)
}
else
{
Dispatcher?.BeginInvoke((Action)(() => TextBoxResults.Text += _resultComparatorList.First(o => o.IsMatch(args.DCSApi)).GetResultString()));
Dispatcher?.BeginInvoke((Action)(() => AddResultText(_resultComparatorList.First(o => o.IsMatch(args.DCSApi)).GetResultString())));
;
AutoResetEvent1.Set();
}
Expand Down Expand Up @@ -584,6 +580,7 @@ private void CheckBoxLoop_OnChecked(object sender, RoutedEventArgs e)
try
{
_doLoop = true;
CheckBoxShowChangesOnly.IsChecked = true;
SetFormState();
}
catch (Exception ex)
Expand Down Expand Up @@ -631,5 +628,29 @@ private void CheckBoxShowChangesOnly_OnUnchecked(object sender, RoutedEventArgs
}
}

private void AddResultText(string text)
{
TextBoxResults.Text += text;
TextBoxResults.ScrollToEnd();
}

private void ComboBoxDecimals_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
var item = ComboBoxDecimals.SelectedValue.ToString();
if (item != null && item != "*")
{
ResultComparator.SetDecimals(true, Convert.ToInt32(item));
return;
}

ResultComparator.SetDecimals(false, 0);
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}
}
}