public override async Task RequestFrameStream( Grpc.Core.IAsyncStreamReader <CameraAcquisitionRequest> requestStream, Grpc.Core.IServerStreamWriter <BufferedFramesResponse> responseStream, Grpc.Core.ServerCallContext context) { lock (_frameStreamWriterLock) { _frameStreamWriter = responseStream; } while (await requestStream.MoveNext() && !context.CancellationToken.IsCancellationRequested) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed var result = await RequestCameraAcquisition(requestStream.Current, context); if (result.Error != null) { lock (_frameStreamWriterLock) { responseStream.WriteAsync(new BufferedFramesResponse() { Error = result.Error }); break; } } #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } lock (_frameStreamWriterLock) { _frameStreamWriter = null; } }
public override async Task <HelloReply> SayHello(Grpc.Core.IAsyncStreamReader <HelloRequest> requestStream, Grpc.Core.ServerCallContext context) { while (await requestStream.MoveNext(context.CancellationToken)) { Console.WriteLine($"Gelen İsim: {requestStream.Current.Name}"); } return(new HelloReply { Message = "Mesaj alındı gardaş.. :)" }); }
public override async Task <SettingsSavedReply> SaveSites(Grpc.Core.IAsyncStreamReader <Settings> requestStream, Grpc.Core.ServerCallContext context) { int savedCount = -1; try { bool nextExist = await requestStream.MoveNext(); String userid = requestStream.Current.Userid; List <String> settings = new List <String>(); //settings.Add(requestStream.Current.Field); //var stopwatch = new System.Diagnostics.Stopwatch(); //stopwatch.Start(); do { settings.Add(requestStream.Current.Field); nextExist = await requestStream.MoveNext(); } while (nextExist); //stopwatch.Stop(); savedCount = db.SetUserSettings(userid, settings, "site"); } catch (Exception e) { Console.WriteLine("\nServer: Error while adding user settings.\n" + e.Message); } finally { Console.WriteLine(savedCount); } return(new SettingsSavedReply { Count = savedCount }); }
public override async Task <GreetResponse> GreetClientStream(Grpc.Core.IAsyncStreamReader <GreetRequest> requestStream, Grpc.Core.ServerCallContext context) { Console.WriteLine("Server received a stream greet request. Server will response normally!!!"); StringBuilder build = new StringBuilder(); while (await requestStream.MoveNext()) { build.Append("Hello "); build.Append(requestStream.Current.Greet.FirstName); build.Append(" "); build.Append(requestStream.Current.Greet.LastName); build.Append(Environment.NewLine); } return(new GreetResponse() { Response = build.ToString() }); }
public override async Task Mailbox(Grpc.Core.IAsyncStreamReader <ForwardMailMessage> requestStream, Grpc.Core.IServerStreamWriter <MailboxMessage> responseStream, Grpc.Core.ServerCallContext context) { var mailboxName = context.RequestHeaders.Single(e => e.Key == "mailbox-name").Value; var mailQueue = _messageQueueRepository.GetMailQueue(mailboxName); _logger.LogInformation($"Connected to {mailboxName}"); mailQueue.Changed += ReportChanges; try { while (await requestStream.MoveNext()) { if (mailQueue.TryForwardMail(out var message)) { _logger.LogInformation($"Forwarded mail:{message.Content}"); } else { _logger.LogWarning("No mail to forward."); } } } finally { mailQueue.Changed -= ReportChanges; } _logger.LogInformation($"{mailboxName} disconnected."); async Task ReportChanges((int totalCount, int forwardCount, MailboxMessage.Types.Reason reason) state) { await responseStream.WriteAsync(new MailboxMessage { Forwarded = state.forwardCount, New = state.totalCount - state.forwardCount, Reason = state.reason }); } }