private void RunPlugin(Plugin plug) { Type ty = GetTypeForFileName(plug.FileName, plug.Type);//Assembly.LoadFrom(plug.FileName).GetType(plug.Type); if (ty == null) { throw new Exception(string.Format("The plugin {0} could not load the type. Are yo missing the Assembly Filename? ", plug.Name)); } try { CheckAndRunDependencies(plug); object obj = Constructor.Create(ty); obj = InjectInputs(obj, plug); MethodInfo runMethod = ty.GetMethod(plug.RunMethod); runMethod.Invoke(obj, new object[] { }); PlugsRegistry.AddLoadedPlugin(plug, obj); PlugsRegistry.ExtractOutputs(obj); string parent = obj.GetType().BaseType.ToString(); if (parent == "System.Windows.Forms.Form" && WinForm == null) { this.WinForm = obj; } } catch (Exception e) { throw new Exception(string.Format("The plugin {0} couldnĀ“t initialize", plug.Name), e); } }
private void RunPlugin(string pluginName) { KeyValuePair <bool, Plugin> val = PlugsRegistry.SearchPlugin(pluginName); if (!val.Key) //chequea q el mismo plugin no corra mas de una vez. TODO: pensar esto { RunPlugin(val.Value); } }
private void RunInitialPlugs() { foreach (Plugin item in PlugsRegistry.GetInitialPlugs()) { if (!PlugsRegistry.IsPluginInstalled(item)) { InstallPlugin(item); } RunPlugin(item); } }
private void CheckAndRunDependencies(Plugin plug) { if (plug != null && plug.DependentPlugins != null && plug.DependentPlugins.Length > 0) { foreach (DependentPlugin item in plug.DependentPlugins) { if (!PlugsRegistry.IsPluginLoaded(item.name)) { RunPlugin(item.name); } } } }
/// <summary> /// Call all plugins called by this plugin /// </summary> /// <param name="obj">The plugin that calls the dependent plugins</param> public void CallPlugins(object obj) { PlugsRegistry.ExtractOutputs(obj); List <Plugin> plugs = PlugsRegistry.GetCalledPlugins(obj.GetType()); if (plugs != null && plugs.Count > 0) { foreach (Plugin item in plugs) { RunPlugin(item); } } }
private ObjectDefinition CreateObjectDefinition(object obj, Plugin plug) { if (plug != null && obj != null && plug.Inputs != null && plug.Inputs.Length > 0) { ObjectDefinition objDef = new ObjectDefinition(); objDef.Name = plug.Name + "Plug"; objDef.Type = obj.GetType().ToString(); List <Property> propertiesToInject = new List <Property>(); foreach (PluginInput input in plug.Inputs) { List <KeyValuePair <string, object> > outList = PlugsRegistry.GetOutputsForType(GetTypeForFileName(input.FileName, input.Type)); if (outList != null) { if (outList.Count == 1 || outList.Count > 1) //TODO: falta Desarrollar cuando hay mas de un plugin para el mismo tipo { propertiesToInject.Add(new Property(input.SetterProperty, outList[0].Value.GetType(), plug.FileName, outList[0].Value)); } } } objDef.Properties = propertiesToInject.ToArray(); return(objDef); } return(null); }
private void PluginLocator_NewPlugins(object sender, NewPlugsEventArgs e) { PlugsRegistry.Add(e.NewPlugins); }
private List <Plugin> SearchPluginsByCategory(string category) { return(PlugsRegistry.SearchPluginsByCategory(category)); }