/// <summary> /// リクエストの送信を完了させます。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> CompleteRequestAsync <TRequest, TResponse>(this AsyncDuplexStreamingCall <TRequest, TResponse> call) { try { await call.RequestStream.CompleteAsync().ConfigureAwait(false); return(new GrpcResult(call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleException(call, ex)); } }
/// <summary> /// リクエストを送信します。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="request">リクエスト</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> WriteAsync <TRequest, TResponse>(this AsyncDuplexStreamingCall <TRequest, TResponse> call, AsyncFunc <TRequest> request) where TRequest : class where TResponse : class { try { await call.RequestStream.WriteAsync(await request().ConfigureAwait(false)).ConfigureAwait(false); return(new GrpcResult(call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleException(call, ex)); } }
/// <summary> /// 全てのレスポンスに対して指定された処理を実行します。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="onResponse">実行する処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> ForEachAsync <TRequest, TResponse>(this AsyncDuplexStreamingCall <TRequest, TResponse> call, AsyncAction <TResponse> onResponse) where TRequest : class where TResponse : class { try { while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { await onResponse(call.ResponseStream.Current).ConfigureAwait(false); } return(new GrpcResult(call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleException(call, ex)); } }
/// <summary> /// 全てのレスポンスを受信します。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <typeparam name="TResult">実行結果の型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="converter">実行結果への変換処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult <IList <TResult> > > ReadAllAsync <TRequest, TResponse, TResult>(this AsyncDuplexStreamingCall <TRequest, TResponse> call, Converter <TResponse, TResult> converter) where TRequest : class where TResponse : class { try { List <TResult> list = new List <TResult>(); while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { list.Add(converter(call.ResponseStream.Current)); } return(GrpcResult.Create <IList <TResult> >(list, call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleResponseListException <TRequest, TResponse, TResult>(call, ex)); } }
/// <summary> /// 全てのリクエストを送信します。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="requests">リクエストを取得する処理</param> /// <param name="completeStream">ストリームを完了させるかどうか</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> WriteAllAsync <TRequest, TResponse>(this AsyncDuplexStreamingCall <TRequest, TResponse> call, IEnumerable <AsyncFunc <TRequest> > requests, bool completeStream) where TRequest : class where TResponse : class { try { foreach (AsyncFunc <TRequest> request in requests) { await call.RequestStream.WriteAsync(await request().ConfigureAwait(false)).ConfigureAwait(false); } return(new GrpcResult(call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleException(call, ex)); } finally { if (completeStream) { await CompleteAsyncInternal(call); } } }