Table of Contents

Class CompositeAssetProvider

Namespace
VpnHood.Net.Toolkit.Assets
Assembly
VpnHood.Net.Toolkit.dll

Provides several providers read as one: an asset is asked of each in turn, and the first that has it answers.

public class CompositeAssetProvider : IAssetProvider
Inheritance
CompositeAssetProvider
Implements
Inherited Members

Remarks

What an app lays over a shared store, such as its own logo, shadows the store's file at the same path, and everything else still comes from the store. Only what a provider classes as absent falls through: a file it finds and cannot open fails where it is, so a broken override is not silently replaced by the default.

Constructors

CompositeAssetProvider(IReadOnlyList<IAssetProvider>)

Initializes a new instance of the CompositeAssetProvider class.

public CompositeAssetProvider(IReadOnlyList<IAssetProvider> providers)

Parameters

providers IReadOnlyList<IAssetProvider>

The providers, in the order they are asked.

Exceptions

ArgumentException

providers is empty.

Methods

OpenReadAsync(string, CancellationToken)

Opens the asset at a path, such as fonts/text.ttf.

public Task<Stream> OpenReadAsync(string assetPath, CancellationToken cancellationToken)

Parameters

assetPath string

The asset's path.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Stream>

A task whose result is a new stream, which the caller owns and disposes.

Remarks

It is asynchronous because a page in a browser fetches over the network and cannot wait. Read the stream forward: whether it can seek is the platform's answer, not a promise; a file can, an HTTP body and an Android asset cannot. A caller that needs more than one pass opens the asset again where it can, and copies it into memory only where it cannot, so the cost is paid where it is decided. A caller that only asks, such as a language falling back to another, takes TryOpenReadAsync, which gives null for an absent asset.

Exceptions

AssetNotFoundException

The provider classes the asset as absent; exactly this type, as a file it finds and cannot open is another failure.