| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.Runtime.Notifications; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Signals that a queued child-workflow dispatch was accepted but activation was denied. |
| | | 7 | | /// </summary> |
| | 7 | 8 | | internal sealed record DispatchWorkflowActivationDenied( |
| | 6 | 9 | | string ParentWorkflowInstanceId, |
| | 6 | 10 | | string WorkflowInstanceId, |
| | 9 | 11 | | string ActivityTypeName, |
| | 13 | 12 | | string StimulusHash) : INotification; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Carries an internal bookmark-resume route through queued definition dispatch without persisting it on a child instan |
| | | 16 | | /// </summary> |
| | | 17 | | internal static class DispatchWorkflowActivationDeniedRoute |
| | | 18 | | { |
| | | 19 | | private const string ActivityTypeNameKey = "__elsa.internal.dispatch-activation-denied.activity-type-name"; |
| | | 20 | | private const string StimulusHashKey = "__elsa.internal.dispatch-activation-denied.stimulus-hash"; |
| | | 21 | | |
| | | 22 | | public static void Add(IDictionary<string, object> properties, string activityTypeName, string stimulusHash) |
| | | 23 | | { |
| | | 24 | | properties[ActivityTypeNameKey] = activityTypeName; |
| | | 25 | | properties[StimulusHashKey] = stimulusHash; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public static IDictionary<string, object>? SanitizeAndRead(IDictionary<string, object>? properties, out (string Acti |
| | | 29 | | { |
| | | 30 | | route = null; |
| | | 31 | | |
| | | 32 | | if (properties == null) |
| | | 33 | | return null; |
| | | 34 | | |
| | | 35 | | if (!properties.ContainsKey(ActivityTypeNameKey) && !properties.ContainsKey(StimulusHashKey)) |
| | | 36 | | return properties; |
| | | 37 | | |
| | | 38 | | // Do not mutate the caller's property bag: it may be shared with dispatch notification handlers. |
| | | 39 | | var sanitizedProperties = new Dictionary<string, object>(properties); |
| | | 40 | | var hasActivityTypeName = sanitizedProperties.Remove(ActivityTypeNameKey, out var activityTypeNameValue); |
| | | 41 | | var hasStimulusHash = sanitizedProperties.Remove(StimulusHashKey, out var stimulusHashValue); |
| | | 42 | | |
| | | 43 | | if (hasActivityTypeName && hasStimulusHash && activityTypeNameValue is string activityTypeName && !string.IsNull |
| | | 44 | | route = (activityTypeName, stimulusHash); |
| | | 45 | | |
| | | 46 | | return sanitizedProperties; |
| | | 47 | | } |
| | | 48 | | } |