diff --git a/FlowStartTool/Program.cs b/FlowStartTool/Program.cs
index 3dcdc74..5a9ea24 100644
--- a/FlowStartTool/Program.cs
+++ b/FlowStartTool/Program.cs
@@ -72,7 +72,7 @@ namespace Serein.FlowStartTool
#endregion
#region 加载项目
- _ = Task.Run(async () => await flowEnv.StartFlow(flowProjectData, fileDataPath));
+ _ = Task.Run( () => flowEnv.StartFlow(flowProjectData, fileDataPath));
while (flowEnv.IsRuning)
{
Console.ReadKey();
diff --git a/Library/Api/IFlowEnvironment.cs b/Library/Api/IFlowEnvironment.cs
index 94e0cbc..6ce4008 100644
--- a/Library/Api/IFlowEnvironment.cs
+++ b/Library/Api/IFlowEnvironment.cs
@@ -1002,7 +1002,7 @@ namespace Serein.Library.Api
/// 消息
/// 输出类型
/// 输出级别
- void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Trivial);
+ void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Debug);
///
/// 提供设置UI上下文的能力
/// 提供设置UI上下文的能力,在WinForm/WPF项目中,在UI线程外对UI元素的修改将会导致异常
diff --git a/Library/Api/IJsonProvider.cs b/Library/Api/IJsonProvider.cs
index 203455e..30e2b5f 100644
--- a/Library/Api/IJsonProvider.cs
+++ b/Library/Api/IJsonProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -9,8 +10,22 @@ namespace Serein.Library.Api
///
/// JSON数据交互的Token接口,允许使用不同的JSON库进行数据处理。
///
- public interface IJsonToken
+ public interface IJsonToken
{
+ ///
+ /// 获取 Token
+ ///
+ ///
+ ///
+ IJsonToken this[object name] { get; }
+
+ /* ///
+ /// 获取 Token 数组的元素,允许通过索引访问数组中的元素。
+ ///
+ ///
+ ///
+ IJsonToken this[int index] { get; }*/
+
///
/// 获取指定名称的属性,如果存在则返回true,并通过out参数返回对应的IJsonToken对象。
///
@@ -83,6 +98,7 @@ namespace Serein.Library.Api
///
public interface IJsonProvider
{
+
///
/// JSON文本转为指定类型
///
diff --git a/Library/Enums/InfoType.cs b/Library/Enums/InfoType.cs
index a399116..3db5f6c 100644
--- a/Library/Enums/InfoType.cs
+++ b/Library/Enums/InfoType.cs
@@ -12,9 +12,9 @@ namespace Serein.Library
public enum InfoClass
{
///
- /// 琐碎的
+ /// 调试
///
- Trivial,
+ Debug,
///
/// 一般的
///
diff --git a/Library/Enums/NodeType.cs b/Library/Enums/NodeType.cs
index 7c64628..40d25c0 100644
--- a/Library/Enums/NodeType.cs
+++ b/Library/Enums/NodeType.cs
@@ -37,15 +37,13 @@ namespace Serein.Library
UI,
///
- /// 触发器节点,必须为标记在可异步等待的方法,建议与继承了 FlowTriggerk<TEnum> 的实例对象搭配使用
+ /// 触发器节点,必须为标记在可异步等待的方法
/// 方法返回值必须为Task<IFlipflopContext<TResult>>,若为其它返回值,将不会创建节点。
/// 触发器根据在分支中的位置,分为两种类型:流程分支中的触发器、全局触发器
/// 一般的触发器:存在于分支某处,也可能是分支的终点,但一定不是流程的起点与分支的起点。
/// 一般的触发器行为:在当前分支中执行一次之后不再执行,一般用于等待某个操作的响应。
- /// 一般的触发器入参:如果使用了 FlowTriggerk<TEnum> ,就会至少有一个枚举类型的参数,参数类型与 TEnum 泛型一致。
/// 全局触发器:没有上游分支、同时并非流程的起始节点。
/// 全局触发器行为:全局触发器会循环执行,直到流程结束。
- /// 一般的触发器入参:如果使用了 FlowTriggerk<TEnum> ,就会至少有一个枚举类型的参数,参数类型与 TEnum 泛型一致。
///
Flipflop,
///
diff --git a/Library/FlowNode/DelegateDetails.cs b/Library/FlowNode/DelegateDetails.cs
index 23f6049..b3756e5 100644
--- a/Library/FlowNode/DelegateDetails.cs
+++ b/Library/FlowNode/DelegateDetails.cs
@@ -159,7 +159,7 @@ namespace Serein.Library
///
/// 类型信息
/// 操作类型
- public DelegateDetails(Type type, EmitType emitType)
+ public DelegateDetails(Type type, EmitType emitType, Type? itemType = null)
{
if (emitType == EmitType.CollectionSetter)
{
@@ -170,7 +170,7 @@ namespace Serein.Library
else if (emitType == EmitType.CollectionGetter)
{
this.emitType = EmitType.CollectionGetter;
- collectionGetter = EmitHelper.CreateCollectionGetter(type);
+ collectionGetter = EmitHelper.CreateCollectionGetter(type, itemType);
}
else if (emitType == EmitType.ArrayCreate)
{
diff --git a/Library/FlowNode/FlipflopContext.cs b/Library/FlowNode/FlipflopContext.cs
index 24d4be7..61bc176 100644
--- a/Library/FlowNode/FlipflopContext.cs
+++ b/Library/FlowNode/FlipflopContext.cs
@@ -1,6 +1,7 @@
using Serein.Library.Api;
using Serein.Library.Utils;
using System;
+using System.Net;
using System.Threading.Tasks;
namespace Serein.Library
@@ -82,33 +83,92 @@ namespace Serein.Library
///
/// 触发类型
///
-
public TriggerDescription Type { get; set; }
///
/// 触发时传递的数据
///
public TResult Value { get; set; }
- ///
- /// 触发器上下文构造函数
- ///
- ///
- public FlipflopContext(FlipflopStateType ffState)
+ public FlipflopContext()
{
- State = ffState;
+
}
///
- /// 触发器上下文构造函数,传入状态和数据值
+ /// 成功触发器上下文,表示触发器执行成功并返回结果
///
- ///
- ///
- public FlipflopContext(FlipflopStateType ffState, TResult value)
+ ///
+ ///
+ ///
+ public static FlipflopContext Ok(TResult result)
{
- State = ffState;
- Value = value;
+ return new FlipflopContext()
+ {
+ State = FlipflopStateType.Succeed,
+ Type = TriggerDescription.External,
+ Value = result,
+ };
}
+ ///
+ /// 表示触发器执行失败
+ ///
+ ///
+ public static FlipflopContext Fail()
+ {
+ return new FlipflopContext()
+ {
+ State = FlipflopStateType.Fail,
+ Type = TriggerDescription.External,
+ Value = default,
+ };
+ }
+
+ ///
+ /// 表示触发器执行过程中发生了错误
+ ///
+ ///
+ public static FlipflopContext Error()
+ {
+ return new FlipflopContext()
+ {
+ State = FlipflopStateType.Error,
+ Type = TriggerDescription.External,
+ Value = default,
+ };
+ }
+
+ ///
+ /// 取消触发器上下文,表示触发器被外部取消
+ ///
+ ///
+ public static FlipflopContext Cancel()
+ {
+ return new FlipflopContext()
+ {
+ State = FlipflopStateType.Cancel,
+ Type = TriggerDescription.External,
+ Value = default,
+ };
+ }
+
+ ///
+ /// 超时触发器上下文,表示触发器在指定时间内未完成
+ ///
+ ///
+ ///
+ public static FlipflopContext Overtime(FlipflopStateType state = FlipflopStateType.Fail)
+ {
+ return new FlipflopContext()
+ {
+ State = state,
+ Type = TriggerDescription.Overtime,
+ Value = default,
+ };
+ }
+
+
+
}
diff --git a/Library/FlowNode/FlowCanvasDetails.cs b/Library/FlowNode/FlowCanvasDetails.cs
index c2f4d54..32aacad 100644
--- a/Library/FlowNode/FlowCanvasDetails.cs
+++ b/Library/FlowNode/FlowCanvasDetails.cs
@@ -98,7 +98,7 @@ namespace Serein.Library
/// 起始节点
///
[DataInfo]
- private IFlowNode _startNode;
+ private IFlowNode? _startNode;
}
diff --git a/Library/FlowNode/LightweightFlowEnvironment.cs b/Library/FlowNode/LightweightFlowEnvironment.cs
index de8c408..eae0978 100644
--- a/Library/FlowNode/LightweightFlowEnvironment.cs
+++ b/Library/FlowNode/LightweightFlowEnvironment.cs
@@ -15,7 +15,6 @@ namespace Serein.Library
{
private readonly SortedDictionary _callNodes = new SortedDictionary();
- //private readonly Dictionary _callNodes = new Dictionary();
///
/// 索引器,允许通过字符串索引访问CallNode
@@ -700,7 +699,7 @@ namespace Serein.Library
}
///
- public void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Trivial)
+ public void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Debug)
{
Console.WriteLine(message);
}
diff --git a/Library/ScriptBaseFunc.cs b/Library/ScriptBaseFunc.cs
index 0e01eae..24f0787 100644
--- a/Library/ScriptBaseFunc.cs
+++ b/Library/ScriptBaseFunc.cs
@@ -1,4 +1,5 @@
using Serein.Library;
+using Serein.Library.Api;
using Serein.Library.Utils;
using System;
using System.Collections.Generic;
@@ -134,6 +135,28 @@ namespace Serein.Library
return obj?.ToString() ?? string.Empty;
}
+
+ #region JSON挂载方法
+
+ ///
+ /// 转为JSON对象
+ ///
+ ///
+ ///
+ public static IJsonToken json(string content)
+ {
+ return JsonHelper.Parse(content);
+ }
+
+
+
+
+
+
+
+ #endregion
+
+
///
/// 获取全局数据
///
@@ -153,11 +176,11 @@ namespace Serein.Library
{
return type.GetType();
}
+
///
- /// 记录日志信息
+ /// 输出内容
///
///
-
public static void log(object value)
{
SereinEnv.WriteLine(InfoType.INFO, value?.ToString());
@@ -168,18 +191,9 @@ namespace Serein.Library
///
///
///
- public static async Task sleep(object value)
+ public static async Task sleep(int value)
{
- if (value is int @int)
- {
- Console.WriteLine($"等待{@int}ms");
- await Task.Delay(@int);
- }
- else if (value is TimeSpan timeSpan)
- {
- Console.WriteLine($"等待{timeSpan}");
- await Task.Delay(timeSpan);
- }
+ await Task.Delay(value);
}
}
diff --git a/Library/Utils/EmitHelper.cs b/Library/Utils/EmitHelper.cs
index b1933b1..02a0f69 100644
--- a/Library/Utils/EmitHelper.cs
+++ b/Library/Utils/EmitHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
@@ -504,58 +505,97 @@ namespace Serein.Library.Utils
///
- /// 构建集合获取委托:Func<object, object, object>
+ /// 构建集合取值委托:(object collection, object index) => object value
+ /// 支持数组、泛型集合、IDictionary 等类型
///
- ///
- ///
- ///
- public static Func