Skip to content

Commit

Permalink
Make available TransientState to JS and Liquid script contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Dec 1, 2020
1 parent 853b756 commit 959dd86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ public Task Handle(EvaluatingJavaScriptExpression notification, CancellationToke

engine.SetValue("input", (Func<string, object>) (name => workflow.Input.GetVariable(name)));
engine.SetValue("variable", (Func<string, object>) (name => executionContext.CurrentScope.GetVariable(name)));
engine.SetValue("transientState", (Func<string, object>) (name => executionContext.TransientState.GetVariable(name)));
engine.SetValue("lastResult", (Func<string, object>) (name => executionContext.CurrentScope.LastResult?.Value));
engine.SetValue("correlationId", (Func<object>) (() => executionContext.Workflow.CorrelationId));
engine.SetValue("currentCulture", (Func<object>) (() => CultureInfo.InvariantCulture));
engine.SetValue("newGuid", (Func<string>) (() => Guid.NewGuid().ToString()));

var variables = executionContext.GetVariables();
var transientState = executionContext.TransientState;

foreach (var variable in variables)
engine.SetValue(variable.Key, variable.Value.Value);

foreach (var variable in transientState)
engine.SetValue(variable.Key, variable.Value.Value);

foreach (var activity in executionContext.Workflow.Activities.Where(x => !string.IsNullOrWhiteSpace(x.Name) && x.Output != null))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public Task Handle(EvaluatingLiquidExpression notification, CancellationToken ca
context.MemberAccessStrategy.Register<WorkflowExecutionContext, LiquidPropertyAccessor>("Input", x => new LiquidPropertyAccessor(name => ToFluidValue(x.Workflow.Input, name)));
context.MemberAccessStrategy.Register<WorkflowExecutionContext, LiquidPropertyAccessor>("Output", x => new LiquidPropertyAccessor(name => ToFluidValue(x.Workflow.Output, name)));
context.MemberAccessStrategy.Register<WorkflowExecutionContext, LiquidPropertyAccessor>("Variables", x => new LiquidPropertyAccessor(name => ToFluidValue(x.GetVariables(), name)));
context.MemberAccessStrategy.Register<WorkflowExecutionContext, LiquidPropertyAccessor>("TransientState", x => new LiquidPropertyAccessor(name => ToFluidValue(x.TransientState, name)));
context.MemberAccessStrategy.Register<WorkflowExecutionContext, LiquidObjectAccessor<IActivity>>("Activities", x => new LiquidObjectAccessor<IActivity>(name => GetActivityAsync(x, name)));
context.MemberAccessStrategy.Register<LiquidObjectAccessor<IActivity>, LiquidObjectAccessor<object>>((x, activityName) => new LiquidObjectAccessor<object>(outputKey => GetActivityOutput(x, activityName, outputKey)));
context.MemberAccessStrategy.Register<LiquidObjectAccessor<object>, object>((x, name) => x.GetValueAsync(name));
Expand Down

0 comments on commit 959dd86

Please sign in to comment.