| | | 1 | | using System.Dynamic; |
| | | 2 | | using System.Text.Json; |
| | | 3 | | using System.Text.Json.Nodes; |
| | | 4 | | using CShells.Features; |
| | | 5 | | using Elsa.Caching.Features; |
| | | 6 | | using Elsa.Common.Features; |
| | | 7 | | using Elsa.Expressions.Contracts; |
| | | 8 | | using Elsa.Extensions; |
| | | 9 | | using Elsa.Features.Attributes; |
| | | 10 | | using Elsa.Workflows.Features; |
| | | 11 | | using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; |
| | | 12 | | using Elsa.Workflows.Management.Contracts; |
| | | 13 | | using Elsa.Workflows.Management.Entities; |
| | | 14 | | using Elsa.Workflows.Management.Extensions; |
| | | 15 | | using Elsa.Workflows.Management.Features; |
| | | 16 | | using Elsa.Workflows.Management.Handlers.Notifications; |
| | | 17 | | using Elsa.Workflows.Management.Mappers; |
| | | 18 | | using Elsa.Workflows.Management.Materializers; |
| | | 19 | | using Elsa.Workflows.Management.Models; |
| | | 20 | | using Elsa.Workflows.Management.Options; |
| | | 21 | | using Elsa.Workflows.Management.Providers; |
| | | 22 | | using Elsa.Workflows.Management.Services; |
| | | 23 | | using Elsa.Workflows.Management.Stores; |
| | | 24 | | using Elsa.Workflows.Serialization.Serializers; |
| | | 25 | | using JetBrains.Annotations; |
| | | 26 | | using Microsoft.Extensions.DependencyInjection; |
| | | 27 | | |
| | | 28 | | namespace Elsa.Workflows.Management.ShellFeatures; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Installs and configures the workflow management feature. |
| | | 32 | | /// </summary> |
| | | 33 | | [ShellFeature( |
| | | 34 | | DisplayName = "Workflow Management", |
| | | 35 | | Description = "Provides comprehensive workflow definition and instance management capabilities", |
| | | 36 | | DependsOn = |
| | | 37 | | [ |
| | | 38 | | "StringCompression", |
| | | 39 | | "Mediator", |
| | | 40 | | "MemoryCache", |
| | | 41 | | "SystemClock", |
| | | 42 | | "Workflows", |
| | | 43 | | "WorkflowDefinitions", |
| | | 44 | | "WorkflowInstances" |
| | | 45 | | ])] |
| | | 46 | | [UsedImplicitly] |
| | | 47 | | public class WorkflowManagementFeature : IShellFeature |
| | | 48 | | { |
| | | 49 | | private const string PrimitivesCategory = "Primitives"; |
| | | 50 | | private const string LookupsCategory = "Lookups"; |
| | | 51 | | private const string DynamicCategory = "Dynamic"; |
| | | 52 | | private const string DataCategory = "Data"; |
| | | 53 | | private const string SystemCategory = "System"; |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// A set of variable types to make available to the system. |
| | | 57 | | /// </summary> |
| | 0 | 58 | | public HashSet<VariableDescriptor> VariableDescriptors { get; } = |
| | 0 | 59 | | [ |
| | 0 | 60 | | new(typeof(object), PrimitivesCategory, "The root class for all objects in the CLR System."), |
| | 0 | 61 | | new(typeof(string), PrimitivesCategory, "Represents a static string of characters."), |
| | 0 | 62 | | new(typeof(bool), PrimitivesCategory, "Represents a true or false value."), |
| | 0 | 63 | | new(typeof(int), PrimitivesCategory, "A 32 bit integer."), |
| | 0 | 64 | | new(typeof(long), PrimitivesCategory, "A 64 bit integer."), |
| | 0 | 65 | | new(typeof(float), PrimitivesCategory, "A 32 bit floating point number."), |
| | 0 | 66 | | new(typeof(double), PrimitivesCategory, "A 64 bit floating point number."), |
| | 0 | 67 | | new(typeof(decimal), PrimitivesCategory, "A decimal number."), |
| | 0 | 68 | | new(typeof(Guid), PrimitivesCategory, "Represents a Globally Unique Identifier."), |
| | 0 | 69 | | new(typeof(DateTime), PrimitivesCategory, "A value type that represents a date and time."), |
| | 0 | 70 | | new(typeof(DateTimeOffset), PrimitivesCategory, "A value type that consists of a DateTime and a time zone offset |
| | 0 | 71 | | new(typeof(TimeSpan), PrimitivesCategory, "Represents a duration of time."), |
| | 0 | 72 | | new(typeof(IDictionary<string, string>), LookupsCategory, "A dictionary with string key and values."), |
| | 0 | 73 | | new(typeof(IDictionary<string, object>), LookupsCategory, "A dictionary with string key and object values."), |
| | 0 | 74 | | new(typeof(ExpandoObject), DynamicCategory, "A dictionary that can be typed as dynamic to access members using d |
| | 0 | 75 | | new(typeof(JsonElement), DynamicCategory, "A JSON element for reading a JSON structure."), |
| | 0 | 76 | | new(typeof(JsonNode), DynamicCategory, "A JSON node for reading and writing a JSON structure."), |
| | 0 | 77 | | new(typeof(JsonObject), DynamicCategory, "A JSON object for reading and writing a JSON structure."), |
| | 0 | 78 | | new(typeof(byte[]), DataCategory, "A byte array."), |
| | 0 | 79 | | new(typeof(Stream), DataCategory, "A stream.") |
| | 0 | 80 | | ]; |
| | | 81 | | |
| | | 82 | | |
| | | 83 | | public void ConfigureServices(IServiceCollection services) |
| | | 84 | | { |
| | 0 | 85 | | services |
| | 0 | 86 | | .AddMemoryStore<WorkflowDefinition, MemoryWorkflowDefinitionStore>() |
| | 0 | 87 | | .AddMemoryStore<WorkflowInstance, MemoryWorkflowInstanceStore>() |
| | 0 | 88 | | .AddActivityProvider<TypedActivityProvider>() |
| | 0 | 89 | | .AddActivityProvider<WorkflowDefinitionActivityProvider>() |
| | 0 | 90 | | .AddScoped<WorkflowDefinitionActivityDescriptorFactory>() |
| | 0 | 91 | | .AddScoped<WorkflowDefinitionActivityProvider>() |
| | 0 | 92 | | .AddScoped<IWorkflowDefinitionActivityRegistryUpdater, WorkflowDefinitionActivityRegistryUpdater>() |
| | 0 | 93 | | .AddScoped<IMaterializerRegistry, MaterializerRegistry>() |
| | 0 | 94 | | .AddScoped<IWorkflowDefinitionService, WorkflowDefinitionService>() |
| | 0 | 95 | | .AddScoped<IWorkflowSerializer, WorkflowSerializer>() |
| | 0 | 96 | | .AddScoped<IWorkflowValidator, WorkflowValidator>() |
| | 0 | 97 | | .AddScoped<IWorkflowReferenceQuery, DefaultWorkflowReferenceQuery>() |
| | 0 | 98 | | .AddScoped<IWorkflowReferenceGraphBuilder, WorkflowReferenceGraphBuilder>() |
| | 0 | 99 | | .AddScoped<IWorkflowDefinitionPublisher, WorkflowDefinitionPublisher>() |
| | 0 | 100 | | .AddScoped<IWorkflowDefinitionImporter, WorkflowDefinitionImporter>() |
| | 0 | 101 | | .AddScoped<IWorkflowDefinitionManager, WorkflowDefinitionManager>() |
| | 0 | 102 | | .AddScoped<IWorkflowInstanceManager, WorkflowInstanceManager>() |
| | 0 | 103 | | .AddScoped<IWorkflowReferenceUpdater, WorkflowReferenceUpdater>() |
| | 0 | 104 | | .AddScoped<IActivityRegistryPopulator, ActivityRegistryPopulator>() |
| | 0 | 105 | | .AddSingleton<IExpressionDescriptorRegistry, ExpressionDescriptorRegistry>() |
| | 0 | 106 | | .AddSingleton<IExpressionDescriptorProvider, DefaultExpressionDescriptorProvider>() |
| | 0 | 107 | | .AddSerializationOptionsConfigurator<SerializationOptionsConfigurator>() |
| | 0 | 108 | | .AddScoped<IWorkflowMaterializer, TypedWorkflowMaterializer>() |
| | 0 | 109 | | .AddScoped<IWorkflowMaterializer, ClrWorkflowMaterializer>() |
| | 0 | 110 | | .AddScoped<IWorkflowMaterializer, JsonWorkflowMaterializer>() |
| | 0 | 111 | | .AddScoped<IActivityResolver, WorkflowDefinitionActivityResolver>() |
| | 0 | 112 | | .AddScoped<IWorkflowInstanceVariableManager, WorkflowInstanceVariableManager>() |
| | 0 | 113 | | .AddScoped<WorkflowDefinitionMapper>() |
| | 0 | 114 | | .AddSingleton<VariableDefinitionMapper>() |
| | 0 | 115 | | .AddSingleton<WorkflowStateMapper>() |
| | 0 | 116 | | .AddScoped<IWorkflowInstanceStore, MemoryWorkflowInstanceStore>() |
| | 0 | 117 | | .AddScoped<IWorkflowDefinitionStore, MemoryWorkflowDefinitionStore>(); |
| | | 118 | | |
| | 0 | 119 | | services |
| | 0 | 120 | | .AddNotificationHandler<DeleteWorkflowInstances>() |
| | 0 | 121 | | .AddNotificationHandler<RefreshActivityRegistry>() |
| | 0 | 122 | | .AddNotificationHandler<UpdateConsumingWorkflows>() |
| | 0 | 123 | | .AddNotificationHandler<ValidateWorkflow>(); |
| | | 124 | | |
| | | 125 | | // Register built-in activities from the Workflows and WorkflowManagement assemblies. |
| | 0 | 126 | | services |
| | 0 | 127 | | .AddActivitiesFrom<WorkflowsFeature>() |
| | 0 | 128 | | .AddActivitiesFrom<WorkflowManagementFeature>(); |
| | | 129 | | |
| | | 130 | | // Register the default variable descriptors declared on this feature. |
| | 0 | 131 | | services.AddVariableDescriptors(VariableDescriptors); |
| | 0 | 132 | | } |
| | | 133 | | } |