Esempio n. 1
0
        public void Accept <TReq, TResp>(MethodDesciptorTyped <TReq, TResp> descr)
            where TReq : class
            where TResp : class
        {
            var method = descr.GetMethod();

            switch (descr.GetMethodType())
            {
            case MethodType.Unary:
                dict.Add(descr.name, new Func <TReq, Task <TResp> >(x => InvokeUnary(method, x)));
                break;

            case MethodType.ClientStreaming:
                dict.Add(descr.name, new Func <IObservable <TReq>, Task <TResp> >(x => InvokeClientStreaming(method, x)));
                break;

            case MethodType.ServerStreaming:
                dict.Add(descr.name, new Func <TReq, IObservable <TResp> >(x => InvokeServerStreaming(method, x)));
                break;

            case MethodType.DuplexStreaming:
                dict.Add(descr.name, new Func <IObservable <TReq>, IObservable <TResp> >(x => InvokeDuplexStreaming(method, x)));
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        public void Accept <TReq, TResp>(MethodDesciptorTyped <TReq, TResp> desc)
            where TReq : class
            where TResp : class
        {
            builder.AddMethod(desc.GetMethod(), async(requestStream, responseStream, context) =>
            {
                var reqStream = requestStream.ToObservable();


                await requestStream.ForEachAsync(async request =>
                {
                    // handle incoming request
                    // push response into stream
                    await responseStream.WriteAsync(new CustomResponse {
                        Payload = request.Payload
                    });
                });
            });
        }