/// <summary>Toggle the enabled status of plugin <paramref name="pluginInstance" /></summary> /// <param name="pluginInstance">The plugin to enable or disable</param> /// <returns></returns> private async Task PluginEnableDisableAsync(PluginInstance pluginInstance) { if (_ignoreEnabledChanged) { _ignoreEnabledChanged = false; return; } if (pluginInstance.Metadata.Enabled) { return; } if (pluginInstance.Status != PluginStatus.Stopped) { if (await PromptUserConfirmationAsync($"{pluginInstance.Metadata.DisplayName} will be stopped. Continue ?").ConfigureAwait(true) == false) { _ignoreEnabledChanged = true; pluginInstance.Metadata.Enabled = true; return; } await PluginMgr.StopPlugin(pluginInstance).ConfigureAwait(true); } pluginInstance.Metadata.Enabled = false; }
public World() { Instance = this; Log.Write("Loading plugins..."); PluginMgr.LoadAll(); TriggerHandler.RegisterTrigger("core.login", @"^\$gmcp\.char\.vitals\.hp ", _GMCPHP); InputHandler.RegisterCommand("commands", "", _Commands, CMDFlags.None, null, 0, ulong.MaxValue, "core", 8); InputHandler.RegisterCommand("lastlines", @"^(\d+)$", _LineInfo, CMDFlags.None, null, 0, ulong.MaxValue, "core", 8); InputHandler.RegisterCommand("plugins", @"^(\w+)(\s+full)?", _PluginInfo, CMDFlags.None, null, 0, ulong.MaxValue, "core", 6); InputHandler.RegisterCommand("shutdown", "", _Shutdown, CMDFlags.None, null, 0, ulong.MaxValue, "core", 8); }
/// <summary>Attempts to install <paramref name="plugin" />.</summary> /// <param name="plugin">The plugin selected in the UI</param> /// <returns></returns> public async Task InstallPluginAsync(PluginPackage <PluginMetadata> plugin) { if (!(plugin is OnlinePluginPackage <PluginMetadata> onlinePlugin)) { LogTo.Error("Install plugin was called with a type that is not OnlinePluginPackage: {V}", plugin.Serialize()); return; } bool success = false; try { Status = PluginManagerStatus.Install; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.InstallPluginAsync(onlinePlugin, onlinePlugin.SelectedVersion, CancellationTokenSource.Token) .ConfigureAwait(true)) == false) { return; } var localPlugin = PluginMgr.AllPlugins.FirstOrDefault(p => p.Package.Id == plugin.Id && p.IsDevelopment == false); if (Plugins.Replace(plugin, localPlugin.Package) == false) { throw new InvalidOperationException("Failed to replace old OnlinePluginPackage with new LocalPluginPackage in Plugins"); } localPlugin.Package.SetOnlineVersions(onlinePlugin); } 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.Install; } }
/// <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>Uninstall <paramref name="pluginPackage" /></summary> /// <param name="pluginPackage">The plugin to uninstall</param> /// <returns></returns> private async Task PluginUninstallAsync(LocalPluginPackage <PluginMetadata> pluginPackage) { bool success = false; try { Status = PluginManagerStatus.Uninstall; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.UninstallPluginAsync(pluginPackage) .ConfigureAwait(true)) == false) { return; } // Attempt to replace the plugin in the list ; otherwise refresh online plugins bool refresh = true; var onlinePluginsCopy = Plugins; if (onlinePluginsCopy != null) { pluginPackage = onlinePluginsCopy.FirstOrDefault(p => p.Id == pluginPackage.Id) as LocalPluginPackage <PluginMetadata>; if (pluginPackage != null && pluginPackage.OnlineVersions != null) { onlinePluginsCopy.Replace(pluginPackage, new OnlinePluginPackage <PluginMetadata>(pluginPackage)); refresh = false; } } if (refresh) { RefreshPluginsAsync(true).RunAsync(); } } catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException) { success = true; } finally { PluginMgr.RemoveLogger(LogOperationOutput); CancellationTokenSource = null; Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Uninstall; } }
/// <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> /// Refresh <see cref="Plugins" /> with the latest list of available plugins from the online API repository and NuGet /// repositories. Cached result might be returned if they <paramref name="forceRefresh" /> is set to false. /// </summary> /// <param name="forceRefresh">Whether to invalidate cache or not</param> /// <returns></returns> public async Task RefreshOnlinePluginsAsync(bool forceRefresh) { try { Status = PluginManagerStatus.Refresh; using (CancellationTokenSource = new CancellationTokenSource(60000)) { var plugins = await PluginMgr.SearchPluginsAsync(forceRefresh : forceRefresh, enablePrerelease : EnablePrerelease, cancellationToken : CancellationTokenSource.Token) .ConfigureAwait(true); if (plugins == null) { ErrorMessage = "Error: Failed to fetch online plugins. Please check your internet connection and try again. If this issue persists, request assistance from our friendly community."; Plugins = null; return; } Plugins = new ObservableCollection <PluginPackage <PluginMetadata> >(plugins); ErrorMessage = null; } } catch (TaskCanceledException) { if (Plugins == null || Plugins.None()) { Plugins = null; ErrorMessage = "The refresh task has been canceled. Use refresh to display the available plugins"; } } finally { CancellationTokenSource = null; Status = Plugins == null ? PluginManagerStatus.Error : PluginManagerStatus.Display; } }
void Log(string message) { PluginMgr.Log(nameof(RpcAgent), LogLevel.Info, message, UInt160.Zero); }
/// <summary> /// Checks whether <paramref name="pluginInstance" /> can be either started or stopped. Icon is hidden otherwise /// </summary> /// <param name="pluginInstance"></param> /// <returns></returns> private bool CanPluginPlayPause(PluginInstance pluginInstance) { return(PluginMgr.CanPluginStartOrPause(pluginInstance)); }
private void OnDataMessage(NetIncomingMessage buff) { PluginMgr.NotifyData(buff); }
private void OnStatusMessage(NetIncomingMessage buff) { PluginMgr.NotifyStatus(buff); }
private void LoadPlugin() { PluginMgr.LoadPlugins(@"./", InnerServer); }