public async Task<ICollection<ChatMessage>> ListenChatAsync(int accountId) { Program.Log($"Starting RPC ListenChatAsync (accountId {accountId})", true); // parameters can be passed to call one by one or be composed // into a CallOptions using a fluent syntax. var callOptions = new CallOptions() .WithCancellationToken(CancellationToken.None) .WithDeadline(DateTime.UtcNow.AddMinutes(2)) .WithHeaders(Metadata.Empty); using (var call = _grpcClient.ListenChat(new ChatMessageRequest { AccountId = accountId }, callOptions)) { // Custom response header Metadata responseHeader = await call.ResponseHeadersAsync; Program.Log($"ListenChatAsync response header {String.Join(",", responseHeader.Select(m => m.ToString()))}"); var chatMessages = new List<ChatMessage>(); while (await call.ResponseStream.MoveNext()) { ChatMessage chatMessage = call.ResponseStream.Current; Program.Log($"RPC ListenChatAsync received {chatMessage}"); chatMessages.Add(chatMessage); } // Custom response trailer Metadata responseTrailer = call.GetTrailers(); Program.Log($"ListenChatAsync response trailer {String.Join(",", responseTrailer.Select(m => m.ToString()))}"); return chatMessages; } }
public void WithMethods() { var options = new CallOptions(); var metadata = new Metadata(); Assert.AreSame(metadata, options.WithHeaders(metadata).Headers); var deadline = DateTime.UtcNow; Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value); var cancellationToken = new CancellationTokenSource().Token; Assert.AreEqual(cancellationToken, options.WithCancellationToken(cancellationToken).CancellationToken); var writeOptions = new WriteOptions(); Assert.AreSame(writeOptions, options.WithWriteOptions(writeOptions).WriteOptions); var propagationToken = new ContextPropagationToken(CallSafeHandle.NullInstance, DateTime.UtcNow, CancellationToken.None, ContextPropagationOptions.Default); Assert.AreSame(propagationToken, options.WithPropagationToken(propagationToken).PropagationToken); var credentials = new FakeCallCredentials(); Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials); // Check that the original instance is unchanged. Assert.IsNull(options.Headers); Assert.IsNull(options.Deadline); Assert.AreEqual(CancellationToken.None, options.CancellationToken); Assert.IsNull(options.WriteOptions); Assert.IsNull(options.PropagationToken); Assert.IsNull(options.Credentials); }
public void WriteOptions_Unary() { helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => { context.WriteOptions = new WriteOptions(WriteFlags.NoCompress); return request; }); var callOptions = new CallOptions(writeOptions: new WriteOptions(WriteFlags.NoCompress)); Calls.BlockingUnaryCall(helper.CreateUnaryCall(callOptions), "abc"); }
protected async Task <TResponse> CallUnaryMethodAsync <TRequest, TResponse>(TRequest request, string serviceName, string methodName, CancellationToken ct) where TRequest : class where TResponse : class { var callOptions = new G.CallOptions(cancellationToken: ct); using (var call = _invoker.AsyncUnaryCall(GetMethodDefinition <TRequest, TResponse>(G.MethodType.Unary, serviceName, methodName), null, callOptions, request)) { return(await call.ResponseAsync.ConfigureAwait(false)); } }
public async Task <TResponse> CallUnaryMethodAsync <TRequest, TResponse>(TRequest request, string serviceName, string methodName, CancellationToken token) where TRequest : class where TResponse : class { var callOptions = new GrpcCore.CallOptions(cancellationToken: token).WithWaitForReady(); var methodDefinition = this.GetMethodDefinition <TRequest, TResponse>(GrpcCore.MethodType.Unary, serviceName, methodName); using (var call = this._invoker.AsyncUnaryCall(methodDefinition, null, callOptions, request)) { var result = await call.ResponseAsync.ConfigureAwait(false); return(result); } }
protected override TResponse CallUnaryMethodCore <TRequest, TResponse>(GrpcProxyMethod methodDef, TRequest request, CancellationToken cancellationToken) { if (methodDef is null) { throw new ArgumentNullException(nameof(methodDef)); } DateTime?deadline = this.GetCallDeadline(); var callOptions = new GrpcCore.CallOptions(deadline: deadline, cancellationToken: cancellationToken); var typedMethod = this.grpcMethodsCache.GetGrpcMethod <TRequest, TResponse>(methodDef); var response = this.grpcInvoker.BlockingUnaryCall(typedMethod, null, callOptions, request); return(response); }
protected override ValueTask <IAsyncStreamingServerCall <TResponse> > CallStreamingMethodAsync <TRequest, TResponse>(TRequest request, GrpcProxyMethod method, CancellationToken cancellationToken) { if (method is null) { throw new ArgumentNullException(nameof(method)); } DateTime?deadline = this.GetStreamingCallDeadline(); var callOptions = new GrpcCore.CallOptions(deadline: deadline, cancellationToken: cancellationToken); var typedMethod = this.grpcMethodsCache.GetGrpcMethod <TRequest, TResponse>(method); #pragma warning disable CA2000 // Dispose objects before losing scope return(new ValueTask <IAsyncStreamingServerCall <TResponse> >( new GrpcAsyncServerStreamingCall <TResponse>(this.grpcInvoker.AsyncServerStreamingCall(typedMethod, null, callOptions, request)))); #pragma warning restore CA2000 // Dispose objects before losing scope }
protected override async Task <TResponse> CallUnaryMethodCoreAsync <TRequest, TResponse>(GrpcProxyMethod methodDef, TRequest request, CancellationToken cancellationToken) { if (methodDef is null) { throw new ArgumentNullException(nameof(methodDef)); } DateTime?deadline = this.GetCallDeadline(); var callOptions = new GrpcCore.CallOptions(deadline: deadline, cancellationToken: cancellationToken); var typedMethod = this.grpcMethodsCache.GetGrpcMethod <TRequest, TResponse>(methodDef); using (var asyncCall = this.grpcInvoker.AsyncUnaryCall(typedMethod, null, callOptions, request)) { var response = await asyncCall.ResponseAsync.ContextFree(); // TODO: Handle response.Status return(response); } }
public void WithMethods() { var options = new CallOptions(); var metadata = new Metadata(); Assert.AreSame(metadata, options.WithHeaders(metadata).Headers); var deadline = DateTime.UtcNow; Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value); var token = new CancellationTokenSource().Token; Assert.AreEqual(token, options.WithCancellationToken(token).CancellationToken); // Change original instance is unchanged. Assert.IsNull(options.Headers); Assert.IsNull(options.Deadline); Assert.AreEqual(CancellationToken.None, options.CancellationToken); Assert.IsNull(options.WriteOptions); Assert.IsNull(options.PropagationToken); Assert.IsNull(options.Credentials); }
public async Task PropagateCancellation() { helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => { // check that we didn't obtain the default cancellation token. Assert.IsTrue(context.CancellationToken.CanBeCanceled); return "PASS"; }); helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => { var propagationToken = context.CreatePropagationToken(); Assert.IsNotNull(propagationToken.ParentCall); var callOptions = new CallOptions(propagationToken: propagationToken); return await Calls.AsyncUnaryCall(helper.CreateUnaryCall(callOptions), "xyz"); }); var cts = new CancellationTokenSource(); var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(cancellationToken: cts.Token))); await call.RequestStream.CompleteAsync(); Assert.AreEqual("PASS", await call); }
public AsyncUnaryCall<global::Walletrpc.CloseWalletResponse> CloseWalletAsync(global::Walletrpc.CloseWalletRequest request, CallOptions options) { var call = CreateCall(__Method_CloseWallet, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.WalletExistsResponse> WalletExistsAsync(global::Walletrpc.WalletExistsRequest request, CallOptions options) { var call = CreateCall(__Method_WalletExists, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.PublishTransactionResponse> PublishTransactionAsync(global::Walletrpc.PublishTransactionRequest request, CallOptions options) { var call = CreateCall(__Method_PublishTransaction, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.ImportPrivateKeyResponse> ImportPrivateKeyAsync(global::Walletrpc.ImportPrivateKeyRequest request, CallOptions options) { var call = CreateCall(__Method_ImportPrivateKey, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.NextAddressResponse> NextAddressAsync(global::Walletrpc.NextAddressRequest request, CallOptions options) { var call = CreateCall(__Method_NextAddress, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.RenameAccountResponse> RenameAccountAsync(global::Walletrpc.RenameAccountRequest request, CallOptions options) { var call = CreateCall(__Method_RenameAccount, options); return Calls.AsyncUnaryCall(call, request); }
public override sealed GrpcCore.AsyncUnaryCall <TResponse> AsyncUnaryCall <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, string host, GrpcCore.CallOptions options, TRequest request) { Assert.NotNull(method); Assert.IsNotEmpty(method.Name); var response = UnaryFunc <TRequest, TResponse>(method.Name, request); return(new GrpcCore.AsyncUnaryCall <TResponse>(Task.FromResult(response), null, null, null, () => { })); }
public virtual grpc.AsyncDuplexStreamingCall <RequestMessage, ResponseMessage> CreateStreaming(grpc.CallOptions options) { return(CallInvoker.AsyncDuplexStreamingCall(__Method_CreateStreaming, null, options)); }
public override sealed GrpcCore.AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, string host, GrpcCore.CallOptions options) { throw new NotImplementedException(); }
public override sealed TResponse BlockingUnaryCall <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, string host, GrpcCore.CallOptions options, TRequest request) { Assert.NotNull(method); Assert.IsNotEmpty(method.Name); var response = UnaryFunc <TRequest, TResponse>(method.Name, request); return(response); }
public AsyncUnaryCall<global::Walletrpc.StartBtcdRpcResponse> StartBtcdRpcAsync(global::Walletrpc.StartBtcdRpcRequest request, CallOptions options) { var call = CreateCall(__Method_StartBtcdRpc, options); return Calls.AsyncUnaryCall(call, request); }
public CallInvocationDetails<string, string> CreateDuplexStreamingCall(CallOptions options = default(CallOptions)) { return new CallInvocationDetails<string, string>(channel, duplexStreamingMethod, options); }
public global::Walletrpc.AccountNumberResponse AccountNumber(global::Walletrpc.AccountNumberRequest request, CallOptions options) { var call = CreateCall(__Method_AccountNumber, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.RenameAccountResponse RenameAccount(global::Walletrpc.RenameAccountRequest request, CallOptions options) { var call = CreateCall(__Method_RenameAccount, options); return Calls.BlockingUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.AccountNumberResponse> AccountNumberAsync(global::Walletrpc.AccountNumberRequest request, CallOptions options) { var call = CreateCall(__Method_AccountNumber, options); return Calls.AsyncUnaryCall(call, request); }
public global::Walletrpc.NextAddressResponse NextAddress(global::Walletrpc.NextAddressRequest request, CallOptions options) { var call = CreateCall(__Method_NextAddress, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.BalanceResponse Balance(global::Walletrpc.BalanceRequest request, CallOptions options) { var call = CreateCall(__Method_Balance, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.ImportPrivateKeyResponse ImportPrivateKey(global::Walletrpc.ImportPrivateKeyRequest request, CallOptions options) { var call = CreateCall(__Method_ImportPrivateKey, options); return Calls.BlockingUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.BalanceResponse> BalanceAsync(global::Walletrpc.BalanceRequest request, CallOptions options) { var call = CreateCall(__Method_Balance, options); return Calls.AsyncUnaryCall(call, request); }
public global::Walletrpc.PublishTransactionResponse PublishTransaction(global::Walletrpc.PublishTransactionRequest request, CallOptions options) { var call = CreateCall(__Method_PublishTransaction, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.GetTransactionsResponse GetTransactions(global::Walletrpc.GetTransactionsRequest request, CallOptions options) { var call = CreateCall(__Method_GetTransactions, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.WalletExistsResponse WalletExists(global::Walletrpc.WalletExistsRequest request, CallOptions options) { var call = CreateCall(__Method_WalletExists, options); return Calls.BlockingUnaryCall(call, request); }
/// <summary> /// Creates a new call to given method. /// </summary> protected CallInvocationDetails <TRequest, TResponse> CreateCall <TRequest, TResponse>(Method <TRequest, TResponse> method, CallOptions options) where TRequest : class where TResponse : class { var interceptor = HeaderInterceptor; if (interceptor != null) { if (options.Headers == null) { options = options.WithHeaders(new Metadata()); } var authUri = authUriBase != null ? authUriBase + method.ServiceName : null; interceptor(authUri, options.Headers); } return(new CallInvocationDetails <TRequest, TResponse>(channel, method, Host, options)); }
public global::Walletrpc.CloseWalletResponse CloseWallet(global::Walletrpc.CloseWalletRequest request, CallOptions options) { var call = CreateCall(__Method_CloseWallet, options); return Calls.BlockingUnaryCall(call, request); }
public AsyncServerStreamingCall<global::Walletrpc.AccountNotificationsResponse> AccountNotifications(global::Walletrpc.AccountNotificationsRequest request, CallOptions options) { var call = CreateCall(__Method_AccountNotifications, options); return Calls.AsyncServerStreamingCall(call, request); }
public global::Walletrpc.StartBtcdRpcResponse StartBtcdRpc(global::Walletrpc.StartBtcdRpcRequest request, CallOptions options) { var call = CreateCall(__Method_StartBtcdRpc, options); return Calls.BlockingUnaryCall(call, request); }
public global::Walletrpc.ChangePassphraseResponse ChangePassphrase(global::Walletrpc.ChangePassphraseRequest request, CallOptions options) { var call = CreateCall(__Method_ChangePassphrase, options); return Calls.BlockingUnaryCall(call, request); }
public CallInvocationDetails<string, string> CreateUnaryCall(CallOptions options = default(CallOptions)) { return new CallInvocationDetails<string, string>(channel, unaryMethod, options); }
public AsyncUnaryCall<global::Walletrpc.ChangePassphraseResponse> ChangePassphraseAsync(global::Walletrpc.ChangePassphraseRequest request, CallOptions options) { var call = CreateCall(__Method_ChangePassphrase, options); return Calls.AsyncUnaryCall(call, request); }
public AsyncUnaryCall<global::Walletrpc.GetTransactionsResponse> GetTransactionsAsync(global::Walletrpc.GetTransactionsRequest request, CallOptions options) { var call = CreateCall(__Method_GetTransactions, options); return Calls.AsyncUnaryCall(call, request); }
public override sealed GrpcCore.AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(GrpcCore.Method <TRequest, TResponse> method, string host, GrpcCore.CallOptions options, TRequest request) { return(new GrpcCore.AsyncServerStreamingCall <TResponse>(ServerStreamingFunc <TRequest, TResponse>(method.Name, request, options.CancellationToken), Task.FromResult(new GrpcCore.Metadata()), null, null, () => { })); }