Beispiel #1
0
        /// <summary>
        /// Imports flight records.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        private void ProcessFlights(IBaseStationDatabaseSQLite source, IBaseStationDatabase dest)
        {
            if (!ImportFlights)
            {
                WriteLog("Flight import skipped");
            }
            else if (!ImportSessions || !ImportLocations)
            {
                WriteLog("Flight import skipped because session import was skipped");
            }
            else if (!ImportAircraft)
            {
                WriteLog("Flight import skipped because aircraft import was skipped");
            }
            else
            {
                WriteLog("Importing flight records");

                var criteria     = new SearchBaseStationCriteria();
                var countFlights = source.GetCountOfFlights(new SearchBaseStationCriteria());
                var countSource  = 0;
                var countDest    = 0;
                var startRow     = 0;
                var pageSize     = 30000;

                while (startRow < countFlights)
                {
                    var allSource = source.GetFlights(criteria, startRow, startRow + (pageSize - 1), "DATE", true, null, false);
                    countSource += allSource.Count;

                    var upsertCandidates = new List <BaseStationFlightUpsert>();
                    var upsertKeys       = new HashSet <string>();
                    foreach (var candidate in allSource)
                    {
                        var key = $"{candidate.AircraftID}-{candidate.StartTime}";
                        if (!upsertKeys.Contains(key) && _AircraftMap.TryGetValue(candidate.AircraftID, out var aircraftID) && _SessionMap.TryGetValue(candidate.SessionID, out var sessionID))
                        {
                            upsertCandidates.Add(new BaseStationFlightUpsert(candidate)
                            {
                                AircraftID = aircraftID,
                                SessionID  = sessionID,
                            });
                            upsertKeys.Add(key);
                        }
                    }

                    var upserted = dest.UpsertManyFlights(upsertCandidates);
                    countDest += upserted.Length;
                    startRow  += pageSize;
                }

                WriteLog($"    Imported {countDest:N0} / {countSource:N0} flights");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Imports Session records.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        private void ProcessSessions(IBaseStationDatabaseSQLite source, IBaseStationDatabase dest)
        {
            _SessionMap.Clear();

            if (!ImportSessions)
            {
                WriteLog("Session import skipped");
            }
            else if (!ImportLocations)
            {
                WriteLog("Session import skipped because location import was skipped");
            }
            else
            {
                WriteLog("Importing Session records");

                var allSource = source.GetSessions();
                var allDest   = dest.GetSessions();

                foreach (var rec in allSource)
                {
                    if (_LocationMap.TryGetValue(rec.LocationID, out var destLocationID))
                    {
                        var sourceID = rec.SessionID;
                        rec.LocationID = destLocationID;

                        var existing = allDest.FirstOrDefault(r => r.SessionID > 0 && r.StartTime == rec.StartTime);
                        if (existing == null)
                        {
                            rec.SessionID = 0;
                            dest.InsertSession(rec);
                        }
                        else
                        {
                            rec.SessionID = existing.SessionID;
                            dest.UpdateSession(rec);
                        }

                        _SessionMap.Add(sourceID, rec.SessionID);
                    }
                }

                WriteLog($"    Imported {allSource.Count:N0} sessions");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Imports aircraft records.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        private void ProcessAircraft(IBaseStationDatabaseSQLite source, IBaseStationDatabase dest)
        {
            _AircraftMap.Clear();

            if (!ImportAircraft)
            {
                WriteLog("Aircraft import skipped");
            }
            else
            {
                WriteLog("Importing Aircraft records");

                var allSource        = source.GetAllAircraft().ToDictionary(r => r.AircraftID, r => r);
                var upsertCandidates = new List <BaseStationAircraftUpsert>();
                var upsertKeys       = new HashSet <string>();
                foreach (var kvp in allSource)
                {
                    if (!upsertKeys.Contains(kvp.Value.ModeS))
                    {
                        upsertCandidates.Add(new BaseStationAircraftUpsert(kvp.Value));
                        upsertKeys.Add(kvp.Value.ModeS);
                    }
                }
                upsertKeys.Clear();

                var upserted = dest.UpsertManyAircraft(upsertCandidates).ToDictionary(r => r.ModeS, r => r);
                upsertCandidates.Clear();

                foreach (var sourceKvp in allSource)
                {
                    var sourceID = sourceKvp.Key;
                    if (upserted.TryGetValue(sourceKvp.Value.ModeS, out var rec))
                    {
                        _AircraftMap.Add(sourceID, rec.AircraftID);
                    }
                }

                WriteLog($"    Imported {upserted.Count:N0} / {allSource.Count:N0} aircraft");
            }
        }