From efc610d297dee1eac7644adfb4eea0a835b19eab Mon Sep 17 00:00:00 2001 From: Jerker Dahlblom Date: Fri, 12 Jan 2024 16:33:49 +0200 Subject: [PATCH] Polling shows changes only (#57) --- src/client/DCSInsight/Events/ICEventHandler.cs | 6 +++++- .../DCSInsight/UserControls/UserControlAPI.xaml.cs | 13 ++++++++++--- .../DCSInsight/UserControls/UserControlAPIBase.cs | 6 +++--- .../UserControls/UserControlLoSetCommandAPI.xaml.cs | 12 +++++++++--- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/client/DCSInsight/Events/ICEventHandler.cs b/src/client/DCSInsight/Events/ICEventHandler.cs index a4d2fc7..f48dc39 100644 --- a/src/client/DCSInsight/Events/ICEventHandler.cs +++ b/src/client/DCSInsight/Events/ICEventHandler.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using DCSInsight.Interfaces; using DCSInsight.JSON; +using DCSInsight.Misc; namespace DCSInsight.Events { @@ -22,7 +23,10 @@ public static void DetachCommandListener(ICommandListener listener) public static void SendCommand(DCSAPI api) { - OnSendCommand?.Invoke(new SendCommandEventArgs {APIObject = api}); + // remove earlier result, no need to send that to server + var command = api.CloneJson(); + command.Result = ""; + OnSendCommand?.Invoke(new SendCommandEventArgs {APIObject = command}); } /* * diff --git a/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs b/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs index fa3c675..8a0a400 100644 --- a/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs +++ b/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs @@ -144,7 +144,7 @@ protected override void BuildUI() LabelPolling = new Label { - Content = "Polling", + Content = "Poll", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 0, 0) }; @@ -207,10 +207,17 @@ public override void SetResult(DCSAPI dcsApi) var result = dcsApi.ErrorThrown ? dcsApi.ErrorMessage : (string.IsNullOrEmpty(dcsApi.Result) ? "nil" : dcsApi.Result); AutoResetEventPolling.Set(); + + if (result == DCSAPI.Result) + { + return; + } + + DCSAPI.Result = result; + if (KeepResults) { - Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, "\n---\n"))); - Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, result))); + Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, result + "\n"))); return; } Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result)); diff --git a/src/client/DCSInsight/UserControls/UserControlAPIBase.cs b/src/client/DCSInsight/UserControls/UserControlAPIBase.cs index 2c6f5e4..c9123de 100644 --- a/src/client/DCSInsight/UserControls/UserControlAPIBase.cs +++ b/src/client/DCSInsight/UserControls/UserControlAPIBase.cs @@ -100,7 +100,7 @@ protected void ButtonSend_OnClick(object sender, RoutedEventArgs e) } } - protected void StartPolling(int milliseconds) + private void StartPolling(int milliseconds) { try { @@ -114,7 +114,7 @@ protected void StartPolling(int milliseconds) } } - protected void StopPolling() + private void StopPolling() { try { @@ -142,7 +142,7 @@ protected void PollingTimerCallback(object state) ICEventHandler.SendErrorMessage( "Timer Polling Error", ex); } } - + protected void CheckBoxPolling_OnUnchecked(object sender, RoutedEventArgs e) { try diff --git a/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs b/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs index df6e4f2..7bf97cb 100644 --- a/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs +++ b/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs @@ -178,7 +178,7 @@ protected override void BuildUI() LabelPolling = new Label { - Content = "Polling", + Content = "Poll", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 0, 0) }; @@ -243,10 +243,16 @@ public override void SetResult(DCSAPI dcsApi) AutoResetEventPolling.Set(); + if (dcsApi.Result == DCSAPI.Result) + { + return; + } + + DCSAPI.Result = dcsApi.Result; + if (KeepResults) { - Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, "\n---\n"))); - Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, result))); + Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, result + "\n"))); return; } Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result));