mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
2. 修复了删除节点时,没有正确消除与之相关的参数获取关系。 3. IFlowNode新增了StartFlowAsync方法。 4. Library项目中FlowNodeExtension拓展类转移到了NodeFlow项目中。 5. 修改了Script自定义参数保存,对参数类型、返回值类型进行保存。 6. Library.Utils.BenchmarkHelpter中添加了Task、Task<>的重载方法。 7. NodeFlow项目中,FlowEnvironment默认使用通过NewtonsoftJson实现的JSON门户类。 8. NodeFlow项目中,FlowControl缓存了 FlowWorkOptions 选项实体,并且对于 FlowWorkManagement 进行了池化管理(但后续的项目中考虑重构流程任务运行时)。
74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using Serein.Library.Api;
|
||
using Serein.Library;
|
||
using Serein.Library.Utils;
|
||
using System;
|
||
|
||
namespace Serein.NodeFlow.Model.Nodes
|
||
{
|
||
/// <summary>
|
||
/// 触发器节点
|
||
/// </summary>
|
||
public class SingleFlipflopNode : NodeModelBase
|
||
{
|
||
|
||
public SingleFlipflopNode(IFlowEnvironment environment) : base(environment)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 执行触发器进行等待触发
|
||
/// </summary>
|
||
/// <param name="context"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="Exception"></exception>
|
||
public override async Task<FlowResult> ExecutingAsync(IFlowContext context, CancellationToken token)
|
||
{
|
||
#region 执行前中断
|
||
if (DebugSetting.IsInterrupt) // 执行触发前
|
||
{
|
||
string guid = Guid.ToString();
|
||
await DebugSetting.GetInterruptTask.Invoke();
|
||
await Console.Out.WriteLineAsync($"[{MethodDetails.MethodName}]中断已取消,开始执行后继分支");
|
||
}
|
||
#endregion
|
||
|
||
MethodDetails md = MethodDetails;
|
||
if (!context.Env.TryGetDelegateDetails(md.AssemblyName, md.MethodName, out var dd)) // 流程运行到某个节点
|
||
{
|
||
throw new Exception("不存在对应委托");
|
||
}
|
||
|
||
var instance = Env.FlowControl.IOC.Get(md.ActingInstanceType);
|
||
if (instance is null)
|
||
{
|
||
Env.FlowControl.IOC.Register(md.ActingInstanceType).Build();
|
||
instance = Env.FlowControl.IOC.Get(md.ActingInstanceType);
|
||
}
|
||
await dd.InvokeAsync(instance, [context]);
|
||
var args = await this.GetParametersAsync(context, token);
|
||
// 因为这里会返回不确定的泛型 IFlipflopContext<TRsult>
|
||
// 而我们只需要获取到 State 和 Value(返回的数据)
|
||
// 所以使用 dynamic 类型接收
|
||
if (token.IsCancellationRequested)
|
||
{
|
||
return null;
|
||
}
|
||
dynamic dynamicFlipflopContext = await dd.InvokeAsync(instance, args);
|
||
FlipflopStateType flipflopStateType = dynamicFlipflopContext.State;
|
||
context.NextOrientation = flipflopStateType.ToContentType();
|
||
|
||
|
||
if (dynamicFlipflopContext.Type == TriggerDescription.Overtime)
|
||
{
|
||
throw new FlipflopException(MethodDetails.MethodName + "触发器超时触发。Guid" + Guid);
|
||
}
|
||
object result = dynamicFlipflopContext.Value;
|
||
var flowReslt = FlowResult.OK(this.Guid, context, result);
|
||
return flowReslt;
|
||
}
|
||
|
||
}
|
||
}
|