コード例 #1
0
        //Execute a given transaction, logs the transaction, and invoke the balancewarning
        //if the users balance gets under 50
        private T ExecuteTransaction <T>(T transaction) where T : Transaction
        {
            try
            {
                transaction.Execute();
                _transactions.Add(transaction);
                LogTransaction(transaction, "Completed");
                if (transaction.User.Balance <= 50)
                {
                    UserBalanceWarning?.Invoke(transaction.User, transaction.User.Balance);
                }

                return(transaction);
            }
            catch (DeactivatedProductExcetion ex)
            {
                LogTransaction(transaction, $"Failed: {ex.Message}");
                throw;
            }
            catch (InsufficientCreditsException ex)
            {
                LogTransaction(transaction, $"Failed: {ex.Message}");
                throw;
            }
        }
コード例 #2
0
 public void WarnUserOfLowBalance(decimal amount)
 {
     foreach (IUser user in Users)
     {
         UserBalanceWarning?.Invoke(user, amount);
     }
 }
コード例 #3
0
 private void OnUserBalanceChangedEvent(IUser user)
 {
     if (user.Balance < 50)
     {
         UserBalanceWarning?.Invoke(user);
     }
 }
コード例 #4
0
 private void SubscribeEvents()
 {
     foreach (IUser user in Users)
     {
         user.LowFundsWarning += (amount) => UserBalanceWarning?.Invoke(user, amount);
     }
 }
コード例 #5
0
 //Helper function for executing both kinds of transactions, while adding them to the log file
 private void ExecuteTransaction(Transaction transaction)
 {
     transaction.Execute();
     if (transaction.User.Balance <= 50)
     {
         UserBalanceWarning?.Invoke(transaction.User, transaction.User.Balance);
     }
     WriteToLogFile(transaction);
     allTransactions.Add(transaction);
 }
コード例 #6
0
        //Find the user with the given username
        public User GetUserByUsername(string username)
        {
            User user = _users.Find(p => p.Username == username);

            if (user != null)
            {
                if (user.Balance < 50)
                {
                    UserBalanceWarning?.Invoke(user, user.Balance);
                }
                return(user);
            }
            throw new UserNotFoundException("User was not found", username);
        }
コード例 #7
0
        public bool ExecuteTransaction(Transaction trans)
        {
            bool success = trans.Execute();

            if (success == true)
            {
                if (trans.User.Balance <= 50)
                {
                    UserBalanceWarning?.Invoke(trans.User, trans.User.Balance);
                }
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(@"Data\Transactions.txt", true))
                {
                    file.WriteLine(trans.LogToString());
                }
                DaAccess.Add(trans);
            }
            return(success);
        }
コード例 #8
0
        public delegate void UserBalanceNotification(object source, int balance); // delegate to pass when user balance fall below critical levels

        protected virtual void OnUserBalanceWarning(int balance)
        {
            UserBalanceWarning?.Invoke(this, balance);
        }
コード例 #9
0
 protected virtual void OnUserBalanceWarning(User user)
 {
     UserBalanceWarning?.Invoke(user, user.Balance);
 }
コード例 #10
0
ファイル: Stregsystem.cs プロジェクト: saxjax/OOP-Eksamen
 protected virtual void OnUserBalanceNotification(LowBalanceEventArgs e)
 {
     UserBalanceWarning?.Invoke(this, e);
 }