private static async Task CompositeCatalogSample() { Console.WriteLine("Composite catalog sample"); // 1. Create a new plugin catalog from the current assembly var assemblyPluginCatalog = new AssemblyPluginCatalog(typeof(Program).Assembly, type => typeof(IPlugin).IsAssignableFrom(type)); // 2. Also create a new plugin catalog from a type var typePluginCatalog = new TypePluginCatalog(typeof(MyPlugin)); // 3. Then combine the catalogs into a composite catalog var compositeCatalog = new CompositePluginCatalog(assemblyPluginCatalog, typePluginCatalog); // 4. Initialize the composite catalog await compositeCatalog.Initialize(); // 5. Get the plugins from the catalog var assemplyPlugins = compositeCatalog.GetPlugins(); foreach (var plugin in assemplyPlugins) { if (plugin.Type.Name == "MyPlugin") { var inst = (IMyPlugin)Activator.CreateInstance(plugin); inst.Run(); } else { var inst = (IPlugin)Activator.CreateInstance(plugin); inst.Run(); } } }
private async Task CreateCatalogs() { // 1. Uses folder catalog to add calculation operations inside the app. Mimics the WPF-sample. var folderPluginCatalog = new FolderPluginCatalog(@"..\..\..\..\Shared\Weikio.PluginFramework.Samples.SharedPlugins\bin\debug\netcoreapp3.1", type => { type.Implements <IOperator>().Tag("operator"); }); _allPlugins.AddCatalog(folderPluginCatalog); var assemblyPluginCatalog = new AssemblyPluginCatalog(typeof(Form1).Assembly, builder => { builder.Implements <IOperator>() .Tag("operator"); }); _allPlugins.AddCatalog(assemblyPluginCatalog); // 2. Another folder catalog is used to add other forms inside the app. For each form a button is added into the toolstrip // Note: WinFormsPluginsLibrary must be manually built as it isn't referenced by this sample app var folderCatalog = new FolderPluginCatalog(@"..\..\..\..\WinFormsPluginsLibrary\bin\debug\netcoreapp3.1", type => { type.Implements <IDialog>() .Tag("dialog"); }); _allPlugins.AddCatalog(folderCatalog); // 3. Lastly, DelegateCatalog is used for creating an exit-button var exitAction = new Action(() => { var result = MessageBox.Show("This is also a plugin. Do you want to exit this sample app?", "Exit App?", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } Application.Exit(); }); var exitCatalog = new DelegatePluginCatalog(exitAction, options: new DelegatePluginCatalogOptions() { Tags = new List <string> { "buttons" } }, pluginName: "Exit"); _allPlugins.AddCatalog(exitCatalog); // Finally the plugin catalog is initialized await _allPlugins.Initialize(); }
private async Task AddCalculationOperators() { var folderPluginCatalog = new FolderPluginCatalog(@"..\..\..\..\Shared\Weikio.PluginFramework.Samples.SharedPlugins\bin\debug\netcoreapp3.1", type => { type.Implements <IOperator>(); }); var assemblyPluginCatalog = new AssemblyPluginCatalog(typeof(Form1).Assembly, type => typeof(IOperator).IsAssignableFrom(type)); var pluginCatalog = new CompositePluginCatalog(folderPluginCatalog, assemblyPluginCatalog); await pluginCatalog.Initialize(); var allPlugins = pluginCatalog.GetPlugins(); foreach (var plugin in allPlugins) { listBox1.Items.Add(plugin); } }
public async Task CanTagUsingDefaultOptions() { var assemblyPluginCatalog = new AssemblyPluginCatalog(@"..\..\..\..\..\Assemblies\bin\netstandard2.0\TestAssembly1.dll"); var typePluginCatalog = new TypePluginCatalog(typeof(TypePlugin)); var compositeCatalog = new CompositePluginCatalog(assemblyPluginCatalog, typePluginCatalog); await compositeCatalog.Initialize(); var customTaggedPlugins = compositeCatalog.GetByTag("CustomTag"); Assert.Equal(2, customTaggedPlugins.Count); var myTaggedPlugins = compositeCatalog.GetByTag("MyTag_1"); Assert.Single(myTaggedPlugins); TypeFinderOptions.Defaults.TypeFinderCriterias.Clear(); }
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { var folderPluginCatalog = new FolderPluginCatalog(@"..\..\..\..\Shared\Weikio.PluginFramework.Samples.SharedPlugins\bin\debug\netcoreapp3.1", type => { type.Implements <IOperator>(); }); var assemblyPluginCatalog = new AssemblyPluginCatalog(typeof(MainWindow).Assembly, type => typeof(IOperator).IsAssignableFrom(type)); var pluginCatalog = new CompositePluginCatalog(folderPluginCatalog, assemblyPluginCatalog); await pluginCatalog.Initialize(); var allPlugins = pluginCatalog.GetPlugins(); foreach (var plugin in allPlugins) { _plugins.Add(plugin); } PluginsList.ItemsSource = _plugins; }
public Task Initialize() { return(internalCatalog?.Initialize()); }