public IReadOnlyList <object> GenerateMethodStubs <TService>(IRpcServerCore rpcServer) where TService : class
        {
            var builder = new LightweightServiceStubBuilder <TService>(null);

            var binder = new TestLightweightMethodBinder();

            builder.GenerateOperationHandlers(rpcServer, binder);

            return(binder.methods);
        }
        public IReadOnlyList <object> GenerateMethodStubs <TService>(IRpcServerCore rpcServer) where TService : class
        {
            var builder = new GrpcServiceStubBuilder <TService>(RpcBuilderUtil.GetServiceInfoFromType(typeof(TService)), null);

            var binder = new TestGrpcMethodBinder();

            builder.GenerateOperationHandlers(rpcServer, binder);

            return(binder.stubs);
        }
Beispiel #3
0
        public GrpcCore.ServerServiceDefinition Build(IRpcServerCore server)
        {
            var grpcServiceBuilder = new GrpcCore.ServerServiceDefinition.Builder();
            var binder             = new GrpcMethodBinder(grpcServiceBuilder);

            this.GenerateOperationHandlers(server, binder);

            var serviceDefinition = grpcServiceBuilder.Build();

            return(serviceDefinition);
        }
Beispiel #4
0
            where TResponseReturn : class;  // Needs to be class due to gRPC constraint


        protected virtual ImmutableRpcServerOptions CreateStubOptions(IRpcServerCore server)
        {
            if (server is null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            var registeredOptions = server.ServiceDefinitionsProvider.GetServiceOptions(typeof(TService));

            return(ImmutableRpcServerOptions.Combine(this.Options, registeredOptions));
        }
Beispiel #5
0
        protected override ImmutableRpcServerOptions CreateStubOptions(IRpcServerCore server)
        {
            var o = this.Options;
            var registeredOptions = server.ServiceDefinitionsProvider.GetServiceOptions(typeof(TService));

            if ((registeredOptions?.ReceiveMaxMessageSize != null && registeredOptions?.ReceiveMaxMessageSize != o?.ReceiveMaxMessageSize) ||
                (registeredOptions?.SendMaxMessageSize != null && registeredOptions?.SendMaxMessageSize != o?.SendMaxMessageSize))
            {
                // TODO: Logger.Warn("Message settings in registered options do not match provided options. Registered settings will be ignored.");
            }

            return(ImmutableRpcServerOptions.Combine(this.Options, registeredOptions));
        }
Beispiel #6
0
        protected RpcStub(IRpcServerCore server, ImmutableRpcServerOptions options)
        {
            this.Server           = server;
            this.ServicePublisher = this.Server.ServicePublisher;

            this.AllowAutoPublish = options?.AllowAutoPublish ?? this.Server.AllowAutoPublish;
            this.Serializer       = options?.Serializer ?? this.Server.Serializer;

            if (options != null && options.ExceptionConverters.Length > 0)
            {
                this.CustomFaultHandler = new RpcServerFaultHandler(this.Server.CustomFaultHandler, options.ExceptionConverters, null);
            }
            else
            {
                this.CustomFaultHandler = this.Server.CustomFaultHandler;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Generates the RPC method definitions and stub handlers and adds them to the provided methodBinder.
        /// </summary>
        /// <returns></returns>
        public RpcStub <TService> GenerateOperationHandlers(IRpcServerCore server, TMethodBinder methodBinder)
        {
            this.serviceStub = this.CreateServiceStub(server);

            foreach (var memberInfo in RpcBuilderUtil.EnumOperationHandlers(this.ServiceInfo, true))
            {
                if (memberInfo is RpcEventInfo eventInfo)
                {
                    this.AddEventHandler(this.serviceStub, eventInfo, methodBinder);
                }
                else if (memberInfo is RpcOperationInfo opInfo)
                {
                    switch (opInfo.MethodType)
                    {
                    case RpcMethodType.Unary:
                        this.CheckMethod(opInfo);
                        this.AddUnaryMethod(this.serviceStub, opInfo, methodBinder);
                        break;

                    case RpcMethodType.ServerStreaming:
                        this.CheckMethod(opInfo);
                        if (opInfo.CallbackParameterIndex == null)
                        {
                            // No callback. Implement using IAsyncEnumerable
                            this.AddServerStreamingMethod(this.serviceStub, opInfo, methodBinder);
                        }
                        else
                        {
                            // Implement using callback
                            this.AddCallbackMethod(this.serviceStub, opInfo, methodBinder);
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(this.serviceStub);
        }