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);
            }
        }
예제 #2
0
        private void FinishTransaction(Transaction transaction)
        {
            var isSuccess = string.IsNullOrEmpty(transaction.ErrorMessage);

            OnTransactionFinished?.Invoke(transaction.GetId(), isSuccess);
        }
예제 #3
0
 private void OnFinish(Transaction transaction)
 {
     OnTransactionFinished?.Invoke(transaction);
 }