示例#1
0
        /// <summary>
        /// Creates a new session.
        /// </summary>
        private void StartSession()
        {
            lock (_SyncLock) {
                if (_Session == null)
                {
                    if (!_Options.Enabled)
                    {
                        Status            = PluginStrings.Disabled;
                        StatusDescription = null;
                    }
                    else if (String.IsNullOrEmpty(_Database.FileName))
                    {
                        Status            = PluginStrings.EnabledNoDatabase;
                        StatusDescription = null;
                    }
                    else if (!Provider.FileExists(_Database.FileName))
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = String.Format(PluginStrings.SomethingDoesNotExist, _Database.FileName);
                    }
                    else if (Provider.FileSize(_Database.FileName) == 0L)
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = String.Format(PluginStrings.SomethingIsZeroLength, _Database.FileName);
                    }
                    else if (!_Options.AllowUpdateOfOtherDatabases && !DatabaseCreatedByPlugin())
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = PluginStrings.UpdatingDatabasesNotCreatedByPluginForbidden;
                    }
                    else
                    {
                        Status            = String.Format(PluginStrings.EnabledAndUpdatingSomething, _Database.FileName);
                        StatusDescription = null;

                        try {
                            _Database.WriteSupportEnabled = true;

                            var location = _Database.GetLocations().OrderBy(c => c.LocationID).FirstOrDefault();

                            _Session = new BaseStationSession()
                            {
                                LocationID = location == null ? 0 : location.LocationID,
                                StartTime  = Provider.LocalNow,
                            };
                            _Database.InsertSession(_Session);
                        } catch (ThreadAbortException) {
                        } catch (Exception ex) {
                            Debug.WriteLine(String.Format("BaseStationDatabaseWriter.Plugin.StartSession caught exception {0}", ex.ToString()));
                            Status            = PluginStrings.EnabledNotUpdating;
                            StatusDescription = String.Format(PluginStrings.ExceptionCaughtWhenStartingSession, ex.Message);

                            Factory.Singleton.Resolve <ILog>().Singleton.WriteLine("Database writer plugin caught exception on starting session: {0}", ex.ToString());
                        }
                    }
                    OnStatusChanged(EventArgs.Empty);
                }
            }
        }
示例#2
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");
            }
        }
示例#3
0
        /// <summary>
        /// Creates a new session.
        /// </summary>
        private void StartSession()
        {
            var feedManager = Factory.Singleton.Resolve <IFeedManager>().Singleton;

            lock (_SyncLock) {
                if (_Session == null)
                {
                    if (!_Options.Enabled)
                    {
                        Status            = PluginStrings.Disabled;
                        StatusDescription = null;
                    }
                    else if (_Options.ReceiverId == 0)
                    {
                        Status = PluginStrings.EnabledNoReceiver;
                    }
                    else if (feedManager.GetByUniqueId(_Options.ReceiverId, ignoreInvisibleFeeds: false) == null)
                    {
                        Status = PluginStrings.EnabledBadReceiver;
                    }
                    else if (String.IsNullOrEmpty(_Database.FileName))
                    {
                        Status            = PluginStrings.EnabledNoDatabase;
                        StatusDescription = null;
                    }
                    else if (!Provider.FileExists(_Database.FileName))
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = String.Format(PluginStrings.SomethingDoesNotExist, _Database.FileName);
                    }
                    else if (Provider.FileSize(_Database.FileName) == 0L)
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = String.Format(PluginStrings.SomethingIsZeroLength, _Database.FileName);
                    }
                    else if (!_Options.AllowUpdateOfOtherDatabases && !DatabaseCreatedByPlugin())
                    {
                        Status            = PluginStrings.EnabledNotUpdating;
                        StatusDescription = PluginStrings.UpdatingDatabasesNotCreatedByPluginForbidden;
                    }
                    else
                    {
                        Status            = String.Format(PluginStrings.EnabledAndUpdatingSomething, _Database.FileName);
                        StatusDescription = null;

                        try {
                            _Database.WriteSupportEnabled = true;

                            var location = _Database.GetLocations().OrderBy(c => c.LocationID).FirstOrDefault();

                            _Session = new BaseStationSession()
                            {
                                LocationID = location == null ? 0 : location.LocationID,
                                StartTime  = Provider.LocalNow,
                            };
                            _Database.InsertSession(_Session);

                            _OnlineLookupCache.Enabled = _Session != null && _Options.SaveDownloadedAircraftDetails;
                        } catch (ThreadAbortException) {
                        } catch (Exception ex) {
                            AbandonSession(ex, PluginStrings.ExceptionCaughtWhenStartingSession);
                            Debug.WriteLine(String.Format("BaseStationDatabaseWriter.Plugin.StartSession caught exception {0}", ex.ToString()));
                            Factory.Singleton.Resolve <ILog>().Singleton.WriteLine("Database writer plugin caught exception on starting session: {0}", ex.ToString());
                        }
                    }
                }
            }
        }