예제 #1
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="parameters"></param>
        public void Startup(PluginStartupParameters parameters)
        {
            lock (_SyncLock) {
                var optionsStorage = new OptionsStorage();
                _Options = optionsStorage.Load(this);

                _Database = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database;
                _Database.FileNameChanging += BaseStationDatabase_FileNameChanging;
                _Database.FileNameChanged  += BaseStationDatabase_FileNameChanged;

                _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton;
                _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted;

                StartSession();

                // If we process messages on the same thread as IAutoConfigListener raises the message received event on then we
                // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many
                // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list
                // we create a background thread and process the messages on that.
                _BackgroundThreadMessageQueue = new BackgroundThreadQueue <BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue");
                _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught);
                var listener = Factory.Singleton.Resolve <IAutoConfigListener>().Singleton.Listener;
                listener.Port30003MessageReceived += MessageListener_MessageReceived;
                listener.SourceChanged            += MessageListener_SourceChanged;

                Factory.Singleton.Resolve <IHeartbeatService>().Singleton.SlowTick += Heartbeat_SlowTick;
            }
        }
예제 #2
0
        private static void SendToWriters(LogEntry entry)
        {
            lock (LockObject)
            {
                var written = false;
                if (BackgroundThreadQueue.WriterCount > 0)
                {
                    BackgroundThreadQueue.AddMessage(entry);
                    written = true;
                }

                if (DirectWriters.Count > 0)
                {
                    foreach (var directWriter in DirectWriters)
                    {
                        directWriter.Write(entry);
                    }
                    written = true;
                }

                if (!written)
                {
                    entry.Message = $"No Writers : {entry.Message}";
                    WriteSystem(entry);
                }
            }
        }
예제 #3
0
        private static void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exc = e.ExceptionObject as Exception;

            if (exc == null)
            {
                string exceptionObjectType     = "NULL",
                       exceptionObjectToString = "NULL";
                if (e.ExceptionObject != null) //ExceptionObject was set but not an exception type
                {
                    exceptionObjectType     = e.ExceptionObject.GetType().FullName;
                    exceptionObjectToString = e.ExceptionObject.ToString();
                }

                var message =
                    $"Unhandled Exception in AppDomain. [IsTerminating: {e.IsTerminating}, ExceptionObjectType: {exceptionObjectType}, ExceptionObject: {exceptionObjectToString}]";

                WriteError(message, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name);

                WriteSystem(message);
            }
            else
            {
                var message = $"Unhandled Exception in AppDomain. [IsTerminating: {e.IsTerminating}]";
                WriteError(message, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name, exc);

                WriteSystem(new LogEntry(Thread.CurrentThread.ManagedThreadId, DateTime.Now, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Error, exc, message));
            }

            BackgroundThreadQueue.Exit(TimeSpan.FromSeconds(5));
        }
예제 #4
0
 public void Enqueue(Type type, object data)
 {
     BackgroundThreadQueue.Enqueue(new Meta(data, this)
     {
         Type = type
     });
 }
        /// <summary>
        /// Disposes of or finalises the object.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                lock (_SyncLock) _Disposed = true;

                foreach (var client in _ConnectedClients.ToArray())
                {
                    try {
                        DisconnectClient(client);
                    } catch {
                    }
                }
                _ConnectedClients.Clear();

                if (_SendQueue != null)
                {
                    _SendQueue.Dispose();
                    _SendQueue = null;
                }

                if (_Listener != null)
                {
                    try {
                        _Listener.Stop();
                        _Listener = null;
                    } catch {
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// See base docs.
        /// </summary>
        protected override void DoInitialise()
        {
            _AutoConfigDatabase = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton;
            _AutoConfigDatabase.Database.AircraftUpdated += BaseStationDatabase_AircraftUpdated;
            _AutoConfigDatabase.Database.FileNameChanged += BaseStationDatabase_FileNameChanged;

            _AircraftOnlineLookupManager = Factory.Singleton.Resolve <IAircraftOnlineLookupManager>().Singleton;
            _AircraftOnlineLookupManager.AircraftFetched += AircraftOnlineLookupManager_AircraftFetched;

            _PictureManager = Factory.Singleton.Resolve <IAircraftPictureManager>().Singleton;
            var autoConfigurationPictureFolderCache = Factory.Singleton.Resolve <IAutoConfigPictureFolderCache>().Singleton;

            _PictureFolderCache = autoConfigurationPictureFolderCache.DirectoryCache;
            autoConfigurationPictureFolderCache.CacheConfigurationChanged += AutoConfigPictureFolderCache_CacheConfigurationChanged;

            _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton;
            _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted;

            if (_PictureLookupThread == null)
            {
                _PictureLookupThread = new BackgroundThreadQueue <LookupPictureDetail>("PictureLookup", BackgroundThreadQueueMechanism.ThreadPool);
                _PictureLookupThread.MaximumParallelThreads = 10;
                _PictureLookupThread.StartBackgroundThread(PictureLookupThread_ProcessLookup, PictureLookupThread_ProcessException);
            }

            base.DoInitialise();
        }
예제 #7
0
 public DatabaseRepository(ITypeTableNameProvider tableNameProvider = null, Func <SchemaDefinition, TypeSchema, string> schemaTempPathProvider = null)
     : base(tableNameProvider, schemaTempPathProvider)
 {
     BlockOnChildWrites    = true;
     BackgroundThreadQueue = new BackgroundThreadQueue <SqlStringBuilder> {
         Process = Execute
     };
 }
예제 #8
0
 public ObjectReaderWriter(string rootDirectory)
     : base()
 {
     RootDirectory         = rootDirectory;
     BackgroundThreadQueue = new BackgroundThreadQueue <Meta> {
         Process = Write
     };
 }
예제 #9
0
        private static void DisposeAllWriters()
        {
            foreach (var writer in DirectWriters)
            {
                writer.Dispose();
            }

            DirectWriters.Clear();

            BackgroundThreadQueue.Exit(TimeSpan.FromSeconds(1));
        }
예제 #10
0
        private static void RemoveWriter(ILogWriter writer)
        {
            if (writer.UseBackgroundThreadQueue)
            {
                BackgroundThreadQueue.Remove(writer);
            }
            else
            {
                DirectWriters.Remove(writer);
            }

            // adding a message as soon as the logger is removed so that the logger has a timestamp in its log for when it was removed
            WriteTrace($"LogWriter '{writer.GetType().Name}'({(writer.UseBackgroundThreadQueue ? "queued" : "not queued")}) removed", typeof(Log).FullName, MethodBase.GetCurrentMethod().Name);
        }
예제 #11
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public Listener()
        {
            _Statistics = Factory.Singleton.Resolve <IStatistics>().Singleton;

            _Port30003MessageTranslator = Factory.Singleton.Resolve <IBaseStationMessageTranslator>();
            _ModeSMessageTranslator     = Factory.Singleton.Resolve <IModeSTranslator>();
            _AdsbMessageTranslator      = Factory.Singleton.Resolve <IAdsbTranslator>();
            _ModeSParity = Factory.Singleton.Resolve <IModeSParity>();

            var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter);

            _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue <MessageDispatch>(messageQueueName);
            _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException);
        }
예제 #12
0
 private static void EnsureQueue()
 {
     _messageQueue = _queueLock.DoubleCheckLock(ref _messageQueue, () =>
     {
         return(new BackgroundThreadQueue <ConsoleMessage>((msg) =>
         {
             lock (_colorLock)
             {
                 Console.ForegroundColor = msg.Colors.ForegroundColor;
                 Console.BackgroundColor = msg.Colors.BackgroundColor;
                 Console.Write(msg.Text);
                 Console.ResetColor();
             }
         }));
     });
 }
예제 #13
0
        #pragma warning restore 0067
        #endregion
        #endregion

        #region Constructor, finaliser
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public MergedFeedListener()
        {
            _Clock           = Factory.Resolve <IClock>();
            Listeners        = new ReadOnlyCollection <IMergedFeedComponentListener>(_Listeners);
            IcaoTimeout      = 5000;
            ConnectionStatus = ConnectionStatus.Connected;

            var messageQueueName = String.Format("MergedFeedListenerMessages_{0}", ++_ListenerCounter);

            _MessageProcessingQueue = new BackgroundThreadQueue <MessageReceived>(messageQueueName, 200000);
            _MessageProcessingQueue.StartBackgroundThread(ProcessReceivedMessage, HandleMessageProcessingException);

            var heartbeatService = Factory.ResolveSingleton <IHeartbeatService>();

            heartbeatService.SlowTick += HeartbeatService_SlowTick;
            _HookedSlowTick            = true;
        }
예제 #14
0
 public DynamicTypeManager(DynamicTypeDataRepository descriptorRepository, DataSettings settings)
 {
     DataSettings  = settings;
     JsonDirectory = settings.GetRootDataDirectory(nameof(DynamicTypeManager));
     if (!JsonDirectory.Exists)
     {
         JsonDirectory.Create();
     }
     descriptorRepository.EnsureDaoAssemblyAndSchema();
     DynamicTypeDataRepository = descriptorRepository;
     JsonFileProcessor         = new BackgroundThreadQueue <DataFile>()
     {
         Process = (df) =>
         {
             ProcessJsonFile(df.TypeName, df.FileInfo);
         }
     };
 }
예제 #15
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="initialStatus"></param>
        public Connection(Connector connector, ConnectionStatus initialStatus)
        {
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }
            _Connector = connector;

            Created = DateTime.UtcNow;

            string operationQueueName;

            lock (_SyncLock) {
                operationQueueName = String.Format("ConnectionOpQueue-{0}-{1}", _Connector.Name ?? "unnamed", ++_ConnectionCount);
            }
            _OperationQueue = new BackgroundThreadQueue <ReadWriteOperation>(operationQueueName, BackgroundThreadQueueMechanism.QueueWithNoBlock, 200000);
            _OperationQueue.StartBackgroundThread(OperationQueue_ProcessOperation, OperationQueue_ProcessException);

            ConnectionStatus = initialStatus;
        }
예제 #16
0
파일: Plugin.cs 프로젝트: vishalishere/vrs
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="parameters"></param>
        public void Startup(PluginStartupParameters parameters)
        {
            Singleton = this;

            lock (_SyncLock) {
                var optionsStorage = new OptionsStorage();
                _Options = optionsStorage.Load();

                _Database = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database;
                _Database.FileNameChanging += BaseStationDatabase_FileNameChanging;
                _Database.FileNameChanged  += BaseStationDatabase_FileNameChanged;

                _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton;
                _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted;

                var feedManager = Factory.Singleton.Resolve <IFeedManager>().Singleton;
                feedManager.FeedsChanged += FeedManager_FeedsChanged;

                _OnlineLookupCache          = Provider.CreateOnlineLookupCache();
                _OnlineLookupCache.Database = _Database;
                _OnlineLookupCache.RefreshOutOfDateAircraft = _Options.RefreshOutOfDateAircraft;
                _OnlineLookupCache.EnabledChanged          += OnlineLookupCache_EnabledChanged;
                StartSession();

                var onlineLookupManager = Factory.Singleton.Resolve <IAircraftOnlineLookupManager>().Singleton;
                onlineLookupManager.RegisterCache(_OnlineLookupCache, 100, letManagerControlLifetime: false);

                // If we process messages on the same thread as the listener raises the message received event on then we
                // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many
                // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list
                // we create a background thread and process the messages on that.
                _BackgroundThreadMessageQueue = new BackgroundThreadQueue <BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue", 200000);
                _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught);

                HookFeed();

                _HeartbeatService           = Factory.Singleton.Resolve <IHeartbeatService>();
                _HeartbeatService.SlowTick += Heartbeat_SlowTick;
                _HeartbeatService.Start();
            }
        }
예제 #17
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public Listener()
        {
            _Clock     = Factory.Singleton.Resolve <IClock>();
            Statistics = Factory.Singleton.Resolve <IStatistics>();
            Statistics.Initialise();

            _Port30003MessageTranslator = Factory.Singleton.Resolve <IBaseStationMessageTranslator>();
            _ModeSMessageTranslator     = Factory.Singleton.Resolve <IModeSTranslator>();
            _AdsbMessageTranslator      = Factory.Singleton.Resolve <IAdsbTranslator>();
            _ModeSParity = Factory.Singleton.Resolve <IModeSParity>();
            _Compressor  = Factory.Singleton.Resolve <IBaseStationMessageCompressor>();
            _AircraftListJsonMessageConverter = Factory.Singleton.Resolve <IAircraftListJsonMessageConverter>();

            _ModeSMessageTranslator.Statistics = Statistics;
            _AdsbMessageTranslator.Statistics  = Statistics;

            var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter);

            _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue <MessageDispatch>(messageQueueName, 200000);
            _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException);
        }
예제 #18
0
        /// <summary>
        /// Flush Queue and shutdowns all Logging.
        /// Waits for the given timeout before forcing the shutdown.
        /// </summary>
        public static bool Exit(TimeSpan?timeout = null)
        {
            if (timeout == null)
            {
                timeout = new TimeSpan(0, 0, 10);
            }

            lock (LockObject)
            {
                SendToWriters(new LogEntry(Thread.CurrentThread.ManagedThreadId, DateTime.Now, typeof(BackgroundThreadQueue).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Trace, null, "BackgroundThreadQueue Exit Requested"));

                var result = true;

                result = BackgroundThreadQueue.Exit(timeout.Value);

                AppDomain.CurrentDomain.UnhandledException -= appDomain_UnhandledException;

                DisposeAllWriters();

                return(result);
            }
        }
예제 #19
0
        private void DoAbandon(bool raiseExceptionEvent)
        {
            var inAbandon = false;
            BackgroundThreadQueue <ReadWriteOperation> operationQueue = null;

            lock (_SyncLock) {
                inAbandon = _InAbandon;
                if (!inAbandon)
                {
                    _InAbandon      = true;
                    operationQueue  = _OperationQueue;
                    _OperationQueue = null;
                }
            }
            if (!inAbandon)
            {
                try {
                    try {
                        AbandonConnection();
                    } catch (Exception ex) {
                        if (_Connector != null && raiseExceptionEvent)
                        {
                            _Connector.RaiseConnectionException(this, ex);
                        }
                    }

                    if (operationQueue != null)
                    {
                        // This will throw a ThreadAborted exception - any code outside of a catch or finally
                        // after this point will not run.
                        operationQueue.Dispose();
                    }
                } finally {
                    _InAbandon = false;
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public Listener()
        {
            _Statistics = Factory.Singleton.Resolve<IStatistics>().Singleton;

            _Port30003MessageTranslator = Factory.Singleton.Resolve<IBaseStationMessageTranslator>();
            _ModeSMessageTranslator = Factory.Singleton.Resolve<IModeSTranslator>();
            _AdsbMessageTranslator = Factory.Singleton.Resolve<IAdsbTranslator>();
            _ModeSParity = Factory.Singleton.Resolve<IModeSParity>();

            var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter);
            _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue<MessageDispatch>(messageQueueName);
            _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException);
        }
        /// <summary>
        /// Disposes of or finalises the object.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            if(disposing) {
                lock(_SyncLock) _Disposed = true;

                foreach(var client in _ConnectedClients.ToArray()) {
                    try {
                        DisconnectClient(client);
                    } catch {
                    }
                }
                _ConnectedClients.Clear();

                if(_SendQueue != null) {
                    _SendQueue.Dispose();
                    _SendQueue = null;
                }

                if(_Listener != null) {
                    try {
                        _Listener.Stop();
                        _Listener = null;
                    } catch {
                    }
                }
            }
        }
 /// <summary>
 /// Creates a new object.
 /// </summary>
 public BroadcastProvider()
 {
     _SendQueue = new BackgroundThreadQueue<byte[]>(String.Format("BroadcastProvider{0}", ++_InstanceCounter));
     _SendQueue.StartBackgroundThread(SendQueueHandler, SendQueueExceptionHandler);
 }
예제 #23
0
 private static void AddQueueWriter(ILogWriter writer)
 {
     BackgroundThreadQueue.Add(writer);
 }
예제 #24
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="parameters"></param>
        public void Startup(PluginStartupParameters parameters)
        {
            lock(_SyncLock) {
                var optionsStorage = new OptionsStorage();
                _Options = optionsStorage.Load(this);

                _Database = Factory.Singleton.Resolve<IAutoConfigBaseStationDatabase>().Singleton.Database;
                _Database.FileNameChanging += BaseStationDatabase_FileNameChanging;
                _Database.FileNameChanged += BaseStationDatabase_FileNameChanged;

                _StandingDataManager = Factory.Singleton.Resolve<IStandingDataManager>().Singleton;
                _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted;

                StartSession();

                // If we process messages on the same thread as IAutoConfigListener raises the message received event on then we
                // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many
                // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list
                // we create a background thread and process the messages on that.
                _BackgroundThreadMessageQueue = new BackgroundThreadQueue<BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue");
                _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught);
                var listener = Factory.Singleton.Resolve<IAutoConfigListener>().Singleton.Listener;
                listener.Port30003MessageReceived += MessageListener_MessageReceived;
                listener.SourceChanged += MessageListener_SourceChanged;

                Factory.Singleton.Resolve<IHeartbeatService>().Singleton.SlowTick += Heartbeat_SlowTick;
            }
        }
 /// <summary>
 /// Creates a new object.
 /// </summary>
 public BroadcastProvider()
 {
     _SendQueue = new BackgroundThreadQueue <byte[]>(String.Format("BroadcastProvider{0}", ++_InstanceCounter));
     _SendQueue.StartBackgroundThread(SendQueueHandler, SendQueueExceptionHandler);
 }