/// <inheritdoc /> public async Task <object> Execute(WorkflowInstanceState state, CancellationToken token) { object result = await node.Execute(state, token); if (operation != null) { if (result != null) { if (!state.Variables.TryGetValue(VariableName, out object lhs)) { lhs = result is string? "" : Activator.CreateInstance(result.GetType()); } result = await operation.ExecuteAsync(new VariableProvider(state.Variables, new Variable("lhs", lhs), new Variable("rhs", result)), token); } } state.Variables[VariableName] = result; return(result); }
async Task <object> Execute(WorkflowInstanceState state, CancellationToken token, IInstanceNode current, object lastresult = null) { while (current != null) { try { if (state.Profiling) { Stopwatch stopwatch = Stopwatch.StartNew(); lastresult = await current.Execute(state, token); state.Logger.Performance(state.Workflow, current.NodeId, current.NodeName, stopwatch.Elapsed); } else { lastresult = await current.Execute(state, token); } if (token.IsCancellationRequested) { throw new TaskCanceledException(); } // used for workflow suspension if (lastresult is SuspendState) { return(lastresult); } } catch (Exception e) { state.Logger.Warning($"Error while executing node '{current.NodeName}'", e.Message); InstanceTransition next = await EvaluateTransitions(current, state.Logger, new VariableProvider(state.Variables, new Variable("error", e)), current.ErrorTransitions, token); if (next == null) { throw; } current = next.Target; continue; } try { InstanceTransition transition; if (lastresult is LoopCommand) { if (current.LoopTransitions.Count == 0) { throw new InvalidOperationException("Iterator node without any loop transitions detected."); } transition = await EvaluateTransitions(current, state.Logger, state.Variables, current.LoopTransitions, token); current = transition?.Target ?? current; } else { transition = await EvaluateTransitions(current, state.Logger, state.Variables, current.Transitions, token); current = transition?.Target; } } catch (Exception e) { state.Logger.Warning($"Error while evaluating transitions of node '{current?.NodeName}'", e.Message); InstanceTransition next = await EvaluateTransitions(current, state.Logger, new VariableProvider(state.Variables, new Variable("error", e)), current?.ErrorTransitions, token); if (next == null) { throw; } current = next.Target; } } return(lastresult); }
public static Task <object> Execute(IInstanceNode node, IDictionary <string, object> variables = null) { variables ??= new Dictionary <string, object>(); return(node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), new WorkableLogger(new NullLogger <NodeTest>(), new WorkableTask()), new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None)); }