暂时实现了简陋的脚本AST分析解释,后面再绑定到控件上

This commit is contained in:
fengjiayi
2024-12-20 23:39:29 +08:00
parent 114e81424b
commit ef119e11e3
52 changed files with 3175 additions and 261 deletions

View File

@@ -22,22 +22,11 @@ namespace Serein.Library
public DelegateDetails(MethodInfo methodInfo)
{
var emitMethodType = EmitHelper.CreateDynamicMethod(methodInfo, out var emitDelegate);
_emitMethodType = emitMethodType;
_emitMethodInfo = emitMethodType;
_emitDelegate = emitDelegate;
}
/// <summary>
/// 记录Emit委托
/// </summary>
/// <param name="EmitMethodType"></param>
/// <param name="EmitDelegate"></param>
public DelegateDetails(EmitMethodType EmitMethodType, Delegate EmitDelegate)
{
_emitMethodType = EmitMethodType;
_emitDelegate = EmitDelegate;
}
/*/// <summary>
/// 更新委托方法
@@ -50,9 +39,13 @@ namespace Serein.Library
_emitDelegate = EmitDelegate;
}*/
private Delegate _emitDelegate;
private EmitMethodType _emitMethodType;
private EmitMethodInfo _emitMethodInfo;
/// <summary>
/// 该Emit委托的相应信息
/// </summary>
public EmitMethodInfo EmitMethodInfo => _emitMethodInfo;
///// <summary>
///// <para>普通方法Func&lt;object,object[],object&gt;</para>
@@ -65,6 +58,22 @@ namespace Serein.Library
///// </summary>
//public EmitMethodType EmitMethodType { get => _emitMethodType; }
public async Task<object> AutoInvokeAsync(object[] args)
{
if (_emitMethodInfo.IsStatic)
{
return await InvokeAsync(null, args);
}
else
{
var obj = Activator.CreateInstance(_emitMethodInfo.DeclaringType);
return await InvokeAsync(obj, args);
}
throw new Exception("Not static method");
}
/// <summary>
/// <para>使用的实例必须能够正确调用该委托,传入的参数也必须符合方法入参信息。</para>
/// </summary>
@@ -77,16 +86,20 @@ namespace Serein.Library
{
args = Array.Empty<object>();
}
if(_emitMethodInfo.IsStatic)
{
instance = null;
}
object result = null;
if (_emitMethodType == EmitMethodType.HasResultTask && _emitDelegate is Func<object, object[], Task<object>> hasResultTask)
if (_emitDelegate is Func<object, object[], Task<object>> hasResultTask)
{
result = await hasResultTask(instance, args);
}
else if (_emitMethodType == EmitMethodType.Task && _emitDelegate is Func<object, object[], Task> task)
else if (_emitDelegate is Func<object, object[], Task> task)
{
await task.Invoke(instance, args);
}
else if (_emitMethodType == EmitMethodType.Func && _emitDelegate is Func<object, object[], object> func)
else if (_emitDelegate is Func<object, object[], object> func)
{
result = func.Invoke(instance, args);
}

View File

@@ -69,14 +69,6 @@ namespace Serein.Library
public abstract partial class NodeModelBase : IDynamicFlowNode
{
/// <summary>
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
/// </summary>
public virtual void OnCreating()
{
}
public NodeModelBase(IFlowEnvironment environment)
{
PreviousNodes = new Dictionary<ConnectionInvokeType, List<NodeModelBase>>();

View File

@@ -29,6 +29,15 @@ namespace Serein.Library
public abstract partial class NodeModelBase : IDynamicFlowNode
{
#region
/// <summary>
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
/// </summary>
public virtual void OnCreating()
{
}
/// <summary>
/// 保存自定义信息
@@ -55,6 +64,7 @@ namespace Serein.Library
{
}
/// <summary>
/// 移除该节点
/// </summary>
@@ -95,7 +105,6 @@ namespace Serein.Library
this.Env = null;
}
/// <summary>
/// 输出方法参数信息
/// </summary>
@@ -125,7 +134,6 @@ namespace Serein.Library
}
/// <summary>
/// 导出为节点信息
/// </summary>
@@ -164,8 +172,6 @@ namespace Serein.Library
return nodeInfo;
}
/// <summary>
/// 从节点信息加载节点
/// </summary>
@@ -244,6 +250,8 @@ namespace Serein.Library
#region
/// <summary>
/// 是否应该退出执行
/// </summary>

View File

@@ -0,0 +1,56 @@
using Serein.Library.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Library
{
/// <summary>
/// 脚本代码中关于流程运行的API
/// </summary>
public class ScriptFlowApi : IScriptFlowApi
{
/// <summary>
/// 流程环境
/// </summary>
public IFlowEnvironment Env { get; private set; }
/// <summary>
/// 创建流程脚本接口
/// </summary>
/// <param name="environment"></param>
public ScriptFlowApi(IFlowEnvironment environment)
{
Env = environment;
}
Task<object> IScriptFlowApi.CallNode(string nodeGuid)
{
throw new NotImplementedException();
}
object IScriptFlowApi.GetDataOfParams(int index)
{
throw new NotImplementedException();
}
object IScriptFlowApi.GetDataOfParams(string name)
{
throw new NotImplementedException();
}
object IScriptFlowApi.GetFlowData()
{
throw new NotImplementedException();
}
object IScriptFlowApi.GetGlobalData(string keyName)
{
throw new NotImplementedException();
}
}
}