diff --git a/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs b/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs index f545b0881..5393a9f80 100644 --- a/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs +++ b/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs @@ -198,7 +198,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// An optional callback to invoke when the activity completes. /// An optional tag to associate with the activity execution. /// An optional list of variables to declare with the activity execution. - public ValueTask ScheduleActivityAsync(IActivity? activity, ActivityCompletionCallback? completionCallback, object? tag = default, IEnumerable? variables = default) + public ValueTask ScheduleActivityAsync(IActivity? activity, ActivityCompletionCallback? completionCallback, object? tag = null, IEnumerable? variables = null) { var options = new ScheduleWorkOptions { @@ -214,7 +214,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// /// The activity to schedule. /// The options used to schedule the activity. - public async ValueTask ScheduleActivityAsync(IActivity? activity, ScheduleWorkOptions? options = default) + public async ValueTask ScheduleActivityAsync(IActivity? activity, ScheduleWorkOptions? options = null) { await ScheduleActivityAsync(activity, this, options); } @@ -225,7 +225,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The activity to schedule. /// The activity execution context that owns the scheduled activity. /// The options used to schedule the activity. - public async ValueTask ScheduleActivityAsync(IActivity? activity, ActivityExecutionContext? owner, ScheduleWorkOptions? options = default) + public async ValueTask ScheduleActivityAsync(IActivity? activity, ActivityExecutionContext? owner, ScheduleWorkOptions? options = null) { var activityNode = activity != null ? WorkflowExecutionContext.FindNodeByActivity(activity) ?? throw new InvalidOperationException("The specified activity is not part of the workflow.") @@ -239,7 +239,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The activity node to schedule. /// The activity execution context that owns the scheduled activity. /// The options used to schedule the activity. - public async ValueTask ScheduleActivityAsync(ActivityNode? activityNode, ActivityExecutionContext? owner = default, ScheduleWorkOptions? options = default) + public async ValueTask ScheduleActivityAsync(ActivityNode? activityNode, ActivityExecutionContext? owner = null, ScheduleWorkOptions? options = null) { if (this.GetIsBackgroundExecution()) { @@ -261,7 +261,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable Variables = options?.Variables?.ToList(), Input = options?.Input } - : default + : null }; var scheduledActivities = this.GetBackgroundScheduledActivities().ToList(); @@ -303,7 +303,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The callback to invoke when the activities complete. /// An optional tag to associate with the activity execution. /// An optional list of variables to declare with the activity execution. - public ValueTask ScheduleActivities(IEnumerable activities, ActivityCompletionCallback? completionCallback, object? tag = default, IEnumerable? variables = default) + public ValueTask ScheduleActivities(IEnumerable activities, ActivityCompletionCallback? completionCallback, object? tag = null, IEnumerable? variables = null) { var options = new ScheduleWorkOptions { @@ -319,7 +319,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// /// The activities to schedule. /// The options used to schedule the activities. - public async ValueTask ScheduleActivities(IEnumerable activities, ScheduleWorkOptions? options = default) + public async ValueTask ScheduleActivities(IEnumerable activities, ScheduleWorkOptions? options = null) { foreach (var activity in activities) await ScheduleActivityAsync(activity, options); @@ -331,7 +331,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The payloads to create bookmarks for. /// An optional callback that is invoked when the bookmark is resumed. /// Whether or not the activity instance ID should be included in the bookmark payload. - public void CreateBookmarks(IEnumerable payloads, ExecuteActivityDelegate? callback = default, bool includeActivityInstanceId = true) + public void CreateBookmarks(IEnumerable payloads, ExecuteActivityDelegate? callback = null, bool includeActivityInstanceId = true) { foreach (var payload in payloads) CreateBookmark(new CreateBookmarkArgs @@ -360,7 +360,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// An optional callback that is invoked when the bookmark is resumed. /// Custom properties to associate with the bookmark. /// The created bookmark. - public Bookmark CreateBookmark(ExecuteActivityDelegate callback, IDictionary? metadata = default) + public Bookmark CreateBookmark(ExecuteActivityDelegate callback, IDictionary? metadata = null) { return CreateBookmark(new CreateBookmarkArgs { @@ -377,7 +377,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// Whether or not the activity instance ID should be included in the bookmark payload. /// Custom properties to associate with the bookmark. /// The created bookmark. - public Bookmark CreateBookmark(object stimulus, ExecuteActivityDelegate callback, bool includeActivityInstanceId = true, IDictionary? customProperties = default) + public Bookmark CreateBookmark(object stimulus, ExecuteActivityDelegate callback, bool includeActivityInstanceId = true, IDictionary? customProperties = null) { return CreateBookmark(new CreateBookmarkArgs { @@ -395,7 +395,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// Specifies whether to include the activity instance ID in the bookmark information. Defaults to true. /// Additional custom properties to associate with the bookmark. Defaults to null. /// The created bookmark. - public Bookmark CreateBookmark(object stimulus, bool includeActivityInstanceId, IDictionary? customProperties = default) + public Bookmark CreateBookmark(object stimulus, bool includeActivityInstanceId, IDictionary? customProperties = null) { return CreateBookmark(new CreateBookmarkArgs { @@ -411,9 +411,9 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The payload to associate with the bookmark. /// Custom properties to associate with the bookmark. /// The created bookmark. - public Bookmark CreateBookmark(object stimulus, IDictionary? metadata = default) + public Bookmark CreateBookmark(object stimulus, IDictionary? metadata = null) { - return CreateBookmark(new CreateBookmarkArgs + return CreateBookmark(new() { Stimulus = stimulus, Metadata = metadata @@ -424,7 +424,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// Creates a bookmark so that this activity can be resumed at a later time. /// Creating a bookmark will automatically suspend the workflow after all pending activities have executed. /// - public Bookmark CreateBookmark(CreateBookmarkArgs? options = default) + public Bookmark CreateBookmark(CreateBookmarkArgs? options = null) { var payload = options?.Stimulus; var callback = options?.Callback; @@ -569,7 +569,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// /// The output. /// The output value. - public object? Get(Output? output) => output == null ? default : Get(output.MemoryBlockReference()); + public object? Get(Output? output) => output == null ? null : Get(output.MemoryBlockReference()); /// /// Gets the value of the specified memory block. @@ -593,7 +593,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable public T? Get(MemoryBlockReference blockReference) { var value = Get(blockReference); - return value != default ? value.ConvertTo() : default; + return value != null ? value.ConvertTo() : default; } /// @@ -628,7 +628,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The memory block reference. /// The value to set. /// An optional callback that can be used to configure the memory block. - public void Set(MemoryBlockReference blockReference, object? value, Action? configure = default) => ExpressionExecutionContext.Set(blockReference, value, configure); + public void Set(MemoryBlockReference blockReference, object? value, Action? configure = null) => ExpressionExecutionContext.Set(blockReference, value, configure); /// /// Sets a value at the specified output. @@ -637,7 +637,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The value to set. /// The name of the output. /// The type of the output. - public void Set(Output? output, T? value, [CallerArgumentExpression("output")] string? outputName = default) => Set((Output?)output, value, outputName); + public void Set(Output? output, T? value, [CallerArgumentExpression("output")] string? outputName = null) => Set((Output?)output, value, outputName); /// /// Sets a value at the specified output. @@ -645,7 +645,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable /// The output. /// The value to set. /// The name of the output. - public void Set(Output? output, object? value, [CallerArgumentExpression("output")] string? outputName = default) + public void Set(Output? output, object? value, [CallerArgumentExpression("output")] string? outputName = null) { // Store the value in the expression execution memory block. ExpressionExecutionContext.Set(output, value); @@ -667,7 +667,7 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable private MemoryBlock? GetMemoryBlock(MemoryBlockReference locationBlockReference) { - return ExpressionExecutionContext.TryGetBlock(locationBlockReference, out var memoryBlock) ? memoryBlock : default; + return ExpressionExecutionContext.TryGetBlock(locationBlockReference, out var memoryBlock) ? memoryBlock : null; } void IDisposable.Dispose() diff --git a/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs index a0fc4e7ad..090cff8b8 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/ActivityExecutionContextExtensions.cs @@ -25,13 +25,13 @@ public static partial class ActivityExecutionContextExtensions /// /// Attempts to get a value from the input provided via . If a value was found, an attempt is made to convert it into the specified type T. /// - public static bool TryGetWorkflowInput(this ActivityExecutionContext context, string key, out T value, JsonSerializerOptions? serializerOptions = default) + public static bool TryGetWorkflowInput(this ActivityExecutionContext context, string key, out T value, JsonSerializerOptions? serializerOptions = null) { var wellKnownTypeRegistry = context.GetRequiredService(); if (context.WorkflowInput.TryGetValue(key, out var v)) { - value = v.ConvertTo(new ObjectConverterOptions(serializerOptions, wellKnownTypeRegistry))!; + value = v.ConvertTo(new(serializerOptions, wellKnownTypeRegistry))!; return true; } @@ -42,15 +42,15 @@ public static partial class ActivityExecutionContextExtensions /// /// Gets a value from the input provided via . If a value was found, an attempt is made to convert it into the specified type T. /// - public static T GetWorkflowInput(this ActivityExecutionContext context, JsonSerializerOptions? serializerOptions = default) => context.GetWorkflowInput(typeof(T).Name, serializerOptions); + public static T GetWorkflowInput(this ActivityExecutionContext context, JsonSerializerOptions? serializerOptions = null) => context.GetWorkflowInput(typeof(T).Name, serializerOptions); /// /// Gets a value from the input provided via . If a value was found, an attempt is made to convert it into the specified type T. /// - public static T GetWorkflowInput(this ActivityExecutionContext context, string key, JsonSerializerOptions? serializerOptions = default) + public static T GetWorkflowInput(this ActivityExecutionContext context, string key, JsonSerializerOptions? serializerOptions = null) { var wellKnownTypeRegistry = context.GetRequiredService(); - return context.WorkflowInput[key].ConvertTo(new ObjectConverterOptions(serializerOptions, wellKnownTypeRegistry))!; + return context.WorkflowInput[key].ConvertTo(new(serializerOptions, wellKnownTypeRegistry))!; } /// @@ -61,7 +61,7 @@ public static partial class ActivityExecutionContextExtensions /// Thrown when the specified activity does not implement . public static void SetResult(this ActivityExecutionContext context, object? value) { - var activity = context.Activity as IActivityWithResult ?? throw new Exception($"Cannot set result on activity {context.Activity.Id} because it does not implement {nameof(IActivityWithResult)}."); + var activity = context.Activity as IActivityWithResult ?? throw new($"Cannot set result on activity {context.Activity.Id} because it does not implement {nameof(IActivityWithResult)}."); context.Set(activity.Result, value, "Result"); } @@ -79,7 +79,7 @@ public static partial class ActivityExecutionContextExtensions /// The type of storage driver to use for the variable. /// A callback to configure the memory block. /// The created . - public static Variable CreateVariable(this ActivityExecutionContext context, string name, object? value, Type? storageDriverType = default, Action? configure = default) => + public static Variable CreateVariable(this ActivityExecutionContext context, string name, object? value, Type? storageDriverType = null, Action? configure = null) => context.ExpressionExecutionContext.CreateVariable(name, value, storageDriverType, configure); /// @@ -90,7 +90,7 @@ public static partial class ActivityExecutionContextExtensions /// The value of the variable. /// A callback to configure the memory block. /// The created . - public static Variable SetVariable(this ActivityExecutionContext context, string name, object? value, Action? configure = default) => + public static Variable SetVariable(this ActivityExecutionContext context, string name, object? value, Action? configure = null) => context.ExpressionExecutionContext.SetVariable(name, value, configure); /// diff --git a/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs index 044abe9b2..6745c6004 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs @@ -88,7 +88,7 @@ public static class WorkflowExecutionContextExtensions : WorkflowExecutionContext.Noop; // Store the bookmark to resume in the context. - workflowExecutionContext.ResumedBookmarkContext = new ResumedBookmarkContext(bookmark); + workflowExecutionContext.ResumedBookmarkContext = new(bookmark); logger.LogDebug("Scheduled activity {ActivityId} to resume from bookmark {BookmarkId}", bookmarkedActivity.Id, bookmark.Id); return workItem; diff --git a/src/modules/Elsa.Workflows.Core/Models/Bookmark.cs b/src/modules/Elsa.Workflows.Core/Models/Bookmark.cs index 9d062b336..e2ba868f8 100644 --- a/src/modules/Elsa.Workflows.Core/Models/Bookmark.cs +++ b/src/modules/Elsa.Workflows.Core/Models/Bookmark.cs @@ -26,13 +26,13 @@ public record Bookmark( string? ActivityInstanceId, DateTimeOffset CreatedAt, bool AutoBurn = true, - string? CallbackMethodName = default, + string? CallbackMethodName = null, bool AutoComplete = true, - IDictionary? Metadata = default) + IDictionary? Metadata = null) { /// [JsonConstructor] - public Bookmark() : this("", "", "", null, "", "", "", default, default) + public Bookmark() : this("", "", "", null, "", "", "", default, false) { } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Services/StimulusSender.cs b/src/modules/Elsa.Workflows.Runtime/Services/StimulusSender.cs index 7ded4d3a3..039bb6b05 100644 --- a/src/modules/Elsa.Workflows.Runtime/Services/StimulusSender.cs +++ b/src/modules/Elsa.Workflows.Runtime/Services/StimulusSender.cs @@ -38,7 +38,7 @@ public class StimulusSender( var resumed = await ResumeExistingWorkflowsAsync(stimulusHash, metadata, cancellationToken); responses.AddRange(resumed); - return new SendStimulusResult(responses); + return new(responses); } private async Task> TriggerNewWorkflowsAsync(string stimulusHash, StimulusMetadata? metadata = null, CancellationToken cancellationToken = default) @@ -129,7 +129,7 @@ public class StimulusSender( WorkflowInstanceId = workflowInstanceId, BookmarkId = metadata?.BookmarkId, StimulusHash = stimulusHash, - Options = new ResumeBookmarkOptions + Options = new() { Input = input, Properties = properties