public void TestReflectTwoPluginImplementations()
        {
            var stream = new MemoryStream();

            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "MyAwesomePlugin");
                builder.ImplementInterface <ILogEntryParserPlugin>("A");
                builder.ImplementInterface <ILogEntryParserPlugin>("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 <ILogEntryParserPlugin>();
                description.PluginImplementations[0].FullTypeName.Should().Be("A");

                description.PluginImplementations[1].InterfaceType.Should().Be <ILogEntryParserPlugin>();
                description.PluginImplementations[1].FullTypeName.Should().Be("B");
            }
        }
        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 <ILogEntryParserPlugin>("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");
                }
            }
        }
        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 <ILogEntryParserPlugin>("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 <ILogEntryParserPlugin>()?.ToList();
                    plugins.Should().NotBeNull();
                    plugins.Should().HaveCount(1);
                    plugins[0].Should().NotBeNull();
                    plugins[0].GetType().FullName.Should().Be("Plugin.FileFormatPlugin");
                }
            }
        }
        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 <ILogEntryParserPlugin>("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 <ILogEntryParserPlugin>();
                    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");
                }
            }
        }
        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 <ILogEntryParserPlugin>("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(ILogEntryParserPlugin));
            var implementationDescription = description.PluginImplementations[0];

            implementationDescription.FullTypeName.Should().Be("sql.LogFilePlugin");
            implementationDescription
            .Version.Should().Be(PluginInterfaceVersionAttribute.GetInterfaceVersion(typeof(ILogEntryParserPlugin)));
        }
        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 <ILogEntryParserPlugin>("Foo2.MyAwesomePlugin");
            builder.Save();
            var description = new PluginDescription
            {
                FilePath = assemblyFileName,
                PluginImplementations = new List <IPluginImplementationDescription>
                {
                    new PluginImplementationDescription("Foo2.MyAwesomePlugin", typeof(ILogEntryParserPlugin))
                }
            };

            using (var scanner = new PluginAssemblyLoader())
            {
                var plugin = scanner.Load <ILogEntryParserPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo2.MyAwesomePlugin");
            }
        }
        public void TestReflectTwoPluginImplementations()
        {
            var builder = new PluginBuilder("Kittyfisto", "TestReflectTwoPluginImplementations", "TestReflectTwoPluginImplementations");

            builder.ImplementInterface <ILogEntryParserPlugin>("A");
            builder.ImplementInterface <ILogEntryParserPlugin>("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 <ILogEntryParserPlugin>();
            description.PluginImplementations[0].FullTypeName.Should().Be("A");

            description.PluginImplementations[1].InterfaceType.Should().Be <ILogEntryParserPlugin>();
            description.PluginImplementations[1].FullTypeName.Should().Be("B");
        }
Пример #8
0
        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 <ILogEntryParserPlugin>("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!");
            }
        }
        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 <ILogEntryParserPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
            return(new PluginId($"{@namespace}.{name}"));
        }
Пример #10
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 <ILogEntryParserPlugin>("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);
            }
        }
        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 <ILogEntryParserPlugin>("Foo3.MyAwesomePlugin");
                builder.Save();

                var description = scanner.ReflectPlugin(assemblyFileName);
                var plugin      = scanner.Load <ILogEntryParserPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo3.MyAwesomePlugin");
            }
        }
Пример #12
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 <ILogEntryParserPlugin>("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));
            }
        }
Пример #13
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());
            }
        }
Пример #14
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 <ILogEntryParserPlugin>("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");
                }
            }
        }