/* 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); } }
/* 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); } }