From e3503309fbedf8c63b5e30682cb82c80d0ef7535 Mon Sep 17 00:00:00 2001 From: Jerker Dahlblom Date: Sat, 6 Apr 2024 12:03:40 +0300 Subject: [PATCH] Various fixes (#77) * Modal dialogs shows properly, before hidden behind main GUI * Channel => ConqurrentQueue --- src/Publish_DCS-INSIGHT.ps1 | 90 ++++++++++--------- .../Communication/TCPClientHandler.cs | 23 +++-- .../CustomControls/TextBlockSelectable.cs | 2 +- .../DCSInsight/DCSInsight - Backup.csproj | 68 -------------- src/client/DCSInsight/DCSInsight.csproj | 2 +- .../DCSInsight/DCSInsight.sln.DotSettings | 2 + src/client/DCSInsight/JSON/DCSAPI.cs | 3 + src/client/DCSInsight/Lua/LuaAssistant.cs | 2 +- src/client/DCSInsight/MainWindow.xaml.cs | 8 +- .../UserControls/UserControlPulseLED.xaml.cs | 8 +- src/client/DCSInsight/Windows/LuaWindow.xaml | 7 +- .../DCSInsight/Windows/LuaWindow.xaml.cs | 3 +- .../DCSInsight/Windows/SettingsWindow.xaml | 4 +- .../DCSInsight/Windows/SettingsWindow.xaml.cs | 1 - 14 files changed, 84 insertions(+), 139 deletions(-) delete mode 100644 src/client/DCSInsight/DCSInsight - Backup.csproj diff --git a/src/Publish_DCS-INSIGHT.ps1 b/src/Publish_DCS-INSIGHT.ps1 index 5b42ffc..bd1ffc6 100644 --- a/src/Publish_DCS-INSIGHT.ps1 +++ b/src/Publish_DCS-INSIGHT.ps1 @@ -15,50 +15,54 @@ if (($null -eq $env:dcsinsightReleaseDestinationFolderPath) -or (-not (Test-Path exit } -#--------------------------------- -# Release version management -#--------------------------------- -Write-Host "Starting release version management" -foregroundcolor "Green" -#Get Path to csproj -$projectFilePath = $clientPath + "\DCSInsight.csproj" -If (-not(Test-Path $projectFilePath)) { - Write-Host "Fatal error. Project path not found: $projectPath" -foregroundcolor "Red" - exit -} - -#Readind project file -$xml = [xml](Get-Content $projectFilePath) -[string]$assemblyVersion = $xml.Project.PropertyGroup.AssemblyVersion - -#Split the Version Numbers -$avMajor, $avMinor, $avPatch = $assemblyVersion.Split('.') - -Write-Host "Current assembly version is: $assemblyVersion" -foregroundcolor "Green" - -#Sets new version into Project -#Warning: for this to work, since the PropertyGroup is indexed, AssemblyVersion must be in the FIRST Propertygroup (or else, change the index). -Write-Host "What kind of release is this? If not minor then patch version will be incremented." -foregroundcolor "Green" -$isMinorRelease = Read-Host "Minor release? Y/N" - -if ($isMinorRelease.Trim().ToLower().Equals("y")) { - [int]$avMinor = [int]$avMinor + 1 - [int]$avPatch = 0 -} -else { - [int]$avPatch = [int]$avPatch + 1 +$changeProjectVersion = Read-Host "Change Project Version? Y/N" + +if($changeProjectVersion.Trim().ToLower().Equals("y")) +{ + #--------------------------------- + # Release version management + #--------------------------------- + Write-Host "Starting release version management" -foregroundcolor "Green" + #Get Path to csproj + $projectFilePath = $clientPath + "\DCSInsight.csproj" + If (-not(Test-Path $projectFilePath)) { + Write-Host "Fatal error. Project path not found: $projectPath" -foregroundcolor "Red" + exit + } + + #Readind project file + $xml = [xml](Get-Content $projectFilePath) + [string]$assemblyVersion = $xml.Project.PropertyGroup.AssemblyVersion + + #Split the Version Numbers + $avMajor, $avMinor, $avPatch = $assemblyVersion.Split('.') + + Write-Host "Current assembly version is: $assemblyVersion" -foregroundcolor "Green" + + #Sets new version into Project + #Warning: for this to work, since the PropertyGroup is indexed, AssemblyVersion must be in the FIRST Propertygroup (or else, change the index). + Write-Host "What kind of release is this? If not minor then patch version will be incremented." -foregroundcolor "Green" + $isMinorRelease = Read-Host "Minor release? Y/N" + + if ($isMinorRelease.Trim().ToLower().Equals("y")) { + [int]$avMinor = [int]$avMinor + 1 + [int]$avPatch = 0 + } + else { + [int]$avPatch = [int]$avPatch + 1 + } + + #Sets new version into Project + #Warning: for this to work, since the PropertyGroup is indexed, AssemblyVersion must be in the FIRST Propertygroup (or else, change the index). + $xml.Project.PropertyGroup.AssemblyVersion = "$avMajor.$avMinor.$avPatch".Trim() + [string]$assemblyVersion = $xml.Project.PropertyGroup.AssemblyVersion + Write-Host "New assembly version is $assemblyVersion" -foregroundcolor "Green" + + #Saving project file + $xml.Save($projectFilePath) + Write-Host "Project file updated" -foregroundcolor "Green" + Write-Host "Finished release version management" -foregroundcolor "Green" } - -#Sets new version into Project -#Warning: for this to work, since the PropertyGroup is indexed, AssemblyVersion must be in the FIRST Propertygroup (or else, change the index). -$xml.Project.PropertyGroup.AssemblyVersion = "$avMajor.$avMinor.$avPatch".Trim() -[string]$assemblyVersion = $xml.Project.PropertyGroup.AssemblyVersion -Write-Host "New assembly version is $assemblyVersion" -foregroundcolor "Green" - -#Saving project file -$xml.Save($projectFilePath) -Write-Host "Project file updated" -foregroundcolor "Green" -Write-Host "Finished release version management" -foregroundcolor "Green" - #--------------------------------- # Client publishing #--------------------------------- diff --git a/src/client/DCSInsight/Communication/TCPClientHandler.cs b/src/client/DCSInsight/Communication/TCPClientHandler.cs index efc9b5f..bb1e04f 100644 --- a/src/client/DCSInsight/Communication/TCPClientHandler.cs +++ b/src/client/DCSInsight/Communication/TCPClientHandler.cs @@ -4,13 +4,12 @@ using Newtonsoft.Json; using NLog; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; using DCSInsight.Interfaces; namespace DCSInsight.Communication @@ -19,7 +18,7 @@ internal class TCPClientHandler : IDisposable, ICommandListener { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly Channel _asyncCommandsChannel = Channel.CreateUnbounded(); + private readonly ConcurrentQueue _commandsQueue = new(); private TcpClient? _tcpClient; private Thread? _clientThread; private bool _isRunning; @@ -48,7 +47,7 @@ public void Dispose() GC.SuppressFinalize(this); } - private async void ClientThread() + private void ClientThread() { if (_tcpClient == null) return; @@ -88,11 +87,12 @@ private async void ClientThread() _requestAPIList = false; } - if (_asyncCommandsChannel.Reader.Count > 0 && _responseReceived) + if (_commandsQueue.Count > 0 && _responseReceived) { - var cts = new CancellationTokenSource(100); - var dcsApi = await _asyncCommandsChannel.Reader.ReadAsync(cts.Token); + if (!_commandsQueue.TryDequeue(out var dcsApi)) continue; + if (LogJSON) Logger.Info(JsonConvert.SerializeObject(dcsApi, Formatting.Indented)); + _tcpClient.GetStream().Write(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(dcsApi) + "\n")); _responseReceived = false; } @@ -209,17 +209,16 @@ public void Disconnect() } } - public async Task AddAsyncCommand(DCSAPI dcsApi) + public void AddCommand(DCSAPI dcsApi) { - var cts = new CancellationTokenSource(100); - await _asyncCommandsChannel.Writer.WriteAsync(dcsApi, cts.Token); + _commandsQueue.Enqueue(dcsApi); } - public async void SendCommand(SendCommandEventArgs args) + public void SendCommand(SendCommandEventArgs args) { try { - await AddAsyncCommand(args.APIObject); + _commandsQueue.Enqueue(args.APIObject); } catch (Exception ex) { diff --git a/src/client/DCSInsight/CustomControls/TextBlockSelectable.cs b/src/client/DCSInsight/CustomControls/TextBlockSelectable.cs index e8155b3..18c4091 100644 --- a/src/client/DCSInsight/CustomControls/TextBlockSelectable.cs +++ b/src/client/DCSInsight/CustomControls/TextBlockSelectable.cs @@ -5,7 +5,7 @@ using System.Windows.Media; using DCSInsight.Misc; -namespace ControlReference.CustomControls +namespace DCSInsight.CustomControls { internal class TextBlockSelectable : TextBlock { diff --git a/src/client/DCSInsight/DCSInsight - Backup.csproj b/src/client/DCSInsight/DCSInsight - Backup.csproj deleted file mode 100644 index 6d90d05..0000000 --- a/src/client/DCSInsight/DCSInsight - Backup.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - WinExe - net6.0-windows - disable - true - true - dcs-insight - 1.0.0 - 1.8.5 - Images\Magnifier_icon.ico - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Always - - - - - True - True - Settings.settings - - - Code - - - Code - - - - - Always - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - \ No newline at end of file diff --git a/src/client/DCSInsight/DCSInsight.csproj b/src/client/DCSInsight/DCSInsight.csproj index 01f82cd..836db51 100644 --- a/src/client/DCSInsight/DCSInsight.csproj +++ b/src/client/DCSInsight/DCSInsight.csproj @@ -8,7 +8,7 @@ dcs-insight 1.0.0 - 1.9.2 + 1.9.3 Images\Magnifier_icon.ico DCS-Skunkworks diff --git a/src/client/DCSInsight/DCSInsight.sln.DotSettings b/src/client/DCSInsight/DCSInsight.sln.DotSettings index 2ce40e6..3d9e681 100644 --- a/src/client/DCSInsight/DCSInsight.sln.DotSettings +++ b/src/client/DCSInsight/DCSInsight.sln.DotSettings @@ -5,7 +5,9 @@ DCSAPI DCSAPIS DCSBIOS + IC JSON + LED TCP UI API diff --git a/src/client/DCSInsight/JSON/DCSAPI.cs b/src/client/DCSInsight/JSON/DCSAPI.cs index b84f836..67ee32c 100644 --- a/src/client/DCSInsight/JSON/DCSAPI.cs +++ b/src/client/DCSInsight/JSON/DCSAPI.cs @@ -68,7 +68,10 @@ public DCSAPI(int id, public enum ParameterTypeEnum { + // ReSharper disable once InconsistentNaming number = 0, + // ReSharper disable once UnusedMember.Global + // ReSharper disable once InconsistentNaming str = 1 } diff --git a/src/client/DCSInsight/Lua/LuaAssistant.cs b/src/client/DCSInsight/Lua/LuaAssistant.cs index b46d083..bda371e 100644 --- a/src/client/DCSInsight/Lua/LuaAssistant.cs +++ b/src/client/DCSInsight/Lua/LuaAssistant.cs @@ -128,7 +128,7 @@ private static KeyValuePair CopyControlFromLuaBuffer(string luaB end, 5, "ARC-210 Display", "COMSEC submode (PT/CT/CT-TD)") */ var startIndex = luaBuffer.IndexOf("\"", StringComparison.Ordinal); - var endIndex = luaBuffer.IndexOf("\"", luaBuffer.IndexOf("\"") + 1); + var endIndex = luaBuffer.IndexOf("\"", luaBuffer.IndexOf("\"", StringComparison.Ordinal) + 1, StringComparison.Ordinal); var controlId = luaBuffer.Substring(startIndex + 1, endIndex - startIndex - 1); return new KeyValuePair(controlId, luaBuffer); diff --git a/src/client/DCSInsight/MainWindow.xaml.cs b/src/client/DCSInsight/MainWindow.xaml.cs index e3ea7e3..4306692 100644 --- a/src/client/DCSInsight/MainWindow.xaml.cs +++ b/src/client/DCSInsight/MainWindow.xaml.cs @@ -103,6 +103,7 @@ private void Connect() if (ItemsControlAPI.Items.Count > 0 && Settings.Default.AskForReloadAPIList) { var windowAskReloadAPIDialog = new WindowAskReloadAPIDialog(); + windowAskReloadAPIDialog.Owner = this; windowAskReloadAPIDialog.ShowDialog(); } @@ -161,7 +162,7 @@ public void ConnectionStatus(ConnectionEventArgs args) } Dispatcher?.BeginInvoke((Action)(() => SetConnectionStatus(args.IsConnected))); - Dispatcher?.BeginInvoke((Action)SetFormState); ; + Dispatcher?.BeginInvoke((Action)SetFormState); } catch (Exception ex) { @@ -570,6 +571,7 @@ private void TextBlockSetDCSBIOSLocation_OnMouseDown(object sender, MouseButtonE try { var settingsWindow = new SettingsWindow(); + settingsWindow.Owner = this; settingsWindow.ShowDialog(); if (settingsWindow.DialogResult == true) { @@ -589,7 +591,8 @@ private void ButtonLuaWindow_OnClick(object sender, RoutedEventArgs e) { _luaWindow?.Close(); _luaWindow = new LuaWindow(); - _luaWindow.Show(); + _luaWindow.Show(); + _luaWindow.Left = Left + Width; } catch (Exception ex) { @@ -623,6 +626,7 @@ private void TextBlockAPIReload_OnMouseDown(object sender, MouseButtonEventArgs try { var windowAskReloadAPIDialog = new WindowAskReloadAPIDialog(); + windowAskReloadAPIDialog.Owner = this; windowAskReloadAPIDialog.ShowDialog(); } catch (Exception ex) diff --git a/src/client/DCSInsight/UserControls/UserControlPulseLED.xaml.cs b/src/client/DCSInsight/UserControls/UserControlPulseLED.xaml.cs index 16ad2aa..eca4c85 100644 --- a/src/client/DCSInsight/UserControls/UserControlPulseLED.xaml.cs +++ b/src/client/DCSInsight/UserControls/UserControlPulseLED.xaml.cs @@ -13,7 +13,7 @@ namespace DCSInsight.UserControls /// public partial class UserControlPulseLED : UserControl, IDisposable, IAsyncDisposable { - private readonly Timer _timerLoopPulse; + private Timer? _timerLoopPulse; public UserControlPulseLED() { @@ -26,6 +26,7 @@ public UserControlPulseLED() public void Dispose() { _timerLoopPulse?.Dispose(); + _timerLoopPulse = null; GC.SuppressFinalize(this); } @@ -34,6 +35,7 @@ public async ValueTask DisposeAsync() if (_timerLoopPulse != null) { await _timerLoopPulse.DisposeAsync(); + _timerLoopPulse = null; GC.SuppressFinalize(this); } } @@ -54,7 +56,7 @@ public void Pulse(int milliseconds = 300) { Dispatcher?.BeginInvoke((Action)(() => SetPulseImage(true))); - _timerLoopPulse.Change(milliseconds, milliseconds); + _timerLoopPulse?.Change(milliseconds, milliseconds); //Dispatcher?.BeginInvoke((Action)(SetFormState)); } catch (Exception ex) @@ -69,7 +71,7 @@ private void PulseTimerCallback(object? state) { Dispatcher?.BeginInvoke((Action)(() => SetPulseImage(false))); //Dispatcher?.BeginInvoke((Action)(() => ToolBarMain.UpdateLayout())); - _timerLoopPulse.Change(Timeout.Infinite, Timeout.Infinite); + _timerLoopPulse?.Change(Timeout.Infinite, Timeout.Infinite); //Dispatcher?.BeginInvoke((Action)(SetFormState)); } catch (Exception ex) diff --git a/src/client/DCSInsight/Windows/LuaWindow.xaml b/src/client/DCSInsight/Windows/LuaWindow.xaml index 81b73e4..2105819 100644 --- a/src/client/DCSInsight/Windows/LuaWindow.xaml +++ b/src/client/DCSInsight/Windows/LuaWindow.xaml @@ -3,11 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:customControls="clr-namespace:ControlReference.CustomControls" + xmlns:customControls="clr-namespace:DCSInsight.CustomControls" mc:Ignorable="d" Title="" Height="400" Width="Auto" MaxWidth="800" - Loaded="LuaWindow_OnLoaded" - WindowStartupLocation="Manual" + Loaded="LuaWindow_OnLoaded" KeyDown="LuaWindow_OnKeyDown" Icon="/Images/Magnifier_icon.png" Closing="LuaWindow_OnClosing"> @@ -49,7 +48,7 @@ - +