Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ private static InvalidOperationException CreateCanNotPerformNetworkScanException
=> new($"The instance can not perform network scan. To perform a network scan, specify {nameof(INetworkScanner)} in the constructor.");

private Stopwatch? timeStampForFullScan;
private TimeSpan networkScanInterval = Timeout.InfiniteTimeSpan;
private TimeSpan networkScanMinInterval = TimeSpan.FromSeconds(20.0);

/// <summary>
/// Gets or sets the <see cref="TimeSpan"/> which represents the interval to perform a network scan.
Expand All @@ -86,16 +84,16 @@ private static InvalidOperationException CreateCanNotPerformNetworkScanException
/// <seealso cref="MacAddressResolverBase.ResolveIPAddressToMacAddressAsync(IPAddress, CancellationToken)" />
/// <seealso cref="MacAddressResolverBase.ResolveMacAddressToIPAddressAsync(PhysicalAddress, CancellationToken)" />
public TimeSpan NetworkScanInterval {
get => networkScanInterval;
get;
set {
if (value <= TimeSpan.Zero) {
if (value != Timeout.InfiniteTimeSpan)
throw new ArgumentOutOfRangeException(message: $"The value must be non-zero positive {nameof(TimeSpan)} or {nameof(Timeout)}.{nameof(Timeout.InfiniteTimeSpan)}.", paramName: nameof(NetworkScanInterval));
}

networkScanInterval = value;
field = value;
}
}
} = Timeout.InfiniteTimeSpan;

/// <summary>
/// Gets or sets the <see cref="TimeSpan"/> which represents the minimum interval to perform a network scan.
Expand All @@ -121,32 +119,32 @@ public TimeSpan NetworkScanInterval {
/// <seealso cref="MacAddressResolverBase.ResolveIPAddressToMacAddressAsync(IPAddress, CancellationToken)" />
/// <seealso cref="MacAddressResolverBase.ResolveMacAddressToIPAddressAsync(PhysicalAddress, CancellationToken)" />
public TimeSpan NetworkScanMinInterval {
get => networkScanMinInterval;
get;
set {
if (value < TimeSpan.Zero) {
if (value != Timeout.InfiniteTimeSpan)
throw new ArgumentOutOfRangeException(message: $"The value must be non-zero positive {nameof(TimeSpan)} or {nameof(Timeout)}.{nameof(Timeout.InfiniteTimeSpan)}.", paramName: nameof(NetworkScanMinInterval));
}

networkScanMinInterval = value;
field = value;
}
}
} = TimeSpan.FromSeconds(20.0);

private bool HasFullScanMinIntervalElapsed =>
networkScanMinInterval == TimeSpan.Zero ||
NetworkScanMinInterval == TimeSpan.Zero ||
(
networkScanMinInterval != Timeout.InfiniteTimeSpan &&
NetworkScanMinInterval != Timeout.InfiniteTimeSpan &&
(
timeStampForFullScan is null || // not performed yet
networkScanMinInterval <= timeStampForFullScan.Elapsed // interval elapsed
NetworkScanMinInterval <= timeStampForFullScan.Elapsed // interval elapsed
)
);

private bool ShouldPerformFullScanBeforeResolution =>
networkScanInterval != Timeout.InfiniteTimeSpan &&
NetworkScanInterval != Timeout.InfiniteTimeSpan &&
(
timeStampForFullScan is null || // not performed yet
networkScanInterval <= timeStampForFullScan.Elapsed // interval elapsed
NetworkScanInterval <= timeStampForFullScan.Elapsed // interval elapsed
);

private readonly ConcurrentSet<IPAddress> invalidatedIPAddressSet = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#if SYSTEM_IO_UNIXFILEMODE || SYSTEM_IO_FILE_GETUNIXFILEMODE
using System.Runtime.InteropServices;
#endif

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

Expand Down
Loading