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");
                }
            }
        }
Example #2
0
        public void TestAddNativeImage1()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                var builder = new AbstractPluginTest.PluginBuilder("Simon", "Foo", "Plugin");
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);

                var fname = Path.Combine(_testData, "Native", "x86", "NativeImage.dll");
                packer.AddFile("NativeImage.dll", fname);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Should().NotBeNull();
                index.Assemblies.Should().NotBeNull();
                index.Assemblies.Should().HaveCount(1);

                index.NativeImages.Should().NotBeNull();
                index.NativeImages.Count.Should().Be(1);
                index.NativeImages[0].EntryName.Should().Be("NativeImage.dll");
                index.NativeImages[0].ImageName.Should().Be("NativeImage");
            }
        }
        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 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");
                }
            }
        }
Example #5
0
        public void TestAddAssembly1()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                var builder = new AbstractPluginTest.PluginBuilder("Simon", "Foo", "Plugin");
                builder.AssemblyVersion              = "4.0.3.1";
                builder.AssemblyFileVersion          = "1.2.3.42";
                builder.AssemblyInformationalVersion = "4.0.0.0-beta";
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Should().NotBeNull();
                index.Name.Should().Be("Plugin");
                index.Assemblies.Should().NotBeNull();
                index.Assemblies.Should().HaveCount(1);
                index.Assemblies[0].EntryName.Should().Be("Plugin.dll");
                index.Assemblies[0].AssemblyName.Should().Be("Plugin");
                index.Assemblies[0].AssemblyVersion.Should().Be(new Version(4, 0, 3, 1));
                index.Assemblies[0].AssemblyFileVersion.Should().Be(new Version(1, 2, 3, 42));
                index.Assemblies[0].AssemblyInformationalVersion.Should().Be("4.0.0.0-beta");
                index.NativeImages.Should().NotBeNull();
                index.NativeImages.Should().HaveCount(0);

                var actualAssembly = reader.LoadAssembly("Plugin.dll");
                actualAssembly.Should().NotBeNull();
            }
        }
Example #6
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");
                }
            }
        }
        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");
                }
            }
        }
Example #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;

                using (var loader = new PluginArchiveLoader(null))
                {
                    var description = loader.ReflectPlugin(stream, true);
                    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");
                }
            }
        }
Example #9
0
 public void TestAddNativeImage2()
 {
     using (var packer = PluginPacker.Create(_fname))
     {
         var fname = Path.Combine(_testData, "Native", "x64", "NativeImage.dll");
         new Action(() => packer.AddFile("NativeImage.dll", fname))
         .ShouldThrow <PackException>()
         .WithMessage("Native images must be compiled for x86");
     }
 }
Example #10
0
 public void TestAddAssembly2()
 {
     using (var packer = PluginPacker.Create(_fname))
     {
         var fname = Path.Combine(_testData, "Managed", "x64", "ClassLibrary1.dll");
         new Action(() => packer.AddFile("ClassLibrary1.dll", fname))
         .ShouldThrow <PackException>()
         .WithMessage("Assemblies must be compiled for x86 or AnyCPU");
     }
 }
Example #11
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;
        }
        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}"));
        }
Example #13
0
        public void TestAddAssembly3()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                var fname = Path.Combine(_testData, "Managed", "x86", "ClassLibrary1.dll");
                packer.AddFile("ClassLibrary1.dll", fname);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Should().NotBeNull();
                index.PluginArchiveVersion.Should().Be(PluginArchive.CurrentPluginArchiveVersion);
                index.Assemblies.Should().NotBeNull();
                index.Assemblies.Should().HaveCount(1);
                index.Assemblies[0].EntryName.Should().Be("ClassLibrary1.dll");
                index.Assemblies[0].AssemblyName.Should().Be("ClassLibrary1");
            }
        }
Example #14
0
        public void TestAddAssembly4()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                var fname = Path.Combine(_testData, "Managed", "x86", "Targets.NET.4.6.dll");
                new Action(() => packer.AddFile("Foo.dll", fname))
                .ShouldThrow <PackException>()
                .WithMessage("Assemblies may only target frameworks of up to .NET 4.5.2");

                fname = Path.Combine(_testData, "Managed", "x86", "Targets.NET.4.6.1.dll");
                new Action(() => packer.AddFile("Foo.dll", fname))
                .ShouldThrow <PackException>()
                .WithMessage("Assemblies may only target frameworks of up to .NET 4.5.2");

                fname = Path.Combine(_testData, "Managed", "x86", "Targets.NET.4.6.2.dll");
                new Action(() => packer.AddFile("Foo.dll", fname))
                .ShouldThrow <PackException>()
                .WithMessage("Assemblies may only target frameworks of up to .NET 4.5.2");
            }
        }
        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);
            }
        }
Example #16
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);
        }
Example #17
0
        public void TestAddAssembly5()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                var builder = new AbstractPluginTest.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));
            }
        }
Example #18
0
        public void TestAddIcon1()
        {
            using (var packer = PluginPacker.Create(_fname))
            {
                using (var icon = File.OpenRead(Path.Combine(_testData, "cropped-uiforetwicon2.png")))
                {
                    packer.SetIcon(icon);
                }
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var stream = reader.ReadIcon();
                stream.Should().NotBeNull();

                using (var image = new Bitmap(stream))
                {
                    image.Width.Should().Be(16);
                    image.Height.Should().Be(16);
                }
            }
        }
Example #19
0
        public void TestLoadAssembly1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new AbstractPluginTest.PluginBuilder("Foo1", "Foo1", "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");
                }
            }
        }
        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());
            }
        }
Example #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();
                }
            }
        }
Example #22
0
        public int Run()
        {
            try
            {
                Log.Info("Creating Tailviewer plugin...");

                using (var pluginStream = new MemoryStream())
                {
                    string pluginVersion;
                    using (var packer = PluginPacker.Create(pluginStream, leaveOpen: true))
                    {
                        var extension = Path.GetExtension(_options.InputFileName)?.ToLowerInvariant();
                        switch (extension)
                        {
                        case ".sln":
                        case ".csproj":
                            Log.Error("Not implemented yet");
                            return(-1);

                        case ".dll":
                            Log.InfoFormat("Adding {0}... ", _options.InputFileName);
                            packer.AddPluginAssembly(_options.InputFileName);
                            Log.Info("OK");
                            break;

                        default:
                            Console.WriteLine("ERROR: Input file must be either a Visual Studio Solution, C# Project or .NET Assembly");
                            return(-1);
                        }

                        foreach (var filename in _options.Files)
                        {
                            Log.InfoFormat("Adding {0}... ", filename);
                            var fullFilename = Path.IsPathRooted(filename)
                                                                ? filename
                                                                : Path.Combine(Directory.GetCurrentDirectory(), filename);
                            AddFile(packer, fullFilename);
                            Log.Info("OK");
                        }

                        if (!string.IsNullOrEmpty(_options.IconFileName))
                        {
                            using (var stream = File.OpenRead(_options.IconFileName))
                            {
                                packer.SetIcon(stream);
                            }
                        }

                        if (!string.IsNullOrEmpty(_options.ChangeListFileName))
                        {
                            packer.SetChanges(_options.ChangeListFileName);
                        }

                        pluginVersion = packer.Version;
                    }

                    var archiveFilename = Path.Combine(Directory.GetCurrentDirectory(), string.Format("{0}.{1}.{2}",
                                                                                                      Path.GetFileNameWithoutExtension(_options.InputFileName),
                                                                                                      pluginVersion,
                                                                                                      PluginArchive.PluginExtension));

                    pluginStream.Position = 0;
                    Log.InfoFormat("Saving plugin => {0}... ", archiveFilename);
                    using (var fileStream = File.Create(archiveFilename))
                    {
                        pluginStream.CopyTo(fileStream);
                    }
                    Log.Info("OK");
                }

                return(0);
            }
            catch (PackException e)
            {
                Log.Error(e.Message);
                return(-1);
            }
        }
Example #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fname"></param>
 /// <returns></returns>
 private static PluginPacker CreatePacker(string fname)
 {
     return(PluginPacker.Create(File.OpenWrite(fname)));
 }