Beispiel #1
0
        public async Task <PluginInformation> InstallPluginAsync(Uri uri, CancellationToken cancellationToken)
        {
            var filename = uri.GetFilename();

            if (!uri.ToString().ToLowerInvariant().EndsWith(".zip"))
            {
                throw new ArgumentException($"Only understands ZIP files: {uri} ({filename})");
            }

            var pluginId = PluginId.With(Path.GetFileNameWithoutExtension(filename).ToLowerInvariant());

            if (_plugins.ContainsKey(pluginId))
            {
                await _pluginInstaller.UninstallPluginAsync(pluginId, cancellationToken).ConfigureAwait(false);
            }

            using (var tempFile = await _restClient.DownloadAsync(uri, cancellationToken).ConfigureAwait(false))
            {
                var pluginPath = await _pluginInstaller.InstallPluginAsync(
                    pluginId,
                    tempFile,
                    PluginPackageType.Zip,
                    cancellationToken)
                                 .ConfigureAwait(false);

                return(await LoadPluginAsync(
                           pluginPath,
                           cancellationToken)
                       .ConfigureAwait(false));
            }
        }
Beispiel #2
0
        public async Task UnloadPlugin([FromBody] TenantMessage tenantMessage, CancellationToken cancellationToken)
        {
            var pId      = RegexUnloadPlugin.Match(tenantMessage.Text).Groups["pluginId"].Value;
            var pluginId = PluginId.With(pId);
            await _pluginApi.UnloadPluginAsync(pluginId, cancellationToken).ConfigureAwait(false);

            await _messageApi.ReplyToAsync(tenantMessage, $"Unloaded plugin {pluginId}", cancellationToken).ConfigureAwait(false);
        }
Beispiel #3
0
        public Task Unload(string pId, CancellationToken cancellationToken)
        {
            var pluginId = PluginId.With(pId);

            return(_pluginManagementService.UnloadPluginAsync(pluginId));
        }