/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; var options = OptionsStorage.Load(this); _HtmlLocaliser = Factory.Resolve <IHtmlLocaliser>(); _HtmlLocaliser.Initialise(); _HtmlLocaliser.AddResourceStrings(typeof(DatabaseEditorStrings)); BaseStationDatabase = Factory.ResolveSingleton <IAutoConfigBaseStationDatabase>().Database; BaseStationDatabase.WriteSupportEnabled = true; _WebSiteExtender = Factory.Resolve <IWebSiteExtender>(); _WebSiteExtender.Enabled = false; _WebSiteExtender.WebRootSubFolder = "Web"; _WebSiteExtender.InjectContent = @"<script src=""script-DatabaseEditor/inject.js"" type=""text/javascript"">"; _WebSiteExtender.InjectMapPages(); _WebSiteExtender.InjectReportPages(); _WebSiteExtender.Initialise(parameters); _WebSiteExtender.ProtectFolder(ProtectedFolder); parameters.WebSite.HtmlLoadedFromFile += WebSite_HtmlLoadedFromFile; var redirection = Factory.ResolveSingleton <IRedirectionConfiguration>(); redirection.AddRedirection("/DatabaseEditor", "/DatabaseEditor/index.html", RedirectionContext.Any); redirection.AddRedirection("/DatabaseEditor/", "/DatabaseEditor/index.html", RedirectionContext.Any); ApplyOptions(options); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _Extender = Factory.Singleton.Resolve <IWebSiteExtender>(); _WebSite = TestUtilities.CreateMockInstance <IWebSite>(); _PluginStartupParameters = new PluginStartupParameters(null, null, _WebSite.Object, "PluginFolder"); _AddSiteRoot = null; _RemoveSiteRoot = null; _WebSite.Setup(r => r.AddSiteRoot(It.IsAny <SiteRoot>())).Callback((SiteRoot siteRoot) => _AddSiteRoot = siteRoot); _WebSite.Setup(r => r.RemoveSiteRoot(It.IsAny <SiteRoot>())).Callback((SiteRoot siteRoot) => _RemoveSiteRoot = siteRoot); _AddHtmlContentInjectors = new List <HtmlContentInjector>(); _RemoveHtmlContentInjectors = new List <HtmlContentInjector>(); _WebSite.Setup(r => r.AddHtmlContentInjector(It.IsAny <HtmlContentInjector>())).Callback((HtmlContentInjector injector) => _AddHtmlContentInjectors.Add(injector)); _WebSite.Setup(r => r.RemoveHtmlContentInjector(It.IsAny <HtmlContentInjector>())).Callback((HtmlContentInjector injector) => _RemoveHtmlContentInjectors.Add(injector)); _AutoConfigWebServer = TestUtilities.CreateMockSingleton <IAutoConfigWebServer>(); _WebServer = TestUtilities.CreateMockInstance <IWebServer>(); _AutoConfigWebServer.Setup(r => r.WebServer).Returns(_WebServer.Object); _Request = TestUtilities.CreateMockInstance <IRequest>(); _Response = TestUtilities.CreateMockInstance <IResponse>(); }
/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; var options = OptionsStorage.Load(this); _HtmlLocaliser = Factory.Singleton.Resolve <IHtmlLocaliser>(); _HtmlLocaliser.Initialise(); _HtmlLocaliser.AddResourceStrings(typeof(DatabaseEditorStrings)); _BaseStationDatabase = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database; _BaseStationDatabase.WriteSupportEnabled = true; _WebSiteExtender = Factory.Singleton.Resolve <IWebSiteExtender>(); _WebSiteExtender.Enabled = false; _WebSiteExtender.WebRootSubFolder = "Web"; _WebSiteExtender.InjectContent = @"<script src=""script-DatabaseEditor/inject.js"" type=""text/javascript"">"; _WebSiteExtender.InjectMapPages(); _WebSiteExtender.InjectReportPages(); _WebSiteExtender.PageHandlers.Add(String.Format("/{0}/SingleAircraftSearch.json", ProtectedFolder), SingleAircraftSearch); _WebSiteExtender.PageHandlers.Add(String.Format("/{0}/SingleAircraftSave.json", ProtectedFolder), SingleAircraftSave); _WebSiteExtender.Initialise(parameters); _WebSiteExtender.ProtectFolder(ProtectedFolder); parameters.WebSite.HtmlLoadedFromFile += WebSite_HtmlLoadedFromFile; ApplyOptions(options); }
/// <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> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; var options = OptionsStorage.Load(this); _HtmlLocaliser = Factory.Resolve <IHtmlLocaliser>(); _HtmlLocaliser.Initialise(); _HtmlLocaliser.AddResourceStrings(typeof(FeedFilterStrings)); _WebSiteExtender = Factory.Resolve <IWebSiteExtender>(); _WebSiteExtender.Enabled = false; _WebSiteExtender.WebRootSubFolder = "Web"; _WebSiteExtender.PageHandlers.Add(String.Format("/{0}/FetchFilterConfiguration.json", ProtectedFolder), FetchFilterConfiguration); _WebSiteExtender.PageHandlers.Add(String.Format("/{0}/SaveFilterConfiguration.json", ProtectedFolder), SaveFilterConfiguration); _WebSiteExtender.Initialise(parameters); var redirection = Factory.ResolveSingleton <IRedirectionConfiguration>(); redirection.AddRedirection("/FeedFilter", "/FeedFilter/index.html", RedirectionContext.Any); redirection.AddRedirection("/FeedFilter/", "/FeedFilter/index.html", RedirectionContext.Any); parameters.WebSite.HtmlLoadedFromFile += WebSite_HtmlLoadedFromFile; ApplyOptions(options); }
private void StartPlugins(IWebSite webSite) { _View.ReportProgress(Strings.SplashScreenStartingPlugins); foreach (var plugin in Factory.ResolveSingleton <IPluginManager>().LoadedPlugins) { try { var parameters = new PluginStartupParameters( _View.FlightSimulatorXAircraftList, _View.UPnpManager, webSite, plugin.PluginFolder); 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.ResolveSingleton <ILog>().WriteLine("Caught exception when starting {0}: {1}", plugin.Name, ex.ToString()); _View.ReportProblem(String.Format(Strings.PluginThrewExceptionFull, plugin.Name, ex.Message), Strings.PluginThrewExceptionTitle, false); } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; _WebSite = parameters.WebSite; var options = OptionsStorage.Load(this); ApplyOptions(options); var heartbeat = Factory.ResolveSingleton <IHeartbeatService>(); heartbeat.SlowTick += Heartbeat_SlowTick; }
/// <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; }
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 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(); }
/// <summary> /// See interface docs. /// </summary> /// <param name="pluginStartupParameters"></param> public void Initialise(PluginStartupParameters pluginStartupParameters) { _WebSite = pluginStartupParameters.WebSite; if (!String.IsNullOrEmpty(WebRootSubFolder)) { _SiteRoot = new SiteRoot() { Folder = Path.Combine(pluginStartupParameters.PluginFolder, WebRootSubFolder), Priority = Priority, }; } if (!String.IsNullOrEmpty(InjectContent)) { var injectContent = InjectContent; Func <string, HtmlContentInjector> createInjector = (string pathAndFile) => new HtmlContentInjector() { Content = () => injectContent, Element = "HEAD", PathAndFile = pathAndFile, Priority = Priority, }; if (InjectPages.Count == 0) { _ContentInjectors.Add(createInjector(null)); } else { foreach (var injectPage in InjectPages) { _ContentInjectors.Add(createInjector(injectPage)); } } } if (PageHandlers.Count > 0) { _WebServer = Factory.Singleton.Resolve <IAutoConfigWebServer>().Singleton.WebServer; _WebServer.BeforeRequestReceived += WebServer_BeforeRequestReceived; foreach (var pageHandler in PageHandlers) { _PageHandlers.Add(pageHandler.Key, pageHandler.Value); } } EnableDisableContent(); }
/// <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(); }
/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; _Options = OptionsStorage.Load(); var pathFromRoot = String.Format("/{0}/", ProtectedFolder); _WebAdminViewManager.Startup(parameters.WebSite); _WebAdminViewManager.RegisterTranslations(typeof(VirtualRadar.WebSite.WebSiteStrings), "", false); _WebAdminViewManager.RegisterTranslations(typeof(VirtualRadar.Localisation.Strings), "Server", false); _WebAdminViewManager.RegisterTranslations(typeof(WebAdminStrings), "WebAdmin", true); // Views that have a menu entry _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "Index.html", WebAdminStrings.WA_Home, () => new View.MainView(parameters.UPnpManager, parameters.FlightSimulatorAircraftList), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "Settings.html", WebAdminStrings.WA_Title_Options, () => new View.SettingsView(), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "Log.html", WebAdminStrings.WA_Title_Log, () => new View.LogView(), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "AircraftDetailLookupLog.html", WebAdminStrings.WS_Title_AircraftLookup_Log, () => new View.AircraftOnlineLookupLogView(), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "ConnectorActivityLog.html", Strings.ConnectorActivityLog, () => new View.ConnectorActivityLogView(), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "Queues.html", WebAdminStrings.WA_Title_Queues, () => new View.QueuesView(), null)); _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "About.html", WebAdminStrings.WA_Title_About, () => new View.AboutView(), null)); // Views that do not have a menu entry _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "Statistics.html", null, () => new View.StatisticsView(), null)); // Plugin options views _WebAdminViewManager.AddWebAdminView(new WebAdminView(pathFromRoot, "WebAdminPluginOptions.html", WebAdminStrings.PluginName, () => new View.WebAdminPluginOptionsView(), null) { Plugin = this, }); _WebAdminViewManager.RegisterWebAdminViewFolder(PluginFolder, "Web"); _WebSiteExtender = Factory.Resolve <IWebSiteExtender>(); _WebSiteExtender.Enabled = _Options.Enabled; _WebSiteExtender.PageHandlers.Add(String.Format("/{0}/ViewMap.json", ProtectedFolder), WebSite_HandleViewMapJson); _WebSiteExtender.ProtectFolder(ProtectedFolder); _WebSiteExtender.Initialise(parameters); var redirection = Factory.ResolveSingleton <IRedirectionConfiguration>(); redirection.AddRedirection("/WebAdmin", "/WebAdmin/Index.html", RedirectionContext.Any); redirection.AddRedirection("/WebAdmin/", "/WebAdmin/Index.html", RedirectionContext.Any); ApplyOptions(_Options); }
/// <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(); } }
/// <summary> /// See IPlugin interface. /// </summary> public void Startup(PluginStartupParameters parameters) { _AircraftListEnumerator = new AircraftListEnumerator(); _Timer = new System.Timers.Timer() { Interval = 1000, // milliseconds Enabled = false, AutoReset = false, }; _Timer.Elapsed += Timer_Elapsed; _Timer.Start(); // An earlier version of this had AutoReset set to true. That works fine with this example but // it could cause issues with other people's code, particularly if whatever they're doing in the // Elapsed event handler takes more than 1000 milliseconds (or however long the timer interval // is set to). AutoReset could trigger overlapping concurrent calls to the event handler, which // might come as a surprise. // // So to be safe I've changed the sample so that the event handler has to explicitly restart the // timer once all of its work is complete. That way there is no possibility of overlapping calls. }
public void SplashPresenter_StartApplication_Sends_Correct_Parameters_To_Plugin_Startup() { var plugin = new Mock <IPlugin>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _PluginManager.Setup(p => p.LoadedPlugins).Returns(new IPlugin[] { plugin.Object }); PluginStartupParameters parameters = null; // we can't just test within Startup.Callback because exceptions from there are caught by design, they won't stop the test plugin.Setup(p => p.Startup(It.IsAny <PluginStartupParameters>())).Callback((PluginStartupParameters p) => { parameters = p; }); _Presenter.Initialise(_View.Object); _Presenter.StartApplication(); plugin.Verify(p => p.Startup(It.IsAny <PluginStartupParameters>()), Times.Once()); Assert.AreSame(_BaseStationAircraftList.Object, parameters.AircraftList); Assert.AreSame(_FlightSimulatorXAircraftList.Object, parameters.FlightSimulatorAircraftList); Assert.AreSame(_UniversalPlugAndPlayManager.Object, parameters.UPnpManager); Assert.AreSame(_WebSite.Object, parameters.WebSite); }
public void Startup(PluginStartupParameters parameters) { }