コード例 #1
0
ファイル: PluginInitializer.cs プロジェクト: giepske/AppDash
        private void InitializePluginPages(string pluginKey)
        {
            var pluginPageInstances = _pluginResolver.GetPluginPages(pluginKey);

            foreach (IPage pluginTileInstance in pluginPageInstances)
            {
                var setDependenciesMethod = pluginTileInstance.GetType().GetMethod("SetDependencies");

                if (setDependenciesMethod != null)
                {
                    object?[]? dependencies = setDependenciesMethod.GetParameters()
                                              .Select(parameter =>
                    {
                        return(_serviceProvider.GetService(parameter.ParameterType));
                    })
                                              .ToArray();

                    setDependenciesMethod.Invoke(pluginTileInstance, dependencies);
                }

                var pluginSettingsProperty = pluginTileInstance.GetType().GetProperty("PluginSettings");

                pluginSettingsProperty?.SetValue(pluginTileInstance, _pluginSettingsManager.GetPluginSettings(pluginKey));

                pluginTileInstance.OnAfterLoad().Wait();
            }
        }
コード例 #2
0
        public void GetPluginPagesTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginPages(typeof(TestPlugin.TestPlugin));

            //Act
            var pages = pluginResolver.GetPluginPages("TestKey").ToList();

            //Assert
            Assert.Equal(2, pages.Count);
            Assert.Equal(2, pages.Count(page => page.PluginKey == "TestKey"));

            //make sure the right amount of pages are in the list
            Assert.Single(pages.Where(tile => tile.GetType() == typeof(TestPage)));
            Assert.Single(pages.Where(tile => tile.GetType() == typeof(MainTestPage)));
        }