| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Features.Abstractions; |
| | | 3 | | using Elsa.Features.Services; |
| | | 4 | | using Elsa.Workflows.CommitStates.Strategies; |
| | | 5 | | using Elsa.Workflows.CommitStates.Tasks; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.CommitStates; |
| | | 9 | | |
| | 129 | 10 | | public class CommitStrategiesFeature(IModule module) : FeatureBase(module) |
| | | 11 | | { |
| | | 12 | | public void AddStandardStrategies() |
| | | 13 | | { |
| | | 14 | | // Workflow commit strategies. |
| | 7 | 15 | | Add(new WorkflowExecutingWorkflowStrategy()); |
| | 7 | 16 | | Add(new WorkflowExecutedWorkflowStrategy()); |
| | 7 | 17 | | Add(new ActivityExecutingWorkflowStrategy()); |
| | 7 | 18 | | Add(new ActivityExecutedWorkflowStrategy()); |
| | | 19 | | |
| | | 20 | | // Activity commit strategies. |
| | 7 | 21 | | Add(new CommitAlwaysActivityStrategy()); |
| | 7 | 22 | | Add(new CommitNeverActivityStrategy()); |
| | 7 | 23 | | Add(new ExecutingActivityStrategy()); |
| | 7 | 24 | | Add(new ExecutedActivityStrategy()); |
| | 7 | 25 | | } |
| | | 26 | | |
| | | 27 | | public void Add(IWorkflowCommitStrategy strategy) |
| | | 28 | | { |
| | 28 | 29 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 28 | 30 | | Add(registration); |
| | 28 | 31 | | } |
| | | 32 | | |
| | | 33 | | public void Add(string displayName, IWorkflowCommitStrategy strategy) |
| | | 34 | | { |
| | 7 | 35 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 7 | 36 | | registration.Metadata.DisplayName = displayName; |
| | 7 | 37 | | Add(registration); |
| | 7 | 38 | | } |
| | | 39 | | |
| | | 40 | | public void Add(string displayName, string description, IWorkflowCommitStrategy strategy) |
| | | 41 | | { |
| | 0 | 42 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 0 | 43 | | registration.Metadata.DisplayName = displayName; |
| | 0 | 44 | | registration.Metadata.Description = description; |
| | 0 | 45 | | Add(registration); |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | public void Add(string name, string displayName, string description, IWorkflowCommitStrategy strategy) |
| | | 49 | | { |
| | 0 | 50 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 0 | 51 | | registration.Metadata.Name = name; |
| | 0 | 52 | | registration.Metadata.DisplayName = displayName; |
| | 0 | 53 | | registration.Metadata.Description = description; |
| | 0 | 54 | | Add(registration); |
| | 0 | 55 | | } |
| | | 56 | | |
| | | 57 | | public void Add(WorkflowCommitStrategyRegistration registration) |
| | | 58 | | { |
| | 70 | 59 | | Services.Configure<CommitStateOptions>(options => options.WorkflowCommitStrategies[registration.Metadata.Name] = |
| | 35 | 60 | | } |
| | | 61 | | |
| | | 62 | | public void Add(IActivityCommitStrategy strategy) |
| | | 63 | | { |
| | 28 | 64 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 28 | 65 | | Add(registration); |
| | 28 | 66 | | } |
| | | 67 | | |
| | | 68 | | public void Add(string displayName, IActivityCommitStrategy strategy) |
| | | 69 | | { |
| | 0 | 70 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 0 | 71 | | registration.Metadata.DisplayName = displayName; |
| | 0 | 72 | | Add(registration); |
| | 0 | 73 | | } |
| | | 74 | | |
| | | 75 | | public void Add(string displayName, string description, IActivityCommitStrategy strategy) |
| | | 76 | | { |
| | 0 | 77 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 0 | 78 | | registration.Metadata.DisplayName = displayName; |
| | 0 | 79 | | registration.Metadata.Description = description; |
| | 0 | 80 | | Add(registration); |
| | 0 | 81 | | } |
| | | 82 | | |
| | | 83 | | public void Add(string name, string displayName, string description, IActivityCommitStrategy strategy) |
| | | 84 | | { |
| | 0 | 85 | | var registration = ObjectRegistrationFactory.Describe(strategy); |
| | 0 | 86 | | registration.Metadata.Name = name; |
| | 0 | 87 | | registration.Metadata.DisplayName = displayName; |
| | 0 | 88 | | registration.Metadata.Description = description; |
| | 0 | 89 | | Add(registration); |
| | 0 | 90 | | } |
| | | 91 | | |
| | | 92 | | public void Add(ActivityCommitStrategyRegistration registration) |
| | | 93 | | { |
| | 56 | 94 | | Services.Configure<CommitStateOptions>(options => options.ActivityCommitStrategies[registration.Metadata.Name] = |
| | 28 | 95 | | } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Sets the specified workflow commit strategy as the global default. |
| | | 99 | | /// The strategy will not be added to the registry and will only serve as a fallback when workflows do not specify t |
| | | 100 | | /// </summary> |
| | | 101 | | /// <param name="strategy">The workflow commit strategy instance to use as the default.</param> |
| | | 102 | | public void SetDefaultWorkflowCommitStrategy(IWorkflowCommitStrategy strategy) |
| | | 103 | | { |
| | 0 | 104 | | Services.Configure<CommitStateOptions>(options => options.DefaultWorkflowCommitStrategy = strategy); |
| | 0 | 105 | | } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Sets the specified activity commit strategy as the global default. |
| | | 109 | | /// The strategy will not be added to the registry and will only serve as a fallback when activities do not specify |
| | | 110 | | /// </summary> |
| | | 111 | | /// <param name="strategy">The activity commit strategy instance to use as the default.</param> |
| | | 112 | | public void SetDefaultActivityCommitStrategy(IActivityCommitStrategy strategy) |
| | | 113 | | { |
| | 0 | 114 | | Services.Configure<CommitStateOptions>(options => options.DefaultActivityCommitStrategy = strategy); |
| | 0 | 115 | | } |
| | | 116 | | |
| | | 117 | | public override void Apply() |
| | | 118 | | { |
| | 129 | 119 | | Services.AddSingleton<ICommitStrategyRegistry, DefaultCommitStrategyRegistry>(); |
| | 129 | 120 | | Services.AddStartupTask<PopulateCommitStrategyRegistry>(); |
| | 129 | 121 | | } |
| | | 122 | | } |