Skip to content

Commit 8f2ee17

Browse files
💾 Feat(Plugin): 新增 IPluginManager 接口及 PluginCallInfo 类,支持插件调用和参数传递;扩展 IWorkflowService 接口以编译和持久化工作流脚本;扩展 IWorkflowStorageService 接口以预加载已编译脚本
1 parent aeb466d commit 8f2ee17

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace KitX.Core.Contract.Workflow;
2+
3+
/// <summary>
4+
/// 插件管理器接口 - BlockScripting 使用此接口调用插件方法。
5+
/// Copy of Kscript.CSharp.Parser.Core.IPluginManager for BlockScripting use
6+
/// without depending on the KCS parser assembly.
7+
/// 实际实现由外部项目(RealPluginManager)提供。
8+
/// </summary>
9+
public interface IPluginManager
10+
{
11+
/// <summary>
12+
/// 调用插件方法
13+
/// </summary>
14+
/// <typeparam name="T">返回值类型</typeparam>
15+
/// <param name="callInfo">调用信息</param>
16+
/// <returns>插件方法的返回值</returns>
17+
T Call<T>(PluginCallInfo callInfo);
18+
19+
/// <summary>
20+
/// 调用插件方法(无返回值)
21+
/// </summary>
22+
/// <param name="callInfo">调用信息</param>
23+
void Call(PluginCallInfo callInfo);
24+
25+
/// <summary>
26+
/// 检查插件是否存在
27+
/// </summary>
28+
/// <param name="pluginName">插件名称</param>
29+
/// <returns>插件是否存在</returns>
30+
bool IsPluginExists(string pluginName);
31+
32+
/// <summary>
33+
/// 检查插件方法是否存在
34+
/// </summary>
35+
/// <param name="pluginName">插件名称</param>
36+
/// <param name="methodName">方法名称</param>
37+
/// <returns>方法是否存在</returns>
38+
bool IsMethodExists(string pluginName, string methodName);
39+
}

KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ Task<BlockScriptExecutionResult> ExecuteBlockScriptAsync(
165165
public interface IWorkflowService : IWorkflowManagementService, IScriptExecutionService,
166166
IWorkflowPluginService, IBlockScriptService
167167
{
168+
/// <summary>
169+
/// Compiles a workflow's BlockScript into a persisted assembly on disk.
170+
/// The compiled assembly is saved under <c>Data/CompiledScripts/{workflowId}/</c>
171+
/// and will be reused on subsequent runs instead of recompiling.
172+
/// </summary>
173+
/// <param name="workflowId">The workflow ID to compile and persist.</param>
174+
/// <returns>True if compilation and persistence succeeded.</returns>
175+
Task<bool> CompileAndPersistWorkflowAsync(string workflowId);
168176
}
169177

170178
/// <summary>

KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowStorageService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ public interface IWorkflowStorageService
6060
/// <param name="workflowId">Workflow ID</param>
6161
/// <returns>Full file path</returns>
6262
string GetWorkflowFilePath(string workflowId);
63+
64+
/// <summary>
65+
/// Preloads all persisted compiled scripts for discovered workflows from disk
66+
/// into the in-memory cache. Called at startup to enable fast first-run execution.
67+
/// </summary>
68+
/// <returns>Number of scripts successfully loaded.</returns>
69+
Task<int> PreloadCompiledScriptsAsync();
6370
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
3+
namespace KitX.Core.Contract.Workflow;
4+
5+
/// <summary>
6+
/// 插件调用信息,用于传递给 IPluginManager.Call 的参数。
7+
/// Copy of Kscript.CSharp.Parser.Models.PluginCallInfo for BlockScripting use
8+
/// without depending on the KCS parser assembly.
9+
/// </summary>
10+
public class PluginCallInfo
11+
{
12+
/// <summary>
13+
/// 插件名称
14+
/// </summary>
15+
public string PluginName { get; set; } = string.Empty;
16+
17+
/// <summary>
18+
/// 方法名称
19+
/// </summary>
20+
public string MethodName { get; set; } = string.Empty;
21+
22+
/// <summary>
23+
/// 方法参数值数组
24+
/// </summary>
25+
public object[] Parameters { get; set; } = Array.Empty<object>();
26+
27+
/// <summary>
28+
/// 参数类型数组
29+
/// </summary>
30+
public Type[] ParameterTypes { get; set; } = Array.Empty<Type>();
31+
32+
/// <summary>
33+
/// 参数名称数组
34+
/// </summary>
35+
public string[] ParameterNames { get; set; } = Array.Empty<string>();
36+
37+
public PluginCallInfo()
38+
{
39+
}
40+
41+
public PluginCallInfo(string pluginName, string methodName, object[] parameters, Type[] parameterTypes, string[] parameterNames)
42+
{
43+
PluginName = pluginName;
44+
MethodName = methodName;
45+
Parameters = parameters;
46+
ParameterTypes = parameterTypes;
47+
ParameterNames = parameterNames;
48+
}
49+
50+
public override string ToString()
51+
{
52+
return $"{PluginName}.{MethodName}({string.Join(", ", Parameters)})";
53+
}
54+
}

0 commit comments

Comments
 (0)