| | | 1 | | using Elsa.Workflows.Activities; |
| | | 2 | | using Elsa.Workflows.Management.Entities; |
| | | 3 | | using Elsa.Workflows.Management.Mappers; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Management.Materializers; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Materializes a <see cref="Workflow"/> from a <see cref="WorkflowDefinition"/>'s JSON data. |
| | | 9 | | /// </summary> |
| | | 10 | | public class JsonWorkflowMaterializer : IWorkflowMaterializer |
| | | 11 | | { |
| | | 12 | | private readonly WorkflowDefinitionMapper _workflowDefinitionMapper; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// The name of the materializer. |
| | | 16 | | /// </summary> |
| | | 17 | | public const string MaterializerName = "Json"; |
| | | 18 | | |
| | | 19 | | /// <inheritdoc /> |
| | 909 | 20 | | public string Name => MaterializerName; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Initializes a new instance of the <see cref="JsonWorkflowMaterializer"/> class. |
| | | 24 | | /// </summary> |
| | 266 | 25 | | public JsonWorkflowMaterializer(WorkflowDefinitionMapper workflowDefinitionMapper) |
| | | 26 | | { |
| | 266 | 27 | | _workflowDefinitionMapper = workflowDefinitionMapper; |
| | 266 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public ValueTask<Workflow> MaterializeAsync(WorkflowDefinition definition, CancellationToken cancellationToken) |
| | | 32 | | { |
| | 901 | 33 | | var workflow = ToWorkflow(definition); |
| | 901 | 34 | | return new(workflow); |
| | | 35 | | } |
| | | 36 | | |
| | 901 | 37 | | private Workflow ToWorkflow(WorkflowDefinition definition) => _workflowDefinitionMapper.Map(definition); |
| | | 38 | | } |