Ejemplo n.º 1
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, INetGrpcBinder <TService> binder)
        {
            var serializer = serviceStub.Serializer;
            ServerStreamingServerMethod <NetGrpcServiceActivator <TService>, TRequest, TResponseReturn> handler = (activator, request, responseStream, context) =>
            {
                return(serviceStub.CallCallbackMethod(
                           request,
                           activator.ServiceProvider,
                           new GrpcCallContext(context),
                           new GrpcAsyncStreamWriter <TResponseReturn>(responseStream),
                           serviceCaller,
                           responseConverter,
                           faultHandler,
                           serializer).AsTask());
            };

            var methodStub = GrpcMethodDefinition.Create <TRequest, TResponseReturn>(
                MethodType.ServerStreaming,
                operationInfo.FullServiceName, operationInfo.Name,
                serializer);

            binder.AddServerStreamingMethod(methodStub, operationInfo.Metadata, handler);
        }
Ejemplo n.º 2
0
        protected override void AddGenericBlockingMethodCore <TRequest, TReturn, TResponseReturn>(
            Func <TService, TRequest, CancellationToken, TReturn> serviceCaller,
            Func <TReturn, TResponseReturn>?responseConverter,
            RpcServerFaultHandler faultHandler,
            RpcStub <TService> serviceStub,
            RpcOperationInfo operationInfo,
            INetGrpcBinder <TService> binder)
        {
            var serializer = serviceStub.Serializer;

            Task <RpcResponse <TResponseReturn> > Handler(NetGrpcServiceActivator <TService> activator, TRequest request, ServerCallContext context)
            => serviceStub.CallBlockingMethod(
                request,
                new GrpcCallContext(context),
                serviceCaller,
                responseConverter,
                faultHandler,
                serializer,
                activator.ServiceProvider).AsTask();

            var methodStub = GrpcMethodDefinition.Create <TRequest, RpcResponse <TResponseReturn> >(
                MethodType.Unary,
                operationInfo.FullServiceName, operationInfo.Name,
                serializer);

            binder.AddUnaryMethod(methodStub, operationInfo.Metadata, Handler);
        }
Ejemplo n.º 3
0
        protected override void AddEventHandlerDefinition <TEventArgs>(
            RpcEventInfo eventInfo,
            Func <RpcObjectRequest, IServiceProvider?, IRpcAsyncStreamWriter <TEventArgs>, IRpcContext, ValueTask> beginEventProducer,
            RpcStub <TService> serviceStub,
            INetGrpcBinder <TService> binder)
        {
            ServerStreamingServerMethod <NetGrpcServiceActivator <TService>, RpcObjectRequest, TEventArgs> handler = (activator, request, responseStream, context) =>
                                                                                                                     beginEventProducer(request, activator.ServiceProvider, new GrpcAsyncStreamWriter <TEventArgs>(responseStream), new GrpcCallContext(context)).AsTask();

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

            binder.AddServerStreamingMethod(
                GrpcMethodDefinition.Create <RpcObjectRequest, TEventArgs>(
                    MethodType.ServerStreaming,
                    eventInfo.FullServiceName,
                    beginEventProducerName,
                    serviceStub.Serializer),
                eventInfo.Metadata,
                handler);
        }