using Serein.Library.Api; using Serein.Library.Entity; using Serein.Library.Enums; namespace Serein.NodeFlow.Base { /// /// 节点基类(数据):条件控件,动作控件,条件区域,动作区域 /// public abstract partial class NodeModelBase :IDynamicFlowNode { public NodeModelBase() { ConnectionType[] ct = [ConnectionType.IsSucceed, ConnectionType.IsFail, ConnectionType.IsError, ConnectionType.Upstream]; PreviousNodes = []; SuccessorNodes = []; foreach (ConnectionType ctType in ct) { PreviousNodes[ctType] = []; SuccessorNodes[ctType] = []; } DebugSetting = new NodeDebugSetting(); } /// /// 调试功能 /// public NodeDebugSetting DebugSetting { get; set; } /// /// 节点对应的控件类型 /// public NodeControlType ControlType { get; set; } /// /// 方法描述,对应DLL的方法 /// public MethodDetails MethodDetails { get; set; } /// /// 节点guid /// public string Guid { get; set; } /// /// 显示名称 /// public string DisplayName { get; set; } /// /// 是否为起点控件 /// public bool IsStart { get; set; } /// /// 运行时的上一节点 /// public NodeModelBase? PreviousNode { get; set; } /// /// 不同分支的父节点 /// public Dictionary> PreviousNodes { get; } /// /// 不同分支的子节点 /// public Dictionary> SuccessorNodes { get; } public ConnectionType NextOrientation { get; set; } = ConnectionType.None; /// /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值) /// public Exception RuningException { get; set; } = null; /// /// 控制FlowData在同一时间只会被同一个线程更改。 /// private readonly ReaderWriterLockSlim _flowDataLock = new ReaderWriterLockSlim(); private object? _flowData; /// /// 当前传递数据(执行了节点对应的方法,才会存在值)。 /// protected object? FlowData { get { _flowDataLock.EnterReadLock(); try { return _flowData; } finally { _flowDataLock.ExitReadLock(); } } set { _flowDataLock.EnterWriteLock(); try { _flowData = value; } finally { _flowDataLock.ExitWriteLock(); } } } } /// /// 节点基类(数据):条件控件,动作控件,条件区域,动作区域 /// //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; // } // /// // /// 节点对应的控件类型 // /// // public NodeControlType ControlType { get; } // /// // /// 方法描述,对应DLL的方法 // /// // public MethodDetails MethodDetails { get; } // /// // /// 节点guid // /// // public string Guid { get; } // /// // /// 显示名称 // /// // public string DisplayName { get;} // /// // /// 是否为起点控件 // /// // public bool IsStart { get; } // /// // /// 运行时的上一节点 // /// // public NodeModelBase? PreviousNode { get; } // /// // /// 上一节点集合 // /// // public List PreviousNodes { get; } = []; // /// // /// 下一节点集合(真分支) // /// // public List SucceedBranch { get; } = []; // /// // /// 下一节点集合(假分支) // /// // public List FailBranch { get; } = []; // /// // /// 异常分支 // /// // public List ErrorBranch { get; } = []; // /// // /// 上游分支 // /// // public List UpstreamBranch { get; } = []; // /// // /// 当前执行状态(进入真分支还是假分支,异常分支在异常中确定) // /// // public FlowStateType FlowState { get; set; } = FlowStateType.None; // /// // /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值) // /// // public Exception RuningException { get; set; } = null; // /// // /// 当前传递数据(执行了节点对应的方法,才会存在值) // /// // public object? FlowData { get; set; } = null; //} }