mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-04 07:16:35 +08:00
修改了流程运行中的bug
This commit is contained in:
@@ -21,10 +21,24 @@ namespace Serein.Library.Api
|
||||
RunState RunState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下一个要执行的节点
|
||||
/// 下一个要执行的节点类别
|
||||
/// </summary>
|
||||
ConnectionInvokeType NextOrientation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置节点的运行时上一节点,用以多线程中隔开不同流程的数据
|
||||
/// </summary>
|
||||
/// <param name="currentNodeModel">当前节点</param>
|
||||
/// <param name="PreviousNode">运行时上一节点</param>
|
||||
void SetPreviousNode(NodeModelBase currentNodeModel, NodeModelBase PreviousNode);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前节点的运行时上一节点,用以流程中获取数据
|
||||
/// </summary>
|
||||
/// <param name="currentNodeModel"></param>
|
||||
/// <returns></returns>
|
||||
NodeModelBase GetPreviousNode(NodeModelBase currentNodeModel);
|
||||
|
||||
/// <summary>
|
||||
/// 获取节点的数据(当前节点需要获取上一节点数据时,需要从 运行时上一节点 的Guid 通过这个方法进行获取
|
||||
/// </summary>
|
||||
@@ -32,6 +46,13 @@ namespace Serein.Library.Api
|
||||
/// <returns></returns>
|
||||
object GetFlowData(string nodeGuid);
|
||||
|
||||
/// <summary>
|
||||
/// 上一节点数据透传到下一节点
|
||||
/// </summary>
|
||||
/// <param name="nodeModel"></param>
|
||||
object TransmissionData(NodeModelBase nodeModel);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新当前节点的数据
|
||||
/// </summary>
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 取消触发器当前所在分支的继续执行
|
||||
/// </summary>
|
||||
Branch,
|
||||
CancelBranch,
|
||||
/// <summary>
|
||||
/// 取消整个触发器流程的再次执行(用于停止全局触发器)
|
||||
/// </summary>
|
||||
Flow,
|
||||
CancelFlow,
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否已取消
|
||||
@@ -27,7 +27,7 @@ namespace Serein.Library
|
||||
/// 取消类型
|
||||
/// </summary>
|
||||
public CancelClass Type { get; }
|
||||
public FlipflopException(string message, bool isCancel = true,CancelClass clsss = CancelClass.Branch) :base(message)
|
||||
public FlipflopException(string message, bool isCancel = true,CancelClass clsss = CancelClass.CancelBranch) :base(message)
|
||||
{
|
||||
IsCancel = isCancel;
|
||||
Type = clsss;
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Serein.Library
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"方法别名:{this.MethodAnotherName}");
|
||||
sb.AppendLine($"方法名称:{this.MethodName}");
|
||||
sb.AppendLine($"需要实例:{this.ActingInstanceType.FullName}");
|
||||
sb.AppendLine($"需要实例:{this.ActingInstanceType?.FullName}");
|
||||
sb.AppendLine($"");
|
||||
sb.AppendLine($"入参参数信息:");
|
||||
foreach (var arg in this.ParameterDetailss)
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 中断级别,暂时停止继续执行后继分支。
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)] // CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);"
|
||||
[PropertyInfo(IsNotification = true, CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);")] // CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);"
|
||||
private bool _isInterrupt = false;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -66,8 +66,8 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 运行时的上一节点
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private NodeModelBase _previousNode ;
|
||||
//[PropertyInfo]
|
||||
//private NodeModelBase _previousNode ;
|
||||
|
||||
/// <summary>
|
||||
/// 当前节点执行完毕后需要执行的下一个分支的类别
|
||||
@@ -86,6 +86,11 @@ namespace Serein.Library
|
||||
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载完成后调用的方法
|
||||
/// </summary>
|
||||
public abstract void OnLoading();
|
||||
|
||||
public NodeModelBase(IFlowEnvironment environment)
|
||||
{
|
||||
PreviousNodes = new Dictionary<ConnectionInvokeType, List<NodeModelBase>>();
|
||||
@@ -100,7 +105,6 @@ namespace Serein.Library
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 不同分支的父节点
|
||||
/// </summary>
|
||||
@@ -111,210 +115,7 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionInvokeType, List<NodeModelBase>> SuccessorNodes { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 控制FlowData在同一时间只会被同一个线程更改。
|
||||
/// </summary>
|
||||
//private readonly ReaderWriterLockSlim _flowDataLock = new ReaderWriterLockSlim();
|
||||
//private object _flowData;
|
||||
///// <summary>
|
||||
///// 当前传递数据(执行了节点对应的方法,才会存在值)。
|
||||
///// </summary>
|
||||
//protected object FlowData
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// _flowDataLock.EnterReadLock();
|
||||
// try
|
||||
// {
|
||||
// return _flowData;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// _flowDataLock.ExitReadLock();
|
||||
// }
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// _flowDataLock.EnterWriteLock();
|
||||
// try
|
||||
// {
|
||||
// _flowData = value;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// _flowDataLock.ExitWriteLock();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
||||
/// </summary>
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 节点保留对环境的引用,因为需要在属性更改时通知
|
||||
/// </summary>
|
||||
public IFlowEnvironment Env { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 在画布中的位置
|
||||
/// </summary>
|
||||
public PositionOfUI Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 附加的调试功能
|
||||
/// </summary>
|
||||
public NodeDebugSetting DebugSetting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述节点对应的控件类型
|
||||
/// </summary>
|
||||
public NodeControlType ControlType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 方法描述。不包含Method与委托,需要通过MethodName从环境中获取委托进行调用。
|
||||
/// </summary>
|
||||
public MethodDetails MethodDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标识节点对象全局唯一
|
||||
/// </summary>
|
||||
public string Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为起点控件
|
||||
/// </summary>
|
||||
public bool IsStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的上一节点
|
||||
/// </summary>
|
||||
public NodeModelBase PreviousNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前节点执行完毕后需要执行的下一个分支的类别
|
||||
/// </summary>
|
||||
public ConnectionType NextOrientation { get; set; } = ConnectionType.None;
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
|
||||
/// </summary>
|
||||
public Exception RuningException { get; set; } = null;
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
||||
/// </summary>
|
||||
//public class NodeModelBaseBuilder
|
||||
//{
|
||||
// public NodeModelBaseBuilder(NodeModelBase builder)
|
||||
// {
|
||||
// this.ControlType = builder.ControlType;
|
||||
// this.MethodDetails = builder.MethodDetails;
|
||||
// this.Guid = builder.Guid;
|
||||
// this.DisplayName = builder.DisplayName;
|
||||
// this.IsStart = builder.IsStart;
|
||||
// this.PreviousNode = builder.PreviousNode;
|
||||
// this.PreviousNodes = builder.PreviousNodes;
|
||||
// this.SucceedBranch = builder.SucceedBranch;
|
||||
// this.FailBranch = builder.FailBranch;
|
||||
// this.ErrorBranch = builder.ErrorBranch;
|
||||
// this.UpstreamBranch = builder.UpstreamBranch;
|
||||
// this.FlowState = builder.FlowState;
|
||||
// this.RuningException = builder.RuningException;
|
||||
// this.FlowData = builder.FlowData;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 节点对应的控件类型
|
||||
// /// </summary>
|
||||
// public NodeControlType ControlType { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 方法描述,对应DLL的方法
|
||||
// /// </summary>
|
||||
// public MethodDetails MethodDetails { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 节点guid
|
||||
// /// </summary>
|
||||
// public string Guid { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 显示名称
|
||||
// /// </summary>
|
||||
// public string DisplayName { get;}
|
||||
|
||||
// /// <summary>
|
||||
// /// 是否为起点控件
|
||||
// /// </summary>
|
||||
// public bool IsStart { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 运行时的上一节点
|
||||
// /// </summary>
|
||||
// public NodeModelBase? PreviousNode { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 上一节点集合
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> PreviousNodes { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 下一节点集合(真分支)
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> SucceedBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 下一节点集合(假分支)
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> FailBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 异常分支
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> ErrorBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 上游分支
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> UpstreamBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 当前执行状态(进入真分支还是假分支,异常分支在异常中确定)
|
||||
// /// </summary>
|
||||
// public FlowStateType FlowState { get; set; } = FlowStateType.None;
|
||||
|
||||
// /// <summary>
|
||||
// /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
|
||||
// /// </summary>
|
||||
// public Exception RuningException { get; set; } = null;
|
||||
|
||||
// /// <summary>
|
||||
// /// 当前传递数据(执行了节点对应的方法,才会存在值)
|
||||
// /// </summary>
|
||||
// public object? FlowData { get; set; } = null;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Serein.Library
|
||||
var cancelType = await upstreamNode.DebugSetting.GetInterruptTask();
|
||||
await Console.Out.WriteLineAsync($"[{upstreamNode.MethodDetails?.MethodName}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
upstreamNode.PreviousNode = currentNode;
|
||||
context.SetPreviousNode(upstreamNode, currentNode);
|
||||
await upstreamNode.StartFlowAsync(context); // 执行流程节点的上游分支
|
||||
if (context.NextOrientation == ConnectionInvokeType.IsError)
|
||||
{
|
||||
@@ -186,6 +186,7 @@ namespace Serein.Library
|
||||
}
|
||||
// 上游分支执行完成,才执行当前节点
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
context.NextOrientation = ConnectionInvokeType.None; // 重置上下文状态
|
||||
object newFlowData = await currentNode.ExecutingAsync(context);
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
|
||||
@@ -204,7 +205,7 @@ namespace Serein.Library
|
||||
// 筛选出启用的节点的节点
|
||||
if (nextNodes[i].DebugSetting.IsEnable)
|
||||
{
|
||||
nextNodes[i].PreviousNode = currentNode;
|
||||
context.SetPreviousNode(nextNodes[i], currentNode);
|
||||
stack.Push(nextNodes[i]);
|
||||
}
|
||||
}
|
||||
@@ -248,7 +249,10 @@ namespace Serein.Library
|
||||
{
|
||||
object[] args = await GetParametersAsync(context, this, md);
|
||||
var result = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
if(context.NextOrientation == ConnectionInvokeType.None) // 没有手动设置时,进行自动设置
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -342,7 +346,10 @@ namespace Serein.Library
|
||||
{
|
||||
if (ed.DataValue.StartsWith("@get", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var previousFlowData = context.GetFlowData(nodeModel?.PreviousNode?.Guid); // 当前传递的数据
|
||||
var previousNode = context.GetPreviousNode(nodeModel);
|
||||
var previousFlowData = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
|
||||
|
||||
// 执行表达式从上一节点获取对象
|
||||
inputParameter = SerinExpressionEvaluator.Evaluate(ed.DataValue, previousFlowData, out _);
|
||||
}
|
||||
@@ -356,7 +363,8 @@ namespace Serein.Library
|
||||
{
|
||||
if (ed.ArgDataSourceType == ConnectionArgSourceType.GetPreviousNodeData)
|
||||
{
|
||||
inputParameter = context.GetFlowData(nodeModel?.PreviousNode?.Guid); // 当前传递的数据
|
||||
var previousNode = context.GetPreviousNode(nodeModel);
|
||||
inputParameter = context.GetFlowData(previousNode.Guid); // 当前传递的数据
|
||||
}
|
||||
else if (ed.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
|
||||
{
|
||||
@@ -509,6 +517,7 @@ namespace Serein.Library
|
||||
public static async Task RefreshFlowDataAndExpInterrupt(IDynamicContext context, NodeModelBase nodeModel, object newData = null)
|
||||
{
|
||||
string guid = nodeModel.Guid;
|
||||
context.AddOrUpdate(guid, newData); // 上下文中更新数据
|
||||
if (newData is null)
|
||||
{
|
||||
}
|
||||
@@ -517,7 +526,6 @@ namespace Serein.Library
|
||||
await MonitorObjExpInterrupt(context, nodeModel, newData, 0); // 首先监视对象
|
||||
await MonitorObjExpInterrupt(context, nodeModel, newData, 1); // 然后监视节点
|
||||
//nodeModel.FlowData = newData; // 替换数据
|
||||
context.AddOrUpdate(guid, newData); // 上下文中更新数据
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Serein.Library
|
||||
{
|
||||
if(_convertor is null)
|
||||
{
|
||||
return $"[{this.Index}] {this.Name} : {this.DataType.FullName}";
|
||||
return $"[{this.Index}] {this.Name} : {this.DataType?.FullName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Utils.SereinExpression
|
||||
{
|
||||
@@ -152,53 +155,88 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
throw new ArgumentException($"Invalid array syntax for member {member}");
|
||||
}
|
||||
|
||||
// 提取数组索引
|
||||
var indexStr = member.Substring(arrayIndexStart + 1, arrayIndexEnd - arrayIndexStart - 1);
|
||||
if (!int.TryParse(indexStr, out int index))
|
||||
var targetType = target?.GetType(); // 目标对象的类型
|
||||
if(targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
||||
{
|
||||
throw new ArgumentException($"Invalid array index '{indexStr}' for member {member}");
|
||||
}
|
||||
|
||||
// 获取数组或集合对象
|
||||
var arrayProperty = target?.GetType().GetProperty(arrayName);
|
||||
if (arrayProperty is null)
|
||||
{
|
||||
var arrayField = target?.GetType().GetField(arrayName);
|
||||
if (arrayField is null)
|
||||
var typetmp = target.GetType().FullName;
|
||||
// 目标是键值对
|
||||
var indexStr = member.Substring(arrayIndexStart + 1, arrayIndexEnd - arrayIndexStart - 1);
|
||||
var method = targetType.GetMethod("get_Item", BindingFlags.Public | BindingFlags.Instance);
|
||||
if(method != null)
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} not found on target.");
|
||||
var result = method.Invoke(target, new object[] { indexStr });
|
||||
if(result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//var dict = target as Dictionary<string, string>;
|
||||
////var dict = (Dictionary<dynamic, dynamic>)target;
|
||||
//var temp = dict[indexStr];
|
||||
////if (target is Dictionary<object, object> dict)
|
||||
////{
|
||||
//// var temp = dict[indexStr];
|
||||
////}
|
||||
//var TMP2= target.GetType().GetEnumValues();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
#region 表达式处理集合对象
|
||||
// 获取数组或集合对象
|
||||
var arrayProperty = target?.GetType().GetProperty(arrayName);
|
||||
if (arrayProperty is null)
|
||||
{
|
||||
var arrayField = target?.GetType().GetField(arrayName);
|
||||
if (arrayField is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayField.GetValue(target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayField.GetValue(target);
|
||||
target = arrayProperty.GetValue(target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayProperty.GetValue(target);
|
||||
|
||||
|
||||
// 提取数组索引
|
||||
var indexStr = member.Substring(arrayIndexStart + 1, arrayIndexEnd - arrayIndexStart - 1);
|
||||
if (!int.TryParse(indexStr, out int index))
|
||||
{
|
||||
throw new ArgumentException($"Invalid array index '{indexStr}' for member {member}");
|
||||
}
|
||||
// 访问数组或集合中的指定索引
|
||||
if (target is Array array)
|
||||
{
|
||||
if (index < 0 || index >= array.Length)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for array {arrayName}");
|
||||
}
|
||||
target = array.GetValue(index);
|
||||
}
|
||||
else if (target is IList<object> list)
|
||||
{
|
||||
if (index < 0 || index >= list.Count)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for list {arrayName}");
|
||||
}
|
||||
target = list[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} is not an array or list.");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
// 访问数组或集合中的指定索引
|
||||
if (target is Array array)
|
||||
{
|
||||
if (index < 0 || index >= array.Length)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for array {arrayName}");
|
||||
}
|
||||
target = array.GetValue(index);
|
||||
}
|
||||
else if (target is IList<object> list)
|
||||
{
|
||||
if (index < 0 || index >= list.Count)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for list {arrayName}");
|
||||
}
|
||||
target = list[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} is not an array or list.");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user