public override async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) }; await responseStream.WriteAsync(response); }); }
/// <summary> /// Generic streaming call handler. /// </summary> public async Task StreamingCall(IAsyncStreamReader <byte[]> requestStream, IServerStreamWriter <byte[]> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { await responseStream.WriteAsync(response); }); }
public override async Task sendRequest(IAsyncStreamReader <Request> requestStream, IServerStreamWriter <Response> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async o => { await responseStream.WriteAsync(HandleRequest(responseStream, o)); }); }
public override async Task <VoidReply> BlockBroadcastStream( IAsyncStreamReader <BlockWithTransactions> requestStream, ServerCallContext context) { Logger.LogDebug($"Block stream started with {context.GetPeerInfo()} - {context.Peer}."); try { var peerPubkey = context.GetPublicKey(); var peer = _connectionService.GetPeerByPubkey(peerPubkey); if (peer.SyncState != SyncState.Finished) { peer.SyncState = SyncState.Finished; } await requestStream.ForEachAsync(block => { peer.TryAddKnownBlock(block.GetHash()); _ = EventBus.PublishAsync(new BlockReceivedEvent(block, peerPubkey)); return(Task.CompletedTask); }); } catch (Exception e) { Logger.LogError(e, $"Block stream error - {context.GetPeerInfo()}: "); throw; } Logger.LogDebug($"Block stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task <HelloReply> SayHelloStream(IAsyncStreamReader <HelloRequest> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(i => Task.FromResult(0)); return(new HelloReply { Message = "Hello" }); }
public static IObservable <T> AsObservable <T>(this IAsyncStreamReader <T> stream, bool observeOnMainThread = true) { var seq = Observable.Create <T>(observer => { return(stream.ForEachAsync(x => observer.OnNext(x)).Subscribe(_ => { }, observer.OnError, observer.OnCompleted)); }); return((observeOnMainThread) ? seq.ObserveOnMainThread() : seq); }
public static async Task<byte[]> Receive(IAsyncStreamReader<byte[]> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(bytes => { throw new NotImplementedException(); }); return EmptyBytes; }
public async Task<Num> Sum(IAsyncStreamReader<Num> requestStream, ServerCallContext context) { long sum = 0; await requestStream.ForEachAsync(async num => { sum += num.Num_; }); return Num.CreateBuilder().SetNum_(sum).Build(); }
public async Task<StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<StreamingInputCallRequest> requestStream, ServerCallContext context) { int sum = 0; await requestStream.ForEachAsync(async request => { sum += request.Payload.Body.Length; }); return new StreamingInputCallResponse { AggregatedPayloadSize = sum }; }
public async Task<StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<StreamingInputCallRequest> requestStream, ServerCallContext context) { int sum = 0; await requestStream.ForEachAsync(async request => { sum += request.Payload.Body.Length; }); return StreamingInputCallResponse.CreateBuilder().SetAggregatedPayloadSize(sum).Build(); }
public override async Task<Num> Sum(IAsyncStreamReader<Num> requestStream, ServerCallContext context) { long sum = 0; await requestStream.ForEachAsync(async num => { sum += num.Num_; }); return new Num { Num_ = sum }; }
public override async Task StreamingCall(IAsyncStreamReader <SimpleRequest> requestStream, IServerStreamWriter <SimpleResponse> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) }; await responseStream.WriteAsync(response); }); }
public async Task <Num> Sum(IAsyncStreamReader <Num> requestStream, ServerCallContext context) { long sum = 0; await requestStream.ForEachAsync(async num => { sum += num.Num_; }); return(Num.CreateBuilder().SetNum_(sum).Build()); }
public async Task <StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader <StreamingInputCallRequest> requestStream, ServerCallContext context) { int sum = 0; await requestStream.ForEachAsync(async request => { sum += request.Payload.Body.Length; }); return(StreamingInputCallResponse.CreateBuilder().SetAggregatedPayloadSize(sum).Build()); }
public override async Task <VoidReply> BlockBroadcastStream(IAsyncStreamReader <BlockWithTransactions> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(r => { _ = EventBus.PublishAsync(new BlockReceivedEvent(r, context.GetPublicKey())); return(Task.CompletedTask); }); return(new VoidReply()); }
public override async Task <VoidReply> TransactionBroadcastStream(IAsyncStreamReader <Transaction> requestStream, ServerCallContext context) { Logger.LogDebug($"Transaction stream started with {context.GetPeerInfo()} - {context.Peer}."); await requestStream.ForEachAsync(async tx => await ProcessTransaction(tx, context)); Logger.LogDebug($"Transaction stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task <VoidReply> AnnouncementBroadcastStream( IAsyncStreamReader <BlockAnnouncement> requestStream, ServerCallContext context) { Logger.LogDebug($"Announcement stream started with {context.GetPeerInfo()} - {context.Peer}."); await requestStream.ForEachAsync(async r => await ProcessAnnouncement(r, context)); Logger.LogDebug($"Announcement stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public async Task FullDuplexCall(IAsyncStreamReader <StreamingOutputCallRequest> requestStream, IServerStreamWriter <StreamingOutputCallResponse> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { foreach (var responseParam in request.ResponseParametersList) { var response = StreamingOutputCallResponse.CreateBuilder() .SetPayload(CreateZerosPayload(responseParam.Size)).Build(); await responseStream.WriteAsync(response); } }); }
public async Task <StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader <StreamingInputCallRequest> requestStream, ServerCallContext context) { int sum = 0; await requestStream.ForEachAsync(async request => { sum += request.Payload.Body.Length; }); return(new StreamingInputCallResponse { AggregatedPayloadSize = sum }); }
public override async Task <Num> Sum(IAsyncStreamReader <Num> requestStream, ServerCallContext context) { long sum = 0; await requestStream.ForEachAsync(async num => { sum += num.Num_; }); return(new Num { Num_ = sum }); }
public async Task <IntMessage> Sum(IAsyncStreamReader <SumRequest> request, ServerCallContext context) { var result = new IntMessage(); int sum = 0; await request.ForEachAsync(req => { sum += req.Num; return(Task.CompletedTask); }); result.Value = sum; return(result); }
public override async Task <StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader <StreamingInputCallRequest> requestStream, ServerCallContext context) { var authContext = context.AuthContext; await requestStream.ForEachAsync(async request => {}); Assert.IsTrue(authContext.IsPeerAuthenticated); Assert.AreEqual("x509_subject_alternative_name", authContext.PeerIdentityPropertyName); Assert.IsTrue(authContext.PeerIdentity.Count() > 0); Assert.AreEqual("ssl", authContext.FindPropertiesByName("transport_security_type").First().Value); return(new StreamingInputCallResponse { AggregatedPayloadSize = 12345 }); }
public override async Task <Empty> Publish(IAsyncStreamReader <Message> requestStream, ServerCallContext context) { await requestStream .ForEachAsync(message => { IEnumerable <Task> writerTasks = _lookup .Lookup(message) .SelectMany(tuple => tuple.Writer.Select(serverStreamWriter => serverStreamWriter.WriteAsync(message))); return(Task.WhenAll(writerTasks)); }) .ConfigureAwait(false); return(_empty); }
public override async Task <VoidReply> BlockBroadcastStream( IAsyncStreamReader <BlockWithTransactions> requestStream, ServerCallContext context) { Logger.LogDebug($"Block stream started with {context.GetPeerInfo()} - {context.Peer}."); await requestStream.ForEachAsync(r => { _ = EventBus.PublishAsync(new BlockReceivedEvent(r, context.GetPublicKey())); return(Task.CompletedTask); }); Logger.LogDebug($"Block stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task sendRequest(IAsyncStreamReader <Request> requestStream, IServerStreamWriter <Response> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async o => { try { await responseStream.WriteAsync(GetResponse(responseStream, o)); } catch (Exception e) { Console.WriteLine(e); } }); }
public override async Task <StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader <StreamingInputCallRequest> requestStream, ServerCallContext context) { await EnsureEchoMetadataAsync(context); int sum = 0; await requestStream.ForEachAsync(request => { sum += request.Payload.Body.Length; return(Task.CompletedTask); }); return(new StreamingInputCallResponse { AggregatedPayloadSize = sum }); }
public override async Task FullDuplexCall(IAsyncStreamReader <StreamingOutputCallRequest> requestStream, IServerStreamWriter <StreamingOutputCallResponse> responseStream, ServerCallContext context) { await EnsureEchoMetadataAsync(context); await requestStream.ForEachAsync(async request => { EnsureEchoStatus(request.ResponseStatus, context); foreach (var responseParam in request.ResponseParameters) { var response = new StreamingOutputCallResponse { Payload = CreateZerosPayload(responseParam.Size) }; await responseStream.WriteAsync(response); } }); }
public override async Task <HelloReply> SayHelloStream(IAsyncStreamReader <HelloRequest> requestStream, ServerCallContext context) { var helloReply = new HelloReply(); var sb = new StringBuilder(); await requestStream.ForEachAsync(req => { sb.AppendLine("Hello " + requestStream.Current.Name); return(Task.CompletedTask); }); //while (await requestStream.MoveNext()) //{ // sb.AppendLine("Hello " + requestStream.Current.Name); //} helloReply.Message = sb.ToString(); return(helloReply); }
public override async Task <Unit> Receive(IAsyncStreamReader <MessageBatch> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(batch => { foreach (var envelope in batch.Envelopes) { var target = envelope.Target; var sender = envelope.Sender; var message = Serialization.Deserialize(envelope.TypeName, envelope.MessageData); target.Request(message, sender); } return(Actor.Done); }); return(new Unit()); }
public override async Task <VoidReply> LibAnnouncementBroadcastStream(IAsyncStreamReader <LibAnnouncement> requestStream, ServerCallContext context) { Logger.LogDebug($"Lib announcement stream started with {context.GetPeerInfo()} - {context.Peer}."); try { await requestStream.ForEachAsync(async r => await ProcessLibAnnouncement(r, context)); } catch (Exception e) { Logger.LogError(e, $"Lib announcement stream error: {context.GetPeerInfo()}"); throw; } Logger.LogDebug($"Lib announcement stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task <VoidReply> TransactionBroadcastStream(IAsyncStreamReader <Transaction> requestStream, ServerCallContext context) { Logger.LogTrace($"Transaction stream started with {context.GetPeerInfo()} - {context.Peer}."); try { await requestStream.ForEachAsync(async tx => await ProcessTransaction(tx, context)); } catch (Exception e) { Logger.LogError(e, $"Transaction stream error - {context.GetPeerInfo()}: "); throw; } Logger.LogTrace($"Transaction stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task <VoidReply> BlockBroadcastStream( IAsyncStreamReader <BlockWithTransactions> requestStream, ServerCallContext context) { Logger.LogDebug($"Block stream started with {context.GetPeerInfo()} - {context.Peer}."); try { var peerPubkey = context.GetPublicKey(); await requestStream.ForEachAsync(async block => await ProcessBlockAsync(block, peerPubkey)); } catch (Exception e) { Logger.LogError(e, $"Block stream error - {context.GetPeerInfo()}: "); throw; } Logger.LogDebug($"Block stream finished with {context.GetPeerInfo()} - {context.Peer}."); return(new VoidReply()); }
public override async Task <VoidReply> TransactionBroadcastStream(IAsyncStreamReader <Transaction> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(async tx => await ProcessTransaction(tx, context)); return(new VoidReply()); }
public override async Task FullDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context) { await EnsureEchoMetadataAsync(context); await requestStream.ForEachAsync(async request => { EnsureEchoStatus(request.ResponseStatus, context); foreach (var responseParam in request.ResponseParameters) { var response = new StreamingOutputCallResponse { Payload = CreateZerosPayload(responseParam.Size) }; await responseStream.WriteAsync(response); } }); }
/// <summary> /// Generic streaming call handler. /// </summary> public async Task StreamingCall(IAsyncStreamReader<byte[]> requestStream, IServerStreamWriter<byte[]> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { await responseStream.WriteAsync(response); }); }
public override async Task DivMany(IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async divArgs => await responseStream.WriteAsync(DivInternal(divArgs))); }
public override async Task DivMany(IAsyncStreamReader <DivArgs> requestStream, IServerStreamWriter <DivReply> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async divArgs => await responseStream.WriteAsync(DivInternal(divArgs))); }
public override async Task <VoidReply> AnnouncementBroadcastStream(IAsyncStreamReader <BlockAnnouncement> requestStream, ServerCallContext context) { await requestStream.ForEachAsync(async r => await ProcessAnnouncement(r, context)); return(new VoidReply()); }
public async Task FullDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context) { await requestStream.ForEachAsync(async request => { foreach (var responseParam in request.ResponseParametersList) { var response = StreamingOutputCallResponse.CreateBuilder() .SetPayload(CreateZerosPayload(responseParam.Size)).Build(); await responseStream.WriteAsync(response); } }); }