Table of Contents

Class CompositeCurrentIpLocationProvider

Namespace
VpnHood.Net.IpLocations
Assembly
VpnHood.Net.IpLocations.dll

Provides the current location from the first of several providers that finds it.

public class CompositeCurrentIpLocationProvider : ICurrentIpLocationProvider, IDisposable
Inheritance
CompositeCurrentIpLocationProvider
Implements
Inherited Members

Remarks

The providers are tried in order. Each gets a token canceled after its timeout, and the next is tried only once it ends, so the timeout holds only for a provider that observes its token. A failure is logged, except NotSupportedException, and the next provider is tried. Disposing this provider disposes them all.

Constructors

CompositeCurrentIpLocationProvider(ILogger, IEnumerable<ICurrentIpLocationProvider>, TimeSpan?)

Provides the current location from the first of several providers that finds it.

public CompositeCurrentIpLocationProvider(ILogger logger, IEnumerable<ICurrentIpLocationProvider> providers, TimeSpan? providerTimeout = null)

Parameters

logger ILogger

The logger the failures go to.

providers IEnumerable<ICurrentIpLocationProvider>

The providers, in the order they are tried; this provider owns them.

providerTimeout TimeSpan?

How long each provider may take before its token is canceled, or null for 5 seconds.

Remarks

The providers are tried in order. Each gets a token canceled after its timeout, and the next is tried only once it ends, so the timeout holds only for a provider that observes its token. A failure is logged, except NotSupportedException, and the next provider is tried. Disposing this provider disposes them all.

Methods

Dispose()

Disposes every provider, in order; a provider that throws stops the rest.

public void Dispose()

GetCurrentLocation(CancellationToken)

Finds where this device's public IP address is.

public Task<IpLocation> GetCurrentLocation(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IpLocation>

A task whose result is the location.

Exceptions

NotSupportedException

The provider does not support the lookup.

KeyNotFoundException

No provider found the location.

OperationCanceledException

cancellationToken was canceled.