From fd054d854b86d685a767b9ca38d5d0404cb53232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Fri, 24 Nov 2023 11:33:24 +0100 Subject: [PATCH] Code cleanup and try to use the RowDetailsTemplate --- src/App.axaml.cs | 1 - src/DiscoveredDeviceViewModel.cs | 108 ++++++++++++++++--------------- src/GlobalUsings.cs | 3 + src/MainWindow.axaml | 34 ++++++---- src/MainWindowViewModel.cs | 21 +++--- src/NetworkAdapter.cs | 2 - src/Program.cs | 7 +- src/SddpViewer.csproj | 1 + 8 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 src/GlobalUsings.cs diff --git a/src/App.axaml.cs b/src/App.axaml.cs index ec292cc..707af5c 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -1,4 +1,3 @@ -using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; diff --git a/src/DiscoveredDeviceViewModel.cs b/src/DiscoveredDeviceViewModel.cs index 2d33d62..2d694fe 100644 --- a/src/DiscoveredDeviceViewModel.cs +++ b/src/DiscoveredDeviceViewModel.cs @@ -1,69 +1,75 @@ -using System.Drawing; -using System.Linq; +namespace SddpViewer; -namespace SddpViewer +using System; +using System.Threading.Tasks; + +using CommunityToolkit.Mvvm.ComponentModel; + +using Rssdp; + +public partial class DiscoveredDeviceViewModel : ObservableObject { - using System; - using System.Threading.Tasks; + private readonly DiscoveredSsdpDevice _device; - using CommunityToolkit.Mvvm.ComponentModel; - - using Rssdp; - - public partial class DiscoveredDeviceViewModel : ObservableObject + public DiscoveredDeviceViewModel(DiscoveredSsdpDevice device) { - private readonly DiscoveredSsdpDevice device; + _device = device; + ResponseHeader = GetResponseHeader(); + } - public DiscoveredDeviceViewModel(DiscoveredSsdpDevice device) - { - this.device = device; - } + private string GetResponseHeader() + { + return string.Join( + "," + Environment.NewLine, + _device.ResponseHeaders.Select(x => $"{{{x.Key} : {string.Join(";", x.Value)}}}") + ); + } - /// - /// Sets or returns the type of notification, being either a uuid, device type, service type or upnp:rootdevice. - /// - public string NotificationType => this.device.NotificationType; + public string ResponseHeader { get; } - /// - /// Sets or returns the universal service name (USN) of the device. - /// - public string Usn => this.device.Usn; + /// + /// Sets or returns the type of notification, being either a uuid, device type, service type or upnp:rootdevice. + /// + public string NotificationType => _device.NotificationType; - /// - /// Sets or returns a URL pointing to the device description document for this device. - /// - public Uri DescriptionLocation => this.device.DescriptionLocation; + /// + /// Sets or returns the universal service name (USN) of the device. + /// + public string Usn => _device.Usn; - /// - /// Sets or returns the length of time this information is valid for (from the time). - /// - public TimeSpan CacheLifetime => this.device.CacheLifetime; + /// + /// Sets or returns a URL pointing to the device description document for this device. + /// + public Uri DescriptionLocation => _device.DescriptionLocation; - /// - /// Sets or returns the date and time this information was received. - /// - public DateTimeOffset AsAt => this.device.AsAt; + /// + /// Sets or returns the length of time this information is valid for (from the time). + /// + public TimeSpan CacheLifetime => _device.CacheLifetime; - [ObservableProperty] - private string _friendlyName = ""; + /// + /// Sets or returns the date and time this information was received. + /// + public DateTimeOffset AsAt => _device.AsAt; - [ObservableProperty] - private SsdpDeviceIcon? _icon; + [ObservableProperty] + private string _friendlyName = ""; - [ObservableProperty] - private Uri? _presentationUrl; + [ObservableProperty] + private SsdpDeviceIcon? _icon; - [ObservableProperty] - private string _modelNumber; + [ObservableProperty] + private Uri? _presentationUrl; - public async Task GetFurtherInformationAsync() - { - var ssdpDevice = await this.device.GetDeviceInfo().ConfigureAwait(false); - FriendlyName = ssdpDevice.FriendlyName; - Icon = ssdpDevice.Icons.MinBy(x=> x.Height); - PresentationUrl = ssdpDevice.PresentationUrl; - ModelNumber = ssdpDevice.ModelNumber; + [ObservableProperty] + private string _modelNumber = ""; - } + public async Task GetFurtherInformationAsync() + { + var ssdpDevice = await _device.GetDeviceInfo().ConfigureAwait(false); + FriendlyName = ssdpDevice.FriendlyName; + Icon = ssdpDevice.Icons.MinBy(x => x.Height); + PresentationUrl = ssdpDevice.PresentationUrl; + ModelNumber = ssdpDevice.ModelNumber; } } diff --git a/src/GlobalUsings.cs b/src/GlobalUsings.cs new file mode 100644 index 0000000..302ce28 --- /dev/null +++ b/src/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using Avalonia; diff --git a/src/MainWindow.axaml b/src/MainWindow.axaml index 7a6073b..c9ad6bf 100644 --- a/src/MainWindow.axaml +++ b/src/MainWindow.axaml @@ -1,25 +1,25 @@ + Title="SDDP viewer" + d:DesignHeight="450" + d:DesignWidth="800" + x:CompileBindings="True" + x:DataType="sddpViewer:MainWindowViewModel" + mc:Ignorable="d"> - + @@ -27,10 +27,22 @@