A non-generic version of GetVariable method has been added to the ExecutionContextProxy.cs, allowing direct access to variables without specifying a type. To leverage this, Python accessors for getting and setting workflow variables have been added to GenerateWorkflowVariableAccessors.cs. This enhances the interaction between the Python scripts and the context variables.
56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using Elsa.Expressions.Helpers;
|
|
using Elsa.Expressions.Models;
|
|
using Elsa.Extensions;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Elsa.Python.Models;
|
|
|
|
/// <summary>
|
|
/// Provides access to the current execution context.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public partial class ExecutionContextProxy
|
|
{
|
|
/// <summary>
|
|
/// Gets the current execution context.
|
|
/// </summary>
|
|
public ExpressionExecutionContext ExpressionExecutionContext { get; }
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ExecutionContextProxy"/> class.
|
|
/// </summary>
|
|
public ExecutionContextProxy(ExpressionExecutionContext expressionExecutionContext)
|
|
{
|
|
ExpressionExecutionContext = expressionExecutionContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the value of the specified variable.
|
|
/// </summary>
|
|
public object? GetVariable<T>(string name) => ExpressionExecutionContext.GetVariableInScope(name).ConvertTo<T>();
|
|
|
|
/// <summary>
|
|
/// Gets the value of the specified variable.
|
|
/// </summary>
|
|
public object? GetVariable(string name) => ExpressionExecutionContext.GetVariableInScope(name);
|
|
|
|
/// <summary>
|
|
/// Sets the value of the specified variable.
|
|
/// </summary>
|
|
public void SetVariable(string name, object? value) => ExpressionExecutionContext.SetVariable(name, value);
|
|
|
|
/// <summary>
|
|
/// Gets the workflow instance ID.
|
|
/// </summary>
|
|
public string WorkflowInstanceId => ExpressionExecutionContext.GetWorkflowExecutionContext().Id;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the correlation ID.
|
|
/// </summary>
|
|
public string? CorrelationId
|
|
{
|
|
get => ExpressionExecutionContext.GetWorkflowExecutionContext().CorrelationId;
|
|
set => ExpressionExecutionContext.GetWorkflowExecutionContext().CorrelationId = value;
|
|
}
|
|
|
|
} |