Exemplo n.º 1
0
        public async Task WalkToRoom()
        {
            BarberState = BarberState.Walking;

            await Task.Delay(_walkingTimeRange.GetDelay());

            if (InvititationBroadcasted != null)
            {
                InvititationBroadcasted.Invoke(this, new InvititationBroadcastedEventArgs("Barber is inviting a customer"));
            }
        }
Exemplo n.º 2
0
        public async Task PerformBarbering(Customer customer)
        {
            BarberState = BarberState.Barbering;

            await Task.Delay(_barberingTimeRange.GetDelay());

            if (BarberingFinished != null)
            {
                BarberingFinished.Invoke(this,
                                         new BarberingFinishedEventArgs("Barber has finished with " + customer));
            }

            await WalkToRoom();
        }
Exemplo n.º 3
0
        public async Task LookAtBarber(Barber barber)
        {
            if (barber.BarberState == BarberState.Sleeping)
            {
                await barber.AwakeBarber(this);
            }

            await Task.Delay(_walkingTimeRange.GetDelay());

            if (SearchingForChairStarted != null)
            {
                SearchingForChairStarted.Invoke(this,
                                                new SearchingForChairStartedEventArgs(this + " is searching for empty chair..."));
            }
        }
Exemplo n.º 4
0
        private static async Task _generateCustomers(Barber barber, DelayRange newCustomerTimeRange, DelayRange walkingTimeRange)
        {
            var customerId = 1;

            while (true)
            {
                await Task.Delay(newCustomerTimeRange.GetDelay());

                var customer = new Customer(customerId, walkingTimeRange);
                customer.SearchingForChairStarted += _customerIsSearchingForChairStarted;
                customerId++;

                await customer.LookAtBarber(barber);
            }
        }