BioCore  5.0.0
A Windows .NET microscopy library and application for viewing, editing, and annotating images.
Loading...
Searching...
No Matches
Plugin.cs
Go to the documentation of this file.
1using AForge;
2using BioCore;
3using SkiaSharp;
4using System;
5using System.Collections.Generic;
6using System.IO;
7using System.Linq;
8using System.Reflection;
9using System.Text;
10using System.Threading.Tasks;
11using static BioCore.Plugin;
12
13namespace BioCore
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)
Definition App.cs:207
static void AddContextMenu(string menu)
Definition App.cs:215
static Dictionary< string, IPlugin > Plugins
Definition Plugin.cs:17
static void Initialize()
Definition Plugin.cs:38
static void Render(object o, PaintEventArgs e)
Definition Plugin.cs:100
static void MouseMove(object o, PointD e, MouseEventArgs buts)
Definition Plugin.cs:107
static void MouseDown(object o, PointD e, MouseEventArgs buts)
Definition Plugin.cs:121
static void Paint(object o, PaintEventArgs e)
Definition Plugin.cs:93
static void KeyPressEvent(object o, KeyPressEventArgs e)
Definition Plugin.cs:79
static void KeyDownEvent(object o, KeyEventArgs e)
Definition Plugin.cs:72
static void KeyUpEvent(object o, KeyEventArgs e)
Definition Plugin.cs:65
static void MouseUp(object o, PointD e, MouseEventArgs buts)
Definition Plugin.cs:114
static void ScrollEvent(object o, MouseEventArgs args)
Definition Plugin.cs:86
void ScrollEvent(object o, MouseEventArgs args)
void MouseUp(object o, PointD e, MouseEventArgs buts)
void KeyPressEvent(object o, KeyPressEventArgs e)
void MouseMove(object o, PointD e, MouseEventArgs buts)
void KeyUpEvent(object o, KeyEventArgs e)
void KeyDownEvent(object o, KeyEventArgs e)
void Render(object o, PaintEventArgs e)
void Paint(object o, PaintEventArgs e)
void MouseDown(object o, PointD e, MouseEventArgs buts)
void Execute(string[] args)