Ejemplo n.º 1
0
        /// <inheritdoc />
        public IPluginDescription ReflectPlugin(string pluginPath)
        {
            try
            {
                var archive     = PluginArchive.OpenRead(pluginPath);
                var description = CreateDescription(archive);
                _archivesByPlugin.Add(description, archive);
                return(description);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Unable to load '{0}': {1}", pluginPath, e);

                string  id;
                Version version;
                ExtractIdAndVersion(pluginPath, out id, out version);
                var description = new PluginDescription
                {
                    Id       = id,
                    Version  = version,
                    Error    = string.Format("The plugin couldn't be loaded: {0}", e.Message),
                    Plugins  = new Dictionary <Type, string>(),
                    FilePath = pluginPath
                };
                _archivesByPlugin.Add(description, new EmptyPluginArchive());
                return(description);
            }
        }
Ejemplo n.º 2
0
        private static IPluginDescription CreateDescription(PluginArchive archive)
        {
            var archiveIndex = archive.Index;

            Uri.TryCreate(archiveIndex.Website, UriKind.Absolute, out var website);

            var plugins = new Dictionary <Type, string>();

            foreach (var pair in archiveIndex.ImplementedPluginInterfaces)
            {
                var pluginInterfaceType = typeof(IPlugin).Assembly.GetType(pair.InterfaceTypename);
                if (pluginInterfaceType != null)
                {
                    plugins.Add(pluginInterfaceType, pair.ImplementationTypename);
                }
                else
                {
                    Log.WarnFormat("Plugin implements unknown interface '{0}', skipping it...", pair.InterfaceTypename);
                }
            }

            var desc = new PluginDescription
            {
                Id          = new PluginId(archiveIndex.Id),
                Name        = archiveIndex.Name,
                Version     = archiveIndex.Version,
                Icon        = LoadIcon(archive.ReadIcon()),
                Author      = archiveIndex.Author,
                Description = archiveIndex.Description,
                Website     = website,
                Plugins     = plugins
            };

            return(desc);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public IPluginDescription ReflectPlugin(Stream stream, bool leaveOpen = false)
        {
            var archive     = PluginArchive.OpenRead(stream, leaveOpen);
            var description = CreateDescription(archive);

            _archivesByPlugin.Add(description, archive);
            return(description);
        }
Ejemplo n.º 4
0
        private IPluginDescription ReflectPlugin(PluginArchive archive)
        {
            var description = CreateDescription(archive);

            _archivesByPlugin.Add(description, archive);

            if (!_pluginStati.ContainsKey(description.Id))
            {
                _pluginStati.Add(description.Id, new PluginStatus
                {
                    IsInstalled = true
                });
            }
            return(description);
        }
Ejemplo n.º 5
0
        public PluginGroup OpenPlugin(string pluginPath)
        {
            var stream = _filesystem.OpenRead(pluginPath);

            try
            {
                // Ownership of the stream transfers to PluginArchive which is disposed of when this class is
                // disposed of....
                var archive = PluginArchive.OpenRead(stream);
                return(Add(pluginPath, archive));
            }
            catch (Exception)
            {
                stream.Dispose();
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Tries to open the file at the given path as a tailviewer plugin.
        ///     Succeeds if the file is a zip archive and its metadata could be read.
        ///     The plugin itself is not loaded until later.
        /// </summary>
        /// <param name="pluginPath"></param>
        private void TryOpenPlugin(string pluginPath)
        {
            Log.DebugFormat("Loading plugin '{0}'...", pluginPath);

            ExtractIdAndVersion(pluginPath, out var id, out var version);
            try
            {
                // DO NOT DISPOSE OF THE STREAM HERE!!!
                // Ownership transfers to PluginArchive which is disposed of when this class is
                // disposed of....
                var stream  = _filesystem.OpenRead(pluginPath).Result;
                var archive = PluginArchive.OpenRead(stream);
                Add(pluginPath, id, version, archive);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Unable to load '{0}': {1}", pluginPath, e);
                Add(pluginPath, id, version, new EmptyPluginArchive(version));
            }
        }
Ejemplo n.º 7
0
        public IPluginDescription ReflectPlugin(Stream stream, bool leaveOpen = false)
        {
            var archive = PluginArchive.OpenRead(stream, leaveOpen);

            return(ReflectPlugin(archive));
        }