尝试将节点流导出为c#代码文件

This commit is contained in:
fengjiayi
2025-07-06 14:34:49 +08:00
parent 162dc7bcf8
commit b25fd9c83c
45 changed files with 1625 additions and 361 deletions

View File

@@ -140,7 +140,7 @@ namespace Serein.NodeFlow.Model
}
object[] args = await this.GetParametersAsync(context, token);
var result = await dd.InvokeAsync(instance, args);
var flowReslt = new FlowResult(this, context, result);
var flowReslt = new FlowResult(this.Guid, context, result);
return flowReslt;
}

View File

@@ -114,7 +114,7 @@ namespace Serein.NodeFlow.Model
{
if (token.IsCancellationRequested)
{
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
// 接收上一节点参数or自定义参数内容
object? parameter;
@@ -128,15 +128,15 @@ namespace Serein.NodeFlow.Model
if (hasNode)
{
context.NextOrientation = ConnectionInvokeType.IsError;
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
if (hasNode)
{
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
{
result = context.GetFlowData(argSourceNode).Value; // 使用自定义节点的参数
result = context.GetFlowData(argSourceNode.Guid).Value; // 使用自定义节点的参数
}
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
{
@@ -148,7 +148,7 @@ namespace Serein.NodeFlow.Model
}
else
{
result = context.TransmissionData(this).Value; // 条件节点透传上一节点的数据
result = context.TransmissionData(this.Guid).Value; // 条件节点透传上一节点的数据
}
parameter = result; // 使用上一节点的参数
@@ -184,7 +184,7 @@ namespace Serein.NodeFlow.Model
SereinEnv.WriteLine(InfoType.INFO, $"{result} {Expression} -> " + context.NextOrientation);
//return result;
return new FlowResult(this, context, judgmentResult);
return new FlowResult(this.Guid, context, judgmentResult);
}

View File

@@ -94,7 +94,7 @@ namespace Serein.NodeFlow.Model
public override async Task<FlowResult> ExecutingAsync(IDynamicContext context, CancellationToken token)
{
if(token.IsCancellationRequested) return new FlowResult(this, context);
if(token.IsCancellationRequested) return new FlowResult(this.Guid, context);
object? parameter = null;// context.TransmissionData(this); // 表达式节点使用上一节点数据
var pd = MethodDetails.ParameterDetailss[0];
@@ -103,12 +103,12 @@ namespace Serein.NodeFlow.Model
if (hasNode)
{
context.NextOrientation = ConnectionInvokeType.IsError;
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
{
// 使用自定义节点的参数
parameter = context.GetFlowData(argSourceNode).Value;
parameter = context.GetFlowData(argSourceNode.Guid).Value;
}
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
{
@@ -122,7 +122,7 @@ namespace Serein.NodeFlow.Model
else
{
// 条件节点透传上一节点的数据
parameter = context.TransmissionData(this);
parameter = context.TransmissionData(this.Guid);
}
try
@@ -139,13 +139,13 @@ namespace Serein.NodeFlow.Model
}
context.NextOrientation = ConnectionInvokeType.IsSucceed;
return new FlowResult(this,context, result);
return new FlowResult(this.Guid, context, result);
}
catch (Exception ex)
{
context.NextOrientation = ConnectionInvokeType.IsError;
context.ExceptionOfRuning = ex;
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
}

View File

@@ -64,7 +64,7 @@ namespace Serein.NodeFlow.Model
throw new FlipflopException(MethodDetails.MethodName + "触发器超时触发。Guid" + Guid);
}
object result = dynamicFlipflopContext.Value;
var flowReslt = new FlowResult(this, context, result);
var flowReslt = new FlowResult(this.Guid, context, result);
return flowReslt;
}

View File

@@ -208,6 +208,14 @@ namespace Serein.NodeFlow.Model
{
TargetNodeGuid = targetNode.Guid;
this.targetNode = targetNode;
if(this.IsShareParam == false)
{
foreach (var item in nodeInfo.ParameterData)
{
}
}
}
else
{
@@ -258,7 +266,7 @@ namespace Serein.NodeFlow.Model
// 此处代码与SereinFlow.Library.FlowNode.ParameterDetails
// ToMethodArgData()方法中判断流程接口节点分支逻辑耦合
// 不要轻易修改
context.AddOrUpdate(targetNode, flowData);
context.AddOrUpdate(targetNode.Guid, flowData);
foreach (ConnectionInvokeType ctType in NodeStaticConfig.ConnectionTypes)
{
if (this.SuccessorNodes[ctType] == null) continue;
@@ -267,7 +275,7 @@ namespace Serein.NodeFlow.Model
if (node.DebugSetting.IsEnable)
{
context.SetPreviousNode(node, this);
context.SetPreviousNode(node.Guid, this.Guid);
}
}
}

View File

@@ -110,18 +110,18 @@ namespace Serein.NodeFlow.Model
/// <returns></returns>
public override async Task<FlowResult> ExecutingAsync(IDynamicContext context, CancellationToken token)
{
if (token.IsCancellationRequested) return new FlowResult(this, context);
if (token.IsCancellationRequested) return new FlowResult(this.Guid, context);
if (string.IsNullOrEmpty(KeyName))
{
context.NextOrientation = ConnectionInvokeType.IsError;
SereinEnv.WriteLine(InfoType.ERROR, $"全局数据的KeyName不能为空[{this.Guid}]");
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
if (DataNode is null)
{
context.NextOrientation = ConnectionInvokeType.IsError;
SereinEnv.WriteLine(InfoType.ERROR, $"全局数据节点没有设置数据来源[{this.Guid}]");
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
try
@@ -135,7 +135,7 @@ namespace Serein.NodeFlow.Model
{
context.NextOrientation = ConnectionInvokeType.IsError;
context.ExceptionOfRuning = ex;
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
}

View File

@@ -136,6 +136,8 @@ namespace Serein.NodeFlow.Model
this.MethodDetails.ParameterDetailss[i].Name = nodeInfo.ParameterData[i].ArgName;
}
ReloadScript();// 加载时重新解析
IsScriptChanged = false; // 重置脚本改变标志
}
@@ -165,6 +167,8 @@ namespace Serein.NodeFlow.Model
var p = new SereinScriptParser(sb.ToString());
//var p = new SereinScriptParser(Script);
mainNode = p.Parse(); // 开始解析
}
catch (Exception ex)
{
@@ -192,9 +196,9 @@ namespace Serein.NodeFlow.Model
/// <returns></returns>
public async Task<FlowResult> ExecutingAsync(NodeModelBase flowCallNode, IDynamicContext context, CancellationToken token)
{
if (token.IsCancellationRequested) return new FlowResult(this, context);
if (token.IsCancellationRequested) return new FlowResult(this.Guid, context);
var @params = await flowCallNode.GetParametersAsync(context, token);
if (token.IsCancellationRequested) return new FlowResult(this, context);
if (token.IsCancellationRequested) return new FlowResult(this.Guid, context);
//context.AddOrUpdate($"{context.Guid}_{this.Guid}_Params", @params[0]); // 后面再改
@@ -204,7 +208,8 @@ namespace Serein.NodeFlow.Model
if (IsScriptChanged)
{
ReloadScript();// 每次都重新解析
IsScriptChanged = false;
IsScriptChanged = false;
context.Env.WriteLine(InfoType.INFO, $"[{Guid}]脚本解析完成");
}
}
}
@@ -233,7 +238,7 @@ namespace Serein.NodeFlow.Model
var result = await ScriptInterpreter.InterpretAsync(scriptContext, mainNode); // 从入口节点执行
envEvent.FlowRunComplete -= onFlowStop;
return new FlowResult(this, context, result);
return new FlowResult(this.Guid, context, result);
}
#region

View File

@@ -17,7 +17,7 @@ namespace Serein.NodeFlow.Model
public override async Task<FlowResult> ExecutingAsync(IDynamicContext context, CancellationToken token)
{
if (token.IsCancellationRequested) return new FlowResult(this,context);
if (token.IsCancellationRequested) return new FlowResult(this.Guid, context);
if(Adapter is null)
{
@@ -34,13 +34,13 @@ namespace Serein.NodeFlow.Model
}
else
{
var p = context.GetPreviousNode(this);
var p = context.GetPreviousNode(this.Guid);
var data = context.GetFlowData(p).Value;
var iflowContorl = Adapter.GetFlowControl();
iflowContorl.OnExecuting(data);
}
return new FlowResult(this, context);
return new FlowResult(this.Guid, context);
}
}
}