예제 #1
0
        private void Notify(int count)
        {
            for (int i = 0; i < count; i++)
            {
                if (!_buyers.TryDequeue(out var buyer))
                {
                    break;
                }

                _readyForService.Add(buyer);
                Availabled?.Invoke(this, new ObjectAvailabledEventArgs(buyer.Id));
            }
        }
예제 #2
0
        public IReadOnlyCollection <Product> TakeAnyProducts(int count, IReadOnlyBuyer buyer)
        {
            if (buyer == null)
            {
                throw new ArgumentNullException(nameof(buyer));
            }

            if (!IsAvailable())
            {
                throw new ShelfIsBusyException();
            }

            _semaphoreSlim.Wait();

            var result = TakeProductInternal(count, buyer);

            _semaphoreSlim.Release();

            Availabled?.Invoke(this, EventArgs.Empty);

            return(result);
        }
예제 #3
0
        public Receipt MakePurchases(IReadOnlyBuyer buyer)
        {
            if (buyer == null)
            {
                throw new ArgumentNullException(nameof(buyer));
            }

            if (!IsAvailable())
            {
                throw new CashboxIsBusyException();
            }

            _semaphoreSlim.Wait();

            MakePurchasesInternal(buyer);

            var result = new Receipt(Supermarket, buyer.Basket.Products);

            _semaphoreSlim.Release();

            Availabled?.Invoke(this, EventArgs.Empty);

            return(result);
        }