Skip to content

Commit

Permalink
Polling shows changes only (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Jan 12, 2024
1 parent 91a353d commit efc610d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/client/DCSInsight/Events/ICEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using DCSInsight.Interfaces;
using DCSInsight.JSON;
using DCSInsight.Misc;

namespace DCSInsight.Events
{
Expand All @@ -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});
}
/*
*
Expand Down
13 changes: 10 additions & 3 deletions src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void ButtonSend_OnClick(object sender, RoutedEventArgs e)
}
}

protected void StartPolling(int milliseconds)
private void StartPolling(int milliseconds)
{
try
{
Expand All @@ -114,7 +114,7 @@ protected void StartPolling(int milliseconds)
}
}

protected void StopPolling()
private void StopPolling()
{
try
{
Expand Down Expand Up @@ -142,7 +142,7 @@ protected void PollingTimerCallback(object state)
ICEventHandler.SendErrorMessage( "Timer Polling Error", ex);
}
}

protected void CheckBoxPolling_OnUnchecked(object sender, RoutedEventArgs e)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit efc610d

Please sign in to comment.