/// <summary>Starts or stops <paramref name="pluginInstance" /> depending on its current status</summary> /// <param name="pluginInstance"></param> /// <param name="attachDebugger"></param> /// <returns></returns> private Task PluginPlayPauseAsync(PluginInstance pluginInstance, bool attachDebugger) { switch (pluginInstance.Status) { case PluginStatus.Stopped: return(PluginMgr.StartPlugin(pluginInstance, attachDebugger)); case PluginStatus.Connected: return(PluginMgr.StopPlugin(pluginInstance)); default: throw new InvalidOperationException($"Invalid plugin status {pluginInstance.Status}"); } }
/// <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; } }