mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-05 07:46:35 +08:00
重新优化了NodeModel类;从硬编码类型改为“注册/获取”的方式,为下一步解耦Workbench与节点UI做准备。
新增了“全局数据节点”;保存项目文件时,不同节点可以使用自定义数据保存自身独特的数据,不再借用“方法参数”。 重新设计了运行时的环境输出;增量式生成器现在可以选择在属性变更的前后时间点插入自定义代码;重写了加载项目、保存项目的方法。
This commit is contained in:
110
NodeFlow/NodeMVVMManagement.cs
Normal file
110
NodeFlow/NodeMVVMManagement.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点类型
|
||||
/// </summary>
|
||||
public class NodeMVVM
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点类型
|
||||
/// </summary>
|
||||
public required NodeControlType NodeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点Model类型
|
||||
/// </summary>
|
||||
public required Type ModelType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点视图控件类型
|
||||
/// </summary>
|
||||
public Type? ControlType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点视图VM类型
|
||||
/// </summary>
|
||||
public Type? ViewModelType { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"$[{NodeType}]类型信息 : ModelType->{ModelType};ControlType->{ControlType};ViewModelType->{ViewModelType}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 节点 数据、视图、VM 管理
|
||||
/// </summary>
|
||||
public static class NodeMVVMManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点对应的控件类型
|
||||
/// </summary>
|
||||
private static ConcurrentDictionary<NodeControlType, NodeMVVM> FlowNodeTypes { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 注册 Model 类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="modelType"></param>
|
||||
public static bool RegisterModel(NodeControlType type, Type modelType)
|
||||
{
|
||||
if(FlowNodeTypes.TryGetValue(type,out var nodeMVVM))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"无法为节点[{type}]注册Model类型[{modelType}],已经注册的类型为{nodeMVVM}。");
|
||||
return false;
|
||||
}
|
||||
nodeMVVM = new NodeMVVM
|
||||
{
|
||||
NodeType = type,
|
||||
ModelType = modelType
|
||||
};
|
||||
return FlowNodeTypes.TryAdd(type, nodeMVVM);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册 UI 类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="controlType"></param>
|
||||
/// <param name="viewModelType"></param>
|
||||
public static bool RegisterUI(NodeControlType type, Type controlType,Type viewModelType)
|
||||
{
|
||||
if (!FlowNodeTypes.TryGetValue(type, out var nodeMVVM))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"无法为节点[{type}]注册UI类型[{controlType}][{viewModelType}],当前类型尚未注册。");
|
||||
return false;
|
||||
}
|
||||
nodeMVVM.ControlType = controlType;
|
||||
nodeMVVM.ViewModelType = viewModelType;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取相应的类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="nodeMVVM"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGetType(NodeControlType type, out NodeMVVM nodeMVVM)
|
||||
{
|
||||
if( FlowNodeTypes.TryGetValue(type, out nodeMVVM))
|
||||
{
|
||||
return nodeMVVM != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user