Skip to content

Commit

Permalink
Add non-generic GetVariable method and Python accessors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfmskywalker committed Dec 28, 2023
1 parent 511f5b5 commit 0bf562f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public Task HandleAsync(EvaluatingPython notification, CancellationToken cancell
sb.AppendLine(" def __init__(self, execution_context):");
sb.AppendLine(" self.execution_context = execution_context");
sb.AppendLine();
sb.AppendLine(" def get(self, name):");
sb.AppendLine(" return self.execution_context.GetVariable(name)");
sb.AppendLine();
sb.AppendLine(" def set(self, name, value):");
sb.AppendLine(" self.execution_context.SetVariable(name, value)");
sb.AppendLine();

foreach (var variable in variables)
{
Expand Down
5 changes: 5 additions & 0 deletions src/modules/Elsa.Python/Models/ExecutionContextProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public ExecutionContextProxy(ExpressionExecutionContext expressionExecutionConte
/// 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.
Expand Down

0 comments on commit 0bf562f

Please sign in to comment.