private async Task Handle(DeleteAccountsStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _executionInfoRepository.GetAsync <DeleteAccountsData>( OperationName, e.OperationId ); if (executionInfo == null) { return; } if (executionInfo.Data.SwitchState(DeleteAccountsState.Initiated, DeleteAccountsState.Started)) { executionInfo.Data.AddFailedIfNotExist(e.FailedAccountIds); sender.SendCommand(new BlockAccountsForDeletionCommand { OperationId = e.OperationId, Timestamp = _systemClock.UtcNow.UtcDateTime, AccountIds = executionInfo.Data.GetAccountsToDelete(), }, _contextNames.TradingEngine); _chaosKitty.Meow( $"{nameof(DeleteAccountsStartedInternalEvent)}: " + "Save_OperationExecutionInfo: " + $"{e.OperationId}"); await _executionInfoRepository.SaveAsync(executionInfo); } }
private async Task Handle(WithdrawalStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _executionInfoRepository.GetAsync <WithdrawalDepositData>(OperationName, e.OperationId); if (executionInfo == null) { return; } if (SwitchState(executionInfo.Data, WithdrawalState.Created, WithdrawalState.FreezingAmount)) { sender.SendCommand( new FreezeAmountForWithdrawalCommand( executionInfo.Id, _systemClock.UtcNow.UtcDateTime, executionInfo.Data.AccountId, executionInfo.Data.Amount, executionInfo.Data.Comment), _contextNames.TradingEngine); _chaosKitty.Meow(e.OperationId); await _executionInfoRepository.SaveAsync(executionInfo); } }
public async Task Handle(RevokeTemporaryCapitalStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _executionInfoRepository.GetAsync <RevokeTemporaryCapitalData>( OperationName, e.OperationId ); if (executionInfo == null) { return; } if (executionInfo.Data.SwitchState(TemporaryCapitalState.Initiated, TemporaryCapitalState.Started)) { executionInfo.Data.RevokedTemporaryCapital = e.RevokedTemporaryCapital; sender.SendCommand( new UpdateBalanceInternalCommand( e.OperationId, executionInfo.Data.AccountId, -executionInfo.Data.RevokedTemporaryCapital.Sum(x => x.Amount), $"{executionInfo.Data.Comment} *** Revoked eventSourceIds: [{string.Join(",", executionInfo.Data.RevokedTemporaryCapital.Select(x => x.Id))}]", executionInfo.Data.AdditionalInfo, OperationName, AccountBalanceChangeReasonType.TemporaryCashAdjustment, executionInfo.Data.EventSourceId, string.Empty, _systemClock.UtcNow.UtcDateTime), _contextNames.AccountsManagement); _chaosKitty.Meow( $"{nameof(RevokeTemporaryCapitalStartedInternalEvent)}: " + "Save_OperationExecutionInfo:" + $"{e.OperationId}"); await _executionInfoRepository.SaveAsync(executionInfo); } }
private async Task Handle(DepositStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _executionInfoRepository.GetAsync <WithdrawalDepositData>( OperationName, e.OperationId ); if (executionInfo == null) { return; } if (SwitchState(executionInfo.Data, WithdrawalState.Created, WithdrawalState.FreezingAmount)) { sender.SendCommand( new FreezeAmountForDepositInternalCommand(e.OperationId), _contextNames.AccountsManagement); _chaosKitty.Meow(e.OperationId); await _executionInfoRepository.SaveAsync(executionInfo); } }
private async Task Handle(UpdateBalanceInternalCommand command, IEventPublisher publisher) { var executionInfo = await _executionInfoRepository.GetOrAddAsync( OperationName, command.OperationId, () => new OperationExecutionInfo<OperationData>( OperationName, command.OperationId, new OperationData { State = OperationState.Created }, _systemClock.UtcNow.UtcDateTime)); if (SwitchState(executionInfo.Data, OperationState.Created, OperationState.Started)) { IAccount account = null; try { account = await _accountsRepository.UpdateBalanceAsync( command.OperationId, command.AccountId, command.AmountDelta, false); } catch (ValidationException ex) { await _log.WriteWarningAsync(nameof(UpdateBalanceCommandsHandler), nameof(UpdateBalanceInternalCommand), ex.Message); publisher.PublishEvent(new AccountBalanceChangeFailedEvent(command.OperationId, _systemClock.UtcNow.UtcDateTime, ex.Message, command.Source)); await _executionInfoRepository.SaveAsync(executionInfo); return; } _chaosKitty.Meow(command.OperationId); var change = new AccountBalanceChangeContract( command.OperationId, account.ModificationTimestamp, account.Id, account.ClientId, command.AmountDelta, account.Balance, account.WithdrawTransferLimit, command.Comment, Convert(command.ChangeReasonType), command.EventSourceId, account.LegalEntity, command.AuditLog, command.AssetPairId, command.TradingDay); var convertedAccount = Convert(account); publisher.PublishEvent( new AccountChangedEvent( change.ChangeTimestamp, command.Source, convertedAccount, AccountChangedEventTypeContract.BalanceUpdated, change, command.OperationId) ); await _executionInfoRepository.SaveAsync(executionInfo); } }