Ejemplo n.º 1
0
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken)
        {
            var context = await _contextProvider.GetContextAsync(message.GetSender(), message.To);

            context.SetMessage(message);

            try
            {
                await
                _textProcessor.ProcessAsync(message.Content.ToString(), context, cancellationToken)
                .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (_exceptionHandler == null ||
                    !await _exceptionHandler.HandleExceptionAsync(ex, message, context, cancellationToken).ConfigureAwait(false))
                {
                    throw;
                }
            }
            finally
            {
                if (context.HasToClearSession())
                {
                    context.Clear();
                }

                await _contextProvider.SaveContextAsync(message.GetSender(), message.To, context);
            }
        }