Exemplo n.º 1
0
        public void RunAuction()
        {
            if (Participants.Count == 0)
            {
                EndAuction();
                Console.WriteLine($"Auction over {auction.Item.Name}, UID {auction.Item.UniqueID} is closed due to no participants.");
                return;
            }
            _notifier.NotifyChange($"Auction for {auction.Item.Name} started!");
            auction.IsActive = true;
            Thread.CurrentThread.IsBackground = false;
            while (auction.IsOver == false)
            {
                DateTime lastBetTime = auction.CurrentBet.BetTime.Value;

                if (lastBetTime.AddSeconds(5) < DateTime.Now && AuctionStage != 4)
                {
                    AuctionStage = 4;
                    _notifier.NotifyChange($"Last call for {auction.Item.Name} auction! Less then 3 seconds remaining for ");
                }
                AskForNewBets();
                Thread.Sleep(1000);
                if (lastBetTime.AddSeconds(5) > DateTime.Now)
                {
                    AuctionStage = 3;
                }
                if (lastBetTime.AddSeconds(8) < DateTime.Now && AuctionStage == 4)
                {
                    EndAuction();
                }
            }
        }
Exemplo n.º 2
0
        public void RunAuctions()
        {
            updateNextAuctions();
            List <AuctionRunner> nextAuctions = new List <AuctionRunner>(_dueToBeginAuctions);

            Parallel.ForEach(nextAuctions ?? new List <AuctionRunner>(), runner =>
            {
                _dueToBeginAuctions.Remove(runner);
                runner.RunAuction();
            });

            if (AuctionRunners?.Where(runner => runner.auction.IsOver == true).ToList().Count == AuctionRunners.Count)
            {
                string msg = "All auctions are over. See you next Time!";
                _notifier.NotifyChange(msg);
                _runAuctionsTimer.Stop();
            }
        }