Example #1
0
        public static async Task <CommandHandlingResult> InterceptAsync(
            IMessageCancellationRegistry messageCancellationRegistry,
            IMessageCancellationService messageCancellationService,
            ILog log,
            object contextMessage,
            object handlerObject,
            Func <Task <CommandHandlingResult> > funcAsync)
        {
            var messageId = messageCancellationRegistry.GetMessageIdOrDefault(contextMessage);

            if (string.IsNullOrEmpty(messageId))
            {
                throw new MessageCancellationInterceptionException($"Message does not contain message id or is not registered. " +
                                                                   $"Message: {contextMessage.ToJson()}, " +
                                                                   $"MessageType: {contextMessage.GetType()}");
            }

            var requiresCancellation = await
                                       messageCancellationService.CheckIfOperationRequiresCancellationAsync(messageId);

            if (requiresCancellation)
            {
                log.Info($"MessageId: {messageId} is cancelled, " +
                         $"HandlerType: {handlerObject}, " +
                         $"MessageType: {contextMessage}", contextMessage);

                return(Cqrs.CommandHandlingResult.Ok());
            }

            return(await funcAsync());
        }
Example #2
0
 public MessageCancellationCommandInterceptor(IMessageCancellationService messageCancellationService,
                                              IMessageCancellationRegistry messageCancellationRegistry,
                                              ILogFactory loggerFactory)
 {
     _messageCancellationService  = messageCancellationService;
     _messageCancellationRegistry = messageCancellationRegistry;
     _log = loggerFactory.CreateLog(this);
 }
 public MessageCancellationController(IMessageCancellationService messageCancellationService)
 {
     _messageCancellationService = messageCancellationService ??
                                   throw new ArgumentException("Should not be null",
                                                               nameof(messageCancellationService));
 }