private static bool CheckMessage(CommandConfirmationMode confirmationMode, object msg)
        {
            switch (msg)
            {
            case AggregateActor.CommandProjected _:
                if (confirmationMode == CommandConfirmationMode.Projected)
                {
                    return(true);
                }
                break;

            case AggregateActor.CommandExecuted _:
                if (confirmationMode == CommandConfirmationMode.Executed)
                {
                    return(true);
                }
                break;

            case IFault fault:
                throw fault.Exception;

            case Status.Failure failure:
                throw failure.Cause;

            default:
                throw new InvalidMessageException($"unexpected message received {msg.GetType()}");
            }

            return(false);
        }
 public Task Execute(ICommand command, IMessageMetadata metadata = null, CommandConfirmationMode mode = CommandConfirmationMode.Projected)
 {
     return(_commandExecutor.Execute(command, metadata, mode));
 }
        public async Task Execute(ICommand command, IMessageMetadata metadata = null, CommandConfirmationMode confirmationMode = CommandConfirmationMode.Projected)
        {
            var envelopedCommand = new MessageMetadataEnvelop(command, metadata ?? CreateEmptyCommandMetadata(command));

            if (confirmationMode == CommandConfirmationMode.None)
            {
                _commandExecutorActor.Tell(envelopedCommand);
                return;
            }

            var inbox = Inbox.Create(_system);

            _commandExecutorActor.Tell(envelopedCommand, inbox.Receiver);

            var msg = await inbox.ReceiveAsync(_defaultTimeout);

            if (CheckMessage(confirmationMode, msg))
            {
                return;
            }

            msg = await inbox.ReceiveAsync(_defaultTimeout);

            if (CheckMessage(confirmationMode, msg))
            {
                return;
            }

            throw new TimeoutException("Command execution took to long");
        }
 public async Task Execute(ICommand command, IMessageMetadata metadata = null, CommandConfirmationMode mode = CommandConfirmationMode.Projected)
 {
     if (!IsConnected)
     {
         throw new NotConnectedException();
     }
     await _commandExecutor.Execute(command, metadata, mode);
 }