From c401a2f2fd1a509cdeb33e850bb5c2827074af48 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 17 三月 2025 08:44:51 +0800
Subject: [PATCH] 完善框架,新增两个close方法;
---
HMI.Base/PluginLoader.cs | 70 +++++++---------------------------
1 files changed, 15 insertions(+), 55 deletions(-)
diff --git a/HMI.Base/PluginLoader.cs b/HMI.Base/PluginLoader.cs
index eef52ba..cf98bd3 100644
--- a/HMI.Base/PluginLoader.cs
+++ b/HMI.Base/PluginLoader.cs
@@ -44,6 +44,14 @@
sqliteHelper = new SqliteHelper(PathHelper.DatabasePath);
}
+ public static void Reset()
+ {
+ if (Instance != null)
+ {
+ Instance = null;
+ }
+ }
+
public static PluginLoader GetLoader()
{
if (Instance == null)
@@ -53,79 +61,29 @@
return Instance;
}
- public void LoadMenuAndPlugin(Dispatcher dispatcher)
+ private IPluginContainer pluginContainer;
+ public void LoadMenuAndPlugin(IPluginContainer container, Dispatcher dispatcher)
{
+ pluginContainer = container;
if (Menus == null)
{
Plugins = new List<PluginInfo>();
Menus = LoadTreeMenu(dispatcher);
+ sqliteHelper.Close();
dispatcher.Invoke(() =>
{
LoadMessageAppend?.Invoke(this, new LoadMsg { Type = LoadMsgType.FINISHED });
});
}
}
-
- private void LoadChildrenMenu(PluginInfo menu, Dispatcher dispatcher)
- {
- LoadMessageAppend?.Invoke(this, new LoadMsg
- {
- Type = LoadMsgType.LOADING,
- Message = $"姝e湪鍔犺浇{menu.Name}鑿滃崟..."
- });
- try
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- if (!string.IsNullOrEmpty(menu.DllPath))
- {
- string dllPath = Path.Combine(PluginFolder, menu.DllPath);
- Assembly ass = Assembly.LoadFrom(dllPath);
- Type ClassType = ass.GetType(menu.ClassName);
- object Instance = Activator.CreateInstance(ClassType);
- menu.Content = Instance;
- if (Instance is IPlugin plugin)
- {
- plugin.SetLogger(LogManager.GetLogger(menu.Code));
- string configFolder = Path.Combine(PathHelper.ConfigFolder, menu.Code);
- if (!Directory.Exists(configFolder))
- {
- Directory.CreateDirectory(configFolder);
- }
- plugin.SetBaseFolder(configFolder);
- plugin.InitFinish();
- }
- Type SettingType = ass.GetType($"{menu.ClassName}_Setting");
- if (SettingType != null)
- {
- object SettingInstance = Activator.CreateInstance(SettingType);
- menu.SettingControl = SettingInstance;
- }
- }
- });
- Thread.Sleep(100);
- }
- catch (Exception ex)
- {
- LoadMessageAppend?.Invoke(this,
- new LoadMsg
- {
- Type = LoadMsgType.LOADING,
- Result = false,
- Message = $"{ex.Message} {ex.StackTrace}"
- });
- }
- }
-
private void LoadChildrenMenu()
{
foreach (var menu in Plugins)
{
CountdownEvent c = new CountdownEvent(1);
- Thread.Sleep(100);
+ Thread.Sleep(80);
Application.Current.Dispatcher.Invoke(new Action(() =>
{
-
try
{
LoadMessageAppend?.Invoke(this,
@@ -152,6 +110,8 @@
}
plugin.SetBaseFolder(configFolder);
plugin.InitFinish();
+ pluginContainer.OnCloseEvent += plugin.OnClose;
+ pluginContainer.DoCloseEvent += plugin.DoClose;
Type SettingType = ass.GetType($"{menu.ClassName}_Setting");
if (SettingType != null)
{
--
Gitblit v1.9.1