Exemplo n.º 1
0
        /// <summary>
        /// Send null messages in all channels
        /// </summary>
        void SendNullMessages()
        {
            ToBankEvent?.Invoke(this, new ShopEventArgs(EventType.Null, threadTime));
            log.WriteLine((threadTime / 1000.0).ToString() + " | message | shop => bank | Null");

            ToBuyerEvent?.Invoke(this, new ShopEventArgs(EventType.Null, threadTime));
            log.WriteLine((threadTime / 1000.0).ToString() + " | message | shop => buyer | Null");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Works on task for some time
        /// </summary>
        /// <param name="task"></param>
        void WorkOnTask(BaseEventArgs task)
        {
            Console.WriteLine((threadTime / 1000.0).ToString() + " | task | shop | " + task.EventType.ToString());
            log.WriteLine((threadTime / 1000.0).ToString() + " | task | shop | " + task.EventType.ToString());

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

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

            if (task.EventType == EventType.BuyInCredit)
            {
                //shop informs bank about transaction
                ToBankEvent?.Invoke(this, new ShopEventArgs(EventType.CreditTransaction, threadTime));
                log.WriteLine((threadTime / 1000.0).ToString() + " | message | shop => bank | CreditTransaction");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create and send random message
        /// </summary>
        void SendNewRandomMessage()
        {
            if (NextMessageCreation < DateTime.Now)
            {
                int addTime = gen.Next(100, 2000);
                NextMessageCreation = DateTime.Now.AddMilliseconds(addTime);
                threadTime         += addTime;

                if (gen.Next(0, 2) == 0)
                {
                    //buyer buys goods
                    ToShopEvent?.Invoke(this, new BuyerEventArgs(EventType.BuyInCredit, threadTime));
                    log.WriteLine((threadTime / 1000.0).ToString() + " | message | buyer => shop | BuyInCredit");
                }
                else
                {
                    //buyer wants to withdraw money from bank
                    ToBankEvent?.Invoke(this, new BuyerEventArgs(EventType.WithdrawMoney, threadTime));
                    log.WriteLine((threadTime / 1000.0).ToString() + " | message | buyer => bank | WithdrawMoney");
                }
            }
        }