2024-10-15 10:55:41 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Utils;
|
2024-10-20 12:10:57 +08:00
|
|
|
|
using Serein.Library.Utils.SereinExpression;
|
2024-10-15 10:55:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-10-24 23:32:43 +08:00
|
|
|
|
using System.ComponentModel.Design;
|
2024-10-15 10:55:41 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
|
using System.Reflection;
|
2024-11-04 23:30:52 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2024-10-15 10:55:41 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
2024-10-20 12:10:57 +08:00
|
|
|
|
namespace Serein.Library
|
2024-10-15 10:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
2024-11-08 17:30:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-10-15 10:55:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract partial class NodeModelBase : IDynamicFlowNode
|
|
|
|
|
|
{
|
2024-12-20 23:39:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void OnCreating()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-14 23:46:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存自定义信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual NodeInfo SaveCustomData(NodeInfo nodeInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
return nodeInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载自定义数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeInfo"></param>
|
|
|
|
|
|
public virtual void LoadCustomData(NodeInfo nodeInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-12 20:31:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 移除该节点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void Remove()
|
|
|
|
|
|
{
|
2024-12-26 22:24:44 +08:00
|
|
|
|
if (this.DebugSetting.CancelInterrupt != null)
|
2024-12-14 23:46:37 +08:00
|
|
|
|
{
|
2024-12-26 22:24:44 +08:00
|
|
|
|
this.DebugSetting.CancelInterrupt?.Invoke();
|
2024-12-14 23:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.DebugSetting.NodeModel = null;
|
|
|
|
|
|
this.DebugSetting = null;
|
2025-03-21 18:26:01 +08:00
|
|
|
|
if (this.MethodDetails.ParameterDetailss != null)
|
2024-12-14 23:46:37 +08:00
|
|
|
|
{
|
2025-03-18 11:52:54 +08:00
|
|
|
|
foreach (var pd in this.MethodDetails.ParameterDetailss)
|
|
|
|
|
|
{
|
|
|
|
|
|
pd.DataValue = null;
|
|
|
|
|
|
pd.Items = null;
|
|
|
|
|
|
pd.NodeModel = null;
|
|
|
|
|
|
pd.ExplicitType = null;
|
|
|
|
|
|
pd.DataType = null;
|
|
|
|
|
|
pd.Name = null;
|
|
|
|
|
|
pd.ArgDataSourceNodeGuid = null;
|
|
|
|
|
|
pd.InputType = ParameterValueInputType.Input;
|
|
|
|
|
|
}
|
2024-12-14 23:46:37 +08:00
|
|
|
|
}
|
2025-03-21 18:26:01 +08:00
|
|
|
|
|
2024-12-26 22:24:44 +08:00
|
|
|
|
this.MethodDetails.ParameterDetailss = null;
|
2025-03-20 22:54:10 +08:00
|
|
|
|
//this.MethodDetails.ActingInstance = null;
|
2024-12-14 23:46:37 +08:00
|
|
|
|
this.MethodDetails.NodeModel = null;
|
|
|
|
|
|
this.MethodDetails.ReturnType = null;
|
|
|
|
|
|
this.MethodDetails.AssemblyName = null;
|
|
|
|
|
|
this.MethodDetails.MethodAnotherName = null;
|
|
|
|
|
|
this.MethodDetails.MethodLockName = null;
|
|
|
|
|
|
this.MethodDetails.MethodName = null;
|
|
|
|
|
|
this.MethodDetails.ActingInstanceType = null;
|
|
|
|
|
|
this.MethodDetails = null;
|
|
|
|
|
|
this.Position = null;
|
|
|
|
|
|
this.DisplayName = null;
|
|
|
|
|
|
|
|
|
|
|
|
this.Env = null;
|
|
|
|
|
|
}
|
2024-12-12 20:31:50 +08:00
|
|
|
|
|
2024-10-15 10:55:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行节点对应的方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context">流程上下文</param>
|
|
|
|
|
|
/// <returns>节点传回数据对象</returns>
|
2025-03-21 18:26:01 +08:00
|
|
|
|
public virtual async Task<FlowResult> ExecutingAsync(IDynamicContext context, CancellationToken token)
|
2024-10-15 10:55:41 +08:00
|
|
|
|
{
|
2024-12-26 22:24:44 +08:00
|
|
|
|
// 执行触发检查是否需要中断
|
2025-03-21 18:26:01 +08:00
|
|
|
|
if (DebugSetting.IsInterrupt)
|
2024-10-15 10:55:41 +08:00
|
|
|
|
{
|
2024-12-26 22:24:44 +08:00
|
|
|
|
context.Env.TriggerInterrupt(Guid, "", InterruptTriggerEventArgs.InterruptTriggerType.Monitor); // 通知运行环境该节点中断了
|
|
|
|
|
|
await DebugSetting.GetInterruptTask.Invoke();
|
|
|
|
|
|
SereinEnv.WriteLine(InfoType.INFO, $"[{this.MethodDetails?.MethodName}]中断已取消,开始执行后继分支");
|
2025-03-20 22:54:10 +08:00
|
|
|
|
if (token.IsCancellationRequested) { return null; }
|
2024-10-15 10:55:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MethodDetails md = MethodDetails;
|
|
|
|
|
|
if (md is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception($"节点{this.Guid}不存在方法信息,请检查是否需要重写节点的ExecutingAsync");
|
|
|
|
|
|
}
|
2024-11-04 23:30:52 +08:00
|
|
|
|
if (!context.Env.TryGetDelegateDetails(md.AssemblyName, md.MethodName, out var dd)) // 流程运行到某个节点
|
2024-10-15 10:55:41 +08:00
|
|
|
|
{
|
2025-03-21 18:26:01 +08:00
|
|
|
|
|
2024-10-15 10:55:41 +08:00
|
|
|
|
throw new Exception($"节点{this.Guid}不存在对应委托");
|
|
|
|
|
|
}
|
2025-03-21 18:26:01 +08:00
|
|
|
|
|
2025-03-20 22:54:10 +08:00
|
|
|
|
var instance = Env.IOC.Get(md.ActingInstanceType);
|
2025-03-21 18:26:01 +08:00
|
|
|
|
if (instance is null)
|
2024-10-15 10:55:41 +08:00
|
|
|
|
{
|
2025-03-20 22:54:10 +08:00
|
|
|
|
Env.IOC.Register(md.ActingInstanceType).Build();
|
|
|
|
|
|
instance = Env.IOC.Get(md.ActingInstanceType);
|
2024-10-15 10:55:41 +08:00
|
|
|
|
}
|
2025-03-21 18:26:01 +08:00
|
|
|
|
object[] args = await this.GetParametersAsync(context, token);
|
2025-03-20 22:54:10 +08:00
|
|
|
|
var result = await dd.InvokeAsync(instance, args);
|
2025-03-21 18:26:01 +08:00
|
|
|
|
var flowReslt = new FlowResult(this, context, result);
|
|
|
|
|
|
return flowReslt;
|
2024-12-26 22:24:44 +08:00
|
|
|
|
|
2024-10-15 10:55:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-04 23:30:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-10-15 10:55:41 +08:00
|
|
|
|
}
|