BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
Plugin.cs
1using AForge;
2using SkiaSharp;
3using SkiaSharp.Views.Desktop;
4using System;
5using System.Collections.Generic;
6using System.IO;
7using System.Linq;
8using System.Reflection;
9using System.Text;
10using System.Threading.Tasks;
11using static BioImager.Plugin;
12
13namespace BioImager
14{
15 public class Plugin
16 {
17 public static Dictionary<string, IPlugin> Plugins = new Dictionary<string, IPlugin>();
18 public interface IPlugin
19 {
20 string Name { get; }
21 string MenuPath { get; }
22 bool ContextMenu { get; }
23 void Execute(string[] args);
24 void KeyUpEvent(object o, KeyEventArgs e);
25 void KeyDownEvent(object o, KeyEventArgs e);
26 void KeyPressEvent(object o, KeyPressEventArgs e);
27 void ScrollEvent(object o, MouseEventArgs args);
28 void Paint(object o, PaintEventArgs e);
29 void Render(object o, PaintEventArgs e);
30 void MouseMove(object o, PointD e, MouseEventArgs buts);
31 void MouseUp(object o, PointD e, MouseEventArgs buts);
32 void MouseDown(object o, PointD e, MouseEventArgs buts);
33 }
34 }
35
36 public static class Plugins
37 {
38 public static void Initialize()
39 {
40 Directory.CreateDirectory("Plugins");
41 foreach (string s in Directory.GetFiles("Plugins"))
42 {
43 if (!s.EndsWith(".dll") || Plugin.Plugins.ContainsKey(Path.GetFileName(s)))
44 continue;
45 // Load the plugin assembly
46 Assembly pluginAssembly = Assembly.LoadFile(Environment.CurrentDirectory + "/" + s);
47 // Find the type which implements the IPlugin interface
48 var pluginType = pluginAssembly.GetTypes().FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsInterface);
49 if (pluginType != null)
50 {
51 // Create an instance of this type
52 IPlugin pluginInstance = Activator.CreateInstance(pluginType) as IPlugin;
53 Plugin.Plugins.Add(Path.GetFileName(s), pluginInstance);
54 if (pluginInstance.ContextMenu)
55 App.AddContextMenu(pluginInstance.MenuPath);
56 else
57 App.AddMenu(pluginInstance.MenuPath);
58 }
59 else
60 {
61 Console.WriteLine("No plugin found in the assembly: " + s);
62 }
63 }
64 }
65 public static void KeyUpEvent(object o, KeyEventArgs e)
66 {
67 foreach (IPlugin p in Plugin.Plugins.Values)
68 {
69 p.KeyUpEvent(o, e);
70 }
71 }
72 public static void KeyDownEvent(object o, KeyEventArgs e)
73 {
74 foreach (IPlugin p in Plugin.Plugins.Values)
75 {
76 p.KeyDownEvent(o, e);
77 }
78 }
79 public static void KeyPressEvent(object o, KeyPressEventArgs e)
80 {
81 foreach (IPlugin p in Plugin.Plugins.Values)
82 {
83 p.KeyPressEvent(o, e);
84 }
85 }
86 public static void ScrollEvent(object o, MouseEventArgs args)
87 {
88 foreach (IPlugin p in Plugin.Plugins.Values)
89 {
90 p.ScrollEvent(o, args);
91 }
92 }
93 public static void Paint(object o, PaintEventArgs e)
94 {
95 foreach (IPlugin p in Plugin.Plugins.Values)
96 {
97 p.Paint(o, e);
98 }
99 }
100 public static void Render(object o, PaintEventArgs e)
101 {
102 foreach (IPlugin p in Plugin.Plugins.Values)
103 {
104 p.Render(o, e);
105 }
106 }
107 public static void MouseMove(object o, PointD e, MouseEventArgs buts)
108 {
109 foreach (IPlugin p in Plugin.Plugins.Values)
110 {
111 p.MouseMove(o, e, buts);
112 }
113 }
114 public static void MouseUp(object o, PointD e, MouseEventArgs buts)
115 {
116 foreach (IPlugin p in Plugin.Plugins.Values)
117 {
118 p.MouseUp(o, e, buts);
119 }
120 }
121 public static void MouseDown(object o, PointD e, MouseEventArgs buts)
122 {
123 foreach (IPlugin p in Plugin.Plugins.Values)
124 {
125 p.MouseDown(o, e, buts);
126 }
127 }
128 }
129
130}
static void AddMenu(string menu, Function f)
Definition App.cs:386
static void AddContextMenu(string menu, Function f)
Definition App.cs:394