mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-02 22:36:35 +08:00
将FlowTrigger触发器整合成接口的形式方便替换
This commit is contained in:
@@ -71,7 +71,7 @@ namespace Serein.Library.Core
|
||||
{
|
||||
public FlipflopStateType State { get; set; }
|
||||
|
||||
public TriggerType Type { get; set; }
|
||||
public TriggerDescription Type { get; set; }
|
||||
public TResult Value { get; set; }
|
||||
|
||||
public FlipflopContext(FlipflopStateType ffState)
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Serein.Library.Framework.NodeFlow
|
||||
{
|
||||
public FlipflopStateType State { get; set; }
|
||||
|
||||
public TriggerType Type { get; set; }
|
||||
public TriggerDescription Type { get; set; }
|
||||
public TResult Value { get; set; }
|
||||
|
||||
public FlipflopContext(FlipflopStateType ffState)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Serein.Library.Api
|
||||
/// <summary>
|
||||
/// 触发类型
|
||||
/// </summary>
|
||||
TriggerType Type { get; set; }
|
||||
TriggerDescription Type { get; set; }
|
||||
/// <summary>
|
||||
/// 触发时传递的数据
|
||||
/// </summary>
|
||||
|
||||
44
Library/Api/IFlowTrigger.cs
Normal file
44
Library/Api/IFlowTrigger.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// 触发器接口
|
||||
/// </summary>
|
||||
/// <typeparam name="TSignal"></typeparam>
|
||||
public interface IFlowTrigger<TSignal>
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待信号触发并指定超时时间
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="signal"></param>
|
||||
/// <param name="outTime"></param>
|
||||
/// <returns></returns>
|
||||
Task<TriggerResult<TResult>> WaitTriggerWithTimeoutAsync<TResult>(TSignal signal, TimeSpan outTime);
|
||||
/// <summary>
|
||||
/// 等待信号触发
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">预期的返回值类型</typeparam>
|
||||
/// <param name="signal"></param>
|
||||
/// <returns></returns>
|
||||
Task<TriggerResult<TResult>> WaitTriggerAsync<TResult>(TSignal signal);
|
||||
/// <summary>
|
||||
/// 调用触发器
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">预期的返回值类型</typeparam>
|
||||
/// <param name="signal">信号</param>
|
||||
/// <param name="value">返回值</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> InvokeTriggerAsync<TResult>(TSignal signal, TResult value);
|
||||
/// <summary>
|
||||
/// 取消所有触发器
|
||||
/// </summary>
|
||||
void CancelAllTrigger();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -72,6 +73,9 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
public enum NodeControlType
|
||||
{
|
||||
/// <summary>
|
||||
/// 预料之外的情况
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 动作节点
|
||||
@@ -81,25 +85,31 @@ namespace Serein.Library
|
||||
/// 触发器节点
|
||||
/// </summary>
|
||||
Flipflop,
|
||||
|
||||
/// <summary>
|
||||
/// 表达式操作节点
|
||||
/// </summary>
|
||||
[Description("base")]
|
||||
ExpOp,
|
||||
/// <summary>
|
||||
/// 表达式操作节点
|
||||
/// </summary>
|
||||
[Description("base")]
|
||||
ExpCondition,
|
||||
/// <summary>
|
||||
/// 条件节点区域
|
||||
/// </summary>
|
||||
[Description("base")]
|
||||
ConditionRegion,
|
||||
/// <summary>
|
||||
/// 全局数据
|
||||
/// </summary>
|
||||
[Description("base")]
|
||||
GlobalData,
|
||||
/// <summary>
|
||||
/// 脚本节点
|
||||
/// </summary>
|
||||
[Description("base")]
|
||||
Script,
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace Serein.Library
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存自定义信息
|
||||
/// </summary>
|
||||
@@ -155,7 +154,7 @@ namespace Serein.Library
|
||||
AssemblyName = MethodDetails.AssemblyName,
|
||||
MethodName = MethodDetails?.MethodName,
|
||||
Label = MethodDetails?.MethodAnotherName,
|
||||
Type = this.GetType().ToString(),
|
||||
Type = ControlType.ToString() , //this.GetType().ToString(),
|
||||
TrueNodes = trueNodes.ToArray(),
|
||||
FalseNodes = falseNodes.ToArray(),
|
||||
UpstreamNodes = upstreamNodes.ToArray(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
@@ -12,18 +13,22 @@ namespace Serein.Library.Utils
|
||||
|
||||
|
||||
|
||||
public class ChannelFlowTrigger<TSignal>
|
||||
public class ChannelFlowTrigger<TSignal> : IFlowTrigger<TSignal>
|
||||
{
|
||||
// 使用并发字典管理每个枚举信号对应的 Channel
|
||||
private readonly ConcurrentDictionary<TSignal, Channel<(TriggerType,object)>> _channels = new ConcurrentDictionary<TSignal, Channel<(TriggerType, object)>>();
|
||||
private readonly ConcurrentDictionary<TSignal, Channel<TriggerResult<object>>> _channels = new ConcurrentDictionary<TSignal, Channel<TriggerResult<object>>>();
|
||||
|
||||
/// <summary>
|
||||
/// 创建信号并指定超时时间,到期后自动触发(异步方法)
|
||||
/// 获取或创建指定信号的 Channel
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <param name="outTime">超时时间</param>
|
||||
/// <returns>等待任务</returns>
|
||||
public async Task<(TriggerType, TResult)> WaitDataWithTimeoutAsync<TResult>(TSignal signal, TimeSpan outTime)
|
||||
/// <returns>对应的 Channel</returns>
|
||||
private Channel<TriggerResult<object>> GetOrCreateChannel(TSignal signal)
|
||||
{
|
||||
return _channels.GetOrAdd(signal, _ => Channel.CreateUnbounded<TriggerResult<object>>());
|
||||
}
|
||||
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerWithTimeoutAsync<TResult>(TSignal signal, TimeSpan outTime)
|
||||
{
|
||||
var channel = GetOrCreateChannel(signal);
|
||||
var cts = new CancellationTokenSource();
|
||||
@@ -34,7 +39,11 @@ namespace Serein.Library.Utils
|
||||
try
|
||||
{
|
||||
await Task.Delay(outTime, cts.Token);
|
||||
await channel.Writer.WriteAsync((TriggerType.Overtime, null));
|
||||
var outResult = new TriggerResult<object>()
|
||||
{
|
||||
Type = TriggerDescription.Overtime
|
||||
};
|
||||
await channel.Writer.WriteAsync(outResult);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -43,45 +52,51 @@ namespace Serein.Library.Utils
|
||||
}, cts.Token);
|
||||
|
||||
// 等待信号传入(超时或手动触发)
|
||||
(var type, var result) = await channel.Reader.ReadAsync();
|
||||
var result = await WaitTriggerAsync<TResult>(signal); // 返回一个可以超时触发的等待任务
|
||||
return result;
|
||||
|
||||
|
||||
return (type, result.ToConvert<TResult>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建信号,直到触发
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <returns>等待任务</returns>
|
||||
public async Task<TResult> WaitData<TResult>(TSignal signal)
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerAsync<TResult>(TSignal signal)
|
||||
{
|
||||
var channel = GetOrCreateChannel(signal);
|
||||
// 等待信号传入(超时或手动触发)
|
||||
(var type, var result) = await channel.Reader.ReadAsync();
|
||||
return result.ToConvert<TResult>();
|
||||
var result = await channel.Reader.ReadAsync();
|
||||
if (result.Value is TResult data)
|
||||
{
|
||||
return new TriggerResult<TResult>()
|
||||
{
|
||||
Value = data,
|
||||
Type = TriggerDescription.External,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TriggerResult<TResult>()
|
||||
{
|
||||
Type = TriggerDescription.TypeInconsistency,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 触发信号
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <returns>是否成功触发</returns>
|
||||
public bool TriggerSignal(TSignal signal, object value)
|
||||
public async Task<bool> InvokeTriggerAsync<TResult>(TSignal signal, TResult value)
|
||||
{
|
||||
if (_channels.TryGetValue(signal, out var channel))
|
||||
{
|
||||
// 手动触发信号
|
||||
channel.Writer.TryWrite((TriggerType.External,value));
|
||||
var result = new TriggerResult<object>()
|
||||
{
|
||||
Type = TriggerDescription.External,
|
||||
Value = value
|
||||
};
|
||||
await channel.Writer.WriteAsync(result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消所有任务
|
||||
/// </summary>
|
||||
public void CancelAllTasks()
|
||||
public void CancelAllTrigger()
|
||||
{
|
||||
foreach (var channel in _channels.Values)
|
||||
{
|
||||
@@ -89,16 +104,6 @@ namespace Serein.Library.Utils
|
||||
}
|
||||
_channels.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或创建指定信号的 Channel
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <returns>对应的 Channel</returns>
|
||||
private Channel<(TriggerType, object)> GetOrCreateChannel(TSignal signal)
|
||||
{
|
||||
return _channels.GetOrAdd(signal, _ => Channel.CreateUnbounded<(TriggerType, object)>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Serein.Library.Utils
|
||||
/// <param name="enumValue">枚举值</param>
|
||||
/// <param name="valueSelector">特性成员选择</param>
|
||||
/// <returns></returns>
|
||||
public static TResult GetBoundValue<TEnum, TAttribute, TResult>(TEnum enumValue,
|
||||
public static TResult GetAttributeValue<TEnum, TAttribute, TResult>(TEnum enumValue,
|
||||
Func<TAttribute, TResult> valueSelector)
|
||||
where TEnum : Enum
|
||||
where TAttribute : Attribute
|
||||
@@ -88,6 +88,22 @@ namespace Serein.Library.Utils
|
||||
return attribute != null ? valueSelector(attribute) : default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从枚举值从获取自定义特性的成员,并自动转换类型
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum">枚举类型</typeparam>
|
||||
/// <typeparam name="TAttribute">自定义特性类型</typeparam>
|
||||
/// <param name="enumValue">枚举值</param>
|
||||
/// <returns></returns>
|
||||
public static TAttribute GetAttribute<TEnum, TAttribute>(TEnum enumValue)
|
||||
where TEnum : Enum
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
var fieldInfo = typeof(TEnum).GetField(enumValue.ToString());
|
||||
var attribute = fieldInfo.GetCustomAttribute<TAttribute>();
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
136
Library/Utils/SingleSyncFlowTrigger.cs
Normal file
136
Library/Utils/SingleSyncFlowTrigger.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步的单体消息触发器
|
||||
/// </summary>
|
||||
/// <typeparam name="TSingle"></typeparam>
|
||||
public class SingleSyncFlowTrigger<TSingle> : IFlowTrigger<TSingle>
|
||||
{
|
||||
private readonly ConcurrentDictionary<TSingle, Queue<TaskCompletionSource<TriggerResult<object>>>> _syncChannel
|
||||
= new ConcurrentDictionary<TSingle, Queue<TaskCompletionSource<TriggerResult<object>>>>();
|
||||
|
||||
public void CancelAllTrigger()
|
||||
{
|
||||
foreach (var triggers in _syncChannel.Values)
|
||||
{
|
||||
foreach (var trigger in triggers)
|
||||
{
|
||||
trigger.SetCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Task<bool> InvokeTriggerAsync<TResult>(TSingle signal, TResult value)
|
||||
{
|
||||
if(_syncChannel.TryGetValue(signal, out var tcss))
|
||||
{
|
||||
var tcs = tcss.Dequeue();
|
||||
var result = new TriggerResult<object>
|
||||
{
|
||||
Type = TriggerDescription.External,
|
||||
Value = value,
|
||||
};
|
||||
tcs.SetResult(result);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerAsync<TResult>(TSingle signal)
|
||||
{
|
||||
if (!_syncChannel.TryGetValue(signal,out var tcss))
|
||||
{
|
||||
tcss = new Queue<TaskCompletionSource<TriggerResult<object>>>();
|
||||
_syncChannel.TryAdd(signal, tcss);
|
||||
}
|
||||
var taskCompletionSource = new TaskCompletionSource<TriggerResult<object>>();
|
||||
tcss.Enqueue(taskCompletionSource);
|
||||
var result = await taskCompletionSource.Task;
|
||||
if (result.Value is TResult result2)
|
||||
{
|
||||
return new TriggerResult<TResult>
|
||||
{
|
||||
Type = TriggerDescription.External,
|
||||
Value = result2,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TriggerResult<TResult>
|
||||
{
|
||||
Type = TriggerDescription.TypeInconsistency,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerWithTimeoutAsync<TResult>(TSingle signal, TimeSpan outTime)
|
||||
{
|
||||
if (!_syncChannel.TryGetValue(signal, out var tcss))
|
||||
{
|
||||
tcss = new Queue<TaskCompletionSource<TriggerResult<object>>>();
|
||||
_syncChannel.TryAdd(signal, tcss);
|
||||
}
|
||||
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<TriggerResult<object>>();
|
||||
tcss.Enqueue(taskCompletionSource);
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
// 异步任务:超时后自动触发信号
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(outTime, cts.Token);
|
||||
if (!cts.IsCancellationRequested) // 如果还没有被取消
|
||||
{
|
||||
var outResult = new TriggerResult<object>()
|
||||
{
|
||||
Type = TriggerDescription.Overtime
|
||||
};
|
||||
taskCompletionSource.SetResult(outResult); // 超时触发
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// 超时任务被取消
|
||||
}
|
||||
finally
|
||||
{
|
||||
cts?.Dispose(); // 确保 cts 被释放
|
||||
}
|
||||
}, cts.Token);
|
||||
var result = await taskCompletionSource.Task;
|
||||
cts?.Cancel();
|
||||
if (result.Value is TResult result2)
|
||||
{
|
||||
return new TriggerResult<TResult>
|
||||
{
|
||||
Type = result.Type,
|
||||
Value = result2,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TriggerResult<TResult>
|
||||
{
|
||||
Type = result.Type,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Serein.Library.Utils;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reactive.Linq;
|
||||
@@ -6,13 +8,16 @@ using System.Reactive.Subjects;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace Serein.Library
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 触发类型
|
||||
/// </summary>
|
||||
public enum TriggerType
|
||||
public enum TriggerDescription
|
||||
{
|
||||
/// <summary>
|
||||
/// 外部触发
|
||||
@@ -21,32 +26,37 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 超时触发
|
||||
/// </summary>
|
||||
Overtime
|
||||
Overtime,
|
||||
/// <summary>
|
||||
/// 触发了,但类型不一致
|
||||
/// </summary>
|
||||
TypeInconsistency
|
||||
}
|
||||
|
||||
public class TriggerResult<T>
|
||||
|
||||
public class TriggerResult<TResult>
|
||||
{
|
||||
public TriggerType Type { get; set; }
|
||||
public T Value { get; set; }
|
||||
public TriggerDescription Type { get; set; }
|
||||
public TResult Value { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信号触发器类,带有消息广播功能。
|
||||
/// 使用枚举作为标记,创建
|
||||
/// </summary>
|
||||
public class FlowTrigger<TSignal> where TSignal : struct, Enum
|
||||
public class TaskFlowTrigger<TSignal> : IFlowTrigger<TSignal> where TSignal : struct, Enum
|
||||
{
|
||||
// 使用并发字典管理每个信号对应的广播列表
|
||||
private readonly ConcurrentDictionary<TSignal, Subject<(TriggerType,object)>> _subscribers = new ConcurrentDictionary<TSignal, Subject<(TriggerType, object)>>();
|
||||
private readonly ConcurrentDictionary<TSignal, Subject<TriggerResult<object>>> _subscribers = new ConcurrentDictionary<TSignal, Subject<TriggerResult<object>>>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或创建指定信号的 Subject(消息广播者)
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <returns>对应的 Subject</returns>
|
||||
private Subject<(TriggerType, object)> GetOrCreateSubject(TSignal signal)
|
||||
private Subject<TriggerResult<object>> GetOrCreateSubject(TSignal signal)
|
||||
{
|
||||
return _subscribers.GetOrAdd(signal, _ => new Subject<(TriggerType, object)>());
|
||||
return _subscribers.GetOrAdd(signal, _ => new Subject<TriggerResult<object>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,20 +65,23 @@ namespace Serein.Library
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <param name="observer">订阅者</param>
|
||||
/// <returns>取消订阅的句柄</returns>
|
||||
public IDisposable Subscribe(TSignal signal, IObserver<(TriggerType, object)> observer)
|
||||
private IDisposable Subscribe<TResult>(TSignal signal, Action<TriggerResult<object>> action)
|
||||
{
|
||||
IObserver<TriggerResult<object>> observer = new Observer<TriggerResult<object>>(action);
|
||||
var subject = GetOrCreateSubject(signal);
|
||||
// (IObserver<(TriggerType, object)>)
|
||||
return subject.Subscribe(observer); // 返回取消订阅的句柄
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建信号并指定超时时间,触发时通知所有订阅者
|
||||
/// 等待触发器并指定超时的时间
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <typeparam name="TResult">返回值类型</typeparam>
|
||||
/// <param name="signal">等待信号</param>
|
||||
/// <param name="outTime">超时时间</param>
|
||||
/// <returns>等待任务,返回值为:状态(超时触发,手动触发),数据(超时触发时会使用设置好的数据)</returns>
|
||||
public async Task<(TriggerType, TResult)> CreateTaskWithTimeoutAsync<TResult>(TSignal signal, TimeSpan outTime, TResult outValue)
|
||||
/// <returns></returns>
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerWithTimeoutAsync<TResult>(TSignal signal, TimeSpan outTime)
|
||||
{
|
||||
var subject = GetOrCreateSubject(signal);
|
||||
var cts = new CancellationTokenSource();
|
||||
@@ -81,7 +94,11 @@ namespace Serein.Library
|
||||
await Task.Delay(outTime, cts.Token);
|
||||
if (!cts.IsCancellationRequested) // 如果还没有被取消
|
||||
{
|
||||
subject.OnNext((TriggerType.Overtime, outValue)); // 广播给所有订阅者
|
||||
var outResult = new TriggerResult<object>()
|
||||
{
|
||||
Type = TriggerDescription.Overtime
|
||||
};
|
||||
subject.OnNext(outResult); // 广播给所有订阅者
|
||||
subject.OnCompleted(); // 通知订阅结束
|
||||
}
|
||||
}
|
||||
@@ -94,65 +111,67 @@ namespace Serein.Library
|
||||
cts?.Dispose(); // 确保 cts 被释放
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
var result = await WaitSignalAsync<TResult>(signal);// 返回一个可以超时触发的等待任务
|
||||
var result = await WaitTriggerAsync<TResult>(signal); // 返回一个可以超时触发的等待任务
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建等待任务,触发时通知所有订阅者
|
||||
/// 等待触发
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <param name="outTime">超时时间</param>
|
||||
/// <returns>等待任务</returns>
|
||||
public async Task<TResult> CreateTaskAsync<TResult>(TSignal signal)
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="signal"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TriggerResult<TResult>> WaitTriggerAsync<TResult>(TSignal signal)
|
||||
{
|
||||
var subject = GetOrCreateSubject(signal);
|
||||
(_,var result) = await WaitSignalAsync<TResult>(signal);
|
||||
|
||||
return result;// 返回一个等待的任务
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 等待指定信号的触发
|
||||
/// </summary>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <returns>等待任务</returns>
|
||||
public async Task<(TriggerType, TResult)> WaitSignalAsync<TResult>(TSignal signal)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<(TriggerType, object)>();
|
||||
var subscription = Subscribe(signal, new Observer<(TriggerType, object)>(taskCompletionSource.SetResult));
|
||||
(var type,var result) = await taskCompletionSource.Task;
|
||||
var taskCompletionSource = new TaskCompletionSource<TriggerResult<object>>();
|
||||
var subscription = Subscribe<TResult>(signal, taskCompletionSource.SetResult);
|
||||
var result = await taskCompletionSource.Task;
|
||||
subscription.Dispose(); // 取消订阅
|
||||
|
||||
return (type, result.ToConvert<TResult>());
|
||||
if(result.Value is TResult data)
|
||||
{
|
||||
return new TriggerResult<TResult>()
|
||||
{
|
||||
Value = data,
|
||||
Type = TriggerDescription.External,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TriggerResult<TResult>()
|
||||
{
|
||||
Type = TriggerDescription.TypeInconsistency,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 手动触发信号,并广播给所有订阅者
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">触发类型</typeparam>
|
||||
/// <param name="signal">枚举信号标识符</param>
|
||||
/// <param name="value">传递的数据</param>
|
||||
/// <returns>是否成功触发</returns>
|
||||
public bool Trigger<TResult>(TSignal signal, TResult value)
|
||||
public Task<bool> InvokeTriggerAsync<TResult>(TSignal signal, TResult value)
|
||||
{
|
||||
if (_subscribers.TryGetValue(signal, out var subject))
|
||||
{
|
||||
subject.OnNext((TriggerType.External, value)); // 广播给所有订阅者
|
||||
//subject.OnCompleted(); // 通知订阅结束
|
||||
return true;
|
||||
var result = new TriggerResult<object>()
|
||||
{
|
||||
Type = TriggerDescription.External,
|
||||
Value = value
|
||||
};
|
||||
subject.OnNext(result); // 广播给所有订阅者
|
||||
subject.OnCompleted(); // 通知订阅结束
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
return false;
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消所有任务
|
||||
/// </summary>
|
||||
public void CancelAllTasks()
|
||||
|
||||
public void CancelAllTrigger()
|
||||
{
|
||||
foreach (var subject in _subscribers.Values)
|
||||
{
|
||||
@@ -160,9 +179,11 @@ namespace Serein.Library
|
||||
}
|
||||
_subscribers.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 观察者类,用于包装 Action
|
||||
/// </summary>
|
||||
@@ -28,16 +28,16 @@ namespace Net462DllTest.LogicControl
|
||||
[NodeAction(NodeType.Flipflop, "等待车位调取命令")]
|
||||
public async Task<IFlipflopContext<string>> GetPparkingSpace(ParkingCommand parkingCommand = ParkingCommand.GetPparkingSpace)
|
||||
{
|
||||
var spaceNum = await PrakingDevice.CreateTaskAsync<string>(parkingCommand);
|
||||
await Console.Out.WriteLineAsync("收到命令:调取车位,车位号" + spaceNum);
|
||||
return new FlipflopContext<string>(FlipflopStateType.Succeed, spaceNum);
|
||||
var result = await PrakingDevice.WaitTriggerAsync<string>(parkingCommand);
|
||||
await Console.Out.WriteLineAsync("收到命令:调取车位,车位号" + result.Value);
|
||||
return new FlipflopContext<string>(FlipflopStateType.Succeed, result.Value);
|
||||
}
|
||||
|
||||
|
||||
[NodeAction(NodeType.Action, "调取指定车位")]
|
||||
public void Storage(string spaceNum = "101")
|
||||
public async Task Storage(string spaceNum = "101")
|
||||
{
|
||||
if (PrakingDevice.Trigger(ParkingCommand.GetPparkingSpace, spaceNum))
|
||||
if (await PrakingDevice.InvokeTriggerAsync(ParkingCommand.GetPparkingSpace, spaceNum))
|
||||
{
|
||||
Console.WriteLine("发送命令成功:调取车位" + spaceNum);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Net462DllTest.LogicControl
|
||||
public void Exit(IDynamicContext context)
|
||||
{
|
||||
MyPlc.Close();
|
||||
MyPlc.CancelAllTasks();
|
||||
MyPlc.CancelAllTrigger();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -50,7 +50,7 @@ namespace Net462DllTest.LogicControl
|
||||
{
|
||||
try
|
||||
{
|
||||
var triggerData = await MyPlc.CreateTaskAsync<object>(varName);
|
||||
var triggerData = await MyPlc.WaitTriggerAsync<object>(varName);
|
||||
await Console.Out.WriteLineAsync($"PLC变量触发器[{varName}]传递数据:{triggerData}");
|
||||
return new FlipflopContext<object>(FlipflopStateType.Succeed, triggerData);
|
||||
}
|
||||
|
||||
@@ -31,15 +31,14 @@ namespace Net462DllTest.LogicControl
|
||||
[NodeAction(NodeType.Flipflop, "等待视图命令")]
|
||||
public async Task<IFlipflopContext<int>> WaitTask(CommandSignal command)
|
||||
{
|
||||
(var type, var result) = await ViewManagement.CreateTaskWithTimeoutAsync(command, TimeSpan.FromHours(10), 0);
|
||||
if (type == TriggerType.Overtime)
|
||||
var result = await ViewManagement.WaitTriggerWithTimeoutAsync<int>(command, TimeSpan.FromHours(10));
|
||||
if (result.Type == TriggerDescription.Overtime)
|
||||
{
|
||||
return new FlipflopContext<int>(FlipflopStateType.Cancel, result);
|
||||
return new FlipflopContext<int>(FlipflopStateType.Cancel, result.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return new FlipflopContext<int>(FlipflopStateType.Succeed, result);
|
||||
return new FlipflopContext<int>(FlipflopStateType.Succeed, result.Value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Serein.Library;
|
||||
namespace Net462DllTest.Trigger
|
||||
{
|
||||
[AutoRegister]
|
||||
public class PrakingDevice : FlowTrigger<ParkingCommand>
|
||||
public class PrakingDevice : TaskFlowTrigger<ParkingCommand>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Net462DllTest.Trigger
|
||||
|
||||
|
||||
[AutoRegister]
|
||||
public class SiemensPlcDevice : FlowTrigger<PlcVarName>
|
||||
public class SiemensPlcDevice : TaskFlowTrigger<PlcVarName>
|
||||
{
|
||||
public SiemensClient Client { get; set; }
|
||||
public SiemensVersion Version { get; set; }
|
||||
@@ -197,7 +197,7 @@ namespace Net462DllTest.Trigger
|
||||
if (isNotification)
|
||||
{
|
||||
Console.WriteLine($"VarName: {signal}\t\tOld Data: {oldData}\tNew Data: {newData}");
|
||||
Trigger(signal, newData);
|
||||
await InvokeTriggerAsync(signal, newData);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace Net462DllTest.Trigger
|
||||
{
|
||||
return VarInfoDict[plcVarEnum];
|
||||
}
|
||||
var plcValue = EnumHelper.GetBoundValue<PlcVarName, PlcVarInfoAttribute, PlcVarInfo>(plcVarEnum, attr => attr.Info)
|
||||
var plcValue = EnumHelper.GetAttributeValue<PlcVarName, PlcVarInfoAttribute, PlcVarInfo>(plcVarEnum, attr => attr.Info)
|
||||
?? throw new Exception($"获取变量异常:{plcVarEnum},没有标记PlcValueAttribute");
|
||||
if (string.IsNullOrEmpty(plcValue.Address))
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Net462DllTest.Trigger
|
||||
/// 视图管理
|
||||
/// </summary>
|
||||
[AutoRegister]
|
||||
public class ViewManagement : FlowTrigger<CommandSignal>
|
||||
public class ViewManagement : TaskFlowTrigger<CommandSignal>
|
||||
{
|
||||
private readonly UIContextOperation uiContextOperation;
|
||||
public ViewManagement(UIContextOperation uiContextOperation)
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Net462DllTest.ViewModel
|
||||
});
|
||||
CommandGetParkingSpace = new RelayCommand((p) =>
|
||||
{
|
||||
viewManagement.Trigger(SelectedSignal, SpcaeNumber);
|
||||
_ = viewManagement.InvokeTriggerAsync(SelectedSignal, SpcaeNumber);
|
||||
});
|
||||
CommandCloseForm = new RelayCommand((p) =>
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Net462DllTest.Web
|
||||
if (EnumHelper.TryConvertEnum<PlcVarName>(var, out var signal))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"外部触发 {signal} 信号,信号内容 : {value} ");
|
||||
plcDevice.Trigger(signal, value);// 通过 Web Api 模拟外部输入信号
|
||||
_ = plcDevice.InvokeTriggerAsync(signal, value);// 通过 Web Api 模拟外部输入信号
|
||||
return new { state = "succeed" };
|
||||
}
|
||||
else
|
||||
@@ -63,7 +63,7 @@ namespace Net462DllTest.Web
|
||||
if (EnumHelper.TryConvertEnum<CommandSignal>(command, out var signal))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"外部触发 {signal} 信号,信号内容 : {value} ");
|
||||
viewManagement.Trigger(signal, value);// 通过 Web Api 模拟外部输入信号
|
||||
_ = viewManagement.InvokeTriggerAsync(signal, value);// 通过 Web Api 模拟外部输入信号
|
||||
return new { state = "succeed" };
|
||||
}
|
||||
else
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Net462DllTest.Web
|
||||
socketServer?.Stop(); // 关闭 Web 服务
|
||||
});
|
||||
MyPlc.Close();
|
||||
MyPlc.CancelAllTasks();
|
||||
MyPlc.CancelAllTrigger();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Serein.NodeFlow.Env
|
||||
// await Task.Delay(500);
|
||||
//});
|
||||
await SendCommandAsync(msgId, theme, data); // 客户端发送消息
|
||||
return await remoteFlowEnvironment.WaitData<TResult>(msgId);
|
||||
return (await remoteFlowEnvironment.WaitTriggerAsync<TResult>(msgId)).Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Serein.NodeFlow.Env
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.GetEnvInfo, IsReturnValue = false)]
|
||||
public void GetEnvInfo([UseMsgId] string msgId, [UseData] FlowEnvInfo flowEnvInfo)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, flowEnvInfo);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, flowEnvInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,19 +93,19 @@ namespace Serein.NodeFlow.Env
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.GetProjectInfo, IsReturnValue = false)]
|
||||
public void GetProjectInfo([UseMsgId] string msgId, [UseData] SereinProjectData sereinProjectData)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, sereinProjectData);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, sereinProjectData);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.SetNodeInterrupt, IsReturnValue = false)]
|
||||
public void SetNodeInterrupt([UseMsgId] string msgId)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, null);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync<object>(msgId, null);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.AddInterruptExpression, IsReturnValue = false)]
|
||||
public void AddInterruptExpression([UseMsgId] string msgId)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, null);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync<object>(msgId, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,37 +113,37 @@ namespace Serein.NodeFlow.Env
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.CreateNode, IsReturnValue = false)]
|
||||
public void CreateNode([UseMsgId] string msgId, [UseData] NodeInfo nodeInfo)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, nodeInfo);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, nodeInfo);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.RemoveNode, IsReturnValue = false)]
|
||||
public void RemoveNode([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, state);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.ConnectInvokeNode, IsReturnValue = false)]
|
||||
public void ConnectInvokeNode([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, state);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.RemoveInvokeConnect, IsReturnValue = false)]
|
||||
public void RemoveInvokeConnect([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, state);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.ConnectArgSourceNode, IsReturnValue = false)]
|
||||
public void ConnectArgSourceNode([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, state);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.RemoveArgSourceConnect, IsReturnValue = false)]
|
||||
public void RemoveArgSourceConnect([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
_ = remoteFlowEnvironment.InvokeTriggerAsync(msgId, state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <summary>
|
||||
/// 远程流程环境
|
||||
/// </summary>
|
||||
public class RemoteFlowEnvironment : ChannelFlowTrigger<string>, IFlowEnvironment
|
||||
public class RemoteFlowEnvironment : ChannelFlowTrigger<string>, IFlowEnvironment
|
||||
{
|
||||
/// <summary>
|
||||
/// 连接到远程环境后切换到的环境接口实现
|
||||
|
||||
@@ -3,8 +3,10 @@ using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Model;
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
namespace Serein.NodeFlow
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -12,18 +14,14 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
public static class FlowFunc
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否为基础节点
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsBaseNode(this NodeControlType nodeControlType)
|
||||
{
|
||||
if(nodeControlType == NodeControlType.ExpCondition
|
||||
|| nodeControlType == NodeControlType.ExpOp
|
||||
|| nodeControlType == NodeControlType.GlobalData
|
||||
|| nodeControlType == NodeControlType.Script)
|
||||
var nodeDesc = EnumHelper.GetAttribute<NodeControlType, DescriptionAttribute>(nodeControlType);
|
||||
if("base".Equals(nodeDesc?.Description, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -81,23 +79,27 @@ namespace Serein.NodeFlow.Env
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public static NodeControlType GetNodeControlType(NodeInfo nodeInfo)
|
||||
{
|
||||
// 创建控件实例
|
||||
NodeControlType controlType = nodeInfo.Type switch
|
||||
if(!EnumHelper.TryConvertEnum<NodeControlType>(nodeInfo.Type, out var controlType))
|
||||
{
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleActionNode)}" => NodeControlType.Action,// 动作节点控件
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleFlipflopNode)}" => NodeControlType.Flipflop, // 触发器节点控件
|
||||
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleConditionNode)}" => NodeControlType.ExpCondition,// 条件表达式控件
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleExpOpNode)}" => NodeControlType.ExpOp, // 操作表达式控件
|
||||
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(CompositeConditionNode)}" => NodeControlType.ConditionRegion, // 条件区域控件
|
||||
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleGlobalDataNode)}" => NodeControlType.GlobalData, // 数据节点
|
||||
$"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleScriptNode)}" => NodeControlType.Script, // 数据节点
|
||||
_ => NodeControlType.None,
|
||||
};
|
||||
|
||||
return NodeControlType.None;
|
||||
}
|
||||
return controlType;
|
||||
// 创建控件实例
|
||||
//NodeControlType controlType = nodeInfo.Type switch
|
||||
//{
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleActionNode)}" => NodeControlType.Action,// 动作节点控件
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleFlipflopNode)}" => NodeControlType.Flipflop, // 触发器节点控件
|
||||
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleConditionNode)}" => NodeControlType.ExpCondition,// 条件表达式控件
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleExpOpNode)}" => NodeControlType.ExpOp, // 操作表达式控件
|
||||
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(CompositeConditionNode)}" => NodeControlType.ConditionRegion, // 条件区域控件
|
||||
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleGlobalDataNode)}" => NodeControlType.GlobalData, // 数据节点
|
||||
// $"{NodeStaticConfig.NodeSpaceName}.{nameof(SingleScriptNode)}" => NodeControlType.Script, // 数据节点
|
||||
// _ => NodeControlType.None,
|
||||
//};
|
||||
//return controlType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,7 +107,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
/// <param name="libraryInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static NodeLibraryInfo ToLibrary(this Library.NodeLibraryInfo libraryInfo)
|
||||
public static NodeLibraryInfo ToLibrary(this NodeLibraryInfo libraryInfo)
|
||||
{
|
||||
return new NodeLibraryInfo
|
||||
{
|
||||
@@ -4,7 +4,6 @@ using Serein.Library.Core;
|
||||
using Serein.Library.Network.WebSocketCommunication;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Library.Web;
|
||||
using Serein.NodeFlow.Env;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -16,6 +15,7 @@ namespace Serein.NodeFlow
|
||||
/// </summary>
|
||||
public class FlowStarter
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 控制全局触发器的结束
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,14 @@ namespace Serein.NodeFlow.Model
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行方法
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public override Task<object> ExecutingAsync(IDynamicContext context)
|
||||
{
|
||||
return base.ExecutingAsync(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Env;
|
||||
using static Serein.Library.Utils.ChannelFlowInterrupt;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
@@ -48,7 +47,9 @@ namespace Serein.NodeFlow.Model
|
||||
dynamic dynamicFlipflopContext = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
FlipflopStateType flipflopStateType = dynamicFlipflopContext.State;
|
||||
context.NextOrientation = flipflopStateType.ToContentType();
|
||||
if (dynamicFlipflopContext.Type == TriggerType.Overtime)
|
||||
|
||||
|
||||
if (dynamicFlipflopContext.Type == TriggerDescription.Overtime)
|
||||
{
|
||||
throw new FlipflopException(base.MethodDetails.MethodName + "触发器超时触发。Guid" + base.Guid);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public partial class SingleScriptNode : NodeModelBase
|
||||
{
|
||||
@@ -58,7 +59,6 @@ namespace Serein.NodeFlow.Model
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OnCreating()
|
||||
{
|
||||
MethodInfo? method = this.GetType().GetMethod(nameof(GetFlowApi));
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Serein.Workbench
|
||||
string filePath;
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\net8.0\PLCproject.dnf";
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\banyunqi\project.dnf";
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\debug\net8.0\project.dnf";
|
||||
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
|
||||
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
||||
App.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
|
||||
|
||||
@@ -2917,8 +2917,6 @@ namespace Serein.Workbench
|
||||
|
||||
//SereinEnv.WriteLine(InfoType.ERROR, $"粘贴节点时发生异常:{ex}");
|
||||
}
|
||||
|
||||
|
||||
// SereinEnv.WriteLine(InfoType.INFO, $"剪贴板文本内容: {clipboardText}");
|
||||
}
|
||||
else if (Clipboard.ContainsImage())
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Serein.Workbench.Node.ViewModel
|
||||
CommandCopyDataExp = new RelayCommand( o =>
|
||||
{
|
||||
string exp = NodeModel.KeyName;
|
||||
string copyValue = "@Data " + exp;
|
||||
string copyValue = $"@Get #{exp}#";
|
||||
Clipboard.SetDataObject(copyValue);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user