public CommandPluginAdapter(ICommandPlugin commandPlugin) { if (commandPlugin == null) throw new ArgumentNullException("commandPlugin"); plugin = commandPlugin; CreateControls(); }
/// <summary> /// Register the plugin with the server. /// TODO: If key is already registered, check if plugin reference is the same and reply if they aren't. (Resolve two plugins trying to use same name). /// </summary> /// <param name="plugin"></param> /// <param name="name"></param> public void RegisterPlugin(object plugin, string name) { Logger.Debug($"Registering plugin {name}"); if (plugin == null) { Logger.Error("Plugin is null, unable to register"); return; } ICommandPlugin plug = plugin as ICommandPlugin; if (plug != null) { try { Plugins.AddSafe(plug.PluginName, plug); plug.MessageReady += OnMessage; } catch (Exception ex) { Logger.Exception("Error registering plugin", ex); } } else { Logger.Error("Tried to register null plugin"); } }
public CommandPluginAdapter(ICommandPlugin commandPlugin) { if (commandPlugin == null) { throw new ArgumentNullException("commandPlugin"); } plugin = commandPlugin; CreateControls(); }
public static int LoadPlugins() { DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); foreach (FileInfo fi in di.GetFiles("ConsoleAssignment.Plugins.*.dll")) { Assembly assembly = Assembly.LoadFrom(fi.FullName); foreach (Type t in assembly.GetTypes()) { if (typeof(ICommandPlugin).IsAssignableFrom(t)) { ConstructorInfo ci = t.GetConstructor(new Type[] { }); ICommandPlugin plugin = (ICommandPlugin)ci.Invoke(new Object[] { }); Commands.Add(plugin); } } } return Commands.Count; }
private static IEnumerable <ICommandPlugin> LoadPluginsFromFile(string file) { List <ICommandPlugin> plugins = new List <ICommandPlugin>(); if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) { return(plugins); } try { Assembly assembly = Assembly.LoadFrom(file); foreach (Type t in assembly.GetTypes()) { if (t.GetInterface("ICommandPlugin") != null) { try { Logger.Trace($"Found correct type in {file}"); ICommandPlugin pluginInstance = Activator.CreateInstance(t) as ICommandPlugin; //Logger.Info($" Loaded {pluginInstance.PluginName} from {file.Substring(file.LastIndexOf(@"\") + 1)}"); if (pluginInstance != null) { plugins.Add(pluginInstance); } else { Logger.Error($"Unable to load plugin: {t.FullName} in {file} - Instance could not be created."); } } catch (Exception ex) { Logger.Exception($"Unable to load plugin: {t.FullName} in {file}\n{ex.Message}\n{ex.StackTrace}", ex); } } } } catch (Exception ex) { Logger.Exception($"Unable to load from: {file}\n{ex.Message}\n{ex.StackTrace}", ex); } return(plugins); }
/// <summary> /// Received message from plugin. /// </summary> /// <param name="sender">ICommandPlugin that is sending the message</param> /// <param name="e">MessageData being sent</param> public void OnMessage(object sender, MessageData e) { Logger.Trace($"Received a message from plugin:\n{e.ToString(3)}"); try { if (e.Destination != "Command-Interface") { // Message is not for Command-Interface, pass it on Logger.Trace("Passing on message, Command-Interface is not the destination"); if (MessageReady != null) { MessageReady(sender, e); } else { Logger.Error("CommandBehavior is not listening"); //TODO: Reply system to notify plugins we're not connected to Command-Server. } return; } Logger.Trace($"Message is for Command-Interface:\n{e.ToString(3)}"); ICommandPlugin s = sender as ICommandPlugin; if (s != null) { // Check if the command is valid if (Commands.ContainsKey(e.Flag)) { Commands[e.Flag](s, e.Data); } else { Logger.Warning($"Invalid command: {e.Flag}"); } } } catch (Exception ex) { Logger.Exception("Exception in OnMessage", ex); } }
protected void AddFeature(ICommandPlugin feature) { feature.BindManager(this); if (FeaturesCollection.ContainsKey(feature.Key)) { if (feature.Priority > FeaturesCollection[feature.Key].Priority) { var oldFeature = FeaturesCollection[feature.Key]; FeaturesCollection[feature.Key] = feature; var message = String.Format("The keyword '{0}' has been reset: plugin '{1}' has been replaced by '{2}'.", feature.Key, oldFeature.GetType().FullName, feature.GetType().FullName); WriteMessage(MessageType.Notice, message); } else { var message = String.Format( "Plugin '{0}' cannot be used. The keyword '{1}' has already been set for a plugin of higher priority.", feature.GetType().FullName, feature.Key); WriteMessage(MessageType.Error, message); } } else { FeaturesCollection[feature.Key] = feature; } }
public bool AddCommandExecuter(string _commandName, ICommandPlugin _commandPlugin) { throw new NotImplementedException(); }
public bool Register(ICommandPlugin commandPlugin) { throw new NotImplementedException(); }
public TSelf WithCommand(ICommandPlugin commandPlugin) { CommandPlugins.Add(commandPlugin.CommandName, commandPlugin); return((TSelf)this); }
public PluginCommandDescriptor(ICommandPlugin command, IDictionary <string, object> metaData) { Command = command; MetaData = metaData; }
public PluginCommandDescriptor(ICommandPlugin command, IDictionary<string, object> metaData) { Command = command; MetaData = metaData; }
public CommandPluginAdapter(ICommandPlugin commandPlugin) { _plugin = commandPlugin ?? throw new ArgumentNullException(nameof(commandPlugin)); CreateControls(); }