using Grpc.Core;
|
using Grpc.Core.Interceptors;
|
using System;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace HotelPms.Data.Util
|
{
|
public class GrpcClientInterceptor : Interceptor
|
{
|
/// <summary>
|
/// 一元调用(UnaryCall)
|
/// </summary>
|
/// <typeparam name="TRequest"></typeparam>
|
/// <typeparam name="TResponse"></typeparam>
|
/// <param name="request"></param>
|
/// <param name="context"></param>
|
/// <param name="continuation"></param>
|
/// <returns></returns>
|
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("AsyncUnaryCall");
|
Console.WriteLine("客户端调用执行开始");
|
var responseCon = continuation(request, context);
|
var response = new AsyncUnaryCall<TResponse>(responseCon.ResponseAsync, responseCon.ResponseHeadersAsync, responseCon.GetStatus, responseCon.GetTrailers, responseCon.Dispose);
|
Console.WriteLine("客户端调用执行结束"); //非同期処理のため、ここには処理未完成
|
return response;
|
}
|
|
private async Task<TResponse> MyAsyncStuff<TResponse>(AsyncUnaryCall<TResponse> responseAsync)
|
{
|
return await responseAsync;
|
}
|
|
public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> context, AsyncClientStreamingCallContinuation<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("AsyncClientStreamingCall");
|
return base.AsyncClientStreamingCall(context, continuation);
|
}
|
|
public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("AsyncDuplexStreamingCall");
|
return base.AsyncDuplexStreamingCall(context, continuation);
|
}
|
|
/// <summary>
|
/// 同期
|
/// </summary>
|
/// <typeparam name="TRequest"></typeparam>
|
/// <typeparam name="TResponse"></typeparam>
|
/// <param name="request"></param>
|
/// <param name="context"></param>
|
/// <param name="continuation"></param>
|
/// <returns></returns>
|
public override TResponse BlockingUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, BlockingUnaryCallContinuation<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("BlockingUnaryCall");
|
return base.BlockingUnaryCall(request, context, continuation);
|
}
|
|
public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("AsyncServerStreamingCall");
|
return base.AsyncServerStreamingCall(request, context, continuation);
|
}
|
|
public override Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, ServerCallContext context, ClientStreamingServerMethod<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("ClientStreamingServerHandler");
|
return base.ClientStreamingServerHandler(requestStream, context, continuation);
|
}
|
|
public override Task DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, DuplexStreamingServerMethod<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("DuplexStreamingServerHandler");
|
return base.DuplexStreamingServerHandler(requestStream, responseStream, context, continuation);
|
}
|
|
public override Task ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, ServerStreamingServerMethod<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("ServerStreamingServerHandler");
|
return base.ServerStreamingServerHandler(request, responseStream, context, continuation);
|
}
|
|
public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
|
{
|
Console.WriteLine("UnaryServerHandler");
|
return base.UnaryServerHandler(request, context, continuation);
|
}
|
}
|
}
|