| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Http.PortResolvers; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Returns a list of outbound activities for a given <see cref="SendHttpRequest"/> activity's expected status codes. |
| | | 8 | | /// </summary> |
| | | 9 | | public class SendHttpRequestActivityResolver : IActivityResolver |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | 328 | 12 | | public int Priority => 0; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | 13540 | 15 | | public bool GetSupportsActivity(IActivity activity) => activity is SendHttpRequest; |
| | | 16 | | |
| | | 17 | | |
| | | 18 | | /// <inheritdoc /> |
| | | 19 | | public ValueTask<IEnumerable<ActivityPort>> GetActivityPortsAsync(IActivity activity, CancellationToken cancellation |
| | | 20 | | { |
| | 0 | 21 | | var ports = GetPortsInternal(activity); |
| | 0 | 22 | | return new(ports); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | private IEnumerable<ActivityPort> GetPortsInternal(IActivity activity) |
| | | 26 | | { |
| | 0 | 27 | | var sendHttpRequest = (SendHttpRequest)activity; |
| | 0 | 28 | | var cases = sendHttpRequest.ExpectedStatusCodes.Where(x => x.Activity != null); |
| | | 29 | | |
| | 0 | 30 | | foreach (var @case in cases) |
| | 0 | 31 | | yield return ActivityPort.FromActivity(@case.Activity!, @case.StatusCode.ToString()); |
| | | 32 | | |
| | 0 | 33 | | if (sendHttpRequest.Timeout != null) |
| | 0 | 34 | | yield return ActivityPort.FromActivity(sendHttpRequest.Timeout, nameof(SendHttpRequest.Timeout)); |
| | | 35 | | |
| | 0 | 36 | | if (sendHttpRequest.FailedToConnect != null) |
| | 0 | 37 | | yield return ActivityPort.FromActivity(sendHttpRequest.FailedToConnect, nameof(SendHttpRequest.FailedToConne |
| | | 38 | | |
| | 0 | 39 | | if (sendHttpRequest.UnmatchedStatusCode != null) |
| | 0 | 40 | | yield return ActivityPort.FromActivity(sendHttpRequest.UnmatchedStatusCode, nameof(SendHttpRequest.Unmatched |
| | 0 | 41 | | } |
| | | 42 | | } |