using Serein.Library;
using Serein.Library.Api;
using Serein.Library.NodeGenerator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Mime;
using System.Threading;
namespace Serein.NodeFlow.Model
{
///
/// 节点基类(数据)
///
[NodeProperty(ValuePath = NodeValuePath.Node)]
public abstract partial class NodeModelBase : IFlowNode
{
///
/// 节点运行环境
///
[PropertyInfo(IsProtection = true)]
private IFlowEnvironment _env;
///
/// 标识节点对象全局唯一
///
[PropertyInfo(IsProtection = true)]
private string _guid;
///
/// 描述节点对应的控件类型
///
[PropertyInfo(IsProtection = true)]
private NodeControlType _controlType;
///
/// 所属画布
///
[PropertyInfo(IsProtection = true)]
private FlowCanvasDetails _canvasDetails ;
///
/// 在画布中的位置
///
[PropertyInfo(IsProtection = true)]
private PositionOfUI _position ;
///
/// 显示名称
///
[PropertyInfo]
private string _displayName;
///
/// 是否公开
///
[PropertyInfo(IsNotification = true)]
private bool _isPublic;
/* ///
/// 是否保护参数
///
[PropertyInfo(IsNotification = true)]
private bool _isProtectionParameter;*/
///
/// 附加的调试功能
///
[PropertyInfo(IsProtection = true)]
private NodeDebugSetting _debugSetting ;
///
/// 方法描述。包含参数信息。不包含Method与委托,如若需要调用对应的方法,需要通过MethodName从环境中获取委托进行调用。
///
[PropertyInfo]
private MethodDetails _methodDetails ;
}
public abstract partial class NodeModelBase : IDynamicFlowNode
{
///
/// 是否为基础节点
///
public virtual bool IsBase { get; } = false;
///
/// 可以放置多少个节点
///
public virtual int MaxChildrenCount { get; } = 0;
public NodeModelBase(IFlowEnvironment environment)
{
PreviousNodes = new Dictionary>();
SuccessorNodes = new Dictionary>();
NeedResultNodes = new Dictionary>();
foreach (ConnectionInvokeType ctType in NodeStaticConfig.ConnectionTypes)
{
PreviousNodes[ctType] = new List();
SuccessorNodes[ctType] = new List();
}
foreach (ConnectionArgSourceType ctType in NodeStaticConfig.ConnectionArgSourceTypes)
{
NeedResultNodes[ctType] = new List();
}
ChildrenNode = new List();
DebugSetting = new NodeDebugSetting(this);
this.Env = environment;
}
///
/// 不同分支的父节点(流程调用)
///
public Dictionary> PreviousNodes { get; }
///
/// 不同分支的子节点(流程调用)
///
public Dictionary> SuccessorNodes { get; set; }
///
/// 需要该节点返回值作为入参参数的节点集合
///
public Dictionary> NeedResultNodes { get;}
///
/// 该节点的容器节点
///
public IFlowNode ContainerNode { get; set; } = null;
///
/// 该节点的子项节点(如果该节点是容器节点,那就会有这个参数)
///
public List ChildrenNode { get; }
///
/// 节点公开状态发生改变
///
partial void OnIsPublicChanged(bool oldValue, bool newValue)
{
var list = CanvasDetails.PublicNodes.ToList();
_ = SereinEnv.TriggerEvent(() =>
{
if (newValue)
{
// 公开节点
if (!CanvasDetails.PublicNodes.Contains(this))
{
list.Add(this);
CanvasDetails.PublicNodes = list;
}
}
else
{
// 取消公开
if (CanvasDetails.PublicNodes.Contains(this))
{
list.Remove(this);
CanvasDetails.PublicNodes = list;
}
}
});
}
}
}