mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
完善节点图的代码生成
This commit is contained in:
@@ -3,7 +3,6 @@ using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Services;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -126,7 +125,6 @@ namespace Serein.NodeFlow.Env
|
||||
};
|
||||
|
||||
|
||||
|
||||
flowWorkManagement = new FlowWorkManagement(flowTaskOptions);
|
||||
var cts = new CancellationTokenSource();
|
||||
try
|
||||
@@ -152,7 +150,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
/// <param name="startNodeGuid"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> StartFlowFromSelectNodeAsync(string startNodeGuid)
|
||||
public async Task<TResult> StartFlowAsync<TResult>(string startNodeGuid)
|
||||
{
|
||||
|
||||
var flowTaskOptions = new FlowWorkOptions
|
||||
@@ -162,19 +160,34 @@ namespace Serein.NodeFlow.Env
|
||||
};
|
||||
var flowTaskManagement = new FlowWorkManagement(flowTaskOptions);
|
||||
|
||||
if (true || flowEnvironment.FlowState == RunState.Running || FlipFlopState == RunState.Running)
|
||||
if (!flowModelService.TryGetNodeModel(startNodeGuid, out var nodeModel) || nodeModel is SingleFlipflopNode)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
if (!flowModelService.TryGetNodeModel(startNodeGuid, out var nodeModel) || nodeModel is SingleFlipflopNode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
await flowTaskManagement.StartFlowInSelectNodeAsync(nodeModel);
|
||||
return true;
|
||||
#if DEBUG
|
||||
|
||||
FlowResult flowResult = await BenchmarkHelpers.BenchmarkAsync(async () =>
|
||||
{
|
||||
var flowResult = await flowTaskManagement.StartFlowInSelectNodeAsync(nodeModel);
|
||||
return flowResult;
|
||||
});
|
||||
#else
|
||||
FlowResult flowResult = await flowTaskManagement.StartFlowInSelectNodeAsync(nodeModel);
|
||||
#endif
|
||||
|
||||
|
||||
if (flowResult.Value is TResult result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else if (flowResult is FlowResult && flowResult is TResult result2)
|
||||
{
|
||||
return result2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
throw new ArgumentNullException($"类型转换失败,流程返回数据与泛型不匹配,当前返回类型为[{flowResult.Value.GetType().FullName}]。");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +344,17 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
}
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
#if DEBUG
|
||||
|
||||
FlowResult flowResult = await BenchmarkHelpers.BenchmarkAsync(async () =>
|
||||
{
|
||||
var flowResult = await flowCallNode.StartFlowAsync(context, cts.Token);
|
||||
return flowResult;
|
||||
});
|
||||
#else
|
||||
var flowResult = await flowCallNode.StartFlowAsync(context, cts.Token);
|
||||
#endif
|
||||
cts?.Cancel();
|
||||
cts?.Dispose();
|
||||
if (flowResult.Value is TResult result)
|
||||
|
||||
@@ -5,7 +5,6 @@ using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Model.Operation;
|
||||
using Serein.NodeFlow.Services;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using static Serein.Library.Api.IFlowEnvironment;
|
||||
@@ -261,7 +260,7 @@ namespace Serein.NodeFlow.Env
|
||||
ChangeType = NodeConnectChangeEventArgs.ConnectChangeType.Create,
|
||||
JunctionOfConnectionType = JunctionOfConnectionType.Arg,
|
||||
};
|
||||
flowOperationService.Execute(operation);
|
||||
flowOperationService.Execute(operation);
|
||||
}
|
||||
|
||||
public void RemoveInvokeConnect(string canvasGuid, string fromNodeGuid, string toNodeGuid, ConnectionInvokeType connectionType)
|
||||
@@ -335,6 +334,15 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public void SetStartNode(string canvasGuid, string nodeGuid)
|
||||
{
|
||||
|
||||
IOperation operation = new SetStartNodeOperation
|
||||
{
|
||||
CanvasGuid = canvasGuid,
|
||||
NewNodeGuid = nodeGuid,
|
||||
};
|
||||
_ = flowOperationService.Execute(operation);
|
||||
|
||||
return;
|
||||
if (!TryGetCanvasModel(canvasGuid, out var canvasModel) || !TryGetNodeModel(nodeGuid, out var newStartNodeModel))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,6 @@ using Serein.Library.Api;
|
||||
using Serein.Library.FlowNode;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Services;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
@@ -58,9 +57,9 @@ namespace Serein.NodeFlow.Env
|
||||
.Register<IFlowControl, FlowControl>()
|
||||
.Register<LocalFlowEnvironment>()
|
||||
.Register<FlowModelService>()
|
||||
.Register<FlowLibraryService>()
|
||||
.Register<FlowOperationService>()
|
||||
.Register<NodeMVVMService>()
|
||||
.Register<FlowLibraryService>()
|
||||
.Build();
|
||||
// 默认使用本地环境
|
||||
currentFlowEnvironment = ioc.Get<LocalFlowEnvironment>();
|
||||
@@ -283,9 +282,9 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<bool> StartFlowFromSelectNodeAsync(string startNodeGuid)
|
||||
public async Task<TResult> StartFlowAsync<TResult>(string startNodeGuid)
|
||||
{
|
||||
return await currentFlowEnvironment.FlowControl.StartFlowFromSelectNodeAsync(startNodeGuid);
|
||||
return await currentFlowEnvironment.FlowControl.StartFlowAsync<TResult>(startNodeGuid);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
Reference in New Issue
Block a user