Exemple #1
0
        /// <summary>
        /// If the ICAO code is in airportList, and the number of runways is at least 1,
        /// we set the list of runways. Then we attempt to download the matar and
        /// select a runway with maximum headwind component.
        ///
        /// If ICAO is not found in airportList, this method clears the list of runways.
        /// If we cannot successfully find the runway with max headwind component, the
        /// selected runway is set arbitrarily.
        ///
        /// GetIcao should always return a non-null result. SetRunways and SetSelectedRunway
        /// should not throw with non-null inputs.
        /// </summary>
        public static async Task UpdateRunways(
            Func <string> GetIcao,
            Action <IEnumerable <string> > SetRunways,
            Action <string> SetSelectedRunway,
            AirportManager airportList)
        {
            var icaoBeforeAwait = GetIcao();
            var rwyList         = airportList.RwyIdents(icaoBeforeAwait)?.ToList();

            if (rwyList != null && rwyList.Count > 0)
            {
                SetRunways(rwyList);
                var runways = airportList[icaoBeforeAwait].Rwys;
                var(success, rwy) = await SelectRwyBasedOnWind(
                    runways, icaoBeforeAwait);

                // Only choose runway based on weather if the ICAO does not change
                // during the await.
                SetSelectedRunway((success && icaoBeforeAwait == GetIcao()) ? rwy : rwyList[0]);
            }
            else
            {
                SetRunways(new string[0]);
            }
        }
 public AlternateFinder(AirportManager airportList)
 {
     this.airportList = airportList;
 }