Changed back all line ending to LF (Unit).

This is what is used in this project.
pull/60/head
Stefan Roelofs 4 years ago
parent 729a8a7e28
commit 58bf3a04b5

@ -1,88 +1,88 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using hass_workstation_service.Communication.NamedPipe; using hass_workstation_service.Communication.NamedPipe;
using JKang.IpcServiceFramework.Client; using JKang.IpcServiceFramework.Client;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using System.Reactive.Linq; using System.Reactive.Linq;
using UserInterface.ViewModels; using UserInterface.ViewModels;
using System.Security; using System.Security;
using hass_workstation_service.Communication.InterProcesCommunication.Models; using hass_workstation_service.Communication.InterProcesCommunication.Models;
namespace UserInterface.Views 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()
{ {
this.InitializeComponent(); this.InitializeComponent();
// register IPC clients // register IPC clients
ServiceProvider serviceProvider = new ServiceCollection() ServiceProvider serviceProvider = new ServiceCollection()
.AddNamedPipeIpcClient<ServiceContractInterfaces>("broker", pipeName: "pipeinternal") .AddNamedPipeIpcClient<ServiceContractInterfaces>("broker", pipeName: "pipeinternal")
.BuildServiceProvider(); .BuildServiceProvider();
// resolve IPC client factory // resolve IPC client factory
IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider
.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) if (DataContext is not BackgroundServiceSettingsViewModel viewModel)
throw new System.Exception("Wrong viewmodel class!"); 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"); viewModel.UpdateStatus(true, "All good");
else else
viewModel.UpdateStatus(false, "Not running"); viewModel.UpdateStatus(false, "Not running");
} }
catch (System.Exception) catch (System.Exception)
{ {
viewModel.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());
viewModel.UpdateAutostartStatus(autostartresult); viewModel.UpdateAutostartStatus(autostartresult);
await Task.Delay(1000); await Task.Delay(1000);
} }
} }
public void Start(object sender, RoutedEventArgs args) public void Start(object sender, RoutedEventArgs args)
{ {
//TODO: fix the path. This will depend on the deployment structure. //TODO: fix the path. This will depend on the deployment structure.
System.Diagnostics.Process.Start("hass-worstation-service.exe"); System.Diagnostics.Process.Start("hass-worstation-service.exe");
} }
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()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
} }
} }

@ -5,25 +5,25 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="UserInterface.Views.CommandSettings"> x:Class="UserInterface.Views.CommandSettings">
<Grid RowDefinitions="Auto, *, Auto, Auto" Margin="30 30 30 10" > <Grid RowDefinitions="Auto, *, Auto, Auto" Margin="30 30 30 10" >
<TextBlock Grid.Row="0" Margin="0 0 0 15" FontSize="18" FontWeight="Bold" Text="Commands"/> <TextBlock Grid.Row="0" Margin="0 0 0 15" FontSize="18" FontWeight="Bold" Text="Commands"/>
<DataGrid Grid.Row="1" x:Name="Grid" IsVisible="{Binding ConfiguredCommands.Count}" <DataGrid Grid.Row="1" x:Name="Grid" IsVisible="{Binding ConfiguredCommands.Count}"
AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single"
Items="{Binding ConfiguredCommands}"> Items="{Binding ConfiguredCommands}">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="Name" <DataGridTextColumn Header="Name"
Binding="{Binding Name}" Binding="{Binding Name}"
Width="1*" /> Width="1*" />
<DataGridTextColumn Header="Type" <DataGridTextColumn Header="Type"
Binding="{Binding Type}" Binding="{Binding Type}"
Width="1*" /> Width="1*" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<TextBlock Grid.Row="2" IsVisible="{Binding !ConfiguredCommands.Count}" Text="Add some commands by clicking the 'Add' button."/> <TextBlock Grid.Row="2" IsVisible="{Binding !ConfiguredCommands.Count}" Text="Add some commands by clicking the 'Add' button."/>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="75" Margin="10 10 0 0" Click="AddCommand" Content="Add"/> <Button Width="75" Margin="10 10 0 0" Click="AddCommand" Content="Add"/>
<Button Width="75" Margin="10 10 0 0" Click="EditCommand" Content="Edit" IsVisible="False"/> <Button Width="75" Margin="10 10 0 0" Click="EditCommand" Content="Edit" IsVisible="False"/>
<Button Width="75" Margin="10 10 0 0" Click="DeleteCommand" Content="Delete"/> <Button Width="75" Margin="10 10 0 0" Click="DeleteCommand" Content="Delete"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

@ -1,97 +1,97 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using hass_workstation_service.Communication.NamedPipe; using hass_workstation_service.Communication.NamedPipe;
using JKang.IpcServiceFramework.Client; using JKang.IpcServiceFramework.Client;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using System.Reactive.Linq; using System.Reactive.Linq;
using UserInterface.ViewModels; using UserInterface.ViewModels;
using System.Security; using System.Security;
using hass_workstation_service.Communication.InterProcesCommunication.Models; using hass_workstation_service.Communication.InterProcesCommunication.Models;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
namespace UserInterface.Views namespace UserInterface.Views
{ {
public class CommandSettings : UserControl public class CommandSettings : UserControl
{ {
private readonly IIpcClient<ServiceContractInterfaces> _client; private readonly IIpcClient<ServiceContractInterfaces> _client;
private readonly DataGrid _dataGrid; private readonly DataGrid _dataGrid;
private bool _sensorsNeedToRefresh; private bool _sensorsNeedToRefresh;
public CommandSettings() public CommandSettings()
{ {
this.InitializeComponent(); this.InitializeComponent();
// register IPC clients // register IPC clients
ServiceProvider serviceProvider = new ServiceCollection() ServiceProvider serviceProvider = new ServiceCollection()
.AddNamedPipeIpcClient<ServiceContractInterfaces>("commands", pipeName: "pipeinternal") .AddNamedPipeIpcClient<ServiceContractInterfaces>("commands", pipeName: "pipeinternal")
.BuildServiceProvider(); .BuildServiceProvider();
// resolve IPC client factory // resolve IPC client factory
IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>(); .GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>();
// create client // create client
this._client = clientFactory.CreateClient("commands"); this._client = clientFactory.CreateClient("commands");
DataContext = new CommandSettingsViewModel(); DataContext = new CommandSettingsViewModel();
GetConfiguredCommands(); GetConfiguredCommands();
this._dataGrid = this.FindControl<DataGrid>("Grid"); this._dataGrid = this.FindControl<DataGrid>("Grid");
} }
public async void GetConfiguredCommands() public async void GetConfiguredCommands()
{ {
_sensorsNeedToRefresh = false; _sensorsNeedToRefresh = false;
List<ConfiguredCommandModel> status = await this._client.InvokeAsync(x => x.GetConfiguredCommands()); List<ConfiguredCommandModel> status = await this._client.InvokeAsync(x => x.GetConfiguredCommands());
((CommandSettingsViewModel)this.DataContext).ConfiguredCommands = status.Select(s => ((CommandSettingsViewModel)this.DataContext).ConfiguredCommands = status.Select(s =>
new CommandViewModel() new CommandViewModel()
{ {
Name = s.Name, Name = s.Name,
Type = s.Type, Type = s.Type,
Id = s.Id Id = s.Id
}).ToList(); }).ToList();
} }
public async void AddCommand(object sender, RoutedEventArgs args) public async void AddCommand(object sender, RoutedEventArgs args)
{ {
var dialog = new AddCommandDialog(); var dialog = new AddCommandDialog();
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
await dialog.ShowDialog(desktop.MainWindow); await dialog.ShowDialog(desktop.MainWindow);
_sensorsNeedToRefresh = true; _sensorsNeedToRefresh = true;
GetConfiguredCommands(); GetConfiguredCommands();
} }
} }
public void EditCommand(object sender, RoutedEventArgs args) public void EditCommand(object sender, RoutedEventArgs args)
{ {
} }
public void DeleteCommand(object sender, RoutedEventArgs args) public void DeleteCommand(object sender, RoutedEventArgs args)
{ {
if (_dataGrid.SelectedItem is not CommandViewModel item) if (_dataGrid.SelectedItem is not CommandViewModel item)
return; return;
this._client.InvokeAsync(x => x.RemoveCommandById(item.Id)); this._client.InvokeAsync(x => x.RemoveCommandById(item.Id));
if (DataContext is not CommandSettingsViewModel viewModel) if (DataContext is not CommandSettingsViewModel viewModel)
return; return;
viewModel.ConfiguredCommands.Remove(item); viewModel.ConfiguredCommands.Remove(item);
_dataGrid.SelectedIndex = -1; _dataGrid.SelectedIndex = -1;
viewModel.TriggerUpdate(); viewModel.TriggerUpdate();
} }
private void InitializeComponent() private void InitializeComponent()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
} }
} }

@ -7,20 +7,20 @@
mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="500" mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="500"
x:Class="UserInterface.Views.MainWindow" x:Class="UserInterface.Views.MainWindow"
Icon="/Assets/hass-workstation-logo.ico" Icon="/Assets/hass-workstation-logo.ico"
MinWidth="700" MinWidth="700"
MinHeight="500" MinHeight="500"
Title="Settings"> Title="Settings">
<Design.DataContext> <Design.DataContext>
<vm:MainWindowViewModel/> <vm:MainWindowViewModel/>
</Design.DataContext> </Design.DataContext>
<Grid ColumnDefinitions="Auto, *, Auto" RowDefinitions="*, *" Margin="10"> <Grid ColumnDefinitions="Auto, *, Auto" RowDefinitions="*, *" Margin="10">
<views:BrokerSettings Grid.Column="0" Grid.Row="0" Margin="10" Grid.RowSpan="2" Background="#2D2D30"/> <views:BrokerSettings Grid.Column="0" Grid.Row="0" Margin="10" Grid.RowSpan="2" Background="#2D2D30"/>
<views:SensorSettings Grid.Column="1" Grid.Row="0" Margin="10" Background="#2D2D30"/> <views:SensorSettings Grid.Column="1" Grid.Row="0" Margin="10" Background="#2D2D30"/>
<views:CommandSettings Grid.Column="1" Grid.Row="1" Margin="10" Background="#2D2D30"/> <views:CommandSettings Grid.Column="1" Grid.Row="1" Margin="10" Background="#2D2D30"/>
<views:BackgroundServiceSettings Grid.Column="2" Grid.Row="0" Margin="10" Background="#2D2D30"/> <views:BackgroundServiceSettings Grid.Column="2" Grid.Row="0" Margin="10" Background="#2D2D30"/>
<views:AppInfo Grid.Column="2" Grid.Row="1" Margin="10" Background="#2D2D30"/> <views:AppInfo Grid.Column="2" Grid.Row="1" Margin="10" Background="#2D2D30"/>
</Grid> </Grid>
</Window> </Window>

@ -9,8 +9,8 @@ namespace UserInterface.Views
{ {
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
_ = new WindowsTrayIcon(); _ = new WindowsTrayIcon();
} }

@ -5,31 +5,31 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="UserInterface.Views.SensorSettings"> x:Class="UserInterface.Views.SensorSettings">
<Grid RowDefinitions="Auto, *, Auto, Auto" Margin="30 30 30 10" > <Grid RowDefinitions="Auto, *, Auto, Auto" Margin="30 30 30 10" >
<TextBlock Grid.Row="0" Margin="0 0 0 15" FontSize="18" FontWeight="Bold" Text="Sensors"/> <TextBlock Grid.Row="0" Margin="0 0 0 15" FontSize="18" FontWeight="Bold" Text="Sensors"/>
<DataGrid Grid.Row="1" x:Name="Grid" IsVisible="{Binding ConfiguredSensors.Count}" <DataGrid Grid.Row="1" x:Name="Grid" IsVisible="{Binding ConfiguredSensors.Count}"
AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single"
Items="{Binding ConfiguredSensors}"> Items="{Binding ConfiguredSensors}">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Header="Name" <DataGridTextColumn Header="Name"
Binding="{Binding Name}" Binding="{Binding Name}"
Width="1*" /> Width="1*" />
<DataGridTextColumn Header="Type" <DataGridTextColumn Header="Type"
Binding="{Binding Type}" Binding="{Binding Type}"
Width="1*" /> Width="1*" />
<DataGridTextColumn Header="Update Interval" <DataGridTextColumn Header="Update Interval"
Binding="{Binding UpdateInterval}" Binding="{Binding UpdateInterval}"
Width="1*" /> Width="1*" />
<DataGridTextColumn Header="Value" <DataGridTextColumn Header="Value"
Binding="{Binding ValueString}" Binding="{Binding ValueString}"
Width="2*" /> Width="2*" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<TextBlock Grid.Row="2" IsVisible="{Binding !ConfiguredSensors.Count}" Text="Add some sensors by clicking the 'Add' button."/> <TextBlock Grid.Row="2" IsVisible="{Binding !ConfiguredSensors.Count}" Text="Add some sensors by clicking the 'Add' button."/>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="75" Margin="10 10 0 0" Click="AddSensor" Content="Add"/> <Button Width="75" Margin="10 10 0 0" Click="AddSensor" Content="Add"/>
<Button Width="75" Margin="10 10 0 0" Click="EditSensor" Content="Edit" IsVisible="False"/> <Button Width="75" Margin="10 10 0 0" Click="EditSensor" Content="Edit" IsVisible="False"/>
<Button Width="75" Margin="10 10 0 0" Click="DeleteSensor" Content="Delete"/> <Button Width="75" Margin="10 10 0 0" Click="DeleteSensor" Content="Delete"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

@ -1,123 +1,123 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using hass_workstation_service.Communication.NamedPipe; using hass_workstation_service.Communication.NamedPipe;
using JKang.IpcServiceFramework.Client; using JKang.IpcServiceFramework.Client;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using System.Reactive.Linq; using System.Reactive.Linq;
using UserInterface.ViewModels; using UserInterface.ViewModels;
using System.Security; using System.Security;
using hass_workstation_service.Communication.InterProcesCommunication.Models; using hass_workstation_service.Communication.InterProcesCommunication.Models;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
namespace UserInterface.Views namespace UserInterface.Views
{ {
public class SensorSettings : UserControl public class SensorSettings : UserControl
{ {
private readonly IIpcClient<ServiceContractInterfaces> _client; private readonly IIpcClient<ServiceContractInterfaces> _client;
private readonly DataGrid _dataGrid; private readonly DataGrid _dataGrid;
private bool _sensorsNeedToRefresh; private bool _sensorsNeedToRefresh;
public SensorSettings() public SensorSettings()
{ {
this.InitializeComponent(); this.InitializeComponent();
// register IPC clients // register IPC clients
ServiceProvider serviceProvider = new ServiceCollection() ServiceProvider serviceProvider = new ServiceCollection()
.AddNamedPipeIpcClient<ServiceContractInterfaces>("sensors", pipeName: "pipeinternal") .AddNamedPipeIpcClient<ServiceContractInterfaces>("sensors", pipeName: "pipeinternal")
.BuildServiceProvider(); .BuildServiceProvider();
// resolve IPC client factory // resolve IPC client factory
IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>(); .GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>();
// create client // create client
this._client = clientFactory.CreateClient("sensors"); this._client = clientFactory.CreateClient("sensors");
DataContext = new SensorSettingsViewModel(); DataContext = new SensorSettingsViewModel();
GetConfiguredSensors(); GetConfiguredSensors();
this._dataGrid = this.FindControl<DataGrid>("Grid"); this._dataGrid = this.FindControl<DataGrid>("Grid");
} }
public async void GetConfiguredSensors() public async void GetConfiguredSensors()
{ {
_sensorsNeedToRefresh = false; _sensorsNeedToRefresh = false;
List<ConfiguredSensorModel> status = await this._client.InvokeAsync(x => x.GetConfiguredSensors()); List<ConfiguredSensorModel> status = await this._client.InvokeAsync(x => x.GetConfiguredSensors());
((SensorSettingsViewModel)this.DataContext).ConfiguredSensors = status.Select(s => ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors = status.Select(s =>
new SensorViewModel() new SensorViewModel()
{ {
Name = s.Name, Name = s.Name,
Type = s.Type, Type = s.Type,
Value = s.Value, Value = s.Value,
Id = s.Id, Id = s.Id,
UpdateInterval = s.UpdateInterval, UpdateInterval = s.UpdateInterval,
UnitOfMeasurement = s.UnitOfMeasurement UnitOfMeasurement = s.UnitOfMeasurement
}).ToList(); }).ToList();
while (!_sensorsNeedToRefresh) while (!_sensorsNeedToRefresh)
{ {
await Task.Delay(1000); await Task.Delay(1000);
List<ConfiguredSensorModel> statusUpdated = await this._client.InvokeAsync(x => x.GetConfiguredSensors()); List<ConfiguredSensorModel> statusUpdated = await this._client.InvokeAsync(x => x.GetConfiguredSensors());
var configuredSensors = ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors; var configuredSensors = ((SensorSettingsViewModel)this.DataContext).ConfiguredSensors;
// this is a workaround for the list showing before it has been completely loaded in the service // this is a workaround for the list showing before it has been completely loaded in the service
if (statusUpdated.Count != configuredSensors.Count) if (statusUpdated.Count != configuredSensors.Count)
{ {
_sensorsNeedToRefresh = true; _sensorsNeedToRefresh = true;
GetConfiguredSensors(); GetConfiguredSensors();
} }
statusUpdated.ForEach(s => statusUpdated.ForEach(s =>
{ {
var configuredSensor = configuredSensors.FirstOrDefault(cs => cs.Id == s.Id); var configuredSensor = configuredSensors.FirstOrDefault(cs => cs.Id == s.Id);
if (configuredSensor != null) if (configuredSensor != null)
{ {
configuredSensor.Value = s.Value; configuredSensor.Value = s.Value;
configuredSensors.FirstOrDefault(cs => cs.Id == s.Id).Value = s.Value; configuredSensors.FirstOrDefault(cs => cs.Id == s.Id).Value = s.Value;
} }
}); });
} }
} }
public async void AddSensor(object sender, RoutedEventArgs args) public async void AddSensor(object sender, RoutedEventArgs args)
{ {
var dialog = new AddSensorDialog(); var dialog = new AddSensorDialog();
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
await dialog.ShowDialog(desktop.MainWindow); await dialog.ShowDialog(desktop.MainWindow);
_sensorsNeedToRefresh = true; _sensorsNeedToRefresh = true;
GetConfiguredSensors(); GetConfiguredSensors();
} }
} }
public void EditSensor(object sender, RoutedEventArgs args) public void EditSensor(object sender, RoutedEventArgs args)
{ {
} }
public void DeleteSensor(object sender, RoutedEventArgs args) public void DeleteSensor(object sender, RoutedEventArgs args)
{ {
if (_dataGrid.SelectedItem is not SensorViewModel item) if (_dataGrid.SelectedItem is not SensorViewModel item)
return; return;
this._client.InvokeAsync(x => x.RemoveSensorById(item.Id)); this._client.InvokeAsync(x => x.RemoveSensorById(item.Id));
if (DataContext is not SensorSettingsViewModel viewModel) if (DataContext is not SensorSettingsViewModel viewModel)
return; return;
viewModel.ConfiguredSensors.Remove(item); viewModel.ConfiguredSensors.Remove(item);
_dataGrid.SelectedIndex = -1; _dataGrid.SelectedIndex = -1;
viewModel.TriggerUpdate(); viewModel.TriggerUpdate();
} }
private void InitializeComponent() private void InitializeComponent()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
} }
} }
Loading…
Cancel
Save