Some refactoring, no functional changes.

pull/60/head
Stefan Roelofs 4 years ago
parent 678f667fda
commit f437c61983

@ -15,7 +15,7 @@ namespace UserInterface.Views
{ {
public class BackgroundServiceSettings : UserControl public class BackgroundServiceSettings : UserControl
{ {
private readonly IIpcClient<ServiceContractInterfaces> client; private readonly IIpcClient<ServiceContractInterfaces> _client;
public BackgroundServiceSettings() public BackgroundServiceSettings()
{ {
@ -30,34 +30,35 @@ namespace UserInterface.Views
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>(); .GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>();
// create client // create client
this.client = clientFactory.CreateClient("broker"); this._client = clientFactory.CreateClient("broker");
DataContext = new BackgroundServiceSettingsViewModel(); DataContext = new BackgroundServiceSettingsViewModel();
Ping(); Ping();
} }
public async void Ping() {
public async void Ping()
{
while (true) while (true)
{ {
if (DataContext is not BackgroundServiceSettingsViewModel viewModel)
throw new System.Exception("Wrong viewmodel class!");
try try
{ {
var result = await this.client.InvokeAsync(x => x.Ping("ping")); var result = await this._client.InvokeAsync(x => x.Ping("ping"));
if (result == "pong") if (result == "pong")
{ viewModel.UpdateStatus(true, "All good");
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(true, "All good");
}
else else
{ viewModel.UpdateStatus(false, "Not running");
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(false, "Not running");
}
} }
catch (System.Exception) catch (System.Exception)
{ {
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(false, "Not running"); viewModel.UpdateStatus(false, "Not running");
} }
var autostartresult = await this.client.InvokeAsync(x => x.IsAutoStartEnabled()); var autostartresult = await this._client.InvokeAsync(x => x.IsAutoStartEnabled());
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateAutostartStatus(autostartresult); viewModel.UpdateAutostartStatus(autostartresult);
await Task.Delay(1000); await Task.Delay(1000);
} }
@ -71,11 +72,12 @@ namespace UserInterface.Views
public void EnableAutostart(object sender, RoutedEventArgs args) public void EnableAutostart(object sender, RoutedEventArgs args)
{ {
this.client.InvokeAsync(x => x.EnableAutostart(true)); this._client.InvokeAsync(x => x.EnableAutostart(true));
} }
public void DisableAutostart(object sender, RoutedEventArgs args) public void DisableAutostart(object sender, RoutedEventArgs args)
{ {
this.client.InvokeAsync(x => x.EnableAutostart(false)); this._client.InvokeAsync(x => x.EnableAutostart(false));
} }
private void InitializeComponent() private void InitializeComponent()

Loading…
Cancel
Save