void AddPluginKey(XmlPluginKey xmlKey) { Key newKey = CreateKeyWithBasicProps(xmlKey); if (null != xmlKey.Plugin && null != xmlKey.Method) { // FIXME: Saving the XML of the xmlKey itself probably is not be the best option. It is done this way to avoid messing with // other pieces of code deep within OptiKey. XmlSerializer xmlSer = new XmlSerializer(typeof(XmlPluginKey)); using (var sww = new StringWriter()) { XmlTextWriter writer = new XmlTextWriter(sww) { Formatting = Formatting.Indented }; xmlSer.Serialize(writer, xmlKey); newKey.Value = new KeyValue(FunctionKeys.Plugin, sww.ToString()); } } else { Log.ErrorFormat("Incomplete plugin key configuration in key {0}", xmlKey.Label ?? xmlKey.Symbol); } PlaceKeyInPosition(newKey, xmlKey.Row, xmlKey.Col, xmlKey.Height, xmlKey.Width); }
public static void RunPlugin_Legacy(Dictionary <string, string> context, XmlPluginKey key) { Plugin plugin = availablePlugins[key.Plugin]; List <string> methodArgs = null; if (key.Arguments?.Argument?.Count > 0) { // FIXME: This logic does not support two methods with the same name and different arguments methodArgs = new List <String>(); foreach (MethodInfo pluginMethod in plugin.Type.GetMethods()) { if (pluginMethod.Name.Equals(key.Method)) { foreach (ParameterInfo pluginMethodParam in pluginMethod.GetParameters()) { string argValue = null; foreach (PluginArgument arg in key.Arguments.Argument) { if (arg.Name.Equals(pluginMethodParam.Name)) { argValue = GetArgumentValue(context, arg.Value); break; } } methodArgs.Add(argValue); } break; } } } plugin.Type.InvokeMember(key.Method, BindingFlags.InvokeMethod, null, plugin.Instance, methodArgs?.ToArray()); }