mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
添加了远程模块
This commit is contained in:
@@ -47,7 +47,7 @@ namespace Serein.NodeFlow.Base
|
||||
#region 导出/导入项目文件节点信息
|
||||
|
||||
internal abstract Parameterdata[] GetParameterdatas();
|
||||
internal virtual NodeInfo ToInfo()
|
||||
public virtual NodeInfo ToInfo()
|
||||
{
|
||||
// if (MethodDetails == null) return null;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Serein.NodeFlow.Base
|
||||
};
|
||||
}
|
||||
|
||||
internal virtual NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
public virtual NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
this.Guid = nodeInfo.Guid;
|
||||
if (this.MethodDetails is not null)
|
||||
@@ -99,14 +99,15 @@ namespace Serein.NodeFlow.Base
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task StartExecute(IDynamicContext context)
|
||||
public async Task StartFlowAsync(IDynamicContext context)
|
||||
{
|
||||
Stack<NodeModelBase> stack = new Stack<NodeModelBase>();
|
||||
stack.Push(this);
|
||||
var flowCts = context.Env.IOC.Get<CancellationTokenSource>(FlowStarter.FlipFlopCtsName);
|
||||
bool hasFlipflow = flowCts != null;
|
||||
while (stack.Count > 0) // 循环中直到栈为空才会退出循环
|
||||
{
|
||||
if (flowCts is not null)
|
||||
if (hasFlipflow && flowCts is not null)
|
||||
{
|
||||
if (flowCts.IsCancellationRequested)
|
||||
break;
|
||||
@@ -131,7 +132,7 @@ namespace Serein.NodeFlow.Base
|
||||
await Console.Out.WriteLineAsync($"[{upstreamNode.MethodDetails?.MethodName}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
upstreamNode.PreviousNode = currentNode;
|
||||
await upstreamNode.StartExecute(context); // 执行流程节点的上游分支
|
||||
await upstreamNode.StartFlowAsync(context); // 执行流程节点的上游分支
|
||||
if (upstreamNode.NextOrientation == ConnectionType.IsError)
|
||||
{
|
||||
// 如果上游分支执行失败,不再继续执行
|
||||
@@ -144,7 +145,7 @@ namespace Serein.NodeFlow.Base
|
||||
|
||||
// 上游分支执行完成,才执行当前节点
|
||||
object? newFlowData = await currentNode.ExecutingAsync(context);
|
||||
if (flowCts is null || flowCts.IsCancellationRequested || currentNode.NextOrientation == ConnectionType.None)
|
||||
if (hasFlipflow && (flowCts is null || flowCts.IsCancellationRequested || currentNode.NextOrientation == ConnectionType.None))
|
||||
{
|
||||
// 不再执行
|
||||
break;
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Serein.NodeFlow
|
||||
/// <summary>
|
||||
/// 容器管理
|
||||
/// </summary>
|
||||
private readonly SereinIOC sereinIOC;
|
||||
public readonly SereinIOC sereinIOC;
|
||||
|
||||
/// <summary>
|
||||
/// 存储加载的程序集路径
|
||||
@@ -166,43 +166,43 @@ namespace Serein.NodeFlow
|
||||
/// <summary>
|
||||
/// 存储加载的程序集
|
||||
/// </summary>
|
||||
private List<NodeLibrary> NodeLibrarys { get; } = [];
|
||||
public List<NodeLibrary> NodeLibrarys { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 存储所有方法信息
|
||||
/// </summary>
|
||||
//private MethodDetailss { get; } = [];
|
||||
private Dictionary<NodeLibrary, List<MethodDetails>> MethodDetailss { get; } = [];
|
||||
public Dictionary<NodeLibrary, List<MethodDetails>> MethodDetailss { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 环境加载的节点集合
|
||||
/// Node Guid - Node Model
|
||||
/// </summary>
|
||||
private Dictionary<string, NodeModelBase> Nodes { get; } = [];
|
||||
public Dictionary<string, NodeModelBase> Nodes { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 存放触发器节点(运行时全部调用)
|
||||
/// </summary>
|
||||
private List<SingleFlipflopNode> FlipflopNodes { get; } = [];
|
||||
private Dictionary<RegisterSequence,List<Type>> AutoRegisterTypes { get; } = [];
|
||||
public List<SingleFlipflopNode> FlipflopNodes { get; } = [];
|
||||
public Dictionary<RegisterSequence,List<Type>> AutoRegisterTypes { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 存放委托
|
||||
///
|
||||
/// md.Methodname - delegate
|
||||
/// </summary>
|
||||
|
||||
private ConcurrentDictionary<string, DelegateDetails> MethodDelegates { get; } = [];
|
||||
|
||||
public ConcurrentDictionary<string, DelegateDetails> MethodDelegates { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 起始节点私有属性
|
||||
/// </summary>
|
||||
private NodeModelBase? _startNode = null;
|
||||
public NodeModelBase? _startNode = null;
|
||||
|
||||
/// <summary>
|
||||
/// 起始节点
|
||||
/// </summary>
|
||||
private NodeModelBase? StartNode
|
||||
public NodeModelBase? StartNode
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -226,7 +226,7 @@ namespace Serein.NodeFlow
|
||||
/// <summary>
|
||||
/// 流程启动器(每次运行时都会重新new一个)
|
||||
/// </summary>
|
||||
private FlowStarter? flowStarter;
|
||||
public FlowStarter? flowStarter;
|
||||
|
||||
|
||||
#endregion
|
||||
@@ -865,7 +865,7 @@ namespace Serein.NodeFlow
|
||||
/// <param name="nodeGuid">节点Guid</param>
|
||||
/// <returns>节点Model</returns>
|
||||
/// <exception cref="ArgumentNullException">无法获取节点、Guid/节点为null时报错</exception>
|
||||
private NodeModelBase? GuidToModel(string nodeGuid)
|
||||
public NodeModelBase? GuidToModel(string nodeGuid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Serein.NodeFlow
|
||||
public async Task StartFlowInSelectNodeAsync(NodeModelBase startNode)
|
||||
{
|
||||
if (Context is null) return;
|
||||
await startNode.StartExecute(Context); // 开始运行时从选定节点开始运行
|
||||
await startNode.StartFlowAsync(Context); // 开始运行时从选定节点开始运行
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ namespace Serein.NodeFlow
|
||||
}).ToArray();
|
||||
_ = Task.WhenAll(tasks);
|
||||
}
|
||||
await startNode.StartExecute(Context); // 开始运行时从起始节点开始运行
|
||||
await startNode.StartFlowAsync(Context); // 开始运行时从起始节点开始运行
|
||||
// 等待结束
|
||||
if(FlipFlopState == RunState.Running && _flipFlopCts is not null)
|
||||
{
|
||||
@@ -407,7 +407,7 @@ namespace Serein.NodeFlow
|
||||
var cancelType = await nextNodes[i].DebugSetting.GetInterruptTask();
|
||||
await Console.Out.WriteLineAsync($"[{nextNodes[i].MethodDetails.MethodName}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
await nextNodes[i].StartExecute(context); // 启动执行触发器后继分支的节点
|
||||
await nextNodes[i].StartFlowAsync(context); // 启动执行触发器后继分支的节点
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Serein.NodeFlow.Model
|
||||
{
|
||||
return [];
|
||||
}
|
||||
internal override NodeInfo? ToInfo()
|
||||
public override NodeInfo? ToInfo()
|
||||
{
|
||||
if (MethodDetails is null) return null;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Serein.NodeFlow.Model
|
||||
return [];
|
||||
}
|
||||
|
||||
internal override NodeInfo ToInfo()
|
||||
public override NodeInfo ToInfo()
|
||||
{
|
||||
//if (MethodDetails == null) return null;
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Serein.NodeFlow.Model
|
||||
|
||||
|
||||
|
||||
internal override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
var node = this;
|
||||
if (node != null)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Serein.NodeFlow.Model
|
||||
|
||||
|
||||
|
||||
internal override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
var node = this;
|
||||
if (node != null)
|
||||
|
||||
@@ -6,17 +6,45 @@ using Serein.Library.Attributes;
|
||||
using Serein.Library.Enums;
|
||||
using Serein.Library.Network.WebSocketCommunication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Serein.NodeFlow;
|
||||
using Serein.Library.Core.NodeFlow;
|
||||
using Serein.Library.NodeFlow.Tool;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.FlowRemoteManagement.Model;
|
||||
|
||||
namespace SereinFlowRemoteManagement
|
||||
{
|
||||
public enum FlowEnvCommand
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
D
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// SereinFlow 远程管理模块
|
||||
/// </summary>
|
||||
[DynamicFlow]
|
||||
[AutoRegister]
|
||||
public class FlowRemoteManagement
|
||||
[AutoSocketModule(ThemeKey ="theme",DataKey ="data")]
|
||||
public class FlowRemoteManagement : FlowTrigger<FlowEnvCommand>, ISocketHandleModule
|
||||
{
|
||||
private readonly IFlowEnvironment environment;
|
||||
#region 初始化
|
||||
public Guid HandleGuid { get; } = new Guid();
|
||||
|
||||
private readonly FlowEnvironment environment;
|
||||
public FlowRemoteManagement(IFlowEnvironment environment)
|
||||
{
|
||||
this.environment = environment;
|
||||
if(environment is FlowEnvironment env)
|
||||
{
|
||||
this.environment = env;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[NodeAction(NodeType.Init)]
|
||||
@@ -30,16 +58,129 @@ namespace SereinFlowRemoteManagement
|
||||
{
|
||||
environment.IOC.Run<WebSocketServer>(async (socketServer) =>
|
||||
{
|
||||
socketServer.MsgHandleHelper.AddModule(this,
|
||||
(ex, send) =>
|
||||
{
|
||||
send(new
|
||||
{
|
||||
code = 400,
|
||||
ex = ex.Message
|
||||
});
|
||||
});
|
||||
await socketServer.StartAsync("http://*:7525/");
|
||||
});
|
||||
SereinProjectData projectData = environment.SaveProject();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 对外接口
|
||||
|
||||
public void GetAllNodeInfo()
|
||||
/// <summary>
|
||||
/// 更改两个节点的连接关系
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
/// <param name="Send"></param>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
[AutoSocketHandle(ThemeValue = "ConnectionChange")]
|
||||
public void ChangeNodeConnection(ConnectionInfoData nodeInfo, Func<object, Task> Send)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeInfo.FromNodeGuid) || string.IsNullOrEmpty(nodeInfo.ToNodeGuid))
|
||||
{
|
||||
throw new InvalidOperationException("Guid错误");
|
||||
}
|
||||
if (!EnumHelper.TryConvertEnum<ConnectionType>(nodeInfo.Type, out var connectionType))
|
||||
{
|
||||
throw new InvalidOperationException("类型错误");
|
||||
}
|
||||
|
||||
if (nodeInfo.Op)
|
||||
{
|
||||
environment.ConnectNode(nodeInfo.FromNodeGuid, nodeInfo.ToNodeGuid, connectionType);
|
||||
}
|
||||
else
|
||||
{
|
||||
environment.RemoteConnect(nodeInfo.FromNodeGuid, nodeInfo.ToNodeGuid, connectionType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 远程调用某个节点
|
||||
/// </summary>
|
||||
[AutoSocketHandle(ThemeValue = "InvokeNode")]
|
||||
public async Task InvokeNode(bool isBranchEx, string nodeGuid, Func<object, Task> Send)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
throw new InvalidOperationException("Guid错误");
|
||||
}
|
||||
if(!environment.Nodes.TryGetValue(nodeGuid, out var nodeModel) )
|
||||
{
|
||||
throw new InvalidOperationException("不存在这样的节点");
|
||||
}
|
||||
IDynamicContext dynamicContext = new DynamicContext(environment);
|
||||
object? result = null;
|
||||
if(isBranchEx)
|
||||
{
|
||||
await nodeModel.StartFlowAsync(dynamicContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await nodeModel.ExecutingAsync(dynamicContext);
|
||||
}
|
||||
|
||||
if(result is not Task)
|
||||
{
|
||||
await Send(new
|
||||
{
|
||||
state = 200,
|
||||
tips = "执行完成",
|
||||
data = result
|
||||
}) ;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目配置文件信息
|
||||
/// </summary>
|
||||
[AutoSocketHandle(ThemeValue = "GetProjectInfo")]
|
||||
public async Task<SereinProjectData> GetProjectInfo()
|
||||
{
|
||||
await Task.Delay(0);
|
||||
return environment.SaveProject();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 测试节点
|
||||
|
||||
[NodeAction(NodeType.Flipflop, "触发器等待")]
|
||||
public async Task<IFlipflopContext<object>> WaitFlipflop(FlowEnvCommand flowEnvCommand)
|
||||
{
|
||||
var result = await this.CreateTaskAsync<object>(flowEnvCommand);
|
||||
return new FlipflopContext<object>(FlipflopStateType.Succeed, result);
|
||||
}
|
||||
|
||||
[NodeAction(NodeType.Action, "测试")]
|
||||
public void Test()
|
||||
{
|
||||
Console.WriteLine("Hello World");
|
||||
}
|
||||
|
||||
[NodeAction(NodeType.Action, "等待")]
|
||||
public async Task Wait(int wait = 5)
|
||||
{
|
||||
await Task.Delay(1000 * wait);
|
||||
}
|
||||
|
||||
[NodeAction(NodeType.Action, "输出")]
|
||||
public void Console2(string value)
|
||||
{
|
||||
Console.WriteLine(value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
17
Serein.FlowRemoteManagement/Model/ConnectionInfoData.cs
Normal file
17
Serein.FlowRemoteManagement/Model/ConnectionInfoData.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.FlowRemoteManagement.Model
|
||||
{
|
||||
public class ConnectionInfoData
|
||||
{
|
||||
public bool Op { get; set; }
|
||||
public string? FromNodeGuid { get; set; }
|
||||
public string? ToNodeGuid { get; set; }
|
||||
// None Upstream IsSucceed IsFail IsError
|
||||
public string? Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,10 @@
|
||||
<BaseOutputPath>D:\Project\C#\DynamicControl\SereinFlow\.Output</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Model\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Library.Core\Serein.Library.Core.csproj" />
|
||||
<ProjectReference Include="..\Library\Serein.Library.csproj" />
|
||||
<ProjectReference Include="..\NodeFlow\Serein.NodeFlow.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -161,7 +161,8 @@ namespace Serein.WorkBench
|
||||
string filePath;
|
||||
//filePath = @"F:\临时\project\tmp\project.dnf";
|
||||
//filePath = @"D:\Project\C#\TestNetFramework\Net45DllTest\Net45DllTest\bin\Debug\project.dnf";
|
||||
filePath = @"D:\Project\C#\DynamicControl\SereinFlow\Net462DllTest\bin\Debug\project.dnf";
|
||||
//filePath = @"D:\Project\C#\DynamicControl\SereinFlow\Net462DllTest\bin\Debug\project.dnf";
|
||||
filePath = @"D:\Project\C#\DynamicControl\SereinFlow\.Output\Debug\net8.0-windows7.0\project.dnf";
|
||||
//string filePath = @"D:\Project\C#\DynamicControl\SereinFlow\.Output\Debug\net8.0-windows7.0\U9 project.dnf";
|
||||
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
|
||||
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
||||
|
||||
Reference in New Issue
Block a user