public void PluginStartupParameters_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var aircraftList = new Mock<IBaseStationAircraftList>(MockBehavior.Strict).Object;
            var fsxAircraftList = new Mock<ISimpleAircraftList>(MockBehavior.Strict).Object;
            var uPnpManager = new Mock<IUniversalPlugAndPlayManager>(MockBehavior.Strict).Object;
            var webSite = new Mock<IWebSite>(MockBehavior.Strict).Object;

            var startupParameters = new PluginStartupParameters(aircraftList, fsxAircraftList, uPnpManager, webSite);

            Assert.AreSame(aircraftList, startupParameters.AircraftList);
            Assert.AreSame(fsxAircraftList, startupParameters.FlightSimulatorAircraftList);
            Assert.AreSame(uPnpManager, startupParameters.UPnpManager);
            Assert.AreSame(webSite, startupParameters.WebSite);
        }
        public void TestInitialise()
        {
            _AutoConfigMessageListener = TestUtilities.CreateMockSingleton<IAutoConfigListener>();
            _Listener = TestUtilities.CreateMockImplementation<IListener>();
            _AutoConfigMessageListener.Setup(r => r.Listener).Returns(_Listener.Object);

            _StartupParameters = new PluginStartupParameters(null, null, null, null);
            _ClassFactorySnapshot = Factory.TakeSnapshot();
            _PluginSettingsStorage = TestUtilities.CreateMockSingleton<IPluginSettingsStorage>();
            _PluginSettings = new PluginSettings();
            _PluginSettingsStorage.Setup(s => s.Load()).Returns(_PluginSettings);
            _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>();
            _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true);

            _BaseStationDatabase = new Mock<IBaseStationDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _BaseStationDatabase.Object.FileName = "fn";
            _AutoConfigBaseStationDatabase = TestUtilities.CreateMockSingleton<IAutoConfigBaseStationDatabase>();
            _AutoConfigBaseStationDatabase.Setup(a => a.Database).Returns(_BaseStationDatabase.Object);

            _BaseStationDatabase.Setup(d => d.GetLocations()).Returns(new List<BaseStationLocation>() { new BaseStationLocation() { LocationID = 9821 } } );
            SetDBHistory(true);

            _StandingDataManager = TestUtilities.CreateMockSingleton<IStandingDataManager>();
            _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>();
            _Log = TestUtilities.CreateMockSingleton<ILog>();

            _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>();
            _Configuration = new Configuration();
            _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration);

            _StatusChangedEvent = new EventRecorder<EventArgs>();

            _Plugin = new PluginNS.Plugin();
            _Provider = new Mock<PluginNS.IPluginProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _Provider.Setup(p => p.FileExists(It.IsAny<string>())).Returns(true);
            _Provider.Setup(p => p.LocalNow).Returns(new DateTime(2001, 2, 3, 4, 5, 6));
            _Provider.Setup(p => p.FileSize(It.IsAny<string>())).Returns(1000000L);
            _OptionsView = new Mock<PluginNS.IOptionsView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _Provider.Setup(p => p.CreateOptionsView()).Returns(_OptionsView.Object);
            _Plugin.Provider = _Provider.Object;
        }
        private void StartPlugins(IWebSite webSite)
        {
            _View.ReportProgress(Strings.SplashScreenStartingPlugins);

            var parameters = new PluginStartupParameters(
                _View.BaseStationAircraftList,
                _View.FlightSimulatorXAircraftList,
                _View.UPnpManager,
                webSite);

            foreach(var plugin in Factory.Singleton.Resolve<IPluginManager>().Singleton.LoadedPlugins) {
                try {
                    plugin.Startup(parameters);

                    if(BackgroundThreadExceptionHandler != null) {
                        IBackgroundThreadExceptionCatcher backgroundExceptionCatcher = plugin as IBackgroundThreadExceptionCatcher;
                        if(backgroundExceptionCatcher != null) backgroundExceptionCatcher.ExceptionCaught += BackgroundThreadExceptionHandler;
                    }
                } catch(Exception ex) {
                    Debug.WriteLine(String.Format("MainPresenter.StartPlugins caught exception: {0}", ex.ToString()));
                    Factory.Singleton.Resolve<ILog>().Singleton.WriteLine("Caught exception when starting {0}: {1}", plugin.Name, ex.ToString());
                    _View.ReportProblem(String.Format(Strings.PluginThrewExceptionFull, plugin.Name, ex.Message), Strings.PluginThrewExceptionTitle, false);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="parameters"></param>
        public void Startup(PluginStartupParameters parameters)
        {
            var pluginSettingsStorage = Factory.Singleton.Resolve<IPluginSettingsStorage>().Singleton;
            var pluginSettings = pluginSettingsStorage.Load();
            _Enabled = pluginSettings.ReadBool(this, EnabledSettingsKey, false);

            var folder = Factory.Singleton.Resolve<IConfigurationStorage>().Folder;
            _Folder = Path.Combine(folder, "BaseStationDatabaseLogger");
            if(!Directory.Exists(_Folder)) Directory.CreateDirectory(_Folder);

            EnableDisableLogging();
        }
 public void Startup(PluginStartupParameters parameters)
 {
 }
Exemplo n.º 6
0
        public void Startup(PluginStartupParameters parameters)
        {
            var pluginSettingsStorage = Factory.Singleton.Resolve<IPluginSettingsStorage>().Singleton;
            var pluginSettings = pluginSettingsStorage.Load();

            _Enabled = pluginSettings.ReadBool(this, EnabledSettingsKey, false);

            var webServer = Factory.Singleton.Resolve<IAutoConfigWebServer>().Singleton.WebServer;
            webServer.BeforeRequestReceived += WebServer_BeforeRequestReceived;
            webServer.ResponseSent += WebServer_ResponseSent;

            UpdateStatus();
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="parameters"></param>
        public void Startup(PluginStartupParameters parameters)
        {
            var pluginSettingsStorage = Factory.Singleton.Resolve<IPluginSettingsStorage>().Singleton;
            var pluginSettings = pluginSettingsStorage.Load();
            _Enabled = pluginSettings.ReadBool(this, EnabledSettingsKey, false);

            InitialiseFile();

            var webServer = Factory.Singleton.Resolve<IAutoConfigWebServer>().Singleton.WebServer;
            webServer.ResponseSent += WebServer_ResponseSent;
        }