Beispiel #1
0
        private static void Main(string[] args)
        {
            var rootFolder = Path.Combine(Environment.CurrentDirectory, "Pipeline");

            while (Console.ReadLine() != "exit")
            {
                using (var manager = new PluginManager(rootFolder))
                {
                    foreach (var plugin in manager.LoadAll())
                    {
                        Console.WriteLine(plugin.DoStuff());
                    }
                }
            }

            ////var plugin1 = manager.Load("ExamplePlugin1");
            ////var plugin2 = manager.Load("ExamplePlugin2");
            ////var plugin3 = manager.Load("ExamplePlugin3");
            ////Console.WriteLine(plugin1.DoStuff());
            ////Console.WriteLine(plugin2.DoStuff());
            ////Console.WriteLine(plugin3.DoStuff());
            ////manager.TryUnload("ExamplePlugin1");
            ////manager.TryUnload("ExamplePlugin2");
            ////manager.TryUnload("ExamplePlugin3");
            ////Console.ReadLine();
        }
        public void PluginWrapperCanCreatePlugins()
        {
            var pluginPath = @"Resources\Pipeline.zip";
            var tempDirectoryName = MethodBase.GetCurrentMethod().Name;
            if (Directory.Exists(tempDirectoryName))
            {
                Directory.Delete(tempDirectoryName, true);
            }

            ZipFile.ExtractToDirectory(pluginPath, tempDirectoryName);

            var rootFolder = Path.Combine(Environment.CurrentDirectory, tempDirectoryName, "Pipeline");

            var manager = new PluginManager(rootFolder);

            var plugin1 = manager.Load("ExamplePlugin1");
            var plugin2 = manager.Load("ExamplePlugin2");
            var plugin3 = manager.Load("ExamplePlugin3");

            plugin1.DoStuff().Should().BeEquivalentTo("From example plugin 1");
            plugin2.DoStuff().Should().BeEquivalentTo("From example plugin 2");
            plugin3.DoStuff().Should().BeEquivalentTo("From example plugin 3");

            manager.TryUnload("ExamplePlugin1").ShouldBeEquivalentTo(true);
            manager.TryUnload("ExamplePlugin2").ShouldBeEquivalentTo(true);
            manager.TryUnload("ExamplePlugin3").ShouldBeEquivalentTo(true);

            Directory.Delete(tempDirectoryName, true);
        }