添加了节点树视图。

This commit is contained in:
fengjiayi
2024-09-26 21:00:17 +08:00
parent e81c527086
commit 42bf85b970
24 changed files with 877 additions and 357 deletions

View File

@@ -7,17 +7,14 @@ namespace Serein.NodeFlow.Base
/// <summary>
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
/// </summary>
public abstract partial class NodeModelBase :IDynamicFlowNode
public abstract partial class NodeModelBase : IDynamicFlowNode
{
private static readonly ConnectionType[] ct = [ConnectionType.IsSucceed,
ConnectionType.IsFail,
ConnectionType.IsError,
ConnectionType.Upstream];
public NodeModelBase()
{
PreviousNodes = [];
SuccessorNodes = [];
foreach (ConnectionType ctType in ct)
foreach (ConnectionType ctType in NodeStaticConfig.ConnectionTypes)
{
PreviousNodes[ctType] = [];
SuccessorNodes[ctType] = [];
@@ -71,6 +68,9 @@ namespace Serein.NodeFlow.Base
/// </summary>
public Dictionary<ConnectionType,List<NodeModelBase>> SuccessorNodes { get; }
/// <summary>
/// 当前节点执行完毕后需要执行的下一个分支的类别
/// </summary>
public ConnectionType NextOrientation { get; set; } = ConnectionType.None;
/// <summary>

View File

@@ -426,10 +426,10 @@ namespace Serein.NodeFlow.Base
private static async Task MonitorObjExpInterrupt(IDynamicContext context, NodeModelBase nodeModel, object data, int type)
{
MonitorObjectEventArgs.ObjSourceType sourceType;
object key;
string key;
if(type == 0)
{
key = data;
key = data.GetType().FullName;
sourceType = MonitorObjectEventArgs.ObjSourceType.IOCObj;
}
else
@@ -450,6 +450,7 @@ namespace Serein.NodeFlow.Base
for (int i = 0; i < exps.Count && !isExpInterrupt; i++)
{
exp = exps[i];
if (string.IsNullOrEmpty(exp)) continue;
isExpInterrupt = SereinConditionParser.To(data, exp);
}
@@ -458,7 +459,7 @@ namespace Serein.NodeFlow.Base
InterruptClass interruptClass = InterruptClass.Branch; // 分支中断
if (context.Env.SetNodeInterrupt(nodeModel.Guid, interruptClass))
{
context.Env.TriggerInterrupt(nodeModel.Guid, exp, InterruptTriggerEventArgs.InterruptTriggerType.Obj);
context.Env.TriggerInterrupt(nodeModel.Guid, exp, InterruptTriggerEventArgs.InterruptTriggerType.Exp);
var cancelType = await nodeModel.DebugSetting.GetInterruptTask();
await Console.Out.WriteLineAsync($"[{data}]中断已{cancelType},开始执行后继分支");
}

View File

@@ -55,8 +55,12 @@ namespace Serein.NodeFlow
FlipflopNodes = new List<SingleFlipflopNode>();
IsGlobalInterrupt = false;
flowStarter = null;
sereinIOC.OnIOCMembersChanged += e => this?.OnIOCMembersChanged?.Invoke(e) ; // 监听IOC容器的注册
}
/// <summary>
/// 节点的命名空间
/// </summary>
@@ -113,6 +117,11 @@ namespace Serein.NodeFlow
/// </summary>
public event ExpInterruptTriggerHandler OnInterruptTrigger;
/// <summary>
/// 容器改变
/// </summary>
public event IOCMembersChangedHandler OnIOCMembersChanged;
#endregion
#region
@@ -133,13 +142,14 @@ namespace Serein.NodeFlow
public ChannelFlowInterrupt ChannelFlowInterrupt { get; set; }
public ISereinIOC IOC { get => this; }
#endregion
#region
/// <summary>
/// 容器管理
/// </summary>
private SereinIOC sereinIOC;
private readonly SereinIOC sereinIOC;
/// <summary>
/// 存储加载的程序集路径
@@ -666,9 +676,9 @@ namespace Serein.NodeFlow
/// <param name="nodeGuid"></param>
/// <param name="expression"></param>
/// <returns></returns>
public bool AddInterruptExpression(object obj, string expression)
public bool AddInterruptExpression(string key, string expression)
{
if (dictMonitorObjExpInterrupt.TryGetValue(obj, out var condition))
if (dictMonitorObjExpInterrupt.TryGetValue(key, out var condition))
{
condition.Clear(); // 暂时
condition.Add(expression);// 暂时
@@ -678,7 +688,7 @@ namespace Serein.NodeFlow
{
var exps = new List<string>();
exps.Add(expression);
dictMonitorObjExpInterrupt.TryAdd(obj, exps);
dictMonitorObjExpInterrupt.TryAdd(key, exps);
return true;
}
}
@@ -735,7 +745,7 @@ namespace Serein.NodeFlow
/// <summary>
/// 要监视的对象,以及与其关联的表达式
/// </summary>
private ConcurrentDictionary<object, List<string>> dictMonitorObjExpInterrupt = [];
private ConcurrentDictionary<string, List<string>> dictMonitorObjExpInterrupt = [];
/// <summary>
/// 设置对象的监视状态
@@ -743,22 +753,22 @@ namespace Serein.NodeFlow
/// <param name="obj"></param>
/// <param name="isMonitor"></param>
/// <returns></returns>
public void SetMonitorObjState(object obj, bool isMonitor)
public void SetMonitorObjState(string key, bool isMonitor)
{
if (obj is null) { return; }
var isExist = dictMonitorObjExpInterrupt.ContainsKey(obj);
if (string.IsNullOrEmpty(key)) { return; }
var isExist = dictMonitorObjExpInterrupt.ContainsKey(key);
if (isExist)
{
if (!isMonitor) // 对象存在且需要不监视
{
dictMonitorObjExpInterrupt.Remove(obj, out _);
dictMonitorObjExpInterrupt.Remove(key, out _);
}
}
else
{
if (isMonitor) // 对象不存在且需要监视,添加在集合中。
{
dictMonitorObjExpInterrupt.TryAdd(obj, new List<string>()); ;
dictMonitorObjExpInterrupt.TryAdd(key, new List<string>()); ;
}
}
}
@@ -769,10 +779,10 @@ namespace Serein.NodeFlow
/// <param name="nodeGuid"></param>
/// <param name="obj"></param>
/// <returns></returns>
public bool CheckObjMonitorState(object obj, out List<string>? exps)
public bool CheckObjMonitorState(string key, out List<string>? exps)
{
if (obj is null) { exps = null; return false; }
return dictMonitorObjExpInterrupt.TryGetValue(obj, out exps);
if (string.IsNullOrEmpty(key)) { exps = null; return false; }
return dictMonitorObjExpInterrupt.TryGetValue(key, out exps);
}
/// <summary>

View File

@@ -1,4 +1,5 @@
using Serein.Library.Api;
using Serein.Library.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,6 +15,10 @@ namespace Serein.NodeFlow
/// </summary>
public const string NodeSpaceName = $"{nameof(Serein)}.{nameof(Serein.NodeFlow)}.{nameof(Serein.NodeFlow.Model)}";
public static readonly ConnectionType[] ConnectionTypes = [
ConnectionType.Upstream,
ConnectionType.IsSucceed,
ConnectionType.IsFail,
ConnectionType.IsError];
}
}