Esempio n. 1
0
        /// <summary>
        /// Works on task for some time
        /// </summary>
        /// <param name="task"></param>
        void WorkOnTask(BaseEventArgs task)
        {
            Console.WriteLine((threadTime / 1000.0).ToString() + " | task | bank | " + task.EventType.ToString());
            log.WriteLine((threadTime / 1000.0).ToString() + " | task | bank | " + task.EventType.ToString());

            int addTime = gen.Next(100, 2000);

            Thread.Sleep(addTime);
            threadTime += addTime;
            SendNullMessages();

            if (task.EventType == EventType.WithdrawMoney)
            {
                if (gen.Next(0, 2) == 0)
                {
                    //bank confirms withdrawal
                    ToBuyerEvent?.Invoke(this, new BankEventArgs(EventType.ConfirmMoneyWithdrawal, threadTime));
                    log.WriteLine((threadTime / 1000.0).ToString() + " | message | bank => buyer | ConfirmMoneyWithdrawal");
                }
                else
                {
                    //bank refuses withdrawal
                    ToBuyerEvent?.Invoke(this, new BankEventArgs(EventType.RefuseMoneyWithdrawal, threadTime));
                    log.WriteLine((threadTime / 1000.0).ToString() + " | message | bank => buyer | RefuseMoneyWithdrawal");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Send null messages in all channels
        /// </summary>
        void SendNullMessages()
        {
            ToShopEvent?.Invoke(this, new BankEventArgs(EventType.Null, threadTime));
            log.WriteLine((threadTime / 1000.0).ToString() + " | message | bank => shop | Null");

            ToBuyerEvent?.Invoke(this, new BankEventArgs(EventType.Null, threadTime));
            log.WriteLine((threadTime / 1000.0).ToString() + " | message | bank => buyer | Null");
        }