| | | 1 | | using System.ComponentModel; |
| | | 2 | | using Elsa.Alterations.Core.Contracts; |
| | | 3 | | using Elsa.Alterations.Core.Entities; |
| | | 4 | | using Elsa.Alterations.Core.Enums; |
| | | 5 | | using Elsa.Alterations.Core.Models; |
| | | 6 | | using Elsa.Common; |
| | | 7 | | using Elsa.Extensions; |
| | | 8 | | using Elsa.Workflows; |
| | | 9 | | using Elsa.Workflows.Attributes; |
| | | 10 | | using Elsa.Workflows.Models; |
| | | 11 | | |
| | | 12 | | namespace Elsa.Alterations.Activities; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Submits an alteration plan for execution. |
| | | 16 | | /// </summary> |
| | | 17 | | [Browsable(false)] |
| | | 18 | | [Output( |
| | | 19 | | DisplayName = "Plan ID", |
| | | 20 | | Description = "The ID of the submitted alteration plan." |
| | | 21 | | )] |
| | | 22 | | [Activity("Elsa", "Alterations", "Submits an Alteration Plan", Kind = ActivityKind.Task)] |
| | | 23 | | public class SubmitAlterationPlan : CodeActivity<string> |
| | | 24 | | { |
| | | 25 | | /// <summary> |
| | | 26 | | /// The parameters for the alteration plan to be submitted. |
| | | 27 | | /// </summary> |
| | 67 | 28 | | public Input<AlterationPlanParams> Params { get; set; } = null!; |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 32 | | { |
| | 0 | 33 | | var systemClock = context.GetRequiredService<ISystemClock>(); |
| | 0 | 34 | | var identityGenerator = context.GetRequiredService<IIdentityGenerator>(); |
| | 0 | 35 | | var now = systemClock.UtcNow; |
| | 0 | 36 | | var planParams = context.Get(Params)!; |
| | | 37 | | |
| | 0 | 38 | | var plan = new AlterationPlan |
| | 0 | 39 | | { |
| | 0 | 40 | | Id = string.IsNullOrWhiteSpace(planParams.Id) ? identityGenerator.GenerateId() : planParams.Id, |
| | 0 | 41 | | Alterations = planParams.Alterations, |
| | 0 | 42 | | WorkflowInstanceFilter = planParams.Filter, |
| | 0 | 43 | | Status = AlterationPlanStatus.Pending, |
| | 0 | 44 | | CreatedAt = now |
| | 0 | 45 | | }; |
| | | 46 | | |
| | 0 | 47 | | var alterationPlanStore = context.GetRequiredService<IAlterationPlanStore>(); |
| | 0 | 48 | | var cancellationToken = context.CancellationToken; |
| | 0 | 49 | | await alterationPlanStore.SaveAsync(plan, cancellationToken); |
| | 0 | 50 | | Result.Set(context, plan.Id); |
| | 0 | 51 | | } |
| | | 52 | | } |