Beispiel #1
0
        public static T GetCurrent <T>(this IAsyncResponseStream <T> responseStream) where T : class
        {
            if (!(responseStream is AsyncResponseStream <T> grpcResponseStream))
            {
                throw new InvalidCastException("The stream is not grpc stream!");
            }

            return(grpcResponseStream.StreamReader.Current);
        }
Beispiel #2
0
        public static Task <bool> MoveNextAsync <T>(this IAsyncResponseStream <T> responseStream, CancellationToken cancellationToken) where T : class
        {
            if (!(responseStream is AsyncResponseStream <T> grpcResponseStream))
            {
                throw new InvalidCastException("The stream is not grpc stream!");
            }

            return(grpcResponseStream.StreamReader.MoveNext(cancellationToken));
        }
Beispiel #3
0
        public static Task WriteAsync <T>(this IAsyncResponseStream <T> serverStream, T message) where T : class
        {
            if (!(serverStream is AsyncResponseStream <T> grpcServerStream))
            {
                throw new InvalidCastException("The stream is not grpc stream!");
            }

            return(grpcServerStream.GrpcWriter.WriteAsync(message));
        }
Beispiel #4
0
        public Task ServerStreamAsync <TRequest, TResponse>(TRequest request, IAsyncResponseStream <TResponse> response, string service, string methodName) where TRequest : class where TResponse : class
        {
            var client      = getProxyer(service);
            var channelInfo = client.GetChannel();
            var invoker     = channelInfo.GetInvoker(_provider);
            var method      = GetMethod <TRequest, TResponse>(service, methodName, MethodType.ClientStreaming);

            var result         = invoker.AsyncServerStreamingCall(method, channelInfo.Options.Address, new CallOptions(), request);
            var responseStream = (AsyncResponseStream <TResponse>)response;

            responseStream.StreamReader = result.ResponseStream;
            return(result.ResponseHeadersAsync);
        }