Exemplo n.º 1
0
        /// <summary>
        /// Closes an open session.
        /// </summary>
        private void EndSession()
        {
            lock (_SyncLock) {
                if (_Session != null)
                {
                    Status = PluginStrings.NotUpdatingDatabase;
                    try {
                        FlushFlights(true);

                        _Session.EndTime = Provider.LocalNow;
                        _Database.UpdateSession(_Session);

                        StatusDescription = null;
                    } catch (ThreadAbortException) {
                    } catch (Exception ex) {
                        Debug.WriteLine(String.Format("BaseStationDatabaseWriter.Plugin.EndSession caught exception {0}", ex.ToString()));
                        StatusDescription = String.Format(PluginStrings.ExceptionCaughtWhenClosingSession, ex.Message);
                        Factory.Singleton.Resolve <ILog>().Singleton.WriteLine("Database writer plugin caught exception on closing session: {0}", ex.ToString());
                    } finally {
                        _Session = null;
                    }
                    OnStatusChanged(EventArgs.Empty);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Closes an open session.
        /// </summary>
        private void EndSession()
        {
            lock (_SyncLock) {
                if (_Session != null)
                {
                    Status = PluginStrings.NotUpdatingDatabase;
                    try {
                        FlushFlights(true);

                        _Session.EndTime = Provider.LocalNow;
                        _Database.UpdateSession(_Session);

                        StatusDescription = null;
                    } catch (ThreadAbortException) {
                    } catch (Exception ex) {
                        AbandonSession(ex, PluginStrings.ExceptionCaughtWhenClosingSession, Status);
                        Debug.WriteLine(String.Format("BaseStationDatabaseWriter.Plugin.EndSession caught exception {0}", ex.ToString()));
                        Factory.Singleton.Resolve <ILog>().Singleton.WriteLine("Database writer plugin caught exception on closing session: {0}", ex.ToString());
                    } finally {
                        _Session = null;
                        _OnlineLookupCache.Enabled = false;
                    }
                }
            }
        }
Exemplo n.º 3
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");
            }
        }