Implement OnDeviceUnavailable
This commit is contained in:
parent
688e724c83
commit
26281bbb5a
@ -31,9 +31,6 @@
|
||||
Grid.Row="1"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding SddpDevices}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="Presentation url" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -22,16 +22,24 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
SelectedNetworkAdapter = NetworkAdapters.FirstOrDefault();
|
||||
}
|
||||
|
||||
private async void LocatorOnDeviceUnavailable(object? sender, DeviceUnavailableEventArgs e) { }
|
||||
private void LocatorOnDeviceUnavailable(object? sender, DeviceUnavailableEventArgs e)
|
||||
{
|
||||
var existingDevice = SddpDevices.FirstOrDefault(x =>
|
||||
string.Equals(x.Usn, e.DiscoveredDevice.Usn, StringComparison.Ordinal));
|
||||
if(existingDevice is null) return;
|
||||
Dispatcher.UIThread.Invoke(() => SddpDevices.Remove(existingDevice));
|
||||
}
|
||||
|
||||
private async void LocatorOnDeviceAvailable(object? sender, DeviceAvailableEventArgs e)
|
||||
{
|
||||
if (e.IsNewlyDiscovered)
|
||||
if (!e.IsNewlyDiscovered)
|
||||
{
|
||||
var discoveredDeviceViewModel = new DiscoveredDeviceViewModel(e.DiscoveredDevice);
|
||||
Dispatcher.UIThread.Invoke(() => SddpDevices.Add(discoveredDeviceViewModel));
|
||||
await discoveredDeviceViewModel.GetFurtherInformationAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var discoveredDeviceViewModel = new DiscoveredDeviceViewModel(e.DiscoveredDevice);
|
||||
Dispatcher.UIThread.Invoke(() => SddpDevices.Add(discoveredDeviceViewModel));
|
||||
await discoveredDeviceViewModel.GetFurtherInformationAsync();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
|
Loading…
x
Reference in New Issue
Block a user