本文整理汇总了C#中Grpc.Core.CallOptions类的典型用法代码示例。如果您正苦于以下问题:C# CallOptions类的具体用法?C# CallOptions怎么用?C# CallOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CallOptions类属于Grpc.Core命名空间,在下文中一共展示了CallOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListenChatAsync
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;
}
}
示例2: WithMethods
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);
}
示例3: WriteOptions_Unary
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");
}
示例4: WithMethods
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);
}
示例5: PropagateCancellation
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);
}
示例6: CreateUnaryCall
public CallInvocationDetails<string, string> CreateUnaryCall(CallOptions options = default(CallOptions))
{
return new CallInvocationDetails<string, string>(channel, unaryMethod, options);
}
示例7: StartBtcdRpc
public global::Walletrpc.StartBtcdRpcResponse StartBtcdRpc(global::Walletrpc.StartBtcdRpcRequest request, CallOptions options)
{
var call = CreateCall(__Method_StartBtcdRpc, options);
return Calls.BlockingUnaryCall(call, request);
}
示例8: CloseWallet
public global::Walletrpc.CloseWalletResponse CloseWallet(global::Walletrpc.CloseWalletRequest request, CallOptions options)
{
var call = CreateCall(__Method_CloseWallet, options);
return Calls.BlockingUnaryCall(call, request);
}
示例9: WalletExists
public global::Walletrpc.WalletExistsResponse WalletExists(global::Walletrpc.WalletExistsRequest request, CallOptions options)
{
var call = CreateCall(__Method_WalletExists, options);
return Calls.BlockingUnaryCall(call, request);
}
示例10: PublishTransaction
public global::Walletrpc.PublishTransactionResponse PublishTransaction(global::Walletrpc.PublishTransactionRequest request, CallOptions options)
{
var call = CreateCall(__Method_PublishTransaction, options);
return Calls.BlockingUnaryCall(call, request);
}
示例11: ImportPrivateKey
public global::Walletrpc.ImportPrivateKeyResponse ImportPrivateKey(global::Walletrpc.ImportPrivateKeyRequest request, CallOptions options)
{
var call = CreateCall(__Method_ImportPrivateKey, options);
return Calls.BlockingUnaryCall(call, request);
}
示例12: BalanceAsync
public AsyncUnaryCall<global::Walletrpc.BalanceResponse> BalanceAsync(global::Walletrpc.BalanceRequest request, CallOptions options)
{
var call = CreateCall(__Method_Balance, options);
return Calls.AsyncUnaryCall(call, request);
}
示例13: Balance
public global::Walletrpc.BalanceResponse Balance(global::Walletrpc.BalanceRequest request, CallOptions options)
{
var call = CreateCall(__Method_Balance, options);
return Calls.BlockingUnaryCall(call, request);
}
示例14: AccountNumberAsync
public AsyncUnaryCall<global::Walletrpc.AccountNumberResponse> AccountNumberAsync(global::Walletrpc.AccountNumberRequest request, CallOptions options)
{
var call = CreateCall(__Method_AccountNumber, options);
return Calls.AsyncUnaryCall(call, request);
}
示例15: AccountNumber
public global::Walletrpc.AccountNumberResponse AccountNumber(global::Walletrpc.AccountNumberRequest request, CallOptions options)
{
var call = CreateCall(__Method_AccountNumber, options);
return Calls.BlockingUnaryCall(call, request);
}