2025-03-14 16:04:06 +08:00
|
|
|
|
using Serein.Library;
|
|
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2025-07-29 14:25:31 +08:00
|
|
|
|
namespace Serein.NodeFlow.Model.Nodes
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单个UI节点,适用于需要在流程中嵌入用户自定义控件的场景。
|
|
|
|
|
|
/// </summary>
|
2025-03-14 16:04:06 +08:00
|
|
|
|
public class SingleUINode : NodeModelBase
|
|
|
|
|
|
{
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 适配的UI控件,必须实现IEmbeddedContent接口。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public IEmbeddedContent? Adapter { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单个UI节点构造函数,初始化流程环境。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="environment"></param>
|
2025-03-14 16:04:06 +08:00
|
|
|
|
public SingleUINode(IFlowEnvironment environment) : base(environment)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 21:15:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行节点逻辑,适用于嵌入式UI控件的流程节点。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-23 16:20:41 +08:00
|
|
|
|
public override async Task<FlowResult> ExecutingAsync(IFlowContext context, CancellationToken token)
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
2025-07-30 11:29:12 +08:00
|
|
|
|
if (token.IsCancellationRequested) return FlowResult.Fail(this.Guid, context, "流程已通过token取消");
|
2025-03-14 16:04:06 +08:00
|
|
|
|
if(Adapter is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-03-20 22:54:10 +08:00
|
|
|
|
var result = await base.ExecutingAsync(context, token);
|
2025-03-21 18:26:01 +08:00
|
|
|
|
if (result.Value is IEmbeddedContent adapter)
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
2025-06-22 21:53:37 +08:00
|
|
|
|
Adapter = adapter;
|
2025-03-14 16:04:06 +08:00
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
context.NextOrientation = ConnectionInvokeType.IsError;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-07-06 14:34:49 +08:00
|
|
|
|
var p = context.GetPreviousNode(this.Guid);
|
2025-03-21 18:26:01 +08:00
|
|
|
|
var data = context.GetFlowData(p).Value;
|
2025-03-17 11:57:06 +08:00
|
|
|
|
var iflowContorl = Adapter.GetFlowControl();
|
|
|
|
|
|
iflowContorl.OnExecuting(data);
|
2025-03-14 16:04:06 +08:00
|
|
|
|
}
|
2025-03-21 18:26:01 +08:00
|
|
|
|
|
2025-07-30 11:29:12 +08:00
|
|
|
|
return FlowResult.OK(this.Guid, context, null);
|
2025-03-14 16:04:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|