| | | 1 | | using System.Dynamic; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Expressions.Helpers; |
| | | 5 | | using Elsa.Workflows.Models; |
| | | 6 | | using Elsa.Workflows.Serialization.Converters; |
| | | 7 | | using Elsa.Workflows.State; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Execute; |
| | | 10 | | |
| | | 11 | | public interface IExecutionRequest |
| | | 12 | | { |
| | | 13 | | string DefinitionId { get; } |
| | | 14 | | string? CorrelationId { get; } |
| | | 15 | | string? Name { get; } |
| | | 16 | | string? TriggerActivityId { get; } |
| | | 17 | | ActivityHandle? ActivityHandle { get; } |
| | | 18 | | VersionOptions? VersionOptions { get; } |
| | | 19 | | |
| | | 20 | | IDictionary<string, object>? GetInputAsDictionary(); |
| | | 21 | | IDictionary<string, object>? GetVariablesAsDictionary(); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | public class PostRequest : IExecutionRequest |
| | | 25 | | { |
| | | 26 | | public string DefinitionId { get; set; } = null!; |
| | | 27 | | public string? CorrelationId { get; set; } |
| | | 28 | | public string? Name { get; set; } |
| | | 29 | | public string? TriggerActivityId { get; set; } |
| | | 30 | | public ActivityHandle? ActivityHandle { get; set; } |
| | | 31 | | public VersionOptions? VersionOptions { get; set; } |
| | | 32 | | |
| | | 33 | | [JsonConverter(typeof(ExpandoObjectConverterFactory))] |
| | | 34 | | public object? Input { get; set; } |
| | | 35 | | |
| | | 36 | | [JsonConverter(typeof(ExpandoObjectConverterFactory))] |
| | | 37 | | public object? Variables { get; set; } |
| | | 38 | | |
| | | 39 | | public IDictionary<string, object>? GetInputAsDictionary() => (IDictionary<string, object>?)Input; |
| | | 40 | | public IDictionary<string, object>? GetVariablesAsDictionary() => (IDictionary<string, object>?)Variables; |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public class GetRequest : IExecutionRequest |
| | | 44 | | { |
| | | 45 | | public string DefinitionId { get; set; } = null!; |
| | | 46 | | public string? CorrelationId { get; set; } |
| | | 47 | | public string? Name { get; set; } |
| | | 48 | | public string? TriggerActivityId { get; set; } |
| | | 49 | | public ActivityHandle? ActivityHandle { get; set; } |
| | | 50 | | public VersionOptions? VersionOptions { get; set; } |
| | | 51 | | public string? Input { get; set; } |
| | | 52 | | public string? Variables { get; set; } |
| | | 53 | | |
| | | 54 | | public IDictionary<string, object>? GetInputAsDictionary() => ParseStringAsDictionary(Input); |
| | | 55 | | public IDictionary<string, object>? GetVariablesAsDictionary() => ParseStringAsDictionary(Variables); |
| | | 56 | | |
| | | 57 | | private IDictionary<string, object>? ParseStringAsDictionary(string? value) |
| | | 58 | | { |
| | | 59 | | var result = value?.TryConvertTo<ExpandoObject>(new() |
| | | 60 | | { |
| | | 61 | | SerializerOptions = new() |
| | | 62 | | { |
| | | 63 | | Converters = { new ExpandoObjectConverter() } |
| | | 64 | | } |
| | | 65 | | }); |
| | | 66 | | |
| | | 67 | | return result?.Success == true ? (IDictionary<string, object>?)result.Value : null; |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | |
| | 19 | 71 | | public class Response(WorkflowState workflowState) |
| | | 72 | | { |
| | 38 | 73 | | public WorkflowState WorkflowState { get; } = workflowState; |
| | | 74 | | } |