Beispiel #1
0
        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();
        }
Beispiel #2
0
        private void LoadScripts(string directoryPath)
        {
            var scriptFiles = Directory.GetFiles(directoryPath, options.ScriptFileNamePattern,
                                                 options.SearchSubfolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            foreach (var scriptFile in scriptFiles)
            {
                try
                {
                    var script        = LoadScript(scriptFile);
                    var scriptCatalog = new RoslynPluginCatalog(script.code, description: script.name, productVersion: script.version);
                    internalCatalog.AddCatalog(scriptCatalog);
                }
                catch (Exception e)
                {
                    options.ScriptLoadFailureCallback?.Invoke(scriptFile, e);
                }
            }
        }