示例#1
0
        protected override void AddEventHandlerDefinition <TEventArgs>(
            RpcEventInfo eventInfo,
            Func <RpcObjectRequest, IServiceProvider?, IRpcAsyncStreamWriter <TEventArgs>, IRpcContext, ValueTask> beginEventProducer,
            RpcStub <TService> serviceStub,
            IGrpcMethodBinder binder)
        {
            GrpcCore.ServerStreamingServerMethod <RpcObjectRequest, TEventArgs> handler = (request, responseStream, context) =>
            {
                using (var scope = CreateServiceScope(serviceStub))
                {
                    return(beginEventProducer(request,
                                              scope?.ServiceProvider,
                                              new GrpcAsyncStreamWriter <TEventArgs>(responseStream),
                                              new GrpcCallContext(context)).AsTask());
                }
            };

            var beginEventProducerName = $"Begin{eventInfo.Name}";

            binder.AddMethod(
                GrpcMethodDefinition.Create <RpcObjectRequest, TEventArgs>(
                    GrpcCore.MethodType.ServerStreaming,
                    eventInfo.FullServiceName,
                    beginEventProducerName,
                    serviceStub.Serializer),
                handler);
        }
示例#2
0
        protected override void AddCallbackMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, Action <TReturn>, CancellationToken, Task> serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter, RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub, RpcOperationInfo operationInfo, IGrpcMethodBinder binder)
            where TResponseReturn : class
        {
            var serializer = serviceStub.Serializer;

            GrpcCore.ServerStreamingServerMethod <TRequest, TResponseReturn> handler = (request, responseStream, context) =>
            {
                using (var serviceScope = CreateServiceScope(serviceStub))
                {
                    return(serviceStub.CallCallbackMethod(
                               request,
                               serviceScope?.ServiceProvider,
                               new GrpcCallContext(context),
                               new GrpcAsyncStreamWriter <TResponseReturn>(responseStream),
                               serviceCaller,
                               responseConverter,
                               faultHandler,
                               serializer).AsTask());
                }
            };

            binder.AddMethod(
                GrpcMethodDefinition.Create <TRequest, TResponseReturn>(
                    GrpcCore.MethodType.ServerStreaming,
                    operationInfo.FullServiceName,
                    operationInfo.Name,
                    serviceStub.Serializer),
                handler);
        }
 public void AddMethod <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, GrpcCore.ServerStreamingServerMethod <TRequest, TResponse> handler) where TResponse : class where TRequest : class
 {
     this.stubs.Add(new TestGrpcMethodStub(method, typeof(TRequest), typeof(TResponse), null));
 }
示例#4
0
 public void AddMethod <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, GrpcCore.ServerStreamingServerMethod <TRequest, TResponse> handler) where TResponse : class where TRequest : class
 {
     this.builder.AddMethod(method, handler);
 }