mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
忘记改啥了*1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Api
|
||||
@@ -20,6 +21,11 @@ namespace Serein.Library.Api
|
||||
/// </summary>
|
||||
RunState RunState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 用来在当前流程上下文间传递数据
|
||||
/// </summary>
|
||||
Dictionary<string, object> ContextShareData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下一个要执行的节点类别
|
||||
/// </summary>
|
||||
@@ -52,7 +58,6 @@ namespace Serein.Library.Api
|
||||
/// <param name="nodeModel"></param>
|
||||
object TransmissionData(NodeModelBase nodeModel);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新当前节点的数据
|
||||
/// </summary>
|
||||
@@ -61,10 +66,12 @@ namespace Serein.Library.Api
|
||||
void AddOrUpdate(string nodeGuid, object flowData);
|
||||
|
||||
/// <summary>
|
||||
/// 用以提前结束分支运行
|
||||
/// 用以提前结束当前上下文流程的运行
|
||||
/// </summary>
|
||||
void Exit();
|
||||
|
||||
|
||||
|
||||
|
||||
/*/// <summary>
|
||||
/// 定时循环触发
|
||||
|
||||
@@ -619,7 +619,7 @@ namespace Serein.Library.Api
|
||||
event EnvOutHandler OnEnvOut;
|
||||
#endregion
|
||||
|
||||
#region 接口
|
||||
#region 流程接口
|
||||
|
||||
/// <summary>
|
||||
/// 设置输出
|
||||
@@ -891,6 +891,24 @@ namespace Serein.Library.Api
|
||||
void TriggerInterrupt(string nodeGuid, string expression, InterruptTriggerEventArgs.InterruptTriggerType type);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 流程依赖类库的接口
|
||||
|
||||
/// <summary>
|
||||
/// 运行时加载
|
||||
/// </summary>
|
||||
/// <param name="file">文件名</param>
|
||||
/// <returns></returns>
|
||||
bool LoadNativeLibraryOfRuning(string file);
|
||||
|
||||
/// <summary>
|
||||
/// 运行时加载指定目录下的类库
|
||||
/// </summary>
|
||||
/// <param name="path">目录</param>
|
||||
/// <param name="isRecurrence">是否递归加载</param>
|
||||
void LoadAllNativeLibraryOfRuning(string path, bool isRecurrence = true);
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI视觉
|
||||
|
||||
@@ -64,13 +64,20 @@ namespace Serein.Library
|
||||
[PropertyInfo]
|
||||
private string _methodAnotherName;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 参数描述
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private ParameterDetails[] _parameterDetailss;
|
||||
|
||||
/// <summary>
|
||||
/// <para>描述该方法是否存在可选参数</para>
|
||||
/// <para>-1表示不存在</para>
|
||||
/// <para>0表示第一个参数是可选参数</para>
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private int _isParamsArgIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// 出参类型
|
||||
/// </summary>
|
||||
@@ -81,6 +88,83 @@ namespace Serein.Library
|
||||
|
||||
public partial class MethodDetails
|
||||
{
|
||||
|
||||
#region 新增可选参数
|
||||
/// <summary>
|
||||
/// 新增可选参数
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public void AddParamsArg(int index = 0)
|
||||
{
|
||||
if (IsParamsArgIndex >= 0 // 方法是否包含可选参数
|
||||
&& index >= 0 // 如果包含,则判断从哪个参数赋值
|
||||
&& index >= IsParamsArgIndex // 需要判断是否为可选参数的部分
|
||||
&& index < ParameterDetailss.Length) // 防止下标越界
|
||||
{
|
||||
var newPd = ParameterDetailss[index].CloneOfModel(this.NodeModel); // 复制出属于本身节点的参数描述
|
||||
newPd.Index = ParameterDetailss.Length; // 更新索引
|
||||
newPd.IsParams = true;
|
||||
ParameterDetailss = AddToArray(ParameterDetailss, newPd); // 新增
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 移除可选参数
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public void RemoveParamsArg(int index = 0)
|
||||
{
|
||||
if (IsParamsArgIndex >= 0 // 方法是否包含可选参数
|
||||
&& index >= 0 // 如果包含,则判断从哪个参数赋值
|
||||
&& index >= IsParamsArgIndex // 需要判断是否为可选参数的部分
|
||||
&& index < ParameterDetailss.Length) // 防止下标越界
|
||||
{
|
||||
//var newPd = ParameterDetailss[index].CloneOfModel(this.NodeModel); // 复制出属于本身节点的参数描述
|
||||
//newPd.Index = ParameterDetailss.Length; // 更新索引
|
||||
ParameterDetailss[index] = null; // 释放对象引用
|
||||
ParameterDetailss = RemoteToArray(ParameterDetailss, index); // 新增
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] AddToArray<T>(T[] original, T newObject)
|
||||
{
|
||||
// 创建一个新数组,比原数组大1
|
||||
T[] newArray = new T[original.Length + 1];
|
||||
|
||||
// 复制原数组的元素
|
||||
for (int i = 0; i < original.Length; i++)
|
||||
{
|
||||
newArray[i] = original[i];
|
||||
}
|
||||
|
||||
// 将新对象放在最后一位
|
||||
newArray[newArray.Length - 1] = newObject;
|
||||
|
||||
return newArray;
|
||||
}
|
||||
public static T[] RemoteToArray<T>(T[] original, int index)
|
||||
{
|
||||
if(index == 0)
|
||||
{
|
||||
return new T[0];
|
||||
}
|
||||
// 创建一个新数组,比原数组小1
|
||||
T[] newArray = new T[original.Length - 1];
|
||||
|
||||
for (int i = 0; i < index; i++)
|
||||
{
|
||||
newArray[i] = original[i];
|
||||
}
|
||||
for (int i = index; i < newArray.Length; i++)
|
||||
{
|
||||
newArray[i] = original[i+1];
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 不包含方法信息的基础节点(后续可能要改为DLL引入基础节点)
|
||||
/// </summary>
|
||||
@@ -91,9 +175,8 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 生成元数据
|
||||
/// </summary>
|
||||
/// <param name="env">节点运行的环境</param>
|
||||
/// <param name="nodeModel">标识属于哪个节点</param>
|
||||
public MethodDetails(IFlowEnvironment env, NodeModelBase nodeModel)
|
||||
public MethodDetails(NodeModelBase nodeModel)
|
||||
{
|
||||
NodeModel = nodeModel;
|
||||
}
|
||||
@@ -114,6 +197,7 @@ namespace Serein.Library
|
||||
MethodDynamicType = nodeType;
|
||||
ReturnType = Type.GetType(Info.ReturnTypeFullName);
|
||||
ParameterDetailss = Info.ParameterDetailsInfos.Select(pinfo => new ParameterDetails(pinfo)).ToArray();
|
||||
IsParamsArgIndex = Info.IsParamsArgIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,25 +206,25 @@ namespace Serein.Library
|
||||
/// <returns></returns>
|
||||
public MethodDetailsInfo ToInfo()
|
||||
{
|
||||
|
||||
|
||||
return new MethodDetailsInfo
|
||||
{
|
||||
MethodName = MethodName,
|
||||
MethodAnotherName = MethodAnotherName,
|
||||
NodeType = MethodDynamicType.ToString(),
|
||||
ParameterDetailsInfos = ParameterDetailss.Select(p => p.ToInfo()).ToArray(),
|
||||
ReturnTypeFullName = ReturnType.FullName,
|
||||
MethodName = this.MethodName,
|
||||
MethodAnotherName = this.MethodAnotherName,
|
||||
NodeType = this.MethodDynamicType.ToString(),
|
||||
ParameterDetailsInfos = this.ParameterDetailss.Select(p => p.ToInfo()).ToArray(),
|
||||
ReturnTypeFullName = this.ReturnType.FullName,
|
||||
IsParamsArgIndex = this.IsParamsArgIndex,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从DLL拖动出来时拷贝属于节点的实例
|
||||
/// 从DLL拖动出来时,从元数据拷贝新的实例,作为属于节点独享的方法描述
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MethodDetails CloneOfNode(IFlowEnvironment env, NodeModelBase nodeModel)
|
||||
public MethodDetails CloneOfNode( NodeModelBase nodeModel)
|
||||
{
|
||||
var md = new MethodDetails(env, nodeModel) // 创建新节点时拷贝实例
|
||||
// this => 是元数据
|
||||
var md = new MethodDetails( nodeModel) // 创建新节点时拷贝实例
|
||||
{
|
||||
ActingInstance = this.ActingInstance,
|
||||
ActingInstanceType = this.ActingInstanceType,
|
||||
@@ -150,8 +234,9 @@ namespace Serein.Library
|
||||
MethodName = this.MethodName,
|
||||
MethodLockName = this.MethodLockName,
|
||||
IsProtectionParameter = this.IsProtectionParameter,
|
||||
IsParamsArgIndex= this.IsParamsArgIndex,
|
||||
};
|
||||
md.ParameterDetailss = this.ParameterDetailss?.Select(p => p?.CloneOfClone(env, nodeModel)).ToArray(); // 拷贝属于节点方法的新入参描述
|
||||
md.ParameterDetailss = this.ParameterDetailss?.Select(p => p?.CloneOfModel(nodeModel)).ToArray(); // 拷贝属于节点方法的新入参描述
|
||||
return md;
|
||||
}
|
||||
|
||||
@@ -163,71 +248,16 @@ namespace Serein.Library
|
||||
sb.AppendLine($"需要实例:{this.ActingInstanceType?.FullName}");
|
||||
sb.AppendLine($"");
|
||||
sb.AppendLine($"入参参数信息:");
|
||||
foreach (var arg in this.ParameterDetailss)
|
||||
for (int i = 0; i < ParameterDetailss.Length; i++)
|
||||
{
|
||||
sb.AppendLine($" {arg.ToString()}");
|
||||
ParameterDetails arg = this.ParameterDetailss[i];
|
||||
}
|
||||
sb.AppendLine($"");
|
||||
sb.AppendLine($"返回值信息:");
|
||||
sb.AppendLine($" {this.ReturnType.FullName}");
|
||||
sb.AppendLine($" {this.ReturnType?.FullName}");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 每个节点有独自的MethodDetails实例
|
||||
///// </summary>
|
||||
//public partial class TmpMethodDetails
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 是否保护参数(目前仅视觉效果参数,不影响运行实现,后续将设置作用在运行逻辑中)
|
||||
// /// </summary>
|
||||
// public bool IsProtectionParameter { get; set; } = false;
|
||||
|
||||
// /// <summary>
|
||||
// /// 作用实例的类型(多个相同的节点将拥有相同的类型)
|
||||
// /// </summary>
|
||||
// public Type ActingInstanceType { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 作用实例(多个相同的节点将会共享同一个实例)
|
||||
// /// </summary>
|
||||
// public object ActingInstance { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 方法名称
|
||||
// /// </summary>
|
||||
// public string MethodName { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 节点类型
|
||||
// /// </summary>
|
||||
// public NodeType MethodDynamicType { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 锁名称(暂未实现)
|
||||
// /// </summary>
|
||||
// public string MethodLockName { get; set; }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 方法说明
|
||||
// /// </summary>
|
||||
// public string MethodTips { get; set; }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 参数描述
|
||||
// /// </summary>
|
||||
|
||||
// public ParameterDetails[] ParameterDetailss { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 出参类型
|
||||
// /// </summary>
|
||||
|
||||
// public Type ReturnType { get; set; }
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ namespace Serein.Library
|
||||
|
||||
public ParameterDetailsInfo[] ParameterDetailsInfos { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可选参数信息
|
||||
/// </summary>
|
||||
public int IsParamsArgIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 出参类型
|
||||
/// </summary>
|
||||
|
||||
@@ -87,9 +87,9 @@ namespace Serein.Library
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载完成后调用的方法
|
||||
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
|
||||
/// </summary>
|
||||
public abstract void OnLoading();
|
||||
public abstract void OnCreating();
|
||||
|
||||
public NodeModelBase(IFlowEnvironment environment)
|
||||
{
|
||||
|
||||
@@ -80,16 +80,43 @@ namespace Serein.Library
|
||||
this.Position = nodeInfo.Position;// 加载位置信息
|
||||
if (this.MethodDetails != null)
|
||||
{
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
if(this.MethodDetails.ParameterDetailss is null)
|
||||
{
|
||||
var mdPd = this.MethodDetails.ParameterDetailss[i];
|
||||
ParameterData pd = nodeInfo.ParameterData[i];
|
||||
mdPd.IsExplicitData = pd.State;
|
||||
mdPd.DataValue = pd.Value;
|
||||
mdPd.ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pd.SourceType);
|
||||
mdPd.ArgDataSourceNodeGuid = pd.SourceNodeGuid;
|
||||
|
||||
this.MethodDetails.ParameterDetailss = new ParameterDetails[nodeInfo.ParameterData.Length];
|
||||
this.MethodDetails.ParameterDetailss = nodeInfo.ParameterData.Select((pd,index) =>
|
||||
{
|
||||
return new ParameterDetails()
|
||||
{
|
||||
Index = index,
|
||||
NodeModel = this,
|
||||
DataType = typeof(object),
|
||||
ExplicitType = typeof(object),
|
||||
Name = string.Empty,
|
||||
ExplicitTypeName = "Value",
|
||||
IsExplicitData = pd.State,
|
||||
DataValue = pd.Value,
|
||||
ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pd.SourceType),
|
||||
ArgDataSourceNodeGuid = pd.SourceNodeGuid,
|
||||
};
|
||||
}).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
var mdPd = this.MethodDetails.ParameterDetailss[i];
|
||||
ParameterData pd = nodeInfo.ParameterData[i];
|
||||
mdPd.IsExplicitData = pd.State;
|
||||
mdPd.DataValue = pd.Value;
|
||||
mdPd.ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pd.SourceType);
|
||||
mdPd.ArgDataSourceNodeGuid = pd.SourceNodeGuid;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -160,7 +187,7 @@ namespace Serein.Library
|
||||
|
||||
// 从栈中弹出一个节点作为当前节点进行处理
|
||||
var currentNode = stack.Pop();
|
||||
|
||||
#if false
|
||||
// 筛选出上游分支
|
||||
var upstreamNodes = currentNode.SuccessorNodes[ConnectionInvokeType.Upstream].ToArray();
|
||||
for (int index = 0; index < upstreamNodes.Length; index++)
|
||||
@@ -183,33 +210,64 @@ namespace Serein.Library
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// 上游分支执行完成,才执行当前节点
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
context.NextOrientation = ConnectionInvokeType.None; // 重置上下文状态
|
||||
object newFlowData = await currentNode.ExecutingAsync(context);
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
|
||||
object newFlowData;
|
||||
try
|
||||
{
|
||||
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
newFlowData = await currentNode.ExecutingAsync(context);
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
if (context.NextOrientation == ConnectionInvokeType.None) // 没有手动设置时,进行自动设置
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
newFlowData = null;
|
||||
await Console.Out.WriteLineAsync($"节点[{this.MethodDetails?.MethodName}]异常:" + ex);
|
||||
context.NextOrientation = ConnectionInvokeType.IsError;
|
||||
currentNode.RuningException = ex;
|
||||
}
|
||||
|
||||
|
||||
await RefreshFlowDataAndExpInterrupt(context, currentNode, newFlowData); // 执行当前节点后刷新数据
|
||||
#endregion
|
||||
|
||||
|
||||
#region 执行完成
|
||||
|
||||
// 选择后继分支
|
||||
var nextNodes = currentNode.SuccessorNodes[context.NextOrientation];
|
||||
|
||||
// 将下一个节点集合中的所有节点逆序推入栈中
|
||||
for (int i = nextNodes.Count - 1; i >= 0; i--)
|
||||
|
||||
|
||||
// 首先将指定类别后继分支的所有节点逆序推入栈中
|
||||
var nextNodes = currentNode.SuccessorNodes[context.NextOrientation];
|
||||
for (int index = nextNodes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
// 筛选出启用的节点的节点
|
||||
if (nextNodes[i].DebugSetting.IsEnable)
|
||||
if (nextNodes[index].DebugSetting.IsEnable)
|
||||
{
|
||||
context.SetPreviousNode(nextNodes[i], currentNode);
|
||||
stack.Push(nextNodes[i]);
|
||||
context.SetPreviousNode(nextNodes[index], currentNode);
|
||||
stack.Push(nextNodes[index]);
|
||||
}
|
||||
}
|
||||
// 然后将指上游分支的所有节点逆序推入栈中
|
||||
var upstreamNodes = currentNode.SuccessorNodes[ConnectionInvokeType.Upstream];
|
||||
for (int index = upstreamNodes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
// 筛选出启用的节点的节点
|
||||
if (upstreamNodes[index].DebugSetting.IsEnable)
|
||||
{
|
||||
context.SetPreviousNode(upstreamNodes[index], currentNode);
|
||||
stack.Push(upstreamNodes[index]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -245,73 +303,20 @@ namespace Serein.Library
|
||||
{
|
||||
md.ActingInstance = context.Env.IOC.Get(md.ActingInstanceType);
|
||||
}
|
||||
try
|
||||
{
|
||||
object[] args = await GetParametersAsync(context, this, md);
|
||||
var result = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
if(context.NextOrientation == ConnectionInvokeType.None) // 没有手动设置时,进行自动设置
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"节点[{this.MethodDetails?.MethodName}]异常:" + ex);
|
||||
context.NextOrientation = ConnectionInvokeType.IsError;
|
||||
RuningException = ex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行单个节点对应的方法,并不做状态检查
|
||||
/// </summary>
|
||||
/// <param name="context">运行时上下文</param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<object> InvokeAsync(IDynamicContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
MethodDetails md = MethodDetails;
|
||||
if (md is null)
|
||||
{
|
||||
throw new Exception($"不存在方法信息{md.MethodName}");
|
||||
}
|
||||
if (!Env.TryGetDelegateDetails(md.MethodName, out var dd))
|
||||
{
|
||||
throw new Exception($"不存在对应委托{md.MethodName}");
|
||||
}
|
||||
if (md.ActingInstance is null)
|
||||
{
|
||||
md.ActingInstance = Env.IOC.Get(md.ActingInstanceType);
|
||||
if (md.ActingInstance is null)
|
||||
{
|
||||
md.ActingInstance = Env.IOC.Instantiate(md.ActingInstanceType);
|
||||
if (md.ActingInstance is null)
|
||||
{
|
||||
throw new Exception($"无法创建相应的实例{md.ActingInstanceType.FullName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
object[] args = await GetParametersAsync(context, this, md);
|
||||
var result = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
return result;
|
||||
|
||||
object[] args = await GetParametersAsync(context, this, md);
|
||||
var result = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"节点[{this.MethodDetails?.MethodName}]异常:" + ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取对应的参数数组
|
||||
/// </summary>
|
||||
public static async Task<object[]> GetParametersAsync(IDynamicContext context, NodeModelBase nodeModel, MethodDetails md)
|
||||
public static async Task<object[]> GetParametersAsync(IDynamicContext context,
|
||||
NodeModelBase nodeModel,
|
||||
MethodDetails md)
|
||||
{
|
||||
await Task.Delay(0);
|
||||
// 用正确的大小初始化参数数组
|
||||
if (md.ParameterDetailss.Length == 0)
|
||||
{
|
||||
@@ -319,14 +324,34 @@ namespace Serein.Library
|
||||
}
|
||||
|
||||
object[] parameters = new object[md.ParameterDetailss.Length];
|
||||
|
||||
|
||||
//var previousFlowData = nodeModel.PreviousNode?.FlowData; // 当前传递的数据
|
||||
|
||||
|
||||
object[] paramsArgs = null; // 初始化可选参数
|
||||
int paramsArgIndex = 0; // 可选参数下标
|
||||
if (md.IsParamsArgIndex >= 0) // 是否存在入参参数
|
||||
{
|
||||
// 可选参数数组长度 = 方法参数个数 - ( 可选入参下标 + 1 )
|
||||
int paramsLength = md.ParameterDetailss.Length - md.IsParamsArgIndex;
|
||||
paramsArgs = new object[paramsLength]; // 重新实例化可选参数
|
||||
parameters[md.ParameterDetailss.Length-1] = paramsArgs; // 如果存在可选参数,入参参数最后一项则为可选参数
|
||||
}
|
||||
|
||||
bool hasParams = false;
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
var pd = md.ParameterDetailss[i]; // 方法入参描述
|
||||
|
||||
// 入参参数下标循环到可选参数时,开始写入到可选参数数组
|
||||
if(i >= md.IsParamsArgIndex)
|
||||
{
|
||||
// 控制参数赋值方向:
|
||||
// true => paramsArgs
|
||||
// false => parameters
|
||||
hasParams = true;
|
||||
}
|
||||
|
||||
#region 获取基础的上下文数据
|
||||
if (pd.DataType == typeof(IFlowEnvironment)) // 获取流程上下文
|
||||
{
|
||||
@@ -344,28 +369,27 @@ namespace Serein.Library
|
||||
object inputParameter; // 存放解析的临时参数
|
||||
if (pd.IsExplicitData) // 判断是否使用显示的输入参数
|
||||
{
|
||||
if (pd.DataValue.StartsWith("@get", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var previousNode = context.GetPreviousNode(nodeModel);
|
||||
var previousFlowData = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
|
||||
|
||||
// 执行表达式从上一节点获取对象
|
||||
inputParameter = SerinExpressionEvaluator.Evaluate(pd.DataValue, previousFlowData, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用输入的固定值
|
||||
inputParameter = pd.DataValue;
|
||||
}
|
||||
// 使用输入的固定值
|
||||
inputParameter = pd.DataValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
#region (默认的)从运行时上游节点获取其返回值
|
||||
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetPreviousNodeData)
|
||||
{
|
||||
var previousNode = context.GetPreviousNode(nodeModel);
|
||||
inputParameter = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
if (previousNode is null)
|
||||
{
|
||||
inputParameter = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputParameter = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 从指定节点获取其返回值
|
||||
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
|
||||
{
|
||||
// 获取指定节点的数据
|
||||
@@ -373,26 +397,47 @@ namespace Serein.Library
|
||||
// 如果执行过,会获取上一次执行结果作为预入参数据
|
||||
inputParameter = context.GetFlowData(pd.ArgDataSourceNodeGuid);
|
||||
}
|
||||
#endregion
|
||||
#region 立刻执行指定节点,然后获取返回值
|
||||
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
|
||||
{
|
||||
// 立刻调用对应节点获取数据。
|
||||
var result = await context.Env.InvokeNodeAsync(context, pd.ArgDataSourceNodeGuid);
|
||||
inputParameter = result;
|
||||
}
|
||||
#endregion
|
||||
#region 意料之外的参数
|
||||
else
|
||||
{
|
||||
throw new Exception("节点执行方法获取入参参数时,ConnectionArgSourceType枚举是意外的枚举值");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
if (inputParameter is null)
|
||||
|
||||
#region 对于非值类型的null检查
|
||||
if (!pd.DataType.IsValueType && inputParameter is null)
|
||||
{
|
||||
parameters[i] = null;
|
||||
throw new Exception($"[arg{pd.Index}][{pd.Name}][{pd.DataType}]参数不能为null");
|
||||
// continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 处理Get表达式
|
||||
if (pd.IsExplicitData // 输入了表达式
|
||||
&& pd.DataValue.StartsWith("@get", StringComparison.OrdinalIgnoreCase) // Get表达式
|
||||
)
|
||||
{
|
||||
//var previousNode = context.GetPreviousNode(nodeModel);
|
||||
//var previousFlowData = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
// 执行表达式从上一节点获取对象
|
||||
inputParameter = SerinExpressionEvaluator.Evaluate(pd.DataValue, inputParameter, out _);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region 入参存在取值转换器,调用对应的转换器获取入参数据
|
||||
// 入参存在取值转换器
|
||||
#region 入参存在取值转换器,调用对应的转换器获取入参数据,如果获取成功(不为null)会跳过循环
|
||||
if (pd.ExplicitType.IsEnum && !(pd.Convertor is null))
|
||||
{
|
||||
//var resultEnum = Enum.ToObject(ed.ExplicitType, ed.DataValue);
|
||||
@@ -405,13 +450,21 @@ namespace Serein.Library
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters[i] = value;
|
||||
if (hasParams)
|
||||
{
|
||||
// 处理可选参数
|
||||
paramsArgs[paramsArgIndex++] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters[i] = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 入参存在基于BinValue的类型转换器,获取枚举转换器中记录的类型
|
||||
#region 入参存在基于BinValue的类型转换器,获取枚举转换器中记录的类型,如果获取成功(不为null)会跳过循环
|
||||
// 入参存在基于BinValue的类型转换器,获取枚举转换器中记录的类型
|
||||
if (pd.ExplicitType.IsEnum && pd.DataType != pd.ExplicitType)
|
||||
{
|
||||
@@ -427,7 +480,15 @@ namespace Serein.Library
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters[i] = value;
|
||||
if (hasParams)
|
||||
{
|
||||
// 处理可选参数
|
||||
paramsArgs[paramsArgIndex++] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters[i] = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -436,16 +497,16 @@ namespace Serein.Library
|
||||
#endregion
|
||||
|
||||
#region 对入参数据尝试进行转换
|
||||
|
||||
object tmpVaue = null; // 临时存放数据,最后才判断是否放置可选参数数组
|
||||
if (inputParameter.GetType() == pd.DataType)
|
||||
{
|
||||
parameters[i] = inputParameter; // 类型一致无需转换,直接装入入参数组
|
||||
tmpVaue = inputParameter; // 类型一致无需转换,直接装入入参数组
|
||||
}
|
||||
else if (pd.DataType.IsValueType)
|
||||
{
|
||||
// 值类型
|
||||
var valueStr = inputParameter?.ToString();
|
||||
parameters[i] = valueStr.ToValueData(pd.DataType); // 类型不一致,尝试进行转换,如果转换失败返回类型对应的默认值
|
||||
tmpVaue = valueStr.ToValueData(pd.DataType); // 类型不一致,尝试进行转换,如果转换失败返回类型对应的默认值
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -453,56 +514,60 @@ namespace Serein.Library
|
||||
if (pd.DataType == typeof(string)) // 转为字符串
|
||||
{
|
||||
var valueStr = inputParameter?.ToString();
|
||||
parameters[i] = valueStr;
|
||||
tmpVaue = valueStr;
|
||||
}
|
||||
else if(pd.DataType.IsSubclassOf(inputParameter.GetType())) // 入参类型 是 预入参数据类型 的 子类/实现类
|
||||
{
|
||||
// 方法入参中,父类不能隐式转为子类,这里需要进行强制转换
|
||||
parameters[i] = ObjectConvertHelper.ConvertParentToChild(inputParameter, pd.DataType);
|
||||
tmpVaue = ObjectConvertHelper.ConvertParentToChild(inputParameter, pd.DataType);
|
||||
}
|
||||
else if(pd.DataType.IsAssignableFrom(inputParameter.GetType())) // 入参类型 是 预入参数据类型 的 父类/接口
|
||||
{
|
||||
parameters[i] = inputParameter;
|
||||
tmpVaue = inputParameter;
|
||||
}
|
||||
// 集合类型
|
||||
else if(inputParameter is IEnumerable collection)
|
||||
{
|
||||
var enumerableMethods = typeof(Enumerable).GetMethods(); // 获取所有的 Enumerable 扩展方法
|
||||
MethodInfo conversionMethod;
|
||||
if (pd.DataType.IsArray) // 转为数组
|
||||
{
|
||||
parameters[i] = inputParameter;
|
||||
conversionMethod = enumerableMethods.FirstOrDefault(m => m.Name == "ToArray" && m.IsGenericMethodDefinition);
|
||||
}
|
||||
else if (pd.DataType.GetGenericTypeDefinition() == typeof(List<>)) // 转为集合
|
||||
{
|
||||
conversionMethod = enumerableMethods.FirstOrDefault(m => m.Name == "ToList" && m.IsGenericMethodDefinition);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("输入对象不是集合或目标类型不支持(目前仅支持Array、List的自动转换)");
|
||||
}
|
||||
var genericMethod = conversionMethod.MakeGenericMethod(pd.DataType);
|
||||
var result = genericMethod.Invoke(null, new object[] { collection });
|
||||
parameters[i] = result;
|
||||
}
|
||||
//else if(inputParameter is IEnumerable collection)
|
||||
//{
|
||||
// var enumerableMethods = typeof(Enumerable).GetMethods(); // 获取所有的 Enumerable 扩展方法
|
||||
// MethodInfo conversionMethod;
|
||||
// if (pd.DataType.IsArray) // 转为数组
|
||||
// {
|
||||
// parameters[i] = inputParameter;
|
||||
// conversionMethod = enumerableMethods.FirstOrDefault(m => m.Name == "ToArray" && m.IsGenericMethodDefinition);
|
||||
// }
|
||||
// else if (pd.DataType.GetGenericTypeDefinition() == typeof(List<>)) // 转为集合
|
||||
// {
|
||||
// conversionMethod = enumerableMethods.FirstOrDefault(m => m.Name == "ToList" && m.IsGenericMethodDefinition);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new InvalidOperationException("输入对象不是集合或目标类型不支持(目前仅支持Array、List的自动转换)");
|
||||
// }
|
||||
// var genericMethod = conversionMethod.MakeGenericMethod(pd.DataType);
|
||||
// var result = genericMethod.Invoke(null, new object[] { collection });
|
||||
// parameters[i] = result;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//else if (ed.DataType == typeof(MethodDetails)) // 希望获取节点对应的方法描述,好像没啥用
|
||||
//{
|
||||
// parameters[i] = md;
|
||||
//}
|
||||
//else if (ed.DataType == typeof(NodeModelBase)) // 希望获取方法生成的节点,好像没啥用
|
||||
//{
|
||||
// parameters[i] = nodeModel;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hasParams)
|
||||
{
|
||||
// 处理可选参数
|
||||
paramsArgs[paramsArgIndex++] = tmpVaue;
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters[i] = tmpVaue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Serein.Library
|
||||
@@ -12,7 +13,7 @@ namespace Serein.Library
|
||||
[NodeProperty(ValuePath = NodeValuePath.Parameter)]
|
||||
public partial class ParameterDetails
|
||||
{
|
||||
private readonly IFlowEnvironment env;
|
||||
// private readonly IFlowEnvironment env;
|
||||
|
||||
/// <summary>
|
||||
/// 所在的节点
|
||||
@@ -48,9 +49,9 @@ namespace Serein.Library
|
||||
|
||||
/// <summary>
|
||||
/// 目前存在三种状态:Select/Bool/Value
|
||||
/// <para>Select : 枚举值</para>
|
||||
/// <para>Select : 枚举值/可选值</para>
|
||||
/// <para>Bool : 布尔类型</para>
|
||||
/// <para>Value : 除以上类型之外的任意参数</para>
|
||||
/// <para>Value :除以上类型之外的任意参数</para>
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private string _explicitTypeName ;
|
||||
@@ -91,6 +92,12 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private string[] _items ;
|
||||
|
||||
/// <summary>
|
||||
/// 指示该属性是可变参数的其中一员(可变参数为数组类型)
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private bool _isParams;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,14 +111,13 @@ namespace Serein.Library
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 为节点实例化新的入参描述
|
||||
/// </summary>
|
||||
public ParameterDetails(IFlowEnvironment env, NodeModelBase nodeModel)
|
||||
public ParameterDetails(NodeModelBase nodeModel)
|
||||
{
|
||||
this.env = env;
|
||||
this.NodeModel = nodeModel;
|
||||
}
|
||||
|
||||
@@ -147,14 +153,13 @@ namespace Serein.Library
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为某个节点拷贝方法描述的入参描述
|
||||
/// 为某个节点从元数据中拷贝方法描述的入参描述
|
||||
/// </summary>
|
||||
/// <param name="env">运行环境</param>
|
||||
/// <param name="nodeModel">对应的节点</param>
|
||||
/// <returns></returns>
|
||||
public ParameterDetails CloneOfClone(IFlowEnvironment env, NodeModelBase nodeModel)
|
||||
public ParameterDetails CloneOfModel(NodeModelBase nodeModel)
|
||||
{
|
||||
var pd = new ParameterDetails(env, nodeModel)
|
||||
var pd = new ParameterDetails(nodeModel)
|
||||
{
|
||||
Index = this.Index,
|
||||
IsExplicitData = this.IsExplicitData,
|
||||
|
||||
@@ -241,15 +241,15 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
public string SourceType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自定义入参
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表达式相关节点的表达式内容
|
||||
/// </summary>
|
||||
public string Expression { get; set; }
|
||||
// public string Expression { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
20
Library/Network/Mqtt/MqttServer.cs
Normal file
20
Library/Network/Mqtt/MqttServer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Network.Mqtt
|
||||
{
|
||||
internal interface IMqttServer
|
||||
{
|
||||
void Staer();
|
||||
|
||||
void Stop();
|
||||
|
||||
void HandleMsg(string msg);
|
||||
|
||||
void AddHandleConfig();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,6 @@ using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Network.WebSocketCommunication.Handle
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Network.WebSocketCommunication.Handle
|
||||
namespace Serein.Library.Network.WebSocketCommunication.Handle
|
||||
{
|
||||
/// <summary>
|
||||
/// 远程环境配置
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Network.WebSocketCommunication.Handle
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Newtonsoft.Json;
|
||||
using Serein.Library.Utils;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Linq.Expressions;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.Library.Network.WebSocketCommunication.Handle
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.0.18</Version>
|
||||
<Version>1.0.19</Version>
|
||||
<TargetFrameworks>net8.0;net462</TargetFrameworks>
|
||||
<!--<TargetFrameworks>net8.0</TargetFrameworks>-->
|
||||
<BaseOutputPath>D:\Project\C#\DynamicControl\SereinFlow\.Output</BaseOutputPath>
|
||||
@@ -32,11 +32,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="FlowNode\Attribute.cs" />
|
||||
<Compile Remove="Utils\NativeDllHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<ProjectReference Include="..\Serein.Library.MyGenerator\Serein.Library.NodeGenerator.csproj" OutputItemType="Analyzer" />
|
||||
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="System.Reactive" Version="6.0.1" />
|
||||
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
@@ -56,43 +57,37 @@ namespace Serein.Library.Utils
|
||||
/// <param name="methodInfo"></param>
|
||||
/// <param name="delegate"></param>
|
||||
/// <returns></returns>
|
||||
public static EmitMethodType CreateDynamicMethod( MethodInfo methodInfo,out Delegate @delegate)
|
||||
public static EmitMethodType CreateDynamicMethod(MethodInfo methodInfo,out Delegate @delegate)
|
||||
{
|
||||
bool IsTask = IsGenericTask(methodInfo.ReturnType, out var taskGenericsType);
|
||||
bool IsTaskGenerics = taskGenericsType != null;
|
||||
DynamicMethod dynamicMethod;
|
||||
if (IsTask)
|
||||
{
|
||||
if (IsTaskGenerics)
|
||||
{
|
||||
|
||||
dynamicMethod = new DynamicMethod(
|
||||
name: methodInfo.Name + "_DynamicMethod",
|
||||
returnType: typeof(Task<object>),
|
||||
parameterTypes: new[] { typeof(object), typeof(object[]) },
|
||||
restrictedSkipVisibility: true // 跳过私有方法访问限制
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamicMethod = new DynamicMethod(
|
||||
name: methodInfo.Name + "_DynamicMethod",
|
||||
returnType: typeof(Task),
|
||||
parameterTypes: new[] { typeof(object), typeof(object[]) },
|
||||
restrictedSkipVisibility: true // 跳过私有方法访问限制
|
||||
);
|
||||
}
|
||||
Type returnType;
|
||||
if (!IsTask)
|
||||
{
|
||||
// 普通方法
|
||||
returnType = typeof(object);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamicMethod = new DynamicMethod(
|
||||
name: methodInfo.Name + "_DynamicMethod",
|
||||
returnType: typeof(object),
|
||||
parameterTypes: new[] { typeof(object), typeof(object[]) },
|
||||
restrictedSkipVisibility: true // 跳过私有方法访问限制
|
||||
);
|
||||
// 异步方法
|
||||
if (IsTaskGenerics)
|
||||
{
|
||||
returnType = typeof(Task<object>);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnType = typeof(Task);
|
||||
}
|
||||
}
|
||||
|
||||
dynamicMethod = new DynamicMethod(
|
||||
name: methodInfo.Name + "_DynamicEmitMethod",
|
||||
returnType: returnType,
|
||||
parameterTypes: new[] { typeof(object), typeof(object[]) }, // 方法实例、方法入参
|
||||
restrictedSkipVisibility: true // 跳过私有方法访问限制
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
13
Library/Utils/NativeDllHelper.cs
Normal file
13
Library/Utils/NativeDllHelper.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
|
||||
}
|
||||
@@ -51,6 +51,10 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
public static object Evaluate(string expression, object targetObJ, out bool isChange)
|
||||
{
|
||||
if(expression is null || targetObJ is null)
|
||||
{
|
||||
throw new Exception("表达式条件expression is null、 targetObJ is null");
|
||||
}
|
||||
var parts = expression.Split(new[] { ' ' }, 2, StringSplitOptions.None);
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
@@ -60,6 +64,7 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
var operation = parts[0].ToLower();
|
||||
var operand = parts[1][0] == '.' ? parts[1].Substring(1) : parts[1];
|
||||
object result;
|
||||
isChange = false;
|
||||
if (operation == "@num")
|
||||
{
|
||||
result = ComputedNumber(targetObJ, operand);
|
||||
@@ -70,10 +75,12 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
}
|
||||
else if (operation == "@get")
|
||||
{
|
||||
isChange = true;
|
||||
result = GetMember(targetObJ, operand);
|
||||
}
|
||||
else if (operation == "@set")
|
||||
{
|
||||
isChange = true;
|
||||
result = SetMember(targetObJ, operand);
|
||||
}
|
||||
else
|
||||
@@ -81,14 +88,7 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
throw new NotSupportedException($"Operation {operation} is not supported.");
|
||||
}
|
||||
|
||||
if(operation == "@set")
|
||||
{
|
||||
isChange = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isChange = false;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user