| | | 1 | | using System.Collections; |
| | | 2 | | using Elsa.Http.Abstractions; |
| | | 3 | | using Elsa.Http.Contexts; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Http.DownloadableContentHandlers; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Handles content that represents a list of downloadable objects. |
| | | 9 | | /// </summary> |
| | | 10 | | public class MultiDownloadableContentHandler : DownloadableContentHandlerBase |
| | | 11 | | { |
| | | 12 | | /// <inheritdoc /> |
| | 0 | 13 | | public override bool GetSupportsContent(object content) => content is IEnumerable and not string and not byte[]; |
| | | 14 | | |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | protected override IEnumerable<Func<ValueTask<Downloadable>>> GetDownloadablesAsync(DownloadableContext context) |
| | | 17 | | { |
| | 0 | 18 | | var collectedDownloadables = new List<Func<ValueTask<Downloadable>>>(); |
| | 0 | 19 | | var content = context.Content; |
| | 0 | 20 | | var enumerable = (IEnumerable) content; |
| | 0 | 21 | | var manager = context.Manager; |
| | | 22 | | |
| | 0 | 23 | | foreach (var item in enumerable) |
| | | 24 | | { |
| | 0 | 25 | | var downloadables = manager.GetDownloadablesAsync(item, context.Options, context.CancellationToken); |
| | 0 | 26 | | collectedDownloadables.AddRange(downloadables); |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | return collectedDownloadables; |
| | | 30 | | } |
| | | 31 | | } |