Exemplo n.º 1
0
        private void ProcessRequests()
        {
            while (true)
            {
                //This loop repeats for every one floor movement

                if (_requestQueue.Count == 0)
                {
                    //Wait when no request until signaled
                    _newRequestSignaling.Reset();
                    _newRequestSignaling.WaitOne();
                }


                if (ElevatorState.Stopped == State)
                {
                    ElevatorRequest elevatorRequest = _requestQueue.Peek();
                    if (elevatorRequest.DestinationFloor > CurrentFloor)
                    {
                        _stateMachine.Fire(ElevatorTrigger.GoUp);
                    }
                    else if (elevatorRequest.DestinationFloor < CurrentFloor)
                    {
                        _stateMachine.Fire(ElevatorTrigger.GoDown);
                    }
                    else if (elevatorRequest.DestinationFloor == CurrentFloor)
                    {
                        OpenDoors();
                    }
                }

                MoveToNextFloor();
            }
        }
Exemplo n.º 2
0
        private void OpenDoors()
        {
            lock (_requestQueue)
            {
                ElevatorRequest currentFloorDestinationRequest = _requestQueue.FirstOrDefault(request => request.DestinationFloor == _floors[CurrentFloor].FloorNumber);

                if (currentFloorDestinationRequest != null)
                {
                    _requestQueue.Remove(currentFloorDestinationRequest);
                    Task.Factory.StartNew((callback) => ((ElevatorCallback)(callback))(this), currentFloorDestinationRequest.DoorsOpenedAtDestinationFloor);
                }
            }

            _stateMachine.Fire(ElevatorTrigger.OpenDoors);
        }