コード例 #1
0
        public Task <List <string> > GetAsync()
        {
            _logger.LogDebug("Recieved Value Request.");
            var valueSequence = _busClient.ExecuteSequence(s => s
                                                           .PublishAsync(new ValuesRequested
            {
                NumberOfValues = _random.Next(1, 10)
            })
                                                           .When <ValueCreationFailed>(
                                                               (failed, context) =>
            {
                _logger.LogWarning("Unable to create Values. Exception: {0}", failed.Exception);
                return(Task.CompletedTask);
            }, it => it.AbortsExecution())
                                                           .Complete <ValuesCalculated>()
                                                           );

            return(valueSequence.Task.ContinueWith(tResponse =>
            {
                if (tResponse.IsFaulted)
                {
                    throw new Exception("No response recieved. Is the Console App started?");
                }

                _logger.LogInformation("Successfully created {valueCount} values", tResponse.Result.Values.Count);
                return valueSequence.Aborted
                                        ? new List <string>()
                                        : tResponse.Result.Values;
            }));
        }
コード例 #2
0
        public async Task <IActionResult> GetAsync()
        {
            _logger.LogDebug("Received Value Request.");

            try
            {
                var valueSequenceTask = _busClient.ExecuteSequence(s => s
                                                                   .PublishAsync(new ValuesRequested
                {
                    NumberOfValues = _random.Next(1, 10)
                })
                                                                   .When <ValueCreationFailed, MessageContext>(
                                                                       (failed, context) =>
                {
                    _logger.LogWarning("Unable to create Values. Exception: {0}", failed.Exception);
                    return(Task.FromResult(true));
                }, it => it.AbortsExecution())
                                                                   .Complete <ValuesCalculated>());

                var valueSequence = await valueSequenceTask.Task;

                _logger.LogInformation("Successfully created {valueCount} values", valueSequence.Values.Count);

                return(Ok(valueSequence.Values));
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, $"No response received. Is the Console App started? \n\nException: {e}"));
            }
        }