public UnitySubscriber(ISub sub, Func <T, Task> action, ILogger logger = null) { _action = action; _sub = sub; _logger = logger; _sub.Subscribe(this); _logger?.Log($"{EventHub.Tag}, Subscribe event: {typeof(T).Name}"); }
public OperationController(IAdd add, IMult mult, IDiv div, ISub sub, ILogger <OperationController> logger) { _add = add; _mult = mult; _div = div; _sub = sub; _logger = logger; }
public ICollection <ISub> LoadPlugins() { Console.WriteLine("Loading plugins..."); plugins = new List <ISub>(); if (Directory.Exists(pluginsDir)) { string[] files = Directory.GetFiles(pluginsDir, "*.dll"); ICollection <Assembly> assemblies = new List <Assembly>(files.Length); foreach (string file in files) { if (file.EndsWith(".dll")) { AssemblyName an = AssemblyName.GetAssemblyName(file); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } } Type interfaceType = typeof(ISub); ICollection <Type> pluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { if (type.GetInterface(interfaceType.FullName) != null) { pluginTypes.Add(type); } } } } } foreach (Type type in pluginTypes) { ISub plugin = (ISub)Activator.CreateInstance(type); plugins.Add(plugin); } return(plugins); } else { Console.WriteLine("Plugins directory doesn't exist."); } return(null); }
//Confirm button private void button1_Click(object sender, EventArgs e) { File.Copy(pluginPath, Properties.Settings.Default.PluginsDir + "\\" + Path.GetFileName(pluginPath)); PluginLoader loader = new PluginLoader(); ISub sub = loader.LoadPlugin(Path.GetFileName(pluginPath)); ((Form1)mainForm).plugins.Add(sub); ((Form1)mainForm).checkedListBox1.Items.Add(sub.name); ((Form1)mainForm).settings.Add(Activator.CreateInstance(sub.settings)); pluginPath = ""; this.Close(); }
public ISub LoadPlugin(string fileName) { string file = pluginsDir + "\\" + fileName; if (Directory.Exists(pluginsDir)) { if (file.EndsWith(".dll")) { AssemblyName an = AssemblyName.GetAssemblyName(file); Assembly assembly = Assembly.Load(an); Type interfaceType = typeof(ISub); if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { if (type.GetInterface(interfaceType.FullName) != null) { ISub plugin = (ISub)Activator.CreateInstance(type); return(plugin); } } } } else { Console.WriteLine("Assembly is null."); } } } return(null); }
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { plugins[e.Index].enabled = (e.NewValue == CheckState.Checked); string desc = plugins[e.Index].description; if (desc == null || desc == "") { desc = "No description provided."; } richTextBox1.Text = desc; label2.Text = plugins[e.Index].name + " - v" + plugins[e.Index].version; string author = plugins[e.Index].author; if (author == null || author == "") { author = "Anonymous"; } label3.Text = "by " + author; button3.Show(); currentlySelectedPlugin = plugins[e.Index]; }
public ImplementingObjectWithArguments(ISub sub) { Sub = sub; }
public string Sub([FromServices] ISub sub, int a, int b) { return($"{a} - {b} = {sub.Calc(a, b)}"); }