2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
using Serein.Library.Entity;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
using Serein.Library.Enums;
|
2024-09-15 22:07:10 +08:00
|
|
|
|
using Serein.Library.Ex;
|
2024-10-10 10:45:53 +08:00
|
|
|
|
using Serein.Library.Utils;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
using Serein.NodeFlow.Base;
|
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-09-15 12:15:32 +08:00
|
|
|
|
public class SingleFlipflopNode : NodeModelBase
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
2024-09-20 10:50:32 +08:00
|
|
|
|
//public override async Task<object?> Executing(IDynamicContext context)
|
|
|
|
|
|
//public override Task<object?> ExecutingAsync(IDynamicContext context)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// NextOrientation = Library.Enums.ConnectionType.IsError;
|
|
|
|
|
|
// RuningException = new FlipflopException ("无法以非await/async的形式调用触发器");
|
|
|
|
|
|
// return null;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-28 23:55:19 +08:00
|
|
|
|
|
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-09-22 17:37:32 +08:00
|
|
|
|
if (DebugSetting.InterruptClass != InterruptClass.None) // 执行触发前
|
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-10-10 10:45:53 +08:00
|
|
|
|
if (!context.Env.TryGetDelegateDetails(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-09-28 23:55:19 +08:00
|
|
|
|
Task<IFlipflopContext> flipflopTask;
|
2024-10-10 10:45:53 +08:00
|
|
|
|
var args = GetParameters(context, this, md);
|
|
|
|
|
|
var delType = dd.EmitMethodType;
|
|
|
|
|
|
var del = dd.EmitDelegate;
|
|
|
|
|
|
if (delType == EmitHelper.EmitMethodType.HasResultTask && del is Func<object, object?[]?, Task<object>> hasResultTask)
|
2024-09-20 10:50:32 +08:00
|
|
|
|
{
|
2024-10-10 10:45:53 +08:00
|
|
|
|
var flipflopTaskObj = await hasResultTask(instance, args);
|
|
|
|
|
|
if(flipflopTaskObj is IFlipflopContext flipflopContext)
|
2024-10-07 15:15:18 +08:00
|
|
|
|
{
|
2024-10-10 10:45:53 +08:00
|
|
|
|
NextOrientation = flipflopContext.State.ToContentType();
|
|
|
|
|
|
if (flipflopContext.TriggerData is null || flipflopContext.TriggerData.Type == Library.NodeFlow.Tool.TriggerType.Overtime)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new FlipflopException(base.MethodDetails.MethodName + "触发器超时触发。Guid" + base.Guid);
|
|
|
|
|
|
}
|
|
|
|
|
|
return flipflopContext.TriggerData.Value;
|
2024-10-07 15:15:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-10-10 10:45:53 +08:00
|
|
|
|
throw new FlipflopException("触发器节点返回了非预期的类型", true, FlipflopException.CancelClass.Flow);
|
2024-10-07 15:15:18 +08:00
|
|
|
|
}
|
2024-09-28 23:55:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-10-10 10:45:53 +08:00
|
|
|
|
throw new FlipflopException("触发器节点构造了非预期的委托", true, FlipflopException.CancelClass.Flow);
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
2024-10-10 10:45:53 +08:00
|
|
|
|
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (FlipflopException ex)
|
|
|
|
|
|
{
|
2024-10-07 15:15:18 +08:00
|
|
|
|
if(ex.Clsss == FlipflopException.CancelClass.Flow)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
await Console.Out.WriteLineAsync($"触发器[{this.MethodDetails.MethodName}]异常:" + ex.Message);
|
2024-09-20 10:50:32 +08:00
|
|
|
|
NextOrientation = ConnectionType.None;
|
|
|
|
|
|
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-07 15:15:18 +08:00
|
|
|
|
await Console.Out.WriteLineAsync($"触发器[{this.MethodDetails.MethodName}]异常:" + ex.Message);
|
2024-09-20 10:50:32 +08:00
|
|
|
|
NextOrientation = ConnectionType.IsError;
|
|
|
|
|
|
RuningException = ex;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-09-21 10:06:44 +08:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
// flipflopTask?.Dispose();
|
|
|
|
|
|
}
|
2024-08-06 16:09:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-17 14:20:27 +08:00
|
|
|
|
internal override Parameterdata[] GetParameterdatas()
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (base.MethodDetails.ExplicitDatas.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return MethodDetails.ExplicitDatas
|
|
|
|
|
|
.Select(it => new Parameterdata
|
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|