diff --git a/src/DiscoveredDeviceViewModel.cs b/src/DiscoveredDeviceViewModel.cs
index 7e787ad..926fec1 100644
--- a/src/DiscoveredDeviceViewModel.cs
+++ b/src/DiscoveredDeviceViewModel.cs
@@ -69,7 +69,7 @@ public partial class DiscoveredDeviceViewModel : ObservableObject, IDisposable
///
/// Sets or returns the universal service name (USN) of the device.
///
- public string Usn => _device.Usn;
+ public string? Usn => _device.Usn;
///
/// Sets or returns a URL pointing to the device description document for this device.
@@ -138,7 +138,15 @@ public partial class DiscoveredDeviceViewModel : ObservableObject, IDisposable
public override bool Equals(object? obj)
{
- return obj is DiscoveredDeviceViewModel viewModel && Equals(viewModel.Usn, Usn);
+ if (obj is not DiscoveredDeviceViewModel viewModel)
+ return false;
+ if (viewModel.Usn != null && !Equals(viewModel.Usn, Usn))
+ return false;
+ if (!Equals(viewModel.MacAddress, MacAddress))
+ return false;
+ if (!Equals(viewModel.IpAddress, IpAddress))
+ return false;
+ return true;
}
public void Dispose()
diff --git a/src/MainWindow.axaml b/src/MainWindow.axaml
index 3fd0694..9fcfa8a 100644
--- a/src/MainWindow.axaml
+++ b/src/MainWindow.axaml
@@ -29,6 +29,11 @@
+
+
+
+
+
@@ -64,6 +69,11 @@
+
+
+
+
+
diff --git a/src/MainWindowViewModel.cs b/src/MainWindowViewModel.cs
index 058d4d6..6867848 100644
--- a/src/MainWindowViewModel.cs
+++ b/src/MainWindowViewModel.cs
@@ -24,25 +24,32 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
private static async void SddpDevices_OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
- switch (e.Action)
+ try
{
- case NotifyCollectionChangedAction.Add:
- await AddAction(e.NewItems);
- break;
- case NotifyCollectionChangedAction.Remove:
- RemoveAction(e.OldItems);
- break;
- case NotifyCollectionChangedAction.Replace:
- RemoveAction(e.OldItems);
- await AddAction(e.NewItems);
- break;
- case NotifyCollectionChangedAction.Reset:
- RemoveAction(sender as ObservableCollection);
- break;
- case NotifyCollectionChangedAction.Move:
- break;
- default:
- throw new ArgumentOutOfRangeException();
+ switch (e.Action)
+ {
+ case NotifyCollectionChangedAction.Add:
+ await AddAction(e.NewItems);
+ break;
+ case NotifyCollectionChangedAction.Remove:
+ RemoveAction(e.OldItems);
+ break;
+ case NotifyCollectionChangedAction.Replace:
+ RemoveAction(e.OldItems);
+ await AddAction(e.NewItems);
+ break;
+ case NotifyCollectionChangedAction.Reset:
+ RemoveAction(sender as ObservableCollection);
+ break;
+ case NotifyCollectionChangedAction.Move:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
}
}
@@ -145,7 +152,7 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
var interNetwork = new IPAddress(ip);
var cidr = $"{interNetwork}/{SelectedNetworkAdapter.PrefixLength}";
var range = CidrHelper.GetIpRangeFromCidr(cidr);
- var ipRange = IpRangeHelper.GetIPRange(range.Start, range.End).Where(IpAddressFilter);
+ var ipRange = IpRangeHelper.GetIPRange(range.Start, range.End).Where(address => IpAddressFilter(address, range));
var collection = new ConcurrentBag();
using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(1);
@@ -158,7 +165,7 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
try
{
token.ThrowIfCancellationRequested();
- DiscoveredSsdpDevice device = new DiscoveredSsdpDevice()
+ DiscoveredSsdpDevice device = new()
{
CacheLifetime = TimeSpan.Zero,
DescriptionLocation = new Uri($"http://{address.ToString()}:8080/discovery/ssdp"),
@@ -177,19 +184,24 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
}
);
- foreach (DiscoveredDeviceViewModel viewModel in collection)
+ Dispatcher.UIThread.Invoke(() =>
{
- Dispatcher.UIThread.Invoke(() => SddpDevices.Add(viewModel));
- }
+ foreach (DiscoveredDeviceViewModel viewModel in collection)
+ {
+ SddpDevices.Add(viewModel);
+ }
+ });
}
}
- private bool IpAddressFilter(IPAddress arg)
+ private bool IpAddressFilter(IPAddress arg, (IPAddress Start, IPAddress End) range)
{
- if (this.SddpDevices.Any(x => Equals(x.IpAddress, arg)))
- {
+ if (Equals(arg, range.Start))
+ return false;
+ if (Equals(arg, range.End))
+ return false;
+ if (this.SddpDevices.Any(x => Equals(x.IpAddress, arg)))
return false;
- }
return true;
}