Beispiel #1
0
        /* After this call is executed successfully, the occupied parking stand
         * becomes Available,and the used runway is InOperation for the
         * length of operation duration parameter and can't handle any other
         * operations during this time. After operation finishes, the runway becomes
         * Available again. The call is non-blocking, i.e. it returns before the
         * runway is cleared. */
        public PerformResult PerformTakeOff(TakeOffRequestToken token)
        {
            token.Stop();
            token.Elapsed -= OnExpiredTakeOffToken;
            if (DateTime.Now <= token.expiration && !token.hasExpired)
            {
                Runway runway = GetRunwayById(token.runwayId);
                // Check if the runway exists and if it has been properly reserved
                if (runway == null || runway.state != Runway.RunwayState.Reserved)
                {
                    ReleaseTakeOffResources(token);
                    return(PerformResult.InvalidParameters);
                }
                runway.aircraftId = token.aircraftId;
                runway.Elapsed   += OnTakeOffOperationComplete;

                ParkingStand parkingStand = GetParkingStandByAircraftId(token.aircraftId);
                parkingStand.aircraftId = Guid.Empty;
                parkingStand.state      = ParkingStand.ParkingStandState.Available;

                token.Dispose();
                runway.Operate();
                return(PerformResult.Success);
            }

            else // Token has expired
            {
                if (!token.hasExpired) // If the token's expiration date has passed but the elapsed event hasn't fired yet, then release the resources
                {
                    ReleaseTakeOffResources(token);
                }
                return(PerformResult.ExpiredToken);
            }
        }
Beispiel #2
0
        // Release resources reserved by a landing request token that will not be used.
        private void ReleaseLandingResources(LandingRequestToken token)
        {
            Runway       runway       = GetRunwayById(token.runwayId);
            ParkingStand parkingStand = GetParkingStandById(token.parkingStandId);

            runway.state            = Runway.RunwayState.Available;
            runway.aircraftId       = Guid.Empty;
            parkingStand.aircraftId = Guid.Empty;
            parkingStand.state      = ParkingStand.ParkingStandState.Available;
            token.Dispose();
        }
Beispiel #3
0
        // Releases resources and updates states accordingly when the landing operation completes (runway's timer elapses).
        private void OnLandingOperationComplete(object source, ElapsedEventArgs e)
        {
            Runway runway = (Runway)source;

            // Unsubscribe from the runway's timer
            runway.Elapsed -= OnLandingOperationComplete;

            ParkingStand parkingStand = GetParkingStandByAircraftId(runway.aircraftId);

            // Update the states and data.
            runway.state       = Runway.RunwayState.Available;
            parkingStand.state = ParkingStand.ParkingStandState.Occupied;
            runway.aircraftId  = Guid.Empty;
        }
Beispiel #4
0
        /* After this call is executed successfully, the used runway is InOperation
         * for the length of operation duration parameter and can't handle any other
         * operations during this time. After the operation is completed, the runway
         * becomes Available again, and the reserved parking stand becomes
         * Occupied. The call is non-blocking, i.e. it returns before the runway is
         * cleared. */
        public PerformResult PerformLanding(LandingRequestToken token)
        {
            token.Stop();
            token.Elapsed -= OnExpiredLandingToken;
            // Token hasn't expired yet
            if (DateTime.Now <= token.expiration && !token.hasExpired)
            {
                Runway runway = GetRunwayById(token.runwayId);
                // Check if the runway exists and if it has been properly reserved
                if (runway == null || runway.state != Runway.RunwayState.Reserved)
                {
                    ReleaseLandingResources(token);
                    return(PerformResult.InvalidParameters);
                }

                ParkingStand parkingStand = GetParkingStandById(token.parkingStandId);
                // Check if the parkingStand exists and if it has been properly reserved
                if (parkingStand == null || parkingStand.state != ParkingStand.ParkingStandState.Reserved)
                {
                    ReleaseLandingResources(token);
                    return(PerformResult.InvalidParameters);
                }
                runway.aircraftId       = token.aircraftId;
                parkingStand.aircraftId = runway.aircraftId;
                runway.Elapsed         += OnLandingOperationComplete;

                token.Dispose();
                runway.Operate();
                return(PerformResult.Success);
            }


            else // Token has expired
            {
                if (!token.hasExpired) // the token's expiration date has passed but the elapsed event hasn't fired yet, then release the resources.
                {
                    ReleaseLandingResources(token);
                }
                return(PerformResult.ExpiredToken);
            }
        }