mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-02 06:26:35 +08:00
添加了@Dtc(数据类型转换)、@Data(获取全局数据)表达式
This commit is contained in:
@@ -323,8 +323,6 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
private FlowStarter? flowStarter;
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 环境对外接口
|
||||
@@ -526,6 +524,8 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载项目文件
|
||||
/// </summary>
|
||||
@@ -535,13 +535,15 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
var projectData = flowEnvInfo.Project;
|
||||
// 加载项目配置文件
|
||||
var dllPaths = projectData.Librarys.Select(it => it.FileName).ToList();
|
||||
var dllPaths = projectData.Librarys.Select(it => it.FilePath).ToList();
|
||||
List<MethodDetails> methodDetailss = [];
|
||||
|
||||
// 遍历依赖项中的特性注解,生成方法详情
|
||||
foreach (var dllPath in dllPaths)
|
||||
{
|
||||
var dllFilePath = Path.GetFullPath(Path.Combine(filePath, dllPath));
|
||||
string cleanedRelativePath = dllPath.TrimStart('.', '\\');
|
||||
var tmpPath = Path.Combine(filePath, cleanedRelativePath);
|
||||
var dllFilePath = Path.GetFullPath(tmpPath);
|
||||
LoadLibrary(dllFilePath); // 加载项目文件时加载对应的程序集
|
||||
}
|
||||
|
||||
@@ -550,39 +552,48 @@ namespace Serein.NodeFlow.Env
|
||||
// 加载节点
|
||||
foreach (NodeInfo? nodeInfo in projectData.Nodes)
|
||||
{
|
||||
var controlType = FlowFunc.GetNodeControlType(nodeInfo);
|
||||
NodeControlType controlType = FlowFunc.GetNodeControlType(nodeInfo);
|
||||
if (controlType == NodeControlType.None)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
MethodDetails? methodDetails = null;
|
||||
|
||||
if (controlType.IsBaseNode())
|
||||
{
|
||||
// 加载基础节点
|
||||
methodDetails = new MethodDetails();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 加载方法节点
|
||||
if (string.IsNullOrEmpty(nodeInfo.AssemblyName) && string.IsNullOrEmpty(nodeInfo.MethodName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
MethodDetails? methodDetails = null;
|
||||
FlowLibraryManagement.TryGetMethodDetails(nodeInfo.AssemblyName, nodeInfo.MethodName,out methodDetails); // 加载项目时尝试获取方法信息
|
||||
var nodeModel = FlowFunc.CreateNode(this, controlType, methodDetails); // 加载项目时创建节点
|
||||
nodeModel.LoadInfo(nodeInfo); // 创建节点model
|
||||
if (nodeModel is null)
|
||||
{
|
||||
nodeInfo.Guid = string.Empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
TryAddNode(nodeModel); // 加载项目时将节点加载到环境中
|
||||
if (nodeInfo.ChildNodeGuids?.Length > 0)
|
||||
{
|
||||
regionChildNodes.Add((nodeModel, nodeInfo.ChildNodeGuids));
|
||||
|
||||
UIContextOperation?.Invoke(() => OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, nodeInfo.Position)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ordinaryNodes.Add((nodeModel, nodeInfo.Position));
|
||||
}
|
||||
FlowLibraryManagement.TryGetMethodDetails(nodeInfo.AssemblyName, nodeInfo.MethodName, out methodDetails); // 加载项目时尝试获取方法信息
|
||||
}
|
||||
|
||||
var nodeModel = FlowFunc.CreateNode(this, controlType, methodDetails); // 加载项目时创建节点
|
||||
nodeModel.LoadInfo(nodeInfo); // 创建节点model
|
||||
if (nodeModel is null)
|
||||
{
|
||||
nodeInfo.Guid = string.Empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
TryAddNode(nodeModel); // 加载项目时将节点加载到环境中
|
||||
if (nodeInfo.ChildNodeGuids?.Length > 0)
|
||||
{
|
||||
regionChildNodes.Add((nodeModel, nodeInfo.ChildNodeGuids));
|
||||
|
||||
UIContextOperation?.Invoke(() => OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, nodeInfo.Position)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ordinaryNodes.Add((nodeModel, nodeInfo.Position));
|
||||
}
|
||||
|
||||
}
|
||||
// 加载区域子项
|
||||
foreach ((NodeModelBase region, string[] childNodeGuids) item in regionChildNodes)
|
||||
@@ -1323,7 +1334,6 @@ namespace Serein.NodeFlow.Env
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录节点更改数据,防止重复更改
|
||||
/// </summary>
|
||||
@@ -1466,6 +1476,31 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
#region 流程依赖类库的接口
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <param name="data">数据集</param>
|
||||
/// <returns></returns>
|
||||
public object AddOrUpdateGlobalData(string keyName, object data)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.AddOrUpdate(keyName, data, (k, o) => data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <returns></returns>
|
||||
public object? GetGlobalData(string keyName)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.TryGetValue(keyName, out var data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 运行时加载
|
||||
/// </summary>
|
||||
|
||||
@@ -455,6 +455,27 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
|
||||
#region 流程依赖类库的接口
|
||||
/// <summary>
|
||||
/// 添加或更新全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <param name="data">数据集</param>
|
||||
/// <returns></returns>
|
||||
public object AddOrUpdateGlobalData(string keyName, object data)
|
||||
{
|
||||
return currentFlowEnvironment.AddOrUpdateGlobalData(keyName, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <returns></returns>
|
||||
public object GetGlobalData(string keyName)
|
||||
{
|
||||
return currentFlowEnvironment.GetGlobalData(keyName);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 运行时加载
|
||||
@@ -574,6 +595,8 @@ namespace Serein.NodeFlow.Env
|
||||
return IOC.Run(action);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,19 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
public static class FlowFunc
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否为基础节点
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsBaseNode(this NodeControlType nodeControlType)
|
||||
{
|
||||
if(nodeControlType == NodeControlType.ExpCondition
|
||||
|| nodeControlType == NodeControlType.ExpOp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点
|
||||
|
||||
@@ -895,6 +895,31 @@ namespace Serein.NodeFlow.Env
|
||||
this.WriteLine(InfoType.INFO, "远程环境尚未实现的接口:LoadAllNativeLibraryOfRuning");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <param name="data">数据集</param>
|
||||
/// <returns></returns>
|
||||
public object AddOrUpdateGlobalData(string keyName, object data)
|
||||
{
|
||||
this.WriteLine(InfoType.INFO, "远程环境尚未实现的接口:AddOrUpdateGlobalData");
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取全局数据
|
||||
/// </summary>
|
||||
/// <param name="keyName">数据名称</param>
|
||||
/// <returns></returns>
|
||||
public object GetGlobalData(string keyName)
|
||||
{
|
||||
this.WriteLine(InfoType.INFO, "远程环境尚未实现的接口:GetGlobalData");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,13 +241,9 @@ namespace Serein.NodeFlow
|
||||
_flipFlopCts?.Dispose();
|
||||
} // 通知所有流程上下文停止运行
|
||||
TerminateAllGlobalFlipflop(); // 确保所有触发器不再运行
|
||||
|
||||
|
||||
SereinEnv.ClearGlobalData(); // 清空全局数据缓存
|
||||
NativeDllHelper.FreeLibrarys(); // 卸载所有已加载的 Native Dll
|
||||
|
||||
//NativeDllHelper.FreeLibrarys(); // 卸载所有已加载的 Native Dll
|
||||
|
||||
|
||||
env.FlowState = RunState.Completion;
|
||||
env.FlipFlopState = RunState.Completion;
|
||||
|
||||
@@ -395,7 +391,7 @@ namespace Serein.NodeFlow
|
||||
}
|
||||
catch (FlipflopException ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"触发器[{singleFlipFlopNode.MethodDetails.MethodName}]因非预期异常终止。"+ex.Message);
|
||||
env.WriteLine(InfoType.ERROR,$"触发器[{singleFlipFlopNode.MethodDetails.MethodName}]因非预期异常终止。"+ex.Message);
|
||||
if (ex.Type == FlipflopException.CancelClass.CancelFlow)
|
||||
{
|
||||
break;
|
||||
@@ -403,7 +399,8 @@ namespace Serein.NodeFlow
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync(ex.Message);
|
||||
env.WriteLine(InfoType.ERROR, $"触发器[{singleFlipFlopNode.Guid}]异常。"+ ex.Message);
|
||||
//await Console.Out.WriteLineAsync(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
30
NodeFlow/Model/SingleGlobalDataNode.cs
Normal file
30
NodeFlow/Model/SingleGlobalDataNode.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局数据节点
|
||||
/// </summary>
|
||||
public class SingleGlobalDataNode : NodeModelBase
|
||||
{
|
||||
public SingleGlobalDataNode(IFlowEnvironment environment) : base(environment)
|
||||
{
|
||||
}
|
||||
|
||||
public override ParameterData[] GetParameterdatas()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnCreating()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,10 +206,8 @@ namespace Serein.NodeFlow.Tool
|
||||
private (NodeLibraryInfo, List<MethodDetailsInfo>) LoadDllNodeInfo(string dllFilePath)
|
||||
{
|
||||
var fileName = Path.GetFileName(dllFilePath); // 获取文件名
|
||||
|
||||
if (SereinLibraryDll.Equals(fileName))
|
||||
{
|
||||
|
||||
return LoadAssembly(typeof(IFlowEnvironment).Assembly, () => {
|
||||
//SereinEnv.PrintInfo(InfoType.WRAN, "基础模块不能卸载");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user