コード例 #1
2
 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);
     });
 }
コード例 #2
0
 /// <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);
     });
 }
コード例 #3
0
 public override async Task sendRequest(IAsyncStreamReader <Request> requestStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
 {
     await requestStream.ForEachAsync(async o =>
     {
         await responseStream.WriteAsync(HandleRequest(responseStream, o));
     });
 }
コード例 #4
0
        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());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: rogeralsing/GrpcDemoCSharp
        public override async Task <HelloReply> SayHelloStream(IAsyncStreamReader <HelloRequest> requestStream, ServerCallContext context)
        {
            await requestStream.ForEachAsync(i => Task.FromResult(0));

            return(new HelloReply {
                Message = "Hello"
            });
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public static async Task<byte[]> Receive(IAsyncStreamReader<byte[]> requestStream, ServerCallContext context)
        {
            await requestStream.ForEachAsync(bytes =>
            {
                throw new NotImplementedException();
            });

            return EmptyBytes;
        }
コード例 #8
0
 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();
 }
コード例 #9
0
ファイル: TestServiceImpl.cs プロジェクト: larsonmpdx/grpc
 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 };
 }
コード例 #10
0
 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();
 }
コード例 #11
0
 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 };
 }
コード例 #12
0
 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);
     });
 }
コード例 #13
0
ファイル: MathServiceImpl.cs プロジェクト: xiexiemanyou/grpc
        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());
        }
コード例 #14
0
ファイル: TestServiceImpl.cs プロジェクト: xiexiemanyou/grpc
        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());
        }
コード例 #15
0
ファイル: GrpcServerService.cs プロジェクト: wymoon2690/AElf
        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());
        }
コード例 #16
0
        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());
        }
コード例 #17
0
        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());
        }
コード例 #18
0
ファイル: TestServiceImpl.cs プロジェクト: xiexiemanyou/grpc
 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);
         }
     });
 }
コード例 #19
0
        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
            });
        }
コード例 #20
0
        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
            });
        }
コード例 #21
0
        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);
        }
コード例 #22
0
            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
                });
            }
コード例 #23
0
        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);
        }
コード例 #24
0
        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());
        }
コード例 #25
0
 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);
         }
     });
 }
コード例 #26
0
        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
            });
        }
コード例 #27
0
        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);
                }
            });
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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());
        }
コード例 #30
0
        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());
        }
コード例 #31
0
        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());
        }
コード例 #32
0
        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());
        }
コード例 #33
0
ファイル: GrpcServerService.cs プロジェクト: wymoon2690/AElf
        public override async Task <VoidReply> TransactionBroadcastStream(IAsyncStreamReader <Transaction> requestStream, ServerCallContext context)
        {
            await requestStream.ForEachAsync(async tx => await ProcessTransaction(tx, context));

            return(new VoidReply());
        }
コード例 #34
0
        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);
                }
            });
        }
コード例 #35
0
ファイル: ServerRunners.cs プロジェクト: rwightman/grpc
 /// <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);
     });
 }
コード例 #36
0
 public override async Task DivMany(IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream, ServerCallContext context)
 {
     await requestStream.ForEachAsync(async divArgs => await responseStream.WriteAsync(DivInternal(divArgs)));
 }
コード例 #37
0
 public override async Task DivMany(IAsyncStreamReader <DivArgs> requestStream, IServerStreamWriter <DivReply> responseStream, ServerCallContext context)
 {
     await requestStream.ForEachAsync(async divArgs => await responseStream.WriteAsync(DivInternal(divArgs)));
 }
コード例 #38
0
ファイル: GrpcServerService.cs プロジェクト: wymoon2690/AElf
        public override async Task <VoidReply> AnnouncementBroadcastStream(IAsyncStreamReader <BlockAnnouncement> requestStream, ServerCallContext context)
        {
            await requestStream.ForEachAsync(async r => await ProcessAnnouncement(r, context));

            return(new VoidReply());
        }
コード例 #39
0
 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);
         }
     });
 }