public async Task<object> ExecuteAsync(object[] parameters, IExecutionContext executionContext, CancellationToken cancellationToken) { if (parameters == null) throw new ArgumentNullException(nameof(parameters)); cancellationToken.ThrowIfCancellationRequested(); //Make sure that the # of parameters match. if (parameters.Length != Arguments.Count) { throw new ArgumentMismatchException($"The function '{Name}' contains {Arguments.Count} arguments but {parameters.Length} were specified."); } int argumentIndex = 0; //Copy the parameter values to the variable values foreach (var argument in Arguments) { //Look for the variable with the same id. var variable = Variables.FirstOrDefault(v => v.Id == argument.Id); //Check to make sure we found it. if (variable == null) { throw new ArgumentException($"Argument variable missing for argument '{argument.Name}' in function '{Name}'."); } //Copy the value variable.Value = parameters[argumentIndex]; argumentIndex++; } //Clear all of the errors Elements.ForAll(e => { var errorSource = e as IErrorSource; errorSource?.ClearErrors(); }); //Create the executor. var executor = new StatementExecutor(); //Execute the function. await executor.ExecuteAsync(executionContext, Elements, cancellationToken); //Find the return variable var returnVariable = Variables.FirstOrDefault(v => v.Id == ReturnValueVariable.ReturnVariableId); //return the returnVariable value (or null) return returnVariable?.Value; }
public async Task ExecuteAsync(IExecutionContext executionContext, CancellationToken token) { var executor = new StatementExecutor(); await executor.ExecuteAsync(executionContext, Elements, token); }