Ejemplo n.º 1
0
        public async Task PingService_PingIpAddressAsync()
        {
            var ipAddress = _networkingSystem.GetDefaultLocalNetworkAddress();
            var pingReply = await _pingService.PingIpAddressAsync(ipAddress);

            pingReply.Should().NotBeNull();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// get arp item as an asynchronous operation.
        /// </summary>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task&lt;ArpItem&gt;.</returns>
        /// <autogeneratedoc />
        public async Task <ArpItem> GetArpItemAsync(IPAddress ipAddress, CancellationToken cancellationToken)
        {
            ArpItem arpItem = null;

            // TODO: Rename to be Sync

            try
            {
                lock (_updateLock)
                {
                    if (_ipAddress2ArpItem.TryGetValue(ipAddress, out arpItem))
                    {
                        return(arpItem);
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                // OK if ping fails or times out at it will still populate the arp cache
                await _pingService.PingIpAddressAsync(ipAddress);

                cancellationToken.ThrowIfCancellationRequested();

                await RefreshInternalAsync(Timeout, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();

                lock (_updateLock)
                {
                    _ipAddress2ArpItem.TryGetValue(ipAddress, out arpItem);
                }
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogDebug(ex, "GetArpItemAsync task cancelled");
            }

            return(arpItem);
        }