예제 #1
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");
            }
        }