45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
namespace SddpViewer;
|
|
|
|
using System.Collections.ObjectModel;
|
|
using System.Threading.Tasks;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using Rssdp;
|
|
|
|
public partial class MainWindowViewModel : ObservableObject
|
|
{
|
|
[ObservableProperty]
|
|
private string _deviceIpAddress = "192.168.42.193";
|
|
|
|
[ObservableProperty]
|
|
private string _notificationFilter = "upnp:rootdevice";
|
|
|
|
public ObservableCollection<DiscoveredDeviceViewModel> SddpDevices { get; } = new();
|
|
|
|
[RelayCommand(AllowConcurrentExecutions = false)]
|
|
private async Task SearchDevicesNowAsync()
|
|
{
|
|
SddpDevices.Clear();
|
|
var locator = new SsdpDeviceLocator(DeviceIpAddress);
|
|
if (!string.IsNullOrWhiteSpace(NotificationFilter))
|
|
{
|
|
locator.NotificationFilter = NotificationFilter;
|
|
}
|
|
var availableDevices = await locator.SearchAsync().ConfigureAwait(true);
|
|
foreach (var ssdpDevice in availableDevices)
|
|
{
|
|
var discoveredDeviceViewModel = new DiscoveredDeviceViewModel(ssdpDevice);
|
|
SddpDevices.Add(discoveredDeviceViewModel);
|
|
}
|
|
await Parallel.ForEachAsync(
|
|
SddpDevices,
|
|
async (device, token) =>
|
|
{
|
|
await device.GetFurtherInformationAsync().ConfigureAwait(true);
|
|
}
|
|
).ConfigureAwait(true);
|
|
}
|
|
}
|