public void SonarQubeServiceWrapper_TryGetPlugins() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup var connectionInfo = new ConnectionInformation(new Uri("http://servername")); var plugin1 = new ServerPlugin { Key = "plugin1" }; var plugin2 = new ServerPlugin { Key = "plugin2" }; var expectedPlugins = new[] { plugin1, plugin2 }; // Setup test server RequestHandler handler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.ServerPluginsInstalledAPI, ctx => ServiceServerPlugins(ctx, expectedPlugins) ); // Act ServerPlugin[] actualPlugins; Assert.IsTrue(testSubject.TryGetPlugins(connectionInfo, CancellationToken.None, out actualPlugins), "TryGetPlugins failed unexpectedly"); // Verify CollectionAssert.AreEqual(expectedPlugins.Select(x => x.Key).ToArray(), actualPlugins.Select(x => x.Key).ToArray(), "Unexpected server plugins"); handler.AssertHandlerCalled(1); } }
Hashtable pluginNameLookup = new Hashtable(); // relative path = plugin name internal void addServerPlugin(ServerPlugin ServerPlugin) { ServerPlugin.onQuit += new LogDelegate(ServerPlugin_onQuit); ServerPlugin.onLog += new LogDelegate(delegate(string s) { log("[" + ServerPlugin.Name() + "]: " + s); }); ServerPlugin.onOutboxMessage += new ServerPlugin.outboxDelegate(plugin_onOutboxMessage); ServerClasses.Add(ServerPlugin); }
public ServerPlugin LoadPlugin(string name) { Assembly plugcode = AppDomain.CurrentDomain.Load(File.ReadAllBytes(GetBaseDir() + name + ".dll"), File.ReadAllBytes(GetBaseDir() + name + ".pdb")); Type[] types = plugcode.GetTypes(); Type pluginbase = null; foreach (Type type in types) { Type[] interfaces = type.GetInterfaces(); if (interfaces.Contains(PluginType)) { pluginbase = type; break; } } if (pluginbase == null) { SysConsole.Output(OutputType.ERROR, "Invalid plugin '" + name + "': no ServerPlugin implementation class!"); return(null); } ServerPlugin pl = (ServerPlugin)Activator.CreateInstance(pluginbase); return(pl); }
public void outboxMessage(ServerPlugin Sender, Event ev) { ev._Source_FullyQualifiedName = Sender.Name(); if (!object.Equals(null, this.onOutboxMessage)) { onOutboxMessage(Sender, ev); } }
/// <summary> /// Install this instance. /// </summary> public override void Install() { // start virtual server m_LogicServer = GameEngine.GetSingleton().LoadPlugin<ServerPlugin>(); if (!m_LogicServer) throw new System.NullReferenceException(); // init socket object base.Install (); }
public void addPlugin(string pathRel) { string pathAbs = path_cache + pathRel; ServerPlugin plugin = compiler.CompileCode(pathAbs); if (!object.Equals(null, plugin)) { pluginNameLookup[pathRel] = plugin.Name(); addServerPlugin(plugin); } }
public void detectPluginChanges() { //string pluginPath = ThingReferences.ThingPath.path_base + // System.IO.Path.DirectorySeparatorChar + // "plugins"; foreach (DirectoryInfo di in new DirectoryInfo(path_cache).GetDirectories()) { string pluginFolderPath = di.FullName; foreach (FileInfo fi in new DirectoryInfo(pluginFolderPath).GetFiles("*.*")) { string ext = Path.GetExtension(fi.Name); if (fi.Name.ToLower().Contains("_server") && (ext == ".cs" || ext == ".vb" || ext == ".js")) { string path_plugin = fi.FullName; try { string md5_plugin = Encryption.md5_file(path_plugin); bool doCompile = false; if (!pluginFileHashes.ContainsKey(path_plugin)) { doCompile = true; } else if (((string)pluginFileHashes[path_plugin]) != md5_plugin) { doCompile = true; } if (doCompile) { ServerPlugin plugin = compiler.CompileCode(path_plugin); if (!object.Equals(null, plugin)) { if (pluginFileHashes.ContainsKey(path_plugin)) { ServerClasses.RemoveAt(plugin.Name()); } pluginFileHashes[path_plugin] = md5_plugin; //pluginAddResourceFolderPath(pluginFolderPath); addServerPlugin(plugin); } } } catch (Exception ex) { log(ex.Message); } } } } }
public ServerPluginPanel(ServerPlugin plugin) : this() { mPlugin = plugin; mConfig = plugin.Config as DistributedConfig; portUpDown.Value = mConfig.Port; if (mPlugin.Started) startButton.Enabled = false; else stopButton.Enabled = false; mPlugin.ClientConnected += (name, source) => Invoke(new Action(() => eventsBox.Text += name + " connected from " + source.Address)); mPlugin.ClientDisconnected += name => Invoke(new Action(() => eventsBox.Text += name + " disconnected")); }
public ServerPluginPanel(ServerPlugin plugin) : this() { mPlugin = plugin; mConfig = plugin.Config as DistributedConfig; portUpDown.Value = mConfig.Port; if (mPlugin.Started) { startButton.Enabled = false; } else { stopButton.Enabled = false; } mPlugin.ClientConnected += (name, source) => Invoke(new Action(() => eventsBox.Text += name + " connected from " + source.Address)); mPlugin.ClientDisconnected += name => Invoke(new Action(() => eventsBox.Text += name + " disconnected")); }
void plugin_onOutboxMessage(ServerPlugin Sender, Event ev) { ev._Source_FullyQualifiedName = Sender.Name(); sourceHub(ev, EventTransfer.SERVERTOCLIENT); }
public void RegisterServerPlugin(ServerPlugin plugin) { this.ServerPlugins.Add(plugin); }
public void LoadPlugins() { if (Plugins.Count > 0) { UnloadPlugins(); } string[] poss = Loader.GetPossiblePlugins(); for (int i = 0; i < poss.Length; i++) { ServerPlugin pl = Loader.LoadPlugin(poss[i]); if (pl != null) { bool valid = true; string[] depends = pl.Dependencies; foreach (string depend in depends) { string dep = depend.ToLowerFast(); bool has = false; foreach (string possib in poss) { if (possib == dep) { has = true; break; } } if (!has) { valid = false; break; } } if (!valid) { StringBuilder sb = new StringBuilder(depends.Length * 50); for (int d = 0; d < depends.Length; d++) { sb.Append(depends[d]); if (d + 1 < depends.Length) { sb.Append(", "); } } SysConsole.Output(OutputType.ERROR, "Plugin has unmet dependencies: '" + Plugins[i].Name + "'... requires: " + sb.ToString()); } else { // TODO: What if a plugin has a dependency, that has a dependency which isn't loaded -> must chain-kill plugins! Plugins.Add(pl); } } } for (int i = 0; i < Plugins.Count; i++) { try { SysConsole.Output(OutputType.INIT, "Loading plugin: " + Plugins[i].Name + " version " + Plugins[i].Version); Plugins[i].Load(this); } catch (Exception ex) { SysConsole.Output("Loading plugin '" + Plugins[i].Name + "'", ex); } } SysConsole.Output(OutputType.INIT, "Plugins loaded!"); }
public void sendEventFromPlugin(ServerPlugin Sender, Event ev) { ev._Source_FullyQualifiedName = Sender.Name(); sendEvent(ev); }
internal static void RegisterCommand(ServerPlugin plugin, string label) { Hooks[label] = plugin; }
internal void AddPlugin(ServerPlugin plugin) { this._plugins.Add(plugin); }
private void RegisterPlugin(ServerPlugin plugin) { plugins.Add(plugin); plugin.Load(); Log($"Loaded {plugin.GetInfoString()}"); }