| | | 1 | | using CShells.Management; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Shells.Api.Endpoints.Shells; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.AspNetCore.Http; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Shells.Api.Endpoints.Shells.Reload; |
| | | 9 | | |
| | | 10 | | [PublicAPI] |
| | 6 | 11 | | internal class Reload(IShellManager shellManager, IApiSerializer apiSerializer) : ElsaEndpointWithoutRequest |
| | | 12 | | { |
| | | 13 | | public override void Configure() |
| | | 14 | | { |
| | 4 | 15 | | Post("/shells/{shellId}/reload"); |
| | 4 | 16 | | ConfigurePermissions("actions:shells:reload"); |
| | 4 | 17 | | } |
| | | 18 | | |
| | | 19 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 20 | | { |
| | 2 | 21 | | var shellId = Route<string>("shellId")!; |
| | | 22 | | |
| | | 23 | | try |
| | | 24 | | { |
| | 2 | 25 | | await shellManager.ReloadShellAsync(shellId, cancellationToken); |
| | 1 | 26 | | } |
| | 1 | 27 | | catch (InvalidOperationException ex) |
| | | 28 | | { |
| | | 29 | | // Shell not found by the provider. |
| | 1 | 30 | | var notFoundResponse = new ShellReloadResponse |
| | 1 | 31 | | { |
| | 1 | 32 | | Status = ShellReloadStatus.NotFound, |
| | 1 | 33 | | RequestedShellId = shellId, |
| | 1 | 34 | | Timestamp = DateTimeOffset.UtcNow, |
| | 1 | 35 | | Message = ex.Message |
| | 1 | 36 | | }; |
| | 1 | 37 | | await SendResponseAsync(notFoundResponse, StatusCodes.Status404NotFound, cancellationToken); |
| | 1 | 38 | | return; |
| | | 39 | | } |
| | | 40 | | |
| | 1 | 41 | | var response = new ShellReloadResponse |
| | 1 | 42 | | { |
| | 1 | 43 | | Status = ShellReloadStatus.Completed, |
| | 1 | 44 | | RequestedShellId = shellId, |
| | 1 | 45 | | Timestamp = DateTimeOffset.UtcNow |
| | 1 | 46 | | }; |
| | 1 | 47 | | await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken); |
| | 2 | 48 | | } |
| | | 49 | | |
| | | 50 | | private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok |
| | | 51 | | { |
| | 2 | 52 | | var serializerOptions = apiSerializer.GetOptions(); |
| | 2 | 53 | | HttpContext.Response.StatusCode = statusCode; |
| | 2 | 54 | | await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken); |
| | 2 | 55 | | } |
| | | 56 | | } |