/// <summary>Updates <paramref name="plugin" /></summary> /// <param name="plugin">The plugin to update</param> /// <returns></returns> private async Task PluginUpdateAsync(LocalPluginPackage <PluginMetadata> plugin) { bool success = false; try { Status = PluginManagerStatus.Update; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.UpdatePluginAsync(plugin, plugin.SelectedVersion, EnablePrerelease, CancellationTokenSource.Token) .ConfigureAwait(true)) == false) { return; } await PluginMgr.StartPlugin(PluginInstances.FirstOrDefault(pi => pi.Package == plugin)).ConfigureAwait(true); } catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException) { success = false; } catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException) { success = true; } finally { PluginMgr.RemoveLogger(LogOperationOutput); CancellationTokenSource = null; Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Update; } }
/// <summary>Removes the plugin from the plugin registry.</summary> /// <returns>The plugin.</returns> /// <param name="assembly">Assembly.</param> public bool RemovePlugin(Assembly assembly) => RemovePlugin(PluginInstances.FirstOrDefault(x => x.GetType().Assembly == assembly));
/// <summary> /// Attempts to get a plugin instance via the name of the plugin. /// </summary> /// <param name="pluginName">The plugin name to check against.</param> /// <returns></returns> public IPlugin GetPlugin(string pluginName) => PluginInstances.FirstOrDefault(x => x.PluginName.ToLowerInvariant() == pluginName.ToLowerInvariant());