public async Task <InvocationResponse> InvokeAsync(FunctionInvocation invocation)
        {
            // TODO: File InvocationResponse removal issue
            InvocationResponse response = new InvocationResponse
            {
                InvocationId = invocation.InvocationId
            };

            FunctionExecutionContext?executionContext = null;

            try
            {
                executionContext = _functionExecutionContextFactory.Create(invocation, _functionMap[invocation.FunctionId]);

                await _functionExecutionDelegate(executionContext);

                var parameterBindings = executionContext.OutputBindings;
                var result            = executionContext.InvocationResult;

                foreach (var paramBinding in parameterBindings)
                {
                    // TODO: ParameterBinding shouldn't happen here

                    foreach (var binding in executionContext.OutputBindings)
                    {
                        var parameterBinding = new ParameterBinding
                        {
                            Name = binding.Key,
                            Data = binding.Value.ToRpc()
                        };
                        response.OutputData.Add(parameterBinding);
                    }
                }
                if (result != null)
                {
                    var returnVal = result.ToRpc();

                    response.ReturnValue = returnVal;
                }

                response.Result = new StatusResult {
                    Status = Status.Success
                };
            }
            catch (Exception ex)
            {
                response.Result = new StatusResult
                {
                    Exception = ex.ToRpcException(),
                    Status    = Status.Failure
                };
            }
            finally
            {
                (executionContext as IDisposable)?.Dispose();
            }

            return(response);
        }
        public DefaultFunctionContext(IServiceScopeFactory serviceScopeFactory, IInvocationFeatures features)
        {
            _serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
            Features             = features ?? throw new ArgumentNullException(nameof(features));

            _invocation        = features.Get <FunctionInvocation>() ?? throw new InvalidOperationException($"The '{nameof(FunctionInvocation)}' feature is required.");
            FunctionDefinition = features.Get <FunctionDefinition>() ?? throw new InvalidOperationException($"The {nameof(Worker.FunctionDefinition)} feature is required.");
        }
Example #3
0
 public DefaultFunctionExecutionContext(IServiceScopeFactory serviceScopeFactory, FunctionInvocation invocation,
                                        FunctionDefinition definition)
 {
     _serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
     Invocation           = invocation ?? throw new ArgumentNullException(nameof(invocation));
     FunctionDefinition   = definition ?? throw new ArgumentNullException(nameof(definition));
     OutputBindings       = new Dictionary <string, object>();
 }
Example #4
0
 public Task <InvocationResponse> InvokeFunctionAsync(FunctionInvocation invocation)
 {
     return(_functionBroker.InvokeAsync(invocation));
 }