private void HandleTransaction(object state) { lock (_syncLock) { _transactions.TryDequeue(out var transaction); if (transaction == null) { return; } var ownerId = transaction.OwnerId; var accountId = transaction.AccountId; var transactionType = transaction.Type; var amount = transaction.Amount; var dbManager = DbManager.GetInstance(); _user = dbManager.GetUserDataBase().Get(ownerId); _account = dbManager.GetAccountDatabase().Get(accountId); TransactionStatus status; try { MakeTransaction(transactionType, amount); status = TransactionStatus.Success; } catch (NotEnoughMoneyException e) { status = TransactionStatus.Error; transaction.ErrorMessage = e.Message; } catch (UnknowTransactionException e) { status = TransactionStatus.Error; transaction.ErrorMessage = e.Message; } catch (Exception) { status = TransactionStatus.Error; transaction.ErrorMessage = "Unknown error"; } transaction.Status = status; transaction.Time = GetCurrentTime(); transaction.TransactionId = GenerateId(); SessionUtils.RegisterTransaction(_account.Id, transaction); OnTransactionFinished?.Invoke(transaction); } }
private void FinishTransaction(Transaction transaction) { var isSuccess = string.IsNullOrEmpty(transaction.ErrorMessage); OnTransactionFinished?.Invoke(transaction.GetId(), isSuccess); }
private void OnFinish(Transaction transaction) { OnTransactionFinished?.Invoke(transaction); }