diff --git a/.editorconfig b/.editorconfig index 4f12c6f1c..e558c49f3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -228,3 +228,8 @@ dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case + +# ReSharper properties +resharper_max_array_initializer_elements_on_line = 50 +resharper_max_initializer_elements_on_line = 1 +resharper_wrap_array_initializer_style = chop_if_long diff --git a/src/modules/Elsa.Workflows.Core/Abstractions/Activity.cs b/src/modules/Elsa.Workflows.Core/Abstractions/Activity.cs index 7d9cebe97..8526ecb3b 100644 --- a/src/modules/Elsa.Workflows.Core/Abstractions/Activity.cs +++ b/src/modules/Elsa.Workflows.Core/Abstractions/Activity.cs @@ -17,7 +17,6 @@ namespace Elsa.Workflows; public abstract class Activity : IActivity, ISignalHandler { private readonly ICollection _signalReceivedHandlers = new List(); - private readonly ICollection _signalCapturedHandlers = new List(); /// /// Constructor. @@ -161,44 +160,6 @@ public abstract class Activity : IActivity, ISignalHandler return ValueTask.CompletedTask; }); } - - /// - /// Override this method to handle any signals sent from downstream activities. - /// - protected virtual ValueTask OnCaptureSignalAsync(object signal, SignalContext context) - { - OnSignalCaptured(signal, context); - return ValueTask.CompletedTask; - } - - /// - /// Override this method to handle any signals sent from downstream activities. - /// - protected virtual void OnSignalCaptured(object signal, SignalContext context) - { - } - - /// - /// Register a signal handler delegate. - /// - protected void OnSignalCaptured(Type signalType, Func handler) => _signalCapturedHandlers.Add(new SignalHandlerRegistration(signalType, handler)); - - /// - /// Register a signal handler delegate. - /// - protected void OnSignalCaptured(Func handler) => OnSignalCaptured(typeof(T), (signal, context) => handler((T)signal, context)); - - /// - /// Register a signal handler delegate. - /// - protected void OnSignalCaptured(Action handler) - { - OnSignalCaptured((signal, context) => - { - handler(signal, context); - return ValueTask.CompletedTask; - }); - } /// /// Notify the workflow that this activity completed. @@ -220,23 +181,7 @@ public abstract class Activity : IActivity, ISignalHandler // Invoke behaviors. foreach (var behavior in Behaviors) await behavior.ExecuteAsync(context); } - - async ValueTask ISignalHandler.CaptureSignalAsync(object signal, SignalContext context) - { - // Give derived activity a chance to do something with the signal. - await OnCaptureSignalAsync(signal, context); - - // Invoke registered signal delegates for this particular type of signal. - var signalType = signal.GetType(); - var handlers = _signalCapturedHandlers.Where(x => x.SignalType == signalType); - - foreach (var registration in handlers) - await registration.Handler(signal, context); - - // Invoke behaviors. - foreach (var behavior in Behaviors) await behavior.CaptureSignalAsync(signal, context); - } - + async ValueTask ISignalHandler.ReceiveSignalAsync(object signal, SignalContext context) { // Give derived activity a chance to do something with the signal. diff --git a/src/modules/Elsa.Workflows.Core/Abstractions/Behavior.cs b/src/modules/Elsa.Workflows.Core/Abstractions/Behavior.cs index 5d1653102..b7fc56ef9 100644 --- a/src/modules/Elsa.Workflows.Core/Abstractions/Behavior.cs +++ b/src/modules/Elsa.Workflows.Core/Abstractions/Behavior.cs @@ -7,7 +7,6 @@ namespace Elsa.Workflows; public abstract class Behavior : IBehavior { private readonly ICollection _signalReceivedHandlers = new List(); - private readonly ICollection _signalCapturedHandlers = new List(); /// /// Initializes a new instance of the class. @@ -71,54 +70,6 @@ public abstract class Behavior : IBehavior { } - /// - /// Registers a delegate to be invoked when a signal of the specified type is received. - /// - /// The type of signal to register a handler for. - /// The delegate to invoke when a signal of the specified type is received. - protected void OnSignalCaptured(Type signalType, Func handler) => _signalCapturedHandlers.Add(new SignalHandlerRegistration(signalType, handler)); - - /// - /// Registers a delegate to be invoked when a signal of the specified type is received. - /// - /// The delegate to invoke when a signal of the specified type is received. - /// The type of signal to register a handler for. - protected void OnSignalCaptured(Func handler) => OnSignalCaptured(typeof(T), (signal, context) => handler((T)signal, context)); - - /// - /// Registers a delegate to be invoked when a signal of the specified type is received. - /// - /// The delegate to invoke when a signal of the specified type is received. - /// The type of signal to register a handler for. - protected void OnSignalCaptured(Action handler) - { - OnSignalCaptured((signal, context) => - { - handler(signal, context); - return ValueTask.CompletedTask; - }); - } - - /// - /// Registers a delegate to be invoked when a signal of the specified type is received. - /// - /// The type of signal to register a handler for. - /// The signal context. - protected virtual ValueTask OnSignalCapturedAsync(object signal, SignalContext context) - { - OnSignalCaptured(signal, context); - return ValueTask.CompletedTask; - } - - /// - /// Registers a delegate to be invoked when a signal of the specified type is received. - /// - /// The signal to register a handler for. - /// The signal context. - protected virtual void OnSignalCaptured(object signal, SignalContext context) - { - } - /// /// /// @@ -137,20 +88,7 @@ public abstract class Behavior : IBehavior protected virtual void Execute(ActivityExecutionContext context) { } - - async ValueTask ISignalHandler.CaptureSignalAsync(object signal, SignalContext context) - { - // Give derived activity a chance to do something with the signal. - await OnSignalCapturedAsync(signal, context); - - // Invoke registered signal delegates for this particular type of signal. - var signalType = signal.GetType(); - var handlers = _signalCapturedHandlers.Where(x => x.SignalType == signalType); - - foreach (var registration in handlers) - await registration.Handler(signal, context); - } - + async ValueTask ISignalHandler.ReceiveSignalAsync(object signal, SignalContext context) { // Give derived activity a chance to do something with the signal. diff --git a/src/modules/Elsa.Workflows.Core/Contracts/ISignalHandler.cs b/src/modules/Elsa.Workflows.Core/Contracts/ISignalHandler.cs index e069ac35a..a1e061992 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/ISignalHandler.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/ISignalHandler.cs @@ -5,11 +5,6 @@ namespace Elsa.Workflows.Contracts; /// public interface ISignalHandler { - /// - /// Captures a signal. - /// - ValueTask CaptureSignalAsync(object signal, SignalContext context); - /// /// Receives a signal. /// diff --git a/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs index b97fa8a03..d69308d04 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs @@ -363,26 +363,9 @@ public static class ActivityExecutionContextExtensions public static async ValueTask SendSignalAsync(this ActivityExecutionContext context, object signal) { var receivingContexts = new[] { context }.Concat(context.GetAncestors()).ToList(); - var capturingContexts = receivingContexts.AsEnumerable().Reverse().ToList(); var logger = context.GetRequiredService>(); - - // Let all ancestors capture the signal. - foreach (var ancestorContext in capturingContexts) - { - var signalContext = new SignalContext(ancestorContext, context, context.CancellationToken); - - if (ancestorContext.Activity is not ISignalHandler handler) - continue; - - logger.LogDebug("Capturing signal {SignalType} on activity {ActivityId} of type {ActivityType}", signal.GetType().Name, ancestorContext.Activity.Id, ancestorContext.Activity.Type); - await handler.CaptureSignalAsync(signal, signalContext); - - if (signalContext.StopPropagationRequested) - { - logger.LogDebug("Propagation of signal {SignalType} on activity {ActivityId} of type {ActivityType} was stopped", signal.GetType().Name, ancestorContext.Activity.Id, ancestorContext.Activity.Type); - return; - } - } + var signalType = signal.GetType(); + var signalTypeName = signalType.Name; // Let all ancestors receive the signal. foreach (var ancestorContext in receivingContexts) @@ -392,12 +375,12 @@ public static class ActivityExecutionContextExtensions if (ancestorContext.Activity is not ISignalHandler handler) continue; - logger.LogDebug("Receiving signal {SignalType} on activity {ActivityId} of type {ActivityType}", signal.GetType().Name, ancestorContext.Activity.Id, ancestorContext.Activity.Type); + logger.LogDebug("Receiving signal {SignalType} on activity {ActivityId} of type {ActivityType}", signalTypeName, ancestorContext.Activity.Id, ancestorContext.Activity.Type); await handler.ReceiveSignalAsync(signal, signalContext); if (signalContext.StopPropagationRequested) { - logger.LogDebug("Propagation of signal {SignalType} on activity {ActivityId} of type {ActivityType} was stopped", signal.GetType().Name, ancestorContext.Activity.Id, ancestorContext.Activity.Type); + logger.LogDebug("Propagation of signal {SignalType} on activity {ActivityId} of type {ActivityType} was stopped", signalTypeName, ancestorContext.Activity.Id, ancestorContext.Activity.Type); return; } } diff --git a/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs b/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs index e3572a7e5..950ce04fc 100644 --- a/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs +++ b/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs @@ -165,10 +165,10 @@ public class WorkflowDefinitionActivity : Composite, IInitializable return workflowGraph; } - private ActivityDescriptor FindActivityDescriptor(IServiceProvider serviceProvider) + private ActivityDescriptor? FindActivityDescriptor(IServiceProvider serviceProvider) { var activityRegistry = serviceProvider.GetRequiredService(); - return activityRegistry.Find(Type, Version) ?? activityRegistry.Find(Type) ?? throw new Exception($"Could not find activity descriptor for {Type}."); + return activityRegistry.Find(Type, Version) ?? activityRegistry.Find(Type); } async ValueTask IInitializable.InitializeAsync(InitializationContext context) @@ -188,10 +188,18 @@ public class WorkflowDefinitionActivity : Composite, IInitializable var activityDescriptor = FindActivityDescriptor(serviceProvider); - // Declare input and output variables. - DeclareInputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable)); - DeclareOutputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable)); - + if (activityDescriptor == null) + { + var logger = serviceProvider.GetRequiredService>(); + logger.LogWarning("Could not find activity descriptor for activity type {ActivityType}", Type); + } + else + { + // Declare input and output variables. + DeclareInputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable)); + DeclareOutputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable)); + } + // Set the root activity. Root = workflowGraph.Workflow; }