Ejemplo n.º 1
0
        public async Task HandleAsync(object message, IRequestInfo requestInfo)
        {
            //var serviceBusMessage = message as IServiceBusMessage;
            //if (serviceBusMessage.BelongsToSaga())
            //{
            //    var context = SagaContext.Create(new SagaId(), "", new List<ISagaContextMetadata>
            //    {
            //        new SagaData(SagaData.OperationIdKey, requestInfo.OperationId.ToString()),
            //        new SagaData(SagaData.UserIdKey, requestInfo.UserId)
            //    });
            //    await _sagaCoordinator.ProcessAsync(serviceBusMessage, context);
            //    return;
            //}


            switch (message)
            {
            case IRejectedEvent rejected:
                requestInfo.Fail();
                _logger.LogInformation($"Operation [{requestInfo.OperationId}]: Rejected Event code: [{rejected.Code}] Reason: {rejected.Reason}");
                await _operationsCache.SaveAsync(requestInfo.OperationId, requestInfo.State.ToString().ToLower(), rejected.Code, rejected.Reason);

                _publisher.PublishEvent(new OperationFailed(rejected.Code, rejected.Reason), requestInfo);
                break;

            case ICommand _:
                _logger.LogInformation($"Operation [{requestInfo.OperationId}]: PENDING");
                await _operationsCache.SaveAsync(requestInfo.OperationId, RequestState.Pending.ToString());

                break;

            case IEvent _:
                requestInfo.Complete();
                _logger.LogInformation($"Operation: [{requestInfo.OperationId}] COMPLETE");
                await _operationsCache.SaveAsync(requestInfo.OperationId, requestInfo.State.ToString().ToLower());

                _publisher.PublishEvent(new OperationComplete(), requestInfo);
                break;

            default:
                break;
            }
        }