2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.Library;
|
2024-10-10 10:45:53 +08:00
|
|
|
|
using Serein.Library.Utils;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.NodeFlow.Env;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
using static Serein.Library.Utils.ChannelFlowInterrupt;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Serein.NodeFlow.Model
|
|
|
|
|
|
{
|
2024-10-20 12:10:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 触发器节点
|
|
|
|
|
|
/// </summary>
|
2024-09-15 12:15:32 +08:00
|
|
|
|
public class SingleFlipflopNode : NodeModelBase
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
2024-10-20 12:10:57 +08:00
|
|
|
|
public SingleFlipflopNode(IFlowEnvironment environment) : base(environment)
|
|
|
|
|
|
{
|
2024-09-20 10:50:32 +08:00
|
|
|
|
|
2024-10-20 12:10:57 +08:00
|
|
|
|
}
|
2024-09-20 10:50:32 +08:00
|
|
|
|
|
2024-10-28 21:52:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载完成后调用的方法
|
|
|
|
|
|
/// </summary>
|
2024-11-02 16:48:40 +08:00
|
|
|
|
public override void OnCreating()
|
2024-10-28 21:52:45 +08:00
|
|
|
|
{
|
2024-11-02 16:48:40 +08:00
|
|
|
|
// Console.WriteLine("SingleFlipflopNode 暂未实现 OnLoading");
|
2024-10-28 21:52:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-28 23:55:19 +08:00
|
|
|
|
|
2024-10-20 12:10:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行触发器进行等待触发
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
2024-09-20 10:50:32 +08:00
|
|
|
|
public override async Task<object?> ExecutingAsync(IDynamicContext context)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
2024-09-20 10:50:32 +08:00
|
|
|
|
#region 执行前中断
|
2024-10-27 00:54:10 +08:00
|
|
|
|
if (DebugSetting.IsInterrupt) // 执行触发前
|
2024-09-20 10:50:32 +08:00
|
|
|
|
{
|
2024-09-21 10:06:44 +08:00
|
|
|
|
string guid = this.Guid.ToString();
|
2024-09-22 17:37:32 +08:00
|
|
|
|
var cancelType = await this.DebugSetting.GetInterruptTask();
|
|
|
|
|
|
await Console.Out.WriteLineAsync($"[{this.MethodDetails.MethodName}]中断已{cancelType},开始执行后继分支");
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
MethodDetails md = MethodDetails;
|
2024-11-03 21:17:45 +08:00
|
|
|
|
if (!context.Env.TryGetDelegateDetails(md.AssemblyName, md.MethodName, out var dd))
|
2024-09-30 02:45:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("不存在对应委托");
|
|
|
|
|
|
}
|
2024-09-20 10:50:32 +08:00
|
|
|
|
object instance = md.ActingInstance;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-11-02 16:48:40 +08:00
|
|
|
|
|
2024-10-24 23:32:43 +08:00
|
|
|
|
var args = await GetParametersAsync(context, this, md);
|
2024-11-02 16:48:40 +08:00
|
|
|
|
// 因为这里会返回不确定的泛型 IFlipflopContext<TRsult>
|
|
|
|
|
|
// 而我们只需要获取到 State 和 Value(返回的数据)
|
|
|
|
|
|
dynamic dynamicFlipflopContext = await dd.InvokeAsync(md.ActingInstance, args);
|
|
|
|
|
|
FlipflopStateType flipflopStateType = dynamicFlipflopContext.State;
|
2024-10-24 23:32:43 +08:00
|
|
|
|
context.NextOrientation = flipflopStateType.ToContentType();
|
2024-11-02 16:48:40 +08:00
|
|
|
|
if (dynamicFlipflopContext.Type == TriggerType.Overtime)
|
2024-09-20 10:50:32 +08:00
|
|
|
|
{
|
2024-10-11 16:46:16 +08:00
|
|
|
|
throw new FlipflopException(base.MethodDetails.MethodName + "触发器超时触发。Guid" + base.Guid);
|
2024-09-28 23:55:19 +08:00
|
|
|
|
}
|
2024-11-02 16:48:40 +08:00
|
|
|
|
return dynamicFlipflopContext.Value;
|
2024-10-11 16:46:16 +08:00
|
|
|
|
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (FlipflopException ex)
|
|
|
|
|
|
{
|
2024-10-28 21:52:45 +08:00
|
|
|
|
if(ex.Type == FlipflopException.CancelClass.CancelFlow)
|
2024-10-07 15:15:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
2024-10-11 16:46:16 +08:00
|
|
|
|
await Console.Out.WriteLineAsync($"触发器[{this.MethodDetails.MethodName}]异常:" + ex);
|
2024-10-24 23:32:43 +08:00
|
|
|
|
context.NextOrientation = ConnectionInvokeType.None;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
RuningException = ex;
|
2024-09-22 14:10:13 +08:00
|
|
|
|
return null;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2024-10-11 16:46:16 +08:00
|
|
|
|
await Console.Out.WriteLineAsync($"触发器[{this.MethodDetails.MethodName}]异常:" + ex);
|
2024-10-24 23:32:43 +08:00
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsError;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
RuningException = ex;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-09-21 10:06:44 +08:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
// flipflopTask?.Dispose();
|
|
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
2024-10-20 12:10:57 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取触发器参数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2024-10-27 00:54:10 +08:00
|
|
|
|
public override ParameterData[] GetParameterdatas()
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-10-13 19:36:45 +08:00
|
|
|
|
if (base.MethodDetails.ParameterDetailss.Length > 0)
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-10-13 19:36:45 +08:00
|
|
|
|
return MethodDetails.ParameterDetailss
|
2024-10-27 00:54:10 +08:00
|
|
|
|
.Select(it => new ParameterData
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-10-27 00:54:10 +08:00
|
|
|
|
SourceNodeGuid = it.ArgDataSourceNodeGuid,
|
|
|
|
|
|
SourceType = it.ArgDataSourceType.ToString(),
|
2024-09-17 14:20:27 +08:00
|
|
|
|
State = it.IsExplicitData,
|
|
|
|
|
|
Value = it.DataValue
|
2024-09-15 12:15:32 +08:00
|
|
|
|
})
|
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|