Files
serein-flow/NodeFlow/Model/SingleFlipflopNode.cs

60 lines
2.1 KiB
C#
Raw Normal View History

using Serein.Library.Api;
using Serein.Library;
using Serein.Library.Utils;
2024-08-06 16:09:46 +08:00
namespace Serein.NodeFlow.Model
{
/// <summary>
/// 触发器节点
/// </summary>
public class SingleFlipflopNode : NodeModelBase
2024-08-06 16:09:46 +08:00
{
public SingleFlipflopNode(IFlowEnvironment environment) : base(environment)
{
}
2024-09-28 23:55:19 +08:00
/// <summary>
/// 执行触发器进行等待触发
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public override async Task<object?> ExecutingAsync(IDynamicContext context)
2024-08-06 16:09:46 +08:00
{
#region
2024-10-27 00:54:10 +08:00
if (DebugSetting.IsInterrupt) // 执行触发前
{
string guid = this.Guid.ToString();
await this.DebugSetting.GetInterruptTask.Invoke();
await Console.Out.WriteLineAsync($"[{this.MethodDetails.MethodName}]中断已取消,开始执行后继分支");
}
#endregion
MethodDetails md = MethodDetails;
if (!context.Env.TryGetDelegateDetails(md.AssemblyName, md.MethodName, out var dd)) // 流程运行到某个节点
{
throw new Exception("不存在对应委托");
}
object instance = md.ActingInstance;
2024-12-10 23:58:49 +08:00
var args = await GetParametersAsync(context);
2024-12-10 23:58:49 +08:00
// 因为这里会返回不确定的泛型 IFlipflopContext<TRsult>
// 而我们只需要获取到 State 和 Value返回的数据
// 所以使用 dynamic 类型接收
dynamic dynamicFlipflopContext = await dd.InvokeAsync(md.ActingInstance, args);
FlipflopStateType flipflopStateType = dynamicFlipflopContext.State;
context.NextOrientation = flipflopStateType.ToContentType();
if (dynamicFlipflopContext.Type == TriggerDescription.Overtime)
2024-12-10 23:58:49 +08:00
{
throw new FlipflopException(base.MethodDetails.MethodName + "触发器超时触发。Guid" + base.Guid);
}
return dynamicFlipflopContext.Value;
2024-08-06 16:09:46 +08:00
}
2024-08-06 16:09:46 +08:00
}
}