コード例 #1
0
        public void TestReflectTwoPluginImplementations()
        {
            var stream = new MemoryStream();

            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "MyAwesomePlugin");
                builder.ImplementInterface <IFileFormatPlugin>("A");
                builder.ImplementInterface <IFileFormatPlugin>("B");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
            _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.UniquePluginId.2.0.tvp"), stream);

            using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
            {
                loader.Plugins.Should().HaveCount(1, "because one plugin should've been loaded");
                var description = loader.Plugins.First();
                description.PluginImplementations.Should().HaveCount(2, "because we've implemented the IFileFormatPlugin twice");
                description.PluginImplementations[0].InterfaceType.Should().Be <IFileFormatPlugin>();
                description.PluginImplementations[0].FullTypeName.Should().Be("A");

                description.PluginImplementations[1].InterfaceType.Should().Be <IFileFormatPlugin>();
                description.PluginImplementations[1].FullTypeName.Should().Be("B");
            }
        }
コード例 #2
0
        public void TestReflectPlugin2()
        {
            var plugin = "sql.dll";

            if (File.Exists(plugin))
            {
                File.Delete(plugin);
            }

            var builder = new PluginBuilder("Simon", "sql", "sql", "SMI", "none of your business", "go away");

            builder.ImplementInterface <IFileFormatPlugin>("sql.LogFilePlugin");
            builder.Save();

            var scanner     = new PluginAssemblyLoader();
            var description = scanner.ReflectPlugin(plugin);

            description.Author.Should().Be("SMI");
            description.Website.Should().Be(new Uri("none of your business", UriKind.RelativeOrAbsolute));
            description.Description.Should().Be("go away");
            description.PluginImplementations.Should().HaveCount(1);
            description.PluginImplementations.Should().Contain(x => x.InterfaceType == typeof(IFileFormatPlugin));
            var implementationDescription = description.PluginImplementations[0];

            implementationDescription.FullTypeName.Should().Be("sql.LogFilePlugin");
            implementationDescription
            .Version.Should().Be(PluginInterfaceVersionAttribute.GetInterfaceVersion(typeof(IFileFormatPlugin)));
        }
コード例 #3
0
        public void TestReflect1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("UniquePluginId", "My very own plugin", "Simon", "http://google.com", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader())
                {
                    var description = loader.ReflectPlugin(stream, true);
                    description.Should().NotBeNull();
                    description.Id.Should().Be("UniquePluginId");
                    description.Name.Should().Be("My very own plugin");
                    description.Version.Should().Be(new Version(0, 0, 0), "because the plugin version should default to 0.0.0 when none has been specified");
                    description.Author.Should().Be("Simon");
                    description.Website.Should().Be(new Uri("http://google.com"));
                    description.Description.Should().Be("get of my lawn");
                }
            }
        }
コード例 #4
0
        public void TestLoad2()
        {
            var assemblyFileName = "Foo2.dll";

            if (File.Exists(assemblyFileName))
            {
                File.Delete(assemblyFileName);
            }

            var builder = new PluginBuilder("Simon", "Foo2", "Foo2", "Simon", "None of your business", "Get of my lawn");

            builder.ImplementInterface <IFileFormatPlugin>("Foo2.MyAwesomePlugin");
            builder.Save();
            var description = new PluginDescription
            {
                FilePath = assemblyFileName,
                PluginImplementations = new List <IPluginImplementationDescription>
                {
                    new PluginImplementationDescription("Foo2.MyAwesomePlugin", typeof(IFileFormatPlugin))
                }
            };

            using (var scanner = new PluginAssemblyLoader())
            {
                var plugin = scanner.Load <IFileFormatPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo2.MyAwesomePlugin");
            }
        }
コード例 #5
0
        public void TestReflectPlugin2()
        {
            var plugin = "sql.dll";

            if (File.Exists(plugin))
            {
                File.Delete(plugin);
            }

            var builder = new PluginBuilder("Simon", "sql", "sql", "SMI", "none of your business", "go away");

            builder.ImplementInterface <IFileFormatPlugin>("sql.LogFilePlugin");
            builder.Save();

            var scanner     = new PluginAssemblyLoader();
            var description = scanner.ReflectPlugin(plugin);

            description.Author.Should().Be("SMI");
            description.Website.Should().Be(new Uri("none of your business", UriKind.RelativeOrAbsolute));
            description.Description.Should().Be("go away");
            description.Plugins.Should().HaveCount(1);
            description.Plugins.Should().Contain(
                new KeyValuePair <Type, string>(typeof(IFileFormatPlugin), "sql.LogFilePlugin")
                );
        }
コード例 #6
0
        public void TestLoadAllOfTypeWithDescription()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "Simon", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                var path = Path.Combine(Constants.PluginPath, "Kittyfisto.Simon.1.0.tvp");
                _filesystem.WriteAllBytes(path, stream.ToArray());

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    var pluginsWithDescription = loader.LoadAllOfTypeWithDescription <IFileFormatPlugin>();
                    pluginsWithDescription.Should().HaveCount(1, "because we've added one plugin which implements the IFileFormatPlugin interface");
                    var description = pluginsWithDescription[0].Description;
                    description.Should().NotBeNull();
                    description.Id.Should().Be(new PluginId("Kittyfisto.Simon"));
                    description.Author.Should().Be("get of my lawn");
                }
            }
        }
コード例 #7
0
        public void TestLoad1()
        {
            var assemblyFileName = "Foo1.dll";

            if (File.Exists(assemblyFileName))
            {
                File.Delete(assemblyFileName);
            }

            var builder = new PluginBuilder("Simon", "Foo1", "Foo1", "Simon", "None of your business", "Get of my lawn");

            builder.ImplementInterface <IFileFormatPlugin>("Foo1.MyAwesomePlugin");
            builder.Save();
            var description = new PluginDescription
            {
                FilePath = assemblyFileName,
                Plugins  = new Dictionary <Type, string>
                {
                    { typeof(IFileFormatPlugin), "Foo1.MyAwesomePlugin" }
                }
            };

            using (var scanner = new PluginAssemblyLoader())
            {
                var plugin = scanner.Load <IFileFormatPlugin>(description);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo1.MyAwesomePlugin");
            }
        }
コード例 #8
0
        public void TestReflect1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "My very own plugin", "Simon", "http://google.com", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.UniquePluginId.2.0.tvp"), stream);

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    loader.Plugins.Should().HaveCount(1, "because one plugin should've been loaded");
                    var description = loader.Plugins.First();
                    description.Should().NotBeNull();
                    description.Id.Should().Be(new PluginId("Kittyfisto.UniquePluginId"));
                    description.Name.Should().Be("My very own plugin");
                    description.Version.Should().Be(new Version(0, 0, 0), "because the plugin version should default to 0.0.0 when none has been specified");
                    description.Author.Should().Be("Simon");
                    description.Website.Should().Be(new Uri("http://google.com"));
                    description.Description.Should().Be("get of my lawn");
                }
            }
        }
コード例 #9
0
        public void TestLoadAllOfType1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "SomePlugin", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.SomePlugin.1.tvp"), stream);

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    var plugins = loader.LoadAllOfType <IFileFormatPlugin>()?.ToList();
                    plugins.Should().NotBeNull();
                    plugins.Should().HaveCount(1);
                    plugins[0].Should().NotBeNull();
                    plugins[0].GetType().FullName.Should().Be("Plugin.FileFormatPlugin");
                }
            }
        }
コード例 #10
0
        public void TestLoadAllOfType1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "SomePlugin", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader(null))
                {
                    var description = loader.ReflectPlugin(stream, true);
                    var plugins     = loader.LoadAllOfType <IFileFormatPlugin>()?.ToList();
                    plugins.Should().NotBeNull();
                    plugins.Should().HaveCount(1);
                    plugins[0].Should().NotBeNull();
                    plugins[0].GetType().FullName.Should().Be("Plugin.FileFormatPlugin");
                }
            }
        }
コード例 #11
0
        public void TestReflectTwoPluginImplementations()
        {
            var builder = new PluginBuilder("Kittyfisto", "TestReflectTwoPluginImplementations", "TestReflectTwoPluginImplementations");

            builder.ImplementInterface <IFileFormatPlugin>("A");
            builder.ImplementInterface <IFileFormatPlugin>("B");
            builder.Save();

            var assemblyLoader = new PluginAssemblyLoader();
            var description    = assemblyLoader.ReflectPlugin(builder.FileName);

            description.PluginImplementations.Should().HaveCount(2, "because we've implemented the IFileFormatPlugin twice");
            description.PluginImplementations[0].InterfaceType.Should().Be <IFileFormatPlugin>();
            description.PluginImplementations[0].FullTypeName.Should().Be("A");

            description.PluginImplementations[1].InterfaceType.Should().Be <IFileFormatPlugin>();
            description.PluginImplementations[1].FullTypeName.Should().Be("B");
        }
コード例 #12
0
        private static void CreatePlugin(MemoryStream stream)
        {
            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "My very own plugin", "Simon", "http://google.com",
                                                "get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
        }
コード例 #13
0
ファイル: PluginPackerTest.cs プロジェクト: radtek/Tailviewer
        public void TestPackPrivatePluginImplementation()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Kittyfisto", "MyPlugin", "My First Plugin");
                builder.PluginVersion = new Version(1, 4, 12034);
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin", TypeAttributes.NotPublic | TypeAttributes.Sealed);
                builder.Save();

                new Action(() => packer.AddPluginAssembly(builder.FileName))
                .Should()
                .Throw <PackException>()
                .WithMessage("Plugin implementations must publicly visible, but 'Plugin.FileFormatPlugin' is not!");
            }
        }
コード例 #14
0
        private static PluginId CreatePlugin(MemoryStream stream)
        {
            var @namespace = "Kittyfisto";
            var name       = "UniquePluginId";

            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder(@namespace, name, "My very own plugin", "Simon", "http://google.com",
                                                "get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
            return(new PluginId($"{@namespace}.{name}"));
        }
コード例 #15
0
        public void TestScanAndLoad()
        {
            using (var scanner = new PluginAssemblyLoader())
            {
                var assemblyFileName = "Foo3.dll";
                if (File.Exists(assemblyFileName))
                {
                    File.Delete(assemblyFileName);
                }

                var builder = new PluginBuilder("Simon", "Foo3", "Foo3", "Simon", "None of your business", "Get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Foo3.MyAwesomePlugin");
                builder.Save();

                var description = scanner.ReflectPlugin(assemblyFileName);
                var plugin      = scanner.Load <IFileFormatPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo3.MyAwesomePlugin");
            }
        }
コード例 #16
0
        private void CreatePlugin(string @namespace, string name, Version version)
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, leaveOpen: true))
                {
                    var builder = new PluginBuilder(@namespace, name, "dawawdwdaaw")
                    {
                        PluginVersion = version
                    };
                    builder.ImplementInterface <IFileFormatPlugin>("dwwwddwawa");
                    builder.Save();
                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                var fileName = Path.Combine(Constants.PluginPath, string.Format("{0}.{1}.{2}.tvp", @namespace, name, version));
                _filesystem.Write(fileName, stream);
            }
        }
コード例 #17
0
        public void TestAddAssembly5()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Kittyfisto", "MyPlugin", "My First Plugin");
                builder.PluginVersion = new Version(1, 4, 12034);
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Version.Should().NotBeNull();
                index.Id.Should().Be("Kittyfisto.MyPlugin");
                index.Name.Should().Be("My First Plugin");
                index.Version.Should().Be(new Version(1, 4, 12034));
            }
        }
コード例 #18
0
        private string CreatePlugin(string @namespace, string name, Version version)
        {
            var fileName = Path.Combine(_pluginFolder, string.Format("{0}.{1}.{2}.dll", @namespace, name, version));

            using (var packer = PluginPacker.Create(fileName))
            {
                var builder = new PluginBuilder(@namespace, name, "dawawdwdaaw")
                {
                    PluginVersion = version
                };
                builder.ImplementInterface <IFileFormatPlugin>("dwwwddwawa");
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);
            }

            var dest = Path.Combine(_pluginFolder, Path.GetFileName(fileName));

            File.Move(fileName, dest);

            return(dest);
        }
コード例 #19
0
        public void TestLoadAssembly1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Simon", "Foo1", "TestLoadAssembly1", "Simon", "None of your business", "Get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Foo1.MyAwesomePlugin");
                    builder.Save();
                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var reader = PluginArchive.OpenRead(stream))
                {
                    var assembly = reader.LoadAssembly("Plugin.dll");
                    assembly.Should().NotBeNull();
                    reader.LoadAssembly("Plugin.dll").Should().BeSameAs(assembly, "because LoadAssembly should return the very same assembly every time");
                }
            }
        }
コード例 #20
0
        private void CreatePlugin <T>(string pluginFolder, PluginId actualId, Version actualVersion, PluginId fakeId, Version fakeVersion) where T : IPlugin
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var idx             = actualId.Value.LastIndexOf(".");
                    var actualNamespace = actualId.Value.Substring(0, idx);
                    var actualName      = actualId.Value.Substring(idx + 1);
                    var builder         = new PluginBuilder(actualNamespace, actualName, "none of your business", "get of my lawn", version: actualVersion);
                    builder.ImplementInterface <T>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }
                stream.Position = 0;

                var path = Path.Combine(pluginFolder, $"{fakeId.Value}.{fakeVersion}.tvp");
                _filesystem.CreateDirectory(pluginFolder);
                _filesystem.WriteAllBytes(path, stream.ToArray());
            }
        }
コード例 #21
0
        public void TestLoad1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "Simon", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader(null))
                {
                    var description = loader.ReflectPlugin(stream, true);
                    var plugin      = loader.Load <IFileFormatPlugin>(description);
                    plugin.Should().NotBeNull();
                }
            }
        }