Пример #1
0
        public override async Task ListFiles(
            Empty request,
            IServerStreamWriter <FileSystemEntry> responseStream,
            ServerCallContext context)
        {
            var root = _options.Value.DataDirectory;

            if (string.IsNullOrWhiteSpace(root))
            {
                _logger.LogInformation("No data directory set, returning");
                return;
            }

            var enumerationOptions = _options.Value.EnumerationOptions;

            _logger.LogTrace("Sending list files request");
            var result = await _sender.Send(new ListFilesRequest(root, enumerationOptions));

            _logger.LogTrace("Got list files response");

            if (!result.Files.Any())
            {
                return;
            }

            _logger.LogTrace("Writing files to response stream");
            await responseStream.WriteAllAsync(result.Files);
        }
Пример #2
0
        public override async Task Join(JoinRequest req, IServerStreamWriter <Message> ssw, ServerCallContext scc)
        {
            var v = 0;

            Lock(msgs);
            msgs.Add(new Message()
            {
                M = $"{req.Un}: Joined!\r\n"
            });

            while (true)
            {
                while (v == msgs.Count)
                {
                    if (scc.CancellationToken.IsCancellationRequested)
                    {
                        msgs.Add(new Message()
                        {
                            M = $"{req.Un}: Left!\r\n"
                        });
                        Drop(msgs);
                        return;
                    }
                    Wait(msgs);
                }

                IEnumerable <Message> pend = msgs.Skip(v);
                v = msgs.Count;

                Drop(msgs);
                await ssw.WriteAllAsync(pend);

                Lock(msgs);
            }
        }
Пример #3
0
        /// <summary>
        /// ¥s¥ÎUtils¤¤ªºmethod¨Ó¶]loop
        /// https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs
        /// </summary>
        /// <param name="requestStream"></param>
        /// <param name="responseStream"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task GetStudentListExtention(IAsyncStreamReader <StudentRequest> requestStream, IServerStreamWriter <Student> responseStream, ServerCallContext context)
        {
            var request = await requestStream.ToListAsync();

            var students = request.Select(x => new Student
            {
                Gender       = x.Gender,
                Id           = x.Id,
                Name         = x.Name,
                ResponseTime = GetDateTimeNowString()
            });
            await responseStream.WriteAllAsync <Student>(students);
        }
Пример #4
0
        /// <summary>
        /// Get Top Customers
        /// </summary>
        /// <param name="request"></param>
        /// <param name="responseStream"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="ValidationException"></exception>
        /// <exception cref="RpcException"></exception>
        public override async Task GetTopCustomers(CustomerDetailRequest request, IServerStreamWriter <CustomerDetailResponse> responseStream, ServerCallContext context)
        {
            try
            {
                if (request.TopCustomers == 0)
                {
                    throw new ValidationException(BusinessRuleResource.Error_InTopCount);
                }
                var customerList = _customerRuleManager.GetTopCustomers(request.TopCustomers).ToArray();

                if (customerList.Any())
                {
                    foreach (var customer in customerList)
                    {
                        await responseStream.WriteAsync(new CustomerDetailResponse
                        {
                            Id                = customer.Id,
                            Street            = customer.Street,
                            Suburb            = customer.Suburb,
                            Contact           = customer.Contact,
                            Country           = customer.Country,
                            Street2           = customer.Street2,
                            StateId           = customer.StateId,
                            FullName          = customer.FullName,
                            LastName          = customer.LastName,
                            AddressId         = customer.AddressId,
                            ContactId         = customer.ContactId,
                            FirstName         = customer.FirstName,
                            StateName         = customer.StateName,
                            CustomerCode      = customer.CustomerCode,
                            DateOfBirth       = customer.DateOfBirth.ToShortDateString(),
                            AddressTypeId     = customer.AddressTypeId,
                            ContactTypeId     = customer.ContactTypeId,
                            CustomerAddressId = customer.CustomerAddressId,
                            CustomerContactId = customer.CustomerContactId
                        });
                    }
                }
                else
                {
                    await responseStream.WriteAllAsync(new CustomerDetailResponse[] { });
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                throw new RpcException(new Status(StatusCode.Aborted, e.Message));
            }
        }
Пример #5
0
        public override async Task GetScores(ScoresRequest request, IServerStreamWriter <ScoreResponse> responseStream,
                                             ServerCallContext context)
        {
            try
            {
                _auth.GetClient(context);
            }
            catch (GrpcError e)
            {
                await responseStream.WriteAsync(new ScoreResponse { ErrorNo = e.ErrorNumber });

                return;
            }

            var scores      = _service.GetScores();
            var protoScores = scores.Select(score => new ScoreResponse {
                Score = score.ToProto()
            });
            await responseStream.WriteAllAsync(protoScores);
        }
        public override async Task SubscribeForConsumingMessages(AnalogyConsumerMessage request, IServerStreamWriter <AnalogyGRPCLogMessage> responseStream, ServerCallContext context)
        {
            _grpcLogConsumer.AddGrpcConsumer(request.Message, responseStream);
            await responseStream.WriteAsync(new AnalogyGRPCLogMessage
            {
                Category    = "Server Message",
                Text        = "Connection Established. Streaming old messages (if Any)",
                Level       = AnalogyGRPCLogLevel.Analogy,
                Date        = Timestamp.FromDateTime(DateTime.UtcNow),
                FileName    = "",
                Id          = Guid.NewGuid().ToString(),
                LineNumber  = 0,
                MachineName = Environment.MachineName,
                Module      = Process.GetCurrentProcess().ProcessName,
                ProcessId   = Process.GetCurrentProcess().Id,
                Source      = "Server Operations",
                ThreadId    = Thread.CurrentThread.ManagedThreadId,
                User        = Environment.UserName
            });

            var oldMessages = await MessageHistoryContainer.GetOldMessages().ConfigureAwait(false);

            if (oldMessages.Any())
            {
                await responseStream.WriteAllAsync(oldMessages);
            }

            try
            {
                await AwaitCancellation(context.CancellationToken);
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Error");
            }
        }