mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-18 05:46:35 +08:00
重新优化了NodeModel类;从硬编码类型改为“注册/获取”的方式,为下一步解耦Workbench与节点UI做准备。
新增了“全局数据节点”;保存项目文件时,不同节点可以使用自定义数据保存自身独特的数据,不再借用“方法参数”。 重新设计了运行时的环境输出;增量式生成器现在可以选择在属性变更的前后时间点插入自定义代码;重写了加载项目、保存项目的方法。
This commit is contained in:
@@ -58,6 +58,15 @@ namespace Serein.NodeFlow.Env
|
||||
};
|
||||
this.UIContextOperation = uiContextOperation; // 为加载的类库提供在UI线程上执行某些操作的封装工具类
|
||||
this.FlowLibraryManagement = new FlowLibraryManagement(this); // 实例化类库管理
|
||||
|
||||
#region 注册基本节点类型
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.Action, typeof(SingleActionNode)); // 动作节点
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.Flipflop, typeof(SingleFlipflopNode)); // 触发器节点
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.ExpOp, typeof(SingleExpOpNode)); // 表达式节点
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.ExpCondition, typeof(SingleConditionNode)); // 条件表达式节点
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.ConditionRegion, typeof(CompositeConditionNode)); // 条件区域
|
||||
NodeMVVMManagement.RegisterModel(NodeControlType.GlobalData, typeof(SingleGlobalDataNode)); // 全局数据节点
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region 远程管理
|
||||
@@ -119,6 +128,11 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
public event ProjectLoadedHandler? OnProjectLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// 项目准备保存
|
||||
/// </summary>
|
||||
public event ProjectSavingHandler? OnProjectSaving;
|
||||
|
||||
/// <summary>
|
||||
/// 节点连接属性改变事件
|
||||
/// </summary>
|
||||
@@ -347,10 +361,10 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
if (@class >= this.InfoClass)
|
||||
{
|
||||
|
||||
OnEnvOut?.Invoke(type, message);
|
||||
}
|
||||
Console.WriteLine($"{DateTime.UtcNow} [{type}] : {message}{Environment.NewLine}");
|
||||
OnEnvOut?.Invoke(type, message);
|
||||
//Console.WriteLine($"{DateTime.UtcNow} [{type}] : {message}{Environment.NewLine}");
|
||||
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
@@ -506,7 +520,7 @@ namespace Serein.NodeFlow.Env
|
||||
// 获取所有的程序集对应的方法信息(程序集相关的数据)
|
||||
var libraryMdss = this.FlowLibraryManagement.GetAllLibraryMds().ToArray();
|
||||
// 获取当前项目的信息(节点相关的数据)
|
||||
var project = await GetProjectInfoAsync();
|
||||
var project = await GetProjectInfoAsync(); // 远程连接获取远程环境项目信息
|
||||
SereinEnv.WriteLine(InfoType.INFO, "已将当前环境信息发送到远程客户端");
|
||||
return new FlowEnvInfo
|
||||
{
|
||||
@@ -526,7 +540,13 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存项目
|
||||
/// </summary>
|
||||
public void SaveProject()
|
||||
{
|
||||
OnProjectSaving?.Invoke(new ProjectSavingEventArgs());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载项目文件
|
||||
@@ -746,6 +766,7 @@ namespace Serein.NodeFlow.Env
|
||||
Nodes = NodeModels.Values.Select(node => node.ToInfo()).Where(info => info is not null).ToArray(),
|
||||
StartNode = NodeModels.Values.FirstOrDefault(it => it.IsStart)?.Guid,
|
||||
};
|
||||
|
||||
return Task.FromResult(projectData);
|
||||
}
|
||||
|
||||
@@ -926,17 +947,14 @@ namespace Serein.NodeFlow.Env
|
||||
if (remoteNode is null)
|
||||
return false;
|
||||
|
||||
//if (remoteNode.IsStart)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
if (remoteNode is SingleFlipflopNode flipflopNode)
|
||||
{
|
||||
flowStarter?.TerminateGlobalFlipflopRuning(flipflopNode); // 假设被移除的是全局触发器,尝试从启动器移除
|
||||
}
|
||||
|
||||
remoteNode.Remove(); // 调用节点的移除方法
|
||||
|
||||
// 遍历所有父节点,从那些父节点中的子节点集合移除该节点
|
||||
// 遍历所有前置节点,从那些前置节点中的后继节点集合移除该节点
|
||||
foreach (var pnc in remoteNode.PreviousNodes)
|
||||
{
|
||||
var pCType = pnc.Key; // 连接类型
|
||||
@@ -955,7 +973,7 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历所有子节点,从那些子节点中的父节点集合移除该节点
|
||||
// 遍历所有后继节点,从那些后继节点中的前置节点集合移除该节点
|
||||
foreach (var snc in remoteNode.SuccessorNodes)
|
||||
{
|
||||
var connectionType = snc.Key; // 连接类型
|
||||
@@ -968,6 +986,8 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 从集合中移除节点
|
||||
NodeModels.Remove(nodeGuid);
|
||||
UIContextOperation?.Invoke(() => OnNodeRemove?.Invoke(new NodeRemoveEventArgs(nodeGuid)));
|
||||
@@ -1434,7 +1454,7 @@ namespace Serein.NodeFlow.Env
|
||||
isPass = nodeModel.MethodDetails.RemoveParamsArg(paramIndex);
|
||||
}
|
||||
|
||||
await Task.Delay(50);
|
||||
await Task.Delay(200);
|
||||
foreach ((var fromGuid, var type, var index) in argInfo)
|
||||
{
|
||||
await UIContextOperation.InvokeAsync(() =>
|
||||
@@ -1487,7 +1507,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <returns></returns>
|
||||
public object AddOrUpdateGlobalData(string keyName, object data)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.AddOrUpdate(keyName, data, (k, o) => data);
|
||||
SereinEnv.AddOrUpdateFlowGlobalData(keyName, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1498,8 +1518,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <returns></returns>
|
||||
public object? GetGlobalData(string keyName)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.TryGetValue(keyName, out var data);
|
||||
return data;
|
||||
return SereinEnv.GetFlowGlobalData(keyName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -86,12 +86,23 @@ namespace Serein.NodeFlow.Env
|
||||
add { currentFlowEnvironment.OnDllLoad += value; }
|
||||
remove { currentFlowEnvironment.OnDllLoad -= value; }
|
||||
}
|
||||
|
||||
public event ProjectLoadedHandler OnProjectLoaded
|
||||
{
|
||||
add { currentFlowEnvironment.OnProjectLoaded += value; }
|
||||
remove { currentFlowEnvironment.OnProjectLoaded -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 项目准备保存
|
||||
/// </summary>
|
||||
public event ProjectSavingHandler? OnProjectSaving
|
||||
{
|
||||
add { currentFlowEnvironment.OnProjectSaving += value; }
|
||||
remove { currentFlowEnvironment.OnProjectSaving -= value; }
|
||||
}
|
||||
|
||||
|
||||
public event NodeConnectChangeHandler OnNodeConnectChange
|
||||
{
|
||||
add { currentFlowEnvironment.OnNodeConnectChange += value; }
|
||||
@@ -289,6 +300,14 @@ namespace Serein.NodeFlow.Env
|
||||
currentFlowEnvironment.LoadLibrary(dllPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存项目
|
||||
/// </summary>
|
||||
public void SaveProject()
|
||||
{
|
||||
currentFlowEnvironment.SaveProject();
|
||||
}
|
||||
|
||||
public void LoadProject(FlowEnvInfo flowEnvInfo, string filePath)
|
||||
{
|
||||
if (flowEnvInfo is null) return;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Model;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
@@ -10,6 +12,8 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
public static class FlowFunc
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否为基础节点
|
||||
/// </summary>
|
||||
@@ -17,13 +21,15 @@ namespace Serein.NodeFlow.Env
|
||||
public static bool IsBaseNode(this NodeControlType nodeControlType)
|
||||
{
|
||||
if(nodeControlType == NodeControlType.ExpCondition
|
||||
|| nodeControlType == NodeControlType.ExpOp)
|
||||
|| nodeControlType == NodeControlType.ExpOp
|
||||
|| nodeControlType == NodeControlType.GlobalData)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点
|
||||
/// </summary>
|
||||
@@ -35,24 +41,16 @@ namespace Serein.NodeFlow.Env
|
||||
public static NodeModelBase CreateNode(IFlowEnvironment env, NodeControlType nodeControlType,
|
||||
MethodDetails? methodDetails = null)
|
||||
{
|
||||
// 确定创建的节点类型
|
||||
Type? nodeType = nodeControlType switch
|
||||
{
|
||||
NodeControlType.Action => typeof(SingleActionNode),
|
||||
NodeControlType.Flipflop => typeof(SingleFlipflopNode),
|
||||
|
||||
NodeControlType.ExpOp => typeof(SingleExpOpNode),
|
||||
NodeControlType.ExpCondition => typeof(SingleConditionNode),
|
||||
NodeControlType.ConditionRegion => typeof(CompositeConditionNode),
|
||||
_ => null
|
||||
};
|
||||
// 尝试获取需要创建的节点类型
|
||||
|
||||
if (nodeType is null)
|
||||
if (!NodeMVVMManagement.TryGetType(nodeControlType, out var nodeMVVM) || nodeMVVM.ModelType == null)
|
||||
{
|
||||
throw new Exception($"节点类型错误[{nodeControlType}]");
|
||||
throw new Exception($"无法创建{nodeControlType}节点,节点类型尚未注册。");
|
||||
}
|
||||
|
||||
// 生成实例
|
||||
var nodeObj = Activator.CreateInstance(nodeType, env);
|
||||
var nodeObj = Activator.CreateInstance(nodeMVVM.ModelType, env);
|
||||
if (nodeObj is not NodeModelBase nodeModel)
|
||||
{
|
||||
throw new Exception($"无法创建目标节点类型的实例[{nodeControlType}]");
|
||||
@@ -90,6 +88,8 @@ namespace Serein.NodeFlow.Env
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleExpOpNode)}" => NodeControlType.ExpOp, // 操作表达式控件
|
||||
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(CompositeConditionNode)}" => NodeControlType.ConditionRegion, // 条件区域控件
|
||||
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleGlobalDataNode)}" => NodeControlType.GlobalData, // 数据节点
|
||||
_ => NodeControlType.None,
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public event LoadDllHandler OnDllLoad;
|
||||
public event ProjectLoadedHandler OnProjectLoaded;
|
||||
/// <summary>
|
||||
/// 项目准备保存
|
||||
/// </summary>
|
||||
public event ProjectSavingHandler? OnProjectSaving;
|
||||
public event NodeConnectChangeHandler OnNodeConnectChange;
|
||||
public event NodeCreateHandler OnNodeCreate;
|
||||
public event NodeRemoveHandler OnNodeRemove;
|
||||
@@ -128,6 +132,15 @@ namespace Serein.NodeFlow.Env
|
||||
return prjectInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存项目
|
||||
/// </summary>
|
||||
public void SaveProject()
|
||||
{
|
||||
OnProjectSaving?.Invoke(new ProjectSavingEventArgs());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 远程环境下加载项目
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user