Various API enhancements
This commit is contained in:
parent
63ffacbb71
commit
f9a7ee45f1
|
|
@ -14,6 +14,17 @@ public enum ForOperator
|
|||
|
||||
public class For : Activity
|
||||
{
|
||||
public For()
|
||||
{
|
||||
}
|
||||
|
||||
public For(int start, int end, ForOperator forOperator = ForOperator.LessThanOrEqual)
|
||||
{
|
||||
Start = new Input<int>(start);
|
||||
End = new Input<int>(end);
|
||||
Operator = new Input<ForOperator>(forOperator);
|
||||
}
|
||||
|
||||
public Input<int> Start { get; set; } = new(0);
|
||||
public Input<int> End { get; set; } = new(0);
|
||||
public Input<int> Step { get; set; } = new(1);
|
||||
|
|
|
|||
36
src/core/Elsa.Core/Expressions/OutputExpression.cs
Normal file
36
src/core/Elsa.Core/Expressions/OutputExpression.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Models;
|
||||
|
||||
namespace Elsa.Expressions;
|
||||
|
||||
public class OutputExpression : IExpression
|
||||
{
|
||||
public OutputExpression(Output? output)
|
||||
{
|
||||
Output = output;
|
||||
}
|
||||
|
||||
public OutputExpression()
|
||||
{
|
||||
}
|
||||
|
||||
public Output? Output { get; set; }
|
||||
}
|
||||
|
||||
public class OutputExpression<T> : OutputExpression
|
||||
{
|
||||
public OutputExpression(Output<T>? output) : base(output)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class OutputExpressionHandler : IExpressionHandler
|
||||
{
|
||||
public ValueTask<object?> EvaluateAsync(IExpression expression, Type returnType, ExpressionExecutionContext context)
|
||||
{
|
||||
var outputExpression = (OutputExpression)expression;
|
||||
var output = outputExpression.Output;
|
||||
var value = context.Get(output);
|
||||
return ValueTask.FromResult(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,9 +33,12 @@ public static class ActivityExtensions
|
|||
|
||||
return query.Select(x => x!).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates an input from the activity's result.
|
||||
/// </summary>
|
||||
public static Input<T> CreateInput<T>(this Activity<T> activity) => activity.Result.CreateInput();
|
||||
|
||||
public static IEnumerable<Variable> GetVariables(this IActivity activity)
|
||||
{
|
||||
var properties = activity.GetType().GetProperties();
|
||||
|
|
|
|||
11
src/core/Elsa.Core/Extensions/OutputExtensions.cs
Normal file
11
src/core/Elsa.Core/Extensions/OutputExtensions.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Elsa.Models;
|
||||
|
||||
namespace Elsa.Extensions;
|
||||
|
||||
public static class OutputExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an input that references the specified output's value.
|
||||
/// </summary>
|
||||
public static Input<T> CreateInput<T>(this Output<T>? output) => new(output);
|
||||
}
|
||||
|
|
@ -38,4 +38,5 @@ public abstract class ActivityWithResult : Activity
|
|||
|
||||
public abstract class Activity<T> : ActivityWithResult
|
||||
{
|
||||
public new Output<T>? Result { get; set; }
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ public class ExpressionExecutionContext
|
|||
public object Get(RegisterLocationReference locationReference) => GetLocation(locationReference).Value!;
|
||||
public T Get<T>(RegisterLocationReference locationReference) => (T)Get(locationReference);
|
||||
public T? Get<T>(Input<T>? input) => input != null ? (T?)GetLocation(input.LocationReference).Value : default;
|
||||
public T? Get<T>(Output<T>? output) => output != null ? (T?)GetLocation(output.LocationReference).Value : default;
|
||||
public object? Get(Output? output) => output != null ? GetLocation(output.LocationReference).Value : default;
|
||||
public T? GetVariable<T>(string name) => (T?)GetVariable(name);
|
||||
public T? GetVariable<T>() => (T?)GetVariable(typeof(T).Name);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,14 @@ public class Input<T> : Input
|
|||
public Input(Variable<T> variable) : base(new VariableExpression(variable), variable, typeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
public Input(Output<T>? output) : base(new OutputExpression<T>(output), output?.LocationReference ?? new Literal(), typeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
public Input(Output? output) : base(new OutputExpression(output), output?.LocationReference ?? new Literal(), typeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
public Input(Literal<T> literal) : base(new LiteralExpression(literal.Value), literal, typeof(T))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
namespace Elsa.Models;
|
||||
|
||||
//public record NodeIdentity(ActivityNode ActivityNode, string NodeName);
|
||||
Loading…
Reference in a new issue