Example #1
0
        public async Task <object> CallAsync(MethodInfo methodInfo, Func <object, Task> callback, CancellationToken token, Stream stream, params object[] pureArgs)
        {
            var call = await _factory.CreateAsync(_timeoutInterval);

            await call.StartAsync();

            //stream
            var contractMethod = _contract.Methods.Find(i => i.MethodInfo == methodInfo);
            var instanceMethod = new InstanceMethod(methodInfo);
            var methodContext  = new MethodContext(contractMethod, instanceMethod);
            var readStream     = GetReadStream(stream);
            var clientContext  = new ClientActionExecutingContext(_clientProxyId, _serviceProvider, _optionsName, call, instanceMethod, callback, token, _contract,
                                                                  contractMethod, readStream, pureArgs);

            //header
            var header = AdditionHeader;

            if (header != null && header.Count > 0)
            {
                foreach (var key in header.Keys)
                {
                    clientContext.Header.Add(key, header[key]);
                }
            }

            if (_middlewareBuilder != null)
            {
                await _middlewareBuilder.InvokeAsync(clientContext);

                return(clientContext.Result);
            }

            //onceTransfer will dispose after stream translate finished in OnceCall.
            return(await call.CallAsync(header, methodContext, callback, token, stream, pureArgs));
        }
 public ClientActionExecutingContext(Guid clientProxyId,
                                     IServiceProvider serviceProvider,
                                     string?optionsName,
                                     IOnceCall onceCall,
                                     InstanceMethod instanceMethod,
                                     Func <object?, Task>?callback,
                                     CancellationToken token,
                                     ContractInfo contract,
                                     ContractMethod contractMethod,
                                     ReadStream?stream,
                                     Dictionary <string, object?> header,
                                     object?[] pureArgs)
 {
     ClientProxyId     = clientProxyId;
     StartTime         = DateTimeOffset.Now;
     ServiceProvider   = serviceProvider;
     OnceCall          = onceCall;
     InstanceMethod    = instanceMethod;
     Callback          = callback;
     Contract          = contract;
     ContractMethod    = contractMethod;
     CancellationToken = token;
     Stream            = stream;
     PureArgs          = pureArgs;
     OptionsName       = optionsName;
     Header            = header;
 }
Example #3
0
        public async Task <object?> CallAsync(MethodInfo methodInfo, Func <object?, Task>?callback, CancellationToken token, Stream?stream,
                                              params object?[] pureArgs)
        {
            //merge header
            var mergeHeader = MergeHeader(AdditionHeader, _actionExecutingContextAccessor.Context?.Header);

            //start
            var call = await _factory.CreateAsync(_timeoutInterval);

            await call.StartAsync(GetAuthorizationToken(mergeHeader));

            //stream
            var contractMethod = _contract.Methods.First(i => i.MethodInfo == methodInfo);
            var instanceMethod = new InstanceMethod(methodInfo);
            var readStream     = GetReadStream(stream);
            var clientContext  = new ClientActionExecutingContext(_clientProxyId, _serviceProvider, _optionsName, call, instanceMethod, callback, token,
                                                                  _contract, contractMethod, readStream, mergeHeader, pureArgs);

            //invoke
            //onceTransfer will dispose after stream translate finished in OnceCall.
            await _middlewareBuilder.InvokeAsync(clientContext);

            return(clientContext.Result !);
        }