Example #1
0
        /// <summary>
        /// Imports Location records.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        private void ProcessLocations(IBaseStationDatabase source, IBaseStationDatabase dest)
        {
            _LocationMap.Clear();

            if (!ImportLocations)
            {
                WriteLog("Location import skipped");
            }
            else
            {
                WriteLog("Importing Location records");

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

                foreach (var rec in allSource)
                {
                    var sourceID = rec.LocationID;

                    var existing = allDest.FirstOrDefault(r => r.LocationID > 0 && String.Equals(r.LocationName, rec.LocationName));
                    if (existing == null)
                    {
                        rec.LocationID = 0;
                        dest.InsertLocation(rec);
                    }
                    else
                    {
                        rec.LocationID      = existing.LocationID;
                        existing.LocationID = -1;
                        dest.UpdateLocation(rec);
                    }

                    _LocationMap.Add(sourceID, rec.LocationID);
                }

                WriteLog($"    Imported {allSource.Count:N0} locations");
            }
        }