public async Task <CommandHandlingResult> Handle(RevokeActiveBatchIdCommand command, IEventPublisher publisher) { var batch = await _cashoutsBatchRepository.GetAsync(command.BatchId); var transitionResult = await batch.RevokeIdAsync(_activeCashoutsBatchIdRepository); _chaosKitty.Meow(command.BatchId); if (transitionResult.ShouldSaveAggregate()) { await _cashoutsBatchRepository.SaveAsync(batch); _chaosKitty.Meow(command.BatchId); } if (transitionResult.ShouldPublishEvents()) { publisher.PublishEvent ( new ActiveBatchIdRevokedEvent { BatchId = batch.BatchId } ); _chaosKitty.Meow(command.BatchId); } return(CommandHandlingResult.Ok()); }
public async Task <CommandHandlingResult> Handle(WaitForBatchExpirationCommand command, IEventPublisher publisher) { var batch = await _cashoutsBatchRepository.GetAsync(command.BatchId); if (!batch.HaveToBeExpired && batch.IsStillFillingUp) { return(CommandHandlingResult.Fail(_batchExpirationMonitoringPeriod)); } var transitionResult = batch.Expire(); if (transitionResult.ShouldSaveAggregate()) { await _cashoutsBatchRepository.SaveAsync(batch); _chaosKitty.Meow(command.BatchId); } if (transitionResult.ShouldPublishEvents()) { publisher.PublishEvent ( new BatchExpiredEvent { BatchId = batch.BatchId } ); _chaosKitty.Meow(command.BatchId); } return(CommandHandlingResult.Ok()); }
public async Task <CommandHandlingResult> Handle(CloseBatchCommand command, IEventPublisher publisher) { var batch = await _cashoutsBatchRepository.GetAsync(command.BatchId); var transitionResult = await batch.CloseAsync(command.Reason, _closedBatchedCashoutRepository); _chaosKitty.Meow(command.BatchId); if (transitionResult.ShouldSaveAggregate()) { await _cashoutsBatchRepository.SaveAsync(batch); _chaosKitty.Meow(command.BatchId); } if (transitionResult.ShouldPublishEvents()) { publisher.PublishEvent ( new BatchClosedEvent { BatchId = batch.BatchId } ); _chaosKitty.Meow(command.BatchId); } return(CommandHandlingResult.Ok()); }
public async Task <CommandHandlingResult> Handle(CompleteBatchCommand command, IEventPublisher publisher) { var batch = await _cashoutsBatchRepository.GetAsync(command.BatchId); var transitionResult = batch.Complete(); if (transitionResult.ShouldSaveAggregate()) { await _cashoutsBatchRepository.SaveAsync(batch); _chaosKitty.Meow(batch.BatchId); } if (transitionResult.ShouldPublishEvents()) { if (!batch.FinishMoment.HasValue) { throw new InvalidOperationException("Finish moment should be not null here"); } publisher.PublishEvent ( new CashoutsBatchCompletedEvent { BatchId = batch.BatchId, AssetId = batch.AssetId, TransactionHash = command.TransactionHash, TransactionFee = command.TransactionFee, Cashouts = batch.Cashouts .Select(c => c.ToContract()) .ToArray(), StartMoment = batch.StartMoment, FinishMoment = batch.FinishMoment.Value } ); _chaosKitty.Meow(batch.BatchId); } return(CommandHandlingResult.Ok()); }