Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance: Add isStart property to determine if current node is a start… #5040

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public record ActivityDescriptor
/// </summary>
public bool IsBrowsable { get; set; }

/// <summary>
/// Whether this activity type is a start activity.
/// </summary>
public bool IsStart { get; set; }

/// <summary>
/// Whether this activity type is a terminal activity.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Elsa.Workflows.Core/Activities/Start.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.CompilerServices;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.Contracts;
using JetBrains.Annotations;

namespace Elsa.Workflows.Activities;
Expand All @@ -9,7 +10,7 @@ namespace Elsa.Workflows.Activities;
/// </summary>
[Activity("Elsa", "Flow", "A milestone activity that marks the start of a flowchart.", Kind = ActivityKind.Action)]
[PublicAPI]
public class Start : CodeActivity
public class Start : CodeActivity, IStartNode
{
/// <inheritdoc />
public Start([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line)
Expand Down
8 changes: 8 additions & 0 deletions src/modules/Elsa.Workflows.Core/Contracts/IStartNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Elsa.Workflows.Contracts;

/// <summary>
/// Marks an activity as a terminal activity.
/// </summary>
public interface IStartNode
{
}
5 changes: 5 additions & 0 deletions src/modules/Elsa.Workflows.Core/Models/ActivityDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class ActivityDescriptor
/// </summary>
public bool IsBrowsable { get; set; } = true;

/// <summary>
/// Whether this activity type is a start activity.
/// </summary>
public bool IsStart { get; set; }

/// <summary>
/// Whether this activity type is a terminal activity.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Elsa.Workflows.Core/Services/ActivityDescriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ where typeof(IActivity).IsAssignableFrom(prop.PropertyType)
var isTrigger = activityType.IsAssignableTo(typeof(ITrigger));
var browsableAttr = activityType.GetCustomAttribute<BrowsableAttribute>();
var isTerminal = activityType.FindInterfaces((type, criteria) => type == typeof(ITerminalNode), null).Any();
var isStart = activityType.FindInterfaces((type, criteria) => type == typeof(IStartNode), null).Any();
var attributes = activityType.GetCustomAttributes(true).Cast<Attribute>().ToList();
var outputAttribute = attributes.OfType<OutputAttribute>().FirstOrDefault();

Expand All @@ -92,6 +93,7 @@ where typeof(IActivity).IsAssignableFrom(prop.PropertyType)
Outputs = (await DescribeOutputPropertiesAsync(outputProperties, cancellationToken)).ToList(),
IsContainer = typeof(IContainer).IsAssignableFrom(activityType),
IsBrowsable = browsableAttr == null || browsableAttr.Browsable,
IsStart = isStart,
IsTerminal = isTerminal,
Attributes = attributes,
Constructor = context =>
Expand Down