2023-09-16 09:06:56 +00:00
using Elsa.Http.Contexts ;
namespace Elsa.Http.Abstractions ;
/// <summary>
2023-09-17 20:35:13 +00:00
/// Provides a base class for <see cref="IDownloadableContentHandler"/> implementations.
2023-09-16 09:06:56 +00:00
/// </summary>
2023-09-17 20:35:13 +00:00
public abstract class DownloadableContentHandlerBase : IDownloadableContentHandler
2023-09-16 09:06:56 +00:00
{
/// <inheritdoc />
public virtual float Priority = > 0 ;
/// <inheritdoc />
public abstract bool GetSupportsContent ( object content ) ;
/// <summary>
/// Returns a list of downloadables from the specified content.
/// </summary>
2023-09-17 20:35:13 +00:00
protected virtual IEnumerable < Func < ValueTask < Downloadable > > > GetDownloadablesAsync ( DownloadableContext context )
2023-09-16 09:06:56 +00:00
{
2023-09-17 20:35:13 +00:00
return new [ ] { GetDownloadableAsync ( context ) } ;
2023-09-16 09:06:56 +00:00
}
/// <summary>
/// Returns a downloadable from the specified content.
/// </summary>
2023-09-17 20:35:13 +00:00
protected virtual Func < ValueTask < Downloadable > > GetDownloadableAsync ( DownloadableContext context )
2023-09-16 09:06:56 +00:00
{
2023-09-17 20:35:13 +00:00
return ( ) = > ValueTask . FromResult ( GetDownloadable ( context ) ) ;
2023-09-16 09:06:56 +00:00
}
/// <summary>
/// Returns a downloadable from the specified content.
/// </summary>
/// <exception cref="NotImplementedException">This method is not implemented. The derived class must implement at least one of the GetDownloadable methods.</exception>
protected virtual Downloadable GetDownloadable ( DownloadableContext context )
{
throw new NotImplementedException ( ) ;
}
2023-09-17 20:35:13 +00:00
IEnumerable < Func < ValueTask < Downloadable > > > IDownloadableContentHandler . GetDownloadablesAsync ( DownloadableContext context )
2023-09-16 09:06:56 +00:00
{
2023-09-17 20:35:13 +00:00
return GetDownloadablesAsync ( context ) ;
2023-09-16 09:06:56 +00:00
}
}