Ejemplo n.º 1
0
        /// <summary>
        /// Fetches many aircraft simultaneously.
        /// </summary>
        /// <param name="fetchedDetails"></param>
        /// <returns></returns>
        protected override bool DoFetchManyAircraft(IEnumerable <AircraftFetcher <string, AircraftDetail> .FetchedDetail> fetchedDetails)
        {
            var allIcaos      = fetchedDetails.Select(r => r.Key).ToArray();
            var newIcaos      = fetchedDetails.Where(r => r.Detail == null || r.Detail.Aircraft == null).Select(r => r.Key).ToArray();
            var existingIcaos = fetchedDetails.Where(r => r.Detail != null && r.Detail.Aircraft != null).Select(r => r.Key).ToArray();

            var aircraftAndFlightCounts = _AutoConfigDatabase.Database.GetManyAircraftAndFlightsCountByCode(newIcaos);
            var aircraft = _AutoConfigDatabase.Database.GetManyAircraftByCode(existingIcaos);

            var combinedAircraft = new Dictionary <string, BaseStationAircraft>();

            foreach (var kvp in aircraftAndFlightCounts)
            {
                combinedAircraft.Add(kvp.Key, kvp.Value);
            }
            foreach (var kvp in aircraft)
            {
                combinedAircraft.Add(kvp.Key, kvp.Value);
            }
            var allOnlineAircraft = _AircraftOnlineLookupManager.LookupMany(allIcaos, combinedAircraft);

            foreach (var kvp in fetchedDetails)
            {
                var icao24        = kvp.Key;
                var fetchedDetail = kvp;

                BaseStationAircraft databaseAircraft = null;
                BaseStationAircraftAndFlightsCount databaseAircraftAndFlights = null;
                if (!aircraft.TryGetValue(icao24, out databaseAircraft))
                {
                    aircraftAndFlightCounts.TryGetValue(icao24, out databaseAircraftAndFlights);
                }
                AircraftOnlineLookupDetail onlineAircraft;
                allOnlineAircraft.TryGetValue(icao24, out onlineAircraft);

                kvp.Detail = ApplyDatabaseRecord(
                    fetchedDetail.Detail,
                    databaseAircraftAndFlights ?? databaseAircraft,
                    onlineAircraft,
                    fetchedDetail.Aircraft,
                    fetchedDetail.IsFirstFetch,
                    databaseAircraftAndFlights != null ? databaseAircraftAndFlights.FlightsCount
                                                       : fetchedDetail.Detail != null ? fetchedDetail.Detail.FlightsCount : 0
                    );
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void AircraftOnlineLookupManager_LookupMany_Fetches_Icaos_From_Cache()
        {
            _Cache2Icaos.Add("ABC123");
            _Cache2Icaos.Add("123456");

            var result = _Manager.LookupMany(new string[] { "ABC123", "123456" }, null);

            Assert.IsTrue(result.ContainsKey("ABC123"));
            Assert.IsTrue(result.ContainsKey("123456"));
        }