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, IDisposableInheritance
Derived
Implements
Inherited Members
Constructors
BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)
Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.
protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)Parameters
agentBlueskyAgent-
The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
httpClientHttpClient?-
The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
Exceptions
- ArgumentNullException
-
Thrown if
agentis null.
BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)
Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.
protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)Parameters
agentBlueskyAgent-
The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
httpClientHttpClient?-
The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
Exceptions
- ArgumentNullException
-
Thrown if
agentis null.
BaseEmbeddedCardGenerator(BlueskyAgent, HttpClient?)
Creates a new instance of idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.
protected BaseEmbeddedCardGenerator(BlueskyAgent agent, HttpClient? httpClient)Parameters
agentBlueskyAgent-
The idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
httpClientHttpClient?-
The idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
Exceptions
- ArgumentNullException
-
Thrown if
agentis null.
Fields
DefaultMaximumPageSize
The default maximum number of bytes read from a webpage when generating a card from it.
public const int DefaultMaximumPageSize = 1048576Field Value
DefaultMaximumPageSize
The default maximum number of bytes read from a webpage when generating a card from it.
public const int DefaultMaximumPageSize = 1048576Field Value
DefaultMaximumPageSize
The default maximum number of bytes read from a webpage when generating a card from it.
public const int DefaultMaximumPageSize = 1048576Field Value
DefaultMaximumThumbnailSize
The default maximum number of bytes downloaded for a card's thumbnail image.
public const long DefaultMaximumThumbnailSize = 1000000Field Value
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 = 1000000Field Value
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 = 1000000Field Value
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 = 81920Field Value
DefaultThumbnailDownloadBufferSize
The default size of the buffer used when downloading a card's thumbnail image.
public const int DefaultThumbnailDownloadBufferSize = 81920Field Value
DefaultThumbnailDownloadBufferSize
The default size of the buffer used when downloading a card's thumbnail image.
public const int DefaultThumbnailDownloadBufferSize = 81920Field Value
Properties
Agent
Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
protected BlueskyAgent Agent { get; }Property Value
Agent
Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
protected BlueskyAgent Agent { get; }Property Value
Agent
Gets the idunno.Bluesky.BlueskyAgent used to upload images for embedded cards.
protected BlueskyAgent Agent { get; }Property Value
HttpClient
Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
protected HttpClient HttpClient { get; }Property Value
HttpClient
Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
protected HttpClient HttpClient { get; }Property Value
HttpClient
Gets the idunno.Bluesky.Embed.BaseEmbeddedCardGenerator.HttpClient used for making HTTP requests.
protected HttpClient HttpClient { get; }Property Value
ILogger
Gets the logger used to log messages
protected ILogger ILogger { get; set; }Property Value
ILogger
Gets the logger used to log messages
protected ILogger ILogger { get; set; }Property Value
ILogger
Gets the logger used to log messages
protected ILogger ILogger { get; set; }Property Value
UnknownImageType
Gets the mime type returned if the content type of an image is unknown.
protected static string UnknownImageType { get; }Property Value
UnknownImageType
Gets the mime type returned if the content type of an image is unknown.
protected static string UnknownImageType { get; }Property Value
UnknownImageType
Gets the mime type returned if the content type of an image is unknown.
protected static string UnknownImageType { get; }Property Value
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
disposingbool-
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
disposingbool-
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
disposingbool-
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
uristring-
The URI of the image to download.
imageMimeTypestring?-
The mime type of the image, if known.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
Exceptions
- ArgumentException
-
Thrown if
uriis not a valid URI. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uriUri-
The URI of the image to download.
imageMimeTypestring?-
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.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uristring-
The URI of the image to download.
imageMimeTypestring?-
The mime type of the image, if known.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
Exceptions
- ArgumentException
-
Thrown if
uriis not a valid URI. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uriUri-
The URI of the image to download.
imageMimeTypestring?-
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.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uristring-
The URI of the image to download.
imageMimeTypestring?-
The mime type of the image, if known.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
Exceptions
- ArgumentException
-
Thrown if
uriis not a valid URI. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uriUri-
The URI of the image to download.
imageMimeTypestring?-
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.
maxDownloadSizelong-
The maximum number of bytes to download.
bufferSizeint-
The size of the buffer to use when downloading the image.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentOutOfRangeException
-
Thrown if
maxDownloadSizeorbufferSizeis 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
uriUri-
The URI to generate the card from.
cancellationTokenCancellationToken-
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
uriUri-
The URI to generate the card from.
cancellationTokenCancellationToken-
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
uriUri-
The URI to generate the card from.
cancellationTokenCancellationToken-
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
uriUri-
The URI of the webpage to retrieve.
maxPageSizeint-
The maximum number of bytes to read from the webpage.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxPageSizeis 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
uriUri-
The URI of the webpage to retrieve.
maxPageSizeint-
The maximum number of bytes to read from the webpage.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxPageSizeis 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
uriUri-
The URI of the webpage to retrieve.
maxPageSizeint-
The maximum number of bytes to read from the webpage.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxPageSizeis 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
uriUri-
The URI of the document to retrieve.
maxDocumentSizeint-
The maximum number of bytes to read from the document.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxDocumentSizeis 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
uriUri-
The URI of the document to retrieve.
maxDocumentSizeint-
The maximum number of bytes to read from the document.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxDocumentSizeis 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
uriUri-
The URI of the document to retrieve.
maxDocumentSizeint-
The maximum number of bytes to read from the document.
cancellationTokenCancellationToken-
A token to cancel the operation.
Returns
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
uriis null. - ArgumentException
-
Thrown if
uriis not a valid http or https URI. - ArgumentOutOfRangeException
-
Thrown if
maxDocumentSizeis zero or negative. - ObjectDisposedException
-
Thrown if the generator has been disposed.