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