using Serein.Library.Api; using System; using System.Collections.Generic; using System.ComponentModel; using System.Threading; namespace Serein.Library { /// /// 节点基类(数据):条件控件,动作控件,条件区域,动作区域 /// [AutoProperty(ValuePath = nameof(NodeModelBase))] // 是否更名为 NodeProperty? public abstract partial class NodeModelBase : IDynamicFlowNode { [PropertyInfo(IsProtection = true)] private IFlowEnvironment _env; /// /// 在画布中的位置 /// [PropertyInfo(IsProtection = true)] private PositionOfUI _position ; /// /// 附加的调试功能 /// [PropertyInfo(IsProtection = true)] private NodeDebugSetting _debugSetting ; /// /// 描述节点对应的控件类型 /// [PropertyInfo(IsProtection = true)] private NodeControlType _controlType ; /// /// 方法描述。不包含Method与委托,需要通过MethodName从环境中获取委托进行调用。 /// [PropertyInfo(IsProtection = true)] private MethodDetails _methodDetails ; /// /// 标识节点对象全局唯一 /// [PropertyInfo(IsProtection = true)] private string _guid ; /// /// 显示名称 /// [PropertyInfo] private string _displayName ; /// /// 是否为起点控件 /// [PropertyInfo] private bool _isStart ; /// /// 运行时的上一节点 /// [PropertyInfo] private NodeModelBase _previousNode ; /// /// 当前节点执行完毕后需要执行的下一个分支的类别 /// [PropertyInfo] private ConnectionType _nextOrientation = ConnectionType.None; /// /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值) /// [PropertyInfo] private Exception _runingException ; } public abstract partial class NodeModelBase : IDynamicFlowNode { public NodeModelBase(IFlowEnvironment environment) { PreviousNodes = new Dictionary>(); SuccessorNodes = new Dictionary>(); foreach (ConnectionType ctType in NodeStaticConfig.ConnectionTypes) { PreviousNodes[ctType] = new List(); SuccessorNodes[ctType] = new List(); } DebugSetting = new NodeDebugSetting(this); this.Env = environment; } /// /// 不同分支的父节点 /// public Dictionary> PreviousNodes { get; } /// /// 不同分支的子节点 /// public Dictionary> SuccessorNodes { get; } /// /// 控制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 abstract partial class NodeModelBase : IDynamicFlowNode { /// /// 节点保留对环境的引用,因为需要在属性更改时通知 /// public IFlowEnvironment Env { get; } /// /// 在画布中的位置 /// public PositionOfUI Position { get; set; } /// /// 附加的调试功能 /// public NodeDebugSetting DebugSetting { get; set; } /// /// 描述节点对应的控件类型 /// public NodeControlType ControlType { get; set; } /// /// 方法描述。不包含Method与委托,需要通过MethodName从环境中获取委托进行调用。 /// public MethodDetails MethodDetails { get; set; } /// /// 标识节点对象全局唯一 /// public string Guid { get; set; } /// /// 显示名称 /// public string DisplayName { get; set; } = string.Empty; /// /// 是否为起点控件 /// public bool IsStart { get; set; } /// /// 运行时的上一节点 /// public NodeModelBase PreviousNode { get; set; } /// /// 当前节点执行完毕后需要执行的下一个分支的类别 /// public ConnectionType NextOrientation { get; set; } = ConnectionType.None; /// /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值) /// public Exception RuningException { get; set; } = null; }*/ /// /// 节点基类(数据):条件控件,动作控件,条件区域,动作区域 /// //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; //} }