Table of Contents

Class BaseEmbeddedCardGenerator

Namespace
idunno.Bluesky.Embed
Assembly
idunno.Bluesky.dll

Abstract class for an idunno.Bluesky.Embed.IEmbeddedCardGenerator which generates an idunno.Bluesky.Embed.EmbeddedExternal card for a given URI from its metadata.

public abstract class BaseEmbeddedCardGenerator : IEmbeddedCardGenerator, IDisposable

Inheritance

Derived

Implements

Inherited Members

Constructors

BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)

Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)

Parameters

agent BlueskyAgent

The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

httpClient HttpClient?

The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

Exceptions

ArgumentNullException

Thrown if agent is null.

BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)

Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)

Parameters

agent BlueskyAgent

The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

httpClient HttpClient?

The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

Exceptions

ArgumentNullException

Thrown if agent is null.

BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)

Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)

Parameters

agent BlueskyAgent

The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

httpClient HttpClient?

The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

Exceptions

ArgumentNullException

Thrown if agent is null.

Fields

DefaultMaximumPageSize

The default maximum number of bytes read from a webpage when generating a card from it.

public const int DefaultMaximumPageSize = 1048576

Field Value

int

DefaultMaximumPageSize

The default maximum number of bytes read from a webpage when generating a card from it.

public const int DefaultMaximumPageSize = 1048576

Field Value

int

DefaultMaximumPageSize

The default maximum number of bytes read from a webpage when generating a card from it.

public const int DefaultMaximumPageSize = 1048576

Field Value

int

DefaultMaximumThumbnailSize

The default maximum number of bytes downloaded for a card's thumbnail image.

public const long DefaultMaximumThumbnailSize = 1000000

Field Value

long

Remarks

app.bsky.embed.external declares a maximum size of one million bytes for a card's thumbnail, so downloading more than that would only produce a blob the service rejects when the post is written.

DefaultMaximumThumbnailSize

The default maximum number of bytes downloaded for a card's thumbnail image.

public const long DefaultMaximumThumbnailSize = 1000000

Field Value

long

Remarks

app.bsky.embed.external declares a maximum size of one million bytes for a card's thumbnail, so downloading more than that would only produce a blob the service rejects when the post is written.

DefaultMaximumThumbnailSize

The default maximum number of bytes downloaded for a card's thumbnail image.

public const long DefaultMaximumThumbnailSize = 1000000

Field Value

long

Remarks

app.bsky.embed.external declares a maximum size of one million bytes for a card's thumbnail, so downloading more than that would only produce a blob the service rejects when the post is written.

DefaultThumbnailDownloadBufferSize

The default size of the buffer used when downloading a card's thumbnail image.

public const int DefaultThumbnailDownloadBufferSize = 81920

Field Value

int

DefaultThumbnailDownloadBufferSize

The default size of the buffer used when downloading a card's thumbnail image.

public const int DefaultThumbnailDownloadBufferSize = 81920

Field Value

int

DefaultThumbnailDownloadBufferSize

The default size of the buffer used when downloading a card's thumbnail image.

public const int DefaultThumbnailDownloadBufferSize = 81920

Field Value

int

Properties

Agent

Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

protected BlueskyAgent Agent { get; }

Property Value

BlueskyAgent

Agent

Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

protected BlueskyAgent Agent { get; }

Property Value

BlueskyAgent

Agent

Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.

protected BlueskyAgent Agent { get; }

Property Value

BlueskyAgent

HttpClient

Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

protected HttpClient HttpClient { get; }

Property Value

HttpClient

HttpClient

Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

protected HttpClient HttpClient { get; }

Property Value

HttpClient

HttpClient

Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.

protected HttpClient HttpClient { get; }

Property Value

HttpClient

ILogger

Gets the logger used to log messages

protected ILogger ILogger { get; set; }

Property Value

ILogger

ILogger

Gets the logger used to log messages

protected ILogger ILogger { get; set; }

Property Value

ILogger

ILogger

Gets the logger used to log messages

protected ILogger ILogger { get; set; }

Property Value

ILogger

UnknownImageType

Gets the mime type returned if the content type of an image is unknown.

protected static string UnknownImageType { get; }

Property Value

string

UnknownImageType

Gets the mime type returned if the content type of an image is unknown.

protected static string UnknownImageType { get; }

Property Value

string

UnknownImageType

Gets the mime type returned if the content type of an image is unknown.

protected static string UnknownImageType { get; }

Property Value

string

Methods

Dispose(bool)

Releases the unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator and optionally disposes of the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to releases only unmanaged resources.

Remarks

Once disposed, a generator throws System.ObjectDisposedException rather than making any further requests.

Dispose()

Disposes of any managed and unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator and optionally disposes of the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to releases only unmanaged resources.

Remarks

Once disposed, a generator throws System.ObjectDisposedException rather than making any further requests.

Dispose()

Disposes of any managed and unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator and optionally disposes of the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to releases only unmanaged resources.

Remarks

Once disposed, a generator throws System.ObjectDisposedException rather than making any further requests.

Dispose()

Disposes of any managed and unmanaged resources used by the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.

public void Dispose()

DownloadAndUploadImageBlob(string, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(string uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri string

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Exceptions

ArgumentException

Thrown if uri is not a valid URI.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

DownloadAndUploadImageBlob(Uri, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(Uri uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known. This is treated as a hint; the type recorded on the blob is always the one sniffed from the content.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Remarks

imageMimeType typically comes from the page being read, which is served by whoever controls it, so it cannot be used to decide what is uploaded. The content is always sniffed and anything which is not a recognised image is rejected.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

UnauthorizedAccessException

Thrown if the agent is not authenticated.

ObjectDisposedException

Thrown if the generator has been disposed.

DownloadAndUploadImageBlob(string, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(string uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri string

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Exceptions

ArgumentException

Thrown if uri is not a valid URI.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

DownloadAndUploadImageBlob(Uri, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(Uri uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known. This is treated as a hint; the type recorded on the blob is always the one sniffed from the content.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Remarks

imageMimeType typically comes from the page being read, which is served by whoever controls it, so it cannot be used to decide what is uploaded. The content is always sniffed and anything which is not a recognised image is rejected.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

UnauthorizedAccessException

Thrown if the agent is not authenticated.

ObjectDisposedException

Thrown if the generator has been disposed.

DownloadAndUploadImageBlob(string, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(string uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri string

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Exceptions

ArgumentException

Thrown if uri is not a valid URI.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

DownloadAndUploadImageBlob(Uri, string?, long, int, CancellationToken)

Gets an image from the specified uri and uploads it to blob storage via the idunno.Bluesky.BlueskyAgent.

protected Task<Blob?> DownloadAndUploadImageBlob(Uri uri, string? imageMimeType = null, long maxDownloadSize = 1000000, int bufferSize = 81920, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the image to download.

imageMimeType string?

The mime type of the image, if known. This is treated as a hint; the type recorded on the blob is always the one sniffed from the content.

maxDownloadSize long

The maximum number of bytes to download.

bufferSize int

The size of the buffer to use when downloading the image.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Blob?>

The uploaded idunno.AtProto.Blob or null if the operation fails.

Remarks

imageMimeType typically comes from the page being read, which is served by whoever controls it, so it cannot be used to decide what is uploaded. The content is always sniffed and anything which is not a recognised image is rejected.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentOutOfRangeException

Thrown if maxDownloadSize or bufferSize is zero or negative.

UnauthorizedAccessException

Thrown if the agent is not authenticated.

ObjectDisposedException

Thrown if the generator has been disposed.

Generate(Uri, CancellationToken)

Generates an idunno.Bluesky.Embed.EmbeddedExternal record for uri.

public abstract Task<EmbeddedExternal?> Generate(Uri uri, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI to generate the card from.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<EmbeddedExternal?>

An idunno.Bluesky.Embed.EmbeddedExternal if OpenGraph data is found; otherwise, null.

Generate(Uri, CancellationToken)

Generates an idunno.Bluesky.Embed.EmbeddedExternal record for uri.

public abstract Task<EmbeddedExternal?> Generate(Uri uri, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI to generate the card from.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<EmbeddedExternal?>

An idunno.Bluesky.Embed.EmbeddedExternal if OpenGraph data is found; otherwise, null.

Generate(Uri, CancellationToken)

Generates an idunno.Bluesky.Embed.EmbeddedExternal record for uri.

public abstract Task<EmbeddedExternal?> Generate(Uri uri, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI to generate the card from.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<EmbeddedExternal?>

An idunno.Bluesky.Embed.EmbeddedExternal if OpenGraph data is found; otherwise, null.

GetPageContent(Uri, int, CancellationToken)

Gets the contents of the webpage at uri as a string.

protected virtual Task<string?> GetPageContent(Uri uri, int maxPageSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the webpage to retrieve.

maxPageSize int

The maximum number of bytes to read from the webpage.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the webpage as a string or null if the request fails.

Remarks

The page is served by whoever controls uri, so at most maxPageSize bytes are read from it. A longer page is truncated rather than rejected, as the metadata a card is built from appears in the document head.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxPageSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.

GetPageContent(Uri, int, CancellationToken)

Gets the contents of the webpage at uri as a string.

protected virtual Task<string?> GetPageContent(Uri uri, int maxPageSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the webpage to retrieve.

maxPageSize int

The maximum number of bytes to read from the webpage.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the webpage as a string or null if the request fails.

Remarks

The page is served by whoever controls uri, so at most maxPageSize bytes are read from it. A longer page is truncated rather than rejected, as the metadata a card is built from appears in the document head.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxPageSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.

GetPageContent(Uri, int, CancellationToken)

Gets the contents of the webpage at uri as a string.

protected virtual Task<string?> GetPageContent(Uri uri, int maxPageSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the webpage to retrieve.

maxPageSize int

The maximum number of bytes to read from the webpage.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the webpage as a string or null if the request fails.

Remarks

The page is served by whoever controls uri, so at most maxPageSize bytes are read from it. A longer page is truncated rather than rejected, as the metadata a card is built from appears in the document head.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxPageSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.

GetPlainTextContent(Uri, int, CancellationToken)

Gets the contents of the plain text document at uri as a string.

protected virtual Task<string?> GetPlainTextContent(Uri uri, int maxDocumentSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the document to retrieve.

maxDocumentSize int

The maximum number of bytes to read from the document.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the document as a string or null if the request fails.

Remarks

This differs from idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.GetPageContent(System.Uri,System.Int32,System.Threading.CancellationToken) only in the media types it asks for. It is used for well known documents, which are plain text rather than markup.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxDocumentSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.

GetPlainTextContent(Uri, int, CancellationToken)

Gets the contents of the plain text document at uri as a string.

protected virtual Task<string?> GetPlainTextContent(Uri uri, int maxDocumentSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the document to retrieve.

maxDocumentSize int

The maximum number of bytes to read from the document.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the document as a string or null if the request fails.

Remarks

This differs from idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.GetPageContent(System.Uri,System.Int32,System.Threading.CancellationToken) only in the media types it asks for. It is used for well known documents, which are plain text rather than markup.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxDocumentSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.

GetPlainTextContent(Uri, int, CancellationToken)

Gets the contents of the plain text document at uri as a string.

protected virtual Task<string?> GetPlainTextContent(Uri uri, int maxDocumentSize = 1048576, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI of the document to retrieve.

maxDocumentSize int

The maximum number of bytes to read from the document.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string?>

The contents of the document as a string or null if the request fails.

Remarks

This differs from idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.GetPageContent(System.Uri,System.Int32,System.Threading.CancellationToken) only in the media types it asks for. It is used for well known documents, which are plain text rather than markup.

Exceptions

ArgumentNullException

Thrown if uri is null.

ArgumentException

Thrown if uri is not a valid http or https URI.

ArgumentOutOfRangeException

Thrown if maxDocumentSize is zero or negative.

ObjectDisposedException

Thrown if the generator has been disposed.