/// <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 AsyncClientStreamingCall <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="TResponse">レスポンスの型</typeparam> /// <typeparam name="TResult">実行結果の型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="converter">実行結果への変換処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult <TResult> > GetResultAsync <TResponse, TResult>(this AsyncUnaryCall <TResponse> call, Converter <TResponse, TResult> converter) where TResponse : class { try { return(GrpcResult.Create <TResult>(converter(await call.ResponseAsync.ConfigureAwait(false)), call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleResponseException <TResponse, TResult>(call, ex)); } finally { call.Dispose(); } }
/// <summary> /// 全てのレスポンスに対して指定された処理を実行します。 /// </summary> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="action">実行する処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> ForEachAsync <TResponse>(this AsyncServerStreamingCall <TResponse> call, Action <TResponse> action) where TResponse : class { try { while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { action(call.ResponseStream.Current); } 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="requests">リクエストを取得する処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult <TResponse> > WriteAndCompleteAsync <TRequest, TResponse>(this AsyncClientStreamingCall <TRequest, TResponse> call, IEnumerable <AsyncFunc <TRequest> > requests) where TRequest : class where TResponse : class { try { foreach (AsyncFunc <TRequest> request in requests) { await call.RequestStream.WriteAsync(await request().ConfigureAwait(false)).ConfigureAwait(false); } await CompleteAsyncInternal(call).ConfigureAwait(false); return(GrpcResult.Create <TResponse>(await call.ResponseAsync.ConfigureAwait(false), call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleResponseException(call, ex)); } }
/// <summary> /// 全てのレスポンスを受信します。 /// </summary> /// <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 <TResponse, TResult>(this AsyncServerStreamingCall <TResponse> call, Converter <TResponse, TResult> converter) 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 <TResponse, TResult>(call, ex)); } }
/// <summary> /// 全てのレスポンスを受信します。 /// </summary> /// <typeparam name="TRequest">リクエストの型</typeparam> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <returns>実行結果</returns> public static async Task <GrpcResult <IList <TResponse> > > ReadAllAsync <TRequest, TResponse>(this AsyncDuplexStreamingCall <TRequest, TResponse> call) where TRequest : class where TResponse : class { try { List <TResponse> list = new List <TResponse>(); while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { list.Add(call.ResponseStream.Current); } return(GrpcResult.Create <IList <TResponse> >(await Task.FromResult(list).ConfigureAwait(false), call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleResponseListException(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); } } }