Minor renaming

This commit is contained in:
Sipke Schoorstra 2022-11-23 11:20:35 +01:00
parent 0f358e72f9
commit 8a4e219e07
15 changed files with 45 additions and 116 deletions

View file

@ -12,6 +12,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Identity.Features;
/// <summary>
/// Provides identity feature to authenticate & authorize API requests.
/// </summary>
[DependsOn(typeof(SystemClockFeature))]
public class IdentityFeature : FeatureBase
{

View file

@ -4,7 +4,7 @@ using Elsa.Workflows.Api.Features;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection;
public static class DependencyInjectionExtensions
public static class ModuleExtensions
{
public static IModule UseWorkflowApiEndpoints(this IModule module, Action<WorkflowsApiFeature>? configure = default)
{

View file

@ -77,14 +77,19 @@ public abstract class Composite : ActivityBase
context.StopPropagation();
}
protected static Inline From(Func<ActivityExecutionContext, ValueTask> activity) => new(activity);
protected static Inline From(Func<ValueTask> activity) => new(activity);
protected static Inline From(Action<ActivityExecutionContext> activity) => new(activity);
protected static Inline From(Action activity) => new(activity);
protected static Inline<TResult> From<TResult>(Func<ActivityExecutionContext, ValueTask<TResult>> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> From<TResult>(Func<ValueTask<TResult>> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> From<TResult>(Func<ActivityExecutionContext, TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> From<TResult>(Func<TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline Inline(Func<ActivityExecutionContext, ValueTask> activity) => new(activity);
protected static Inline Inline(Func<ValueTask> activity) => new(activity);
protected static Inline Inline(Action<ActivityExecutionContext> activity) => new(activity);
protected static Inline Inline(Action activity) => new(activity);
protected static Inline<TResult> Inline<TResult>(Func<ActivityExecutionContext, ValueTask<TResult>> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> Inline<TResult>(Func<ValueTask<TResult>> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> Inline<TResult>(Func<ActivityExecutionContext, TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static Inline<TResult> Inline<TResult>(Func<TResult> activity, MemoryBlockReference? output = default) => new(activity, output);
protected static SetVariable<T> SetVariable<T>(Variable<T> variable, T value) => new(variable, value);
protected static SetVariable<T> SetVariable<T>(Variable<T> variable, Func<ExpressionExecutionContext, T> value) => new(variable, value);
protected static SetVariable<T> SetVariable<T>(Variable<T> variable, Func<T> value) => new(variable, value);
protected static SetVariable<T> SetVariable<T>(Variable<T> variable, Variable<T> value) => new(variable, value);
}
/// <summary>

View file

@ -10,7 +10,7 @@ namespace Elsa.Workflows.Core.Activities.Flowchart.Activities;
[Activity("Elsa", "Flow", "Merge multiple branches into a single branch of execution.")]
public class FlowJoin : ActivityBase, IJoinNode
{
[Input] public Input<Models.JoinMode> Mode { get; set; } = new(Models.JoinMode.WaitAll);
[Input] public Input<Models.FlowJoinMode> Mode { get; set; } = new(Models.FlowJoinMode.WaitAll);
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
@ -23,14 +23,14 @@ public class FlowJoin : ActivityBase, IJoinNode
switch (mode)
{
case Models.JoinMode.WaitAll:
case Models.FlowJoinMode.WaitAll:
// If all left-inbound activities have executed, complete & continue.
var haveAllInboundActivitiesExecuted = inboundActivities.All(x => flowScope.GetExecutionCount(x) > executionCount);
if (haveAllInboundActivitiesExecuted)
await context.CompleteActivityAsync();
break;
case Models.JoinMode.WaitAny:
case Models.FlowJoinMode.WaitAny:
// Only complete if we haven't already executed.
var alreadyExecuted = inboundActivities.Max(x => flowScope.GetExecutionCount(x)) == executionCount;

View file

@ -1,6 +1,6 @@
namespace Elsa.Workflows.Core.Activities.Flowchart.Models;
public enum JoinMode
public enum FlowJoinMode
{
WaitAll,
WaitAny

View file

@ -1,5 +1,6 @@
using System.Collections.Immutable;
using Elsa.Common.Extensions;
using Elsa.Workflows.Core.Activities.Flowchart.Models;
using Elsa.Workflows.Core.Attributes;
using Elsa.Workflows.Core.Behaviors;
using Elsa.Workflows.Core.Models;
@ -8,18 +9,13 @@ using Elsa.Workflows.Core.Services;
namespace Elsa.Workflows.Core.Activities;
[Activity("Elsa", "Control Flow", "Branch execution into multiple branches.")]
public class Fork : Activity
public class Fork : ActivityBase
{
public Fork()
{
Behaviors.Remove<AutoCompleteBehavior>();
}
/// <summary>
/// Controls when this activity yields control back to its parent activity.
/// </summary>
[Input]
public JoinMode JoinMode { get; set; } = JoinMode.WaitAny;
public ForkJoinMode JoinMode { get; set; } = ForkJoinMode.WaitAny;
/// <summary>
/// The branches to schedule.
@ -27,6 +23,7 @@ public class Fork : Activity
[Port]
public ICollection<IActivity> Branches { get; set; } = new List<IActivity>();
/// <inheritdoc />
protected override void Execute(ActivityExecutionContext context) => context.ScheduleActivities(Branches.Reverse(), CompleteChildAsync);
private async ValueTask CompleteChildAsync(ActivityExecutionContext context, ActivityExecutionContext childContext)
@ -46,7 +43,7 @@ public class Fork : Activity
switch (joinMode)
{
case JoinMode.WaitAny:
case ForkJoinMode.WaitAny:
{
// Remove any and all bookmarks from other branches.
RemoveBookmarks(context);
@ -55,7 +52,7 @@ public class Fork : Activity
await CompleteAsync(context);
}
break;
case JoinMode.WaitAll:
case ForkJoinMode.WaitAll:
{
var allSet = allChildActivityIds.All(x => completedActivityIds.Contains(x));

View file

@ -0,0 +1,7 @@
namespace Elsa.Workflows.Core.Activities;
public enum ForkJoinMode
{
WaitAll,
WaitAny
}

View file

@ -1,84 +0,0 @@
using Elsa.Common.Extensions;
using Elsa.Workflows.Core.Attributes;
using Elsa.Workflows.Core.Models;
namespace Elsa.Workflows.Core.Activities;
public enum JoinMode
{
WaitAny,
WaitAll
}
public class Join : Activity
{
public Join(JoinMode joinMode = Activities.JoinMode.WaitAny)
{
JoinMode = new Input<JoinMode>(joinMode);
}
[Input] public Input<JoinMode> JoinMode { get; set; }
protected override void Execute(ActivityExecutionContext context)
{
var joinMode = context.Get(JoinMode);
switch (joinMode)
{
case Activities.JoinMode.WaitAny:
{
// Remove any and all bookmarks from other branches.
RemoveBookmarks(context);
}
break;
case Activities.JoinMode.WaitAll:
{
var workflowExecutionContext = context.WorkflowExecutionContext;
// Record last executed activity ID.
var lastActivityId = context.WorkflowExecutionContext.ExecutionLog.LastOrDefault(x => x.EventName == WorkflowExecutionLogEventNames.Executed)?.ActivityId;
if (lastActivityId != null)
{
var recordedActivitiesKey = $"{Id}:RecordedActivities";
var recordedActivityIds = workflowExecutionContext.UpdateProperty<HashSet<string>>(recordedActivitiesKey, set =>
{
set ??= new HashSet<string>();
set.Add(lastActivityId);
return set;
});
var inboundActivityIds = context.ActivityNode.Parents.Select(x => x.Activity.Id).ToHashSet();
var allSet = inboundActivityIds.All(x => recordedActivityIds.Contains(x));
if (!allSet)
{
// If not all inbound activities have executed yet, instruct engine to not complete this activity.
context.PreventContinuation();
}
else
{
// If all inbound activities have executed, clean global state.
workflowExecutionContext.Properties.Remove(recordedActivitiesKey);
}
}
break;
}
}
}
private void RemoveBookmarks(ActivityExecutionContext context)
{
var workflowExecutionContext = context.WorkflowExecutionContext;
// Remove all bookmarks of ancestors and siblings.
var joinNode = context.ActivityNode;
var ancestors = joinNode.Ancestors().Select(x => x.Activity.Id);
var siblingsAndCousins = joinNode.SiblingsAndCousins().Select(x => x.Activity.Id);
var activitiesInPath = ancestors.Concat(siblingsAndCousins).ToHashSet();
// Remove any bookmarks of any ancestors.
workflowExecutionContext.Bookmarks.RemoveWhere(x => activitiesInPath.Contains(x.ActivityId));
}
}

View file

@ -5,7 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Workflows.Core;
public static class DependencyInjectionExtensions
public static class ModuleExtensions
{
public static IModule UseWorkflows(this IModule configuration, Action<WorkflowsFeature>? configure = default)
{
@ -13,7 +13,7 @@ public static class DependencyInjectionExtensions
return configuration;
}
public static IServiceCollection AddDataDrive<T>(this IServiceCollection services) where T : class, IStorageDriver
public static IServiceCollection AddStorageDriver<T>(this IServiceCollection services) where T : class, IStorageDriver
{
return services.AddSingleton<IStorageDriver, T>();
}

View file

@ -89,8 +89,8 @@ public class WorkflowsFeature : FeatureBase
// Data drives.
.AddSingleton<IStorageDriverManager, StorageDriverManager>()
.AddDataDrive<WorkflowStateStorageDriver>()
.AddDataDrive<MemoryStorageDriver>()
.AddStorageDriver<WorkflowStateStorageDriver>()
.AddStorageDriver<MemoryStorageDriver>()
// Logging
.AddLogging();

View file

@ -12,12 +12,12 @@ public abstract class Trigger : ActivityBase, ITrigger
{
}
ValueTask<IEnumerable<object>> ITrigger.GetTriggerPayloadsAsync(TriggerIndexingContext context) => GetTriggerDataAsync(context);
ValueTask<IEnumerable<object>> ITrigger.GetTriggerPayloadsAsync(TriggerIndexingContext context) => GetTriggerPayloadsAsync(context);
/// <summary>
/// Override this method to return trigger data.
/// </summary>
protected virtual ValueTask<IEnumerable<object>> GetTriggerDataAsync(TriggerIndexingContext context)
protected virtual ValueTask<IEnumerable<object>> GetTriggerPayloadsAsync(TriggerIndexingContext context)
{
var hashes = GetTriggerPayloads(context);
return ValueTask.FromResult(hashes);

View file

@ -1,6 +1,7 @@
using Elsa.Extensions;
using Elsa.Features.Extensions;
using Elsa.Identity;
using Elsa.Identity.Extensions;
using Elsa.Identity.Features;
using Elsa.Identity.Options;
using Elsa.JavaScript.Activities;
@ -60,7 +61,7 @@ services
.AddActivity<Event>()
.AddActivitiesFrom<Program>()
)
.Use<IdentityFeature>(identity =>
.UseIdentity(identity =>
{
identity.CreateDefaultUser = true;
identity.IdentityOptions = options => identitySection.Bind(options);

View file

@ -9,7 +9,7 @@ public class FinishForkedWorkflow : WorkflowBase
{
workflow.WithRoot(new Fork
{
JoinMode = JoinMode.WaitAll,
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence

View file

@ -50,7 +50,7 @@ public class JoinAnyForkWorkflow : WorkflowBase
}
},
},
JoinMode = JoinMode.WaitAny
JoinMode = ForkJoinMode.WaitAny
},
new WriteLine("End")
}

View file

@ -21,7 +21,7 @@ public class BreakWhileBlockForkWorkflow : WorkflowBase
{
new Fork
{
JoinMode = JoinMode.WaitAll,
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence