| | | 1 | | using Elsa.Features.Services; |
| | | 2 | | using Elsa.Workflows; |
| | | 3 | | using Elsa.Workflows.Activities; |
| | | 4 | | using Elsa.Workflows.Management.Features; |
| | | 5 | | using Elsa.Workflows.Options; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | using Elsa.Common.Serialization; |
| | | 8 | | |
| | | 9 | | // ReSharper disable once CheckNamespace |
| | | 10 | | namespace Elsa.Extensions; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Provides extensions to the specified <see cref="IModule"/>/ |
| | | 14 | | /// </summary> |
| | | 15 | | public static class ModuleExtensions |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Adds the workflow management feature to the specified module. |
| | | 19 | | /// </summary> |
| | | 20 | | public static IModule UseWorkflowManagement(this IModule module, Action<WorkflowManagementFeature>? configure = null |
| | | 21 | | { |
| | 36 | 22 | | module.Configure<WorkflowManagementFeature>(management => |
| | 36 | 23 | | { |
| | 36 | 24 | | management.AddActivity<NotFoundActivity>(); |
| | 36 | 25 | | configure?.Invoke(management); |
| | 72 | 26 | | }); |
| | 36 | 27 | | return module; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Adds the default workflow management feature to the specified module. |
| | | 32 | | /// </summary> |
| | | 33 | | public static WorkflowManagementFeature UseWorkflowDefinitions(this WorkflowManagementFeature feature, Action<Workfl |
| | | 34 | | { |
| | 0 | 35 | | feature.Module.Configure(configure); |
| | 0 | 36 | | return feature; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Adds the workflow instance feature to workflow management module. |
| | | 41 | | /// </summary> |
| | | 42 | | public static WorkflowManagementFeature UseWorkflowInstances(this WorkflowManagementFeature feature, Action<Workflow |
| | | 43 | | { |
| | 0 | 44 | | feature.Module.Configure(configure); |
| | 0 | 45 | | return feature; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Adds all types implementing <see cref="IActivity"/> to the system. |
| | | 50 | | /// </summary> |
| | 30 | 51 | | public static IModule AddActivitiesFrom<TMarkerType>(this IModule module) => module.UseWorkflowManagement(management |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Adds the specified activity type to the system. |
| | | 55 | | /// </summary> |
| | 0 | 56 | | public static IModule AddActivity<T>(this IModule module) where T : IActivity => module.UseWorkflowManagement(manage |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Registers the specified activity host type to the workflow system. |
| | | 60 | | /// </summary> |
| | 12 | 61 | | public static IModule AddActivityHost<T>(this IModule module) where T : class => module.UseWorkflowManagement(manage |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Removes the specified activity type from the system. |
| | | 65 | | /// </summary> |
| | 0 | 66 | | public static IModule RemoveActivity<T>(this IModule module) where T : IActivity => module.UseWorkflowManagement(man |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Adds the specified variable type to the system. |
| | | 70 | | /// </summary> |
| | 0 | 71 | | public static IModule AddVariableType<T>(this IModule module, string category) => module.UseWorkflowManagement(manag |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Adds a variable type and its alias to the specified module. |
| | | 75 | | /// </summary> |
| | | 76 | | public static IModule AddVariableTypeAndAlias<T>(this IModule module, string alias, string category) |
| | | 77 | | { |
| | 0 | 78 | | module.Services.Configure<SerializationTypeOptions>(options => options.RegisterTypeAlias(typeof(T), alias)); |
| | | 79 | | |
| | 0 | 80 | | return module |
| | 0 | 81 | | .UseWorkflowManagement(management => management.AddVariableType<T>(category)) |
| | 0 | 82 | | .AddTypeAlias<T>(alias); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Adds caching stores feature to the workflow management feature. |
| | | 87 | | /// </summary> |
| | | 88 | | public static WorkflowManagementFeature UseCache(this WorkflowManagementFeature feature, Action<CachingWorkflowDefin |
| | | 89 | | { |
| | 6 | 90 | | feature.Module.Configure(configure); |
| | 6 | 91 | | return feature; |
| | | 92 | | } |
| | | 93 | | } |