Files
serein-flow/Library/FlowNode/FlowResult.cs
fengjiayi 48289dae11 1. 修改了FlowResult的创建方式,新增了IsSuccess与Message,为后续进行流程日志追踪准备。
2. 修复了删除节点时,没有正确消除与之相关的参数获取关系。
3. IFlowNode新增了StartFlowAsync方法。
4. Library项目中FlowNodeExtension拓展类转移到了NodeFlow项目中。
5.  修改了Script自定义参数保存,对参数类型、返回值类型进行保存。
6. Library.Utils.BenchmarkHelpter中添加了Task、Task<>的重载方法。
7. NodeFlow项目中,FlowEnvironment默认使用通过NewtonsoftJson实现的JSON门户类。
8. NodeFlow项目中,FlowControl缓存了 FlowWorkOptions 选项实体,并且对于 FlowWorkManagement 进行了池化管理(但后续的项目中考虑重构流程任务运行时)。
2025-07-30 11:29:12 +08:00

124 lines
3.4 KiB
C#

using Serein.Library.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Library
{
/// <summary>
/// 表示空数据
/// </summary>
/*public readonly struct Unit : IEquatable<Unit>
{
public static readonly Unit Default = default;
public bool Equals(Unit _) => true;
public override bool Equals(object obj) => obj is Unit;
public override int GetHashCode() => 0;
}*/
/// <summary>
/// 流程返回值的包装
/// </summary>
public sealed class FlowResult
{
/// <summary>
/// 实例化返回值
/// </summary>
/// <param name="nodeGuid"></param>
/// <param name="context"></param>
public static FlowResult OK(string nodeGuid, IFlowContext context, object value)
{
FlowResult flowResult = new FlowResult
{
SourceNodeGuid = nodeGuid,
ContextGuid = context.Guid,
Value = value,
IsSuccess = true,
};
return flowResult;
}
/// <summary>
/// 失败
/// </summary>
/// <param name="nodeGuid"></param>
/// <param name="context"></param>
/// <param name="message"></param>
public static FlowResult Fail(string nodeGuid, IFlowContext context, string message)
{
FlowResult flowResult = new FlowResult
{
SourceNodeGuid = nodeGuid,
ContextGuid = context.Guid,
Value = Unit.Default,
IsSuccess = true,
Message = message,
};
return flowResult;
}
/// <summary>
/// 尝试获取值
/// </summary>
/// <param name="targetType">目标类型</param>
/// <param name="value">返回值</param>
/// <returns>指示是否获取成功</returns>
/// <exception cref="ArgumentNullException">无法转为对应类型</exception>
public bool TryGetValue(Type targetType, out object value)
{
if (targetType is null)
throw new ArgumentNullException(nameof(targetType));
if (targetType.IsInstanceOfType(Value))
{
value = Value;
return true;
}
value = Unit.Default;
return false;
}
/// <summary>
/// 指示是否成功
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
/// 执行结果消息(提示异常)
/// </summary>
public string Message { get; set; } = string.Empty;
/// <summary>
/// 来源节点Guid
/// </summary>
public string SourceNodeGuid{ get; private set; }
/// <summary>
/// 来源上下文Guid
/// </summary>
public string ContextGuid { get; private set; }
/// <summary>
/// 数据值
/// </summary>
public object Value { get; private set; }
/// <summary>
/// 生成时间
/// </summary>
public DateTime ResultTime { get; } = DateTime.MinValue;
/// <summary>
/// 是否自动回收
/// </summary>
public bool IsAutoRecovery { get; set; }
}
}