Minor changes

This commit is contained in:
Holger Börchers 2025-04-04 08:58:03 +02:00
parent af503dc1bb
commit 56fa20b86f
3 changed files with 42 additions and 49 deletions

View File

@ -109,14 +109,11 @@ public partial class DiscoveredDeviceViewModel : ObservableObject, IDisposable
public async Task GetFurtherInformationAsync() public async Task GetFurtherInformationAsync()
{ {
_ssdpDevice = await _device.GetDeviceInfo().ConfigureAwait(false); _ssdpDevice = await _device.GetDeviceInfo().ConfigureAwait(false);
FriendlyName = _ssdpDevice.ModelDescription; FriendlyName = _ssdpDevice.FriendlyName;
Icon = _ssdpDevice.Icons.MinBy(x => x.Height); Icon = _ssdpDevice.Icons.MinBy(x => x.Height);
PresentationUrl = _ssdpDevice.PresentationUrl; PresentationUrl = _ssdpDevice.PresentationUrl;
ModelNumber = _ssdpDevice.ModelNumber; ModelNumber = _ssdpDevice.ModelNumber;
Version = _ssdpDevice.SerialNumber?.Split(',').Last() ?? new Version().ToString(); Version = _ssdpDevice.SerialNumber?.Split(',').Last() ?? new Version().ToString();
using var client = new HttpClient();
var response = await client.GetAsync(_ssdpDevice.ModelUrl).ConfigureAwait(false);
ResponseHeader = await response.Content.ReadAsStringAsync();
} }
private string EvaluateHostName() => Dns.GetHostEntry(IpAddress).HostName; private string EvaluateHostName() => Dns.GetHostEntry(IpAddress).HostName;
@ -129,6 +126,8 @@ public partial class DiscoveredDeviceViewModel : ObservableObject, IDisposable
private string EvaluateMacAddress() private string EvaluateMacAddress()
{ {
if (!ArpLookup.Arp.IsSupported)
return "not supported";
var lookupResult = ArpLookup.Arp.Lookup(IpAddress); var lookupResult = ArpLookup.Arp.Lookup(IpAddress);
return lookupResult is null ? "Unknown" : string.Join(":", lookupResult.GetAddressBytes().Select(b => $"{b:x2}")); return lookupResult is null ? "Unknown" : string.Join(":", lookupResult.GetAddressBytes().Select(b => $"{b:x2}"));
} }

View File

@ -1,16 +1,16 @@
<Window <Window
x:Class="SddpViewer.MainWindow"
xmlns="https://github.com/avaloniaui"
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:sddpViewer="clr-namespace:SddpViewer"
Title="SDDP viewer" Title="SDDP viewer"
d:DesignHeight="450" d:DesignHeight="450"
d:DesignWidth="800" d:DesignWidth="800"
mc:Ignorable="d"
x:Class="SddpViewer.MainWindow"
x:CompileBindings="True" x:CompileBindings="True"
x:DataType="sddpViewer:MainWindowViewModel" x:DataType="sddpViewer:MainWindowViewModel"
mc:Ignorable="d"> xmlns="https://github.com/avaloniaui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sddpViewer="clr-namespace:SddpViewer"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.DataContext> <Window.DataContext>
<sddpViewer:MainWindowViewModel /> <sddpViewer:MainWindowViewModel />
</Window.DataContext> </Window.DataContext>
@ -18,8 +18,8 @@
<StackPanel Margin="10" Spacing="5"> <StackPanel Margin="10" Spacing="5">
<TextBlock Text="Device IP Address" /> <TextBlock Text="Device IP Address" />
<ComboBox <ComboBox
HorizontalAlignment="Stretch"
DisplayMemberBinding="{Binding DisplayName}" DisplayMemberBinding="{Binding DisplayName}"
HorizontalAlignment="Stretch"
ItemsSource="{Binding NetworkAdapters}" ItemsSource="{Binding NetworkAdapters}"
SelectedItem="{Binding SelectedNetworkAdapter}" /> SelectedItem="{Binding SelectedNetworkAdapter}" />
<TextBlock Text="Notification filter" /> <TextBlock Text="Notification filter" />
@ -30,7 +30,7 @@
<Button Command="{Binding ResearchCommand}" Content="Search more" /> <Button Command="{Binding ResearchCommand}" Content="Search more" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<Grid Grid.Row="0" Grid.Column="1"> <Grid Grid.Column="1" Grid.Row="0">
<TextBox <TextBox
IsReadOnly="True" IsReadOnly="True"
Text="{ReflectionBinding SelectedItem.ResponseHeader, Text="{ReflectionBinding SelectedItem.ResponseHeader,
@ -38,23 +38,25 @@
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</Grid> </Grid>
<DataGrid <DataGrid
x:Name="DevicesDataGrid"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
AutoGenerateColumns="False" AutoGenerateColumns="False"
FrozenColumnCount="2" FrozenColumnCount="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
IsReadOnly="True" IsReadOnly="True"
ItemsSource="{Binding SddpDevices}"> ItemsSource="{Binding SddpDevices}"
x:Name="DevicesDataGrid">
<DataGrid.Columns> <DataGrid.Columns>
<DataGridCheckBoxColumn <DataGridCheckBoxColumn
Width="50"
Binding="{Binding Online}" Binding="{Binding Online}"
IsReadOnly="True" /> IsReadOnly="True"
Width="50" />
<DataGridTextColumn Binding="{Binding FriendlyName}" Header="Name" /> <DataGridTextColumn Binding="{Binding FriendlyName}" Header="Name" />
<DataGridTextColumn Binding="{Binding Usn}" Header="Usn" /> <DataGridTextColumn Binding="{Binding DescriptionLocation}" Header="Location" />
<!-- <DataGridTextColumn Binding="{Binding Usn}" Header="Usn" /> -->
<DataGridTextColumn <DataGridTextColumn
Binding="{Binding IpAddress}" CanUserSort="True" Binding="{Binding IpAddress}"
CanUserSort="True"
CustomSortComparer="{StaticResource IpAddressComparer}" CustomSortComparer="{StaticResource IpAddressComparer}"
Header="Ip address" /> Header="Ip address" />
<DataGridTextColumn Binding="{Binding HostName}" Header="Hostname" /> <DataGridTextColumn Binding="{Binding HostName}" Header="Hostname" />

View File

@ -21,35 +21,26 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
private static async void SddpDevices_OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) private static async void SddpDevices_OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{ {
try switch (e.Action)
{ {
switch (e.Action) case NotifyCollectionChangedAction.Add:
{ await AddAction(e.NewItems);
case NotifyCollectionChangedAction.Add: break;
await AddAction(e.NewItems); case NotifyCollectionChangedAction.Remove:
break; RemoveAction(e.OldItems);
case NotifyCollectionChangedAction.Remove: break;
RemoveAction(e.OldItems); case NotifyCollectionChangedAction.Replace:
break; RemoveAction(e.OldItems);
case NotifyCollectionChangedAction.Replace: await AddAction(e.NewItems);
RemoveAction(e.OldItems); break;
await AddAction(e.NewItems); case NotifyCollectionChangedAction.Reset:
break; RemoveAction(sender as ObservableCollection<DiscoveredDeviceViewModel>);
case NotifyCollectionChangedAction.Reset: break;
RemoveAction(sender as ObservableCollection<DiscoveredDeviceViewModel>); case NotifyCollectionChangedAction.Move:
break; break;
case NotifyCollectionChangedAction.Move: default:
break; throw new ArgumentOutOfRangeException();
default:
throw new ArgumentOutOfRangeException();
}
} }
catch (Exception ex)
{
throw; // TODO handle exception
}
return;
} }
private static void RemoveAction(IList? list) private static void RemoveAction(IList? list)
@ -119,6 +110,7 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
_locator.StopListeningForNotifications(); _locator.StopListeningForNotifications();
_locator.DeviceAvailable -= LocatorOnDeviceAvailable; _locator.DeviceAvailable -= LocatorOnDeviceAvailable;
_locator.DeviceUnavailable -= LocatorOnDeviceUnavailable; _locator.DeviceUnavailable -= LocatorOnDeviceUnavailable;
_locator.Dispose();
} }
await StartListening(async locator => await StartListening(async locator =>