mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-05 15:56:33 +08:00
修改了无法添加基础节点的bug,增加WebSocket JSON ID字段,远程环境交互使用消息ID作为响应key。
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息主题
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Bson;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Network.WebSocketCommunication;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Sockets;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using static Serein.Library.Utils.ChannelFlowInterrupt;
|
||||
using static Serein.NodeFlow.FlowStarter;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
@@ -41,6 +28,7 @@ namespace Serein.NodeFlow.Env
|
||||
public const string SpaceName = $"{nameof(Serein)}.{nameof(NodeFlow)}.{nameof(Model)}";
|
||||
public const string ThemeKey = "theme";
|
||||
public const string DataKey = "data";
|
||||
public const string MsgIdKey = "msgid";
|
||||
|
||||
/// <summary>
|
||||
/// 流程运行环境
|
||||
@@ -80,10 +68,6 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开远程管理
|
||||
/// </summary>
|
||||
@@ -112,6 +96,7 @@ namespace Serein.NodeFlow.Env
|
||||
Console.WriteLine("结束远程管理异常:" + ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 环境运行事件
|
||||
@@ -347,7 +332,6 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步运行
|
||||
/// </summary>
|
||||
@@ -566,8 +550,17 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
else
|
||||
{
|
||||
MethodDetails? methodDetails = null;
|
||||
if (!string.IsNullOrEmpty(nodeInfo.MethodName))
|
||||
{
|
||||
MethodDetailss.TryGetValue(nodeInfo.MethodName, out methodDetails);// 加载项目时尝试获取方法信息
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
MethodDetailss.TryGetValue(nodeInfo.MethodName, out var methodDetails);// 加载项目时尝试获取方法信息
|
||||
}
|
||||
|
||||
|
||||
var nodeModel = FlowFunc.CreateNode(this, controlType, methodDetails); // 加载项目时创建节点
|
||||
nodeModel.LoadInfo(nodeInfo); // 创建节点model
|
||||
if (nodeModel is null)
|
||||
@@ -575,6 +568,8 @@ namespace Serein.NodeFlow.Env
|
||||
nodeInfo.Guid = string.Empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
TryAddNode(nodeModel); // 加载项目时将节点加载到环境中
|
||||
if (nodeInfo.ChildNodeGuids?.Length > 0)
|
||||
{
|
||||
@@ -662,9 +657,6 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载远程环境
|
||||
/// </summary>
|
||||
@@ -679,7 +671,17 @@ namespace Serein.NodeFlow.Env
|
||||
return (false, null);
|
||||
}
|
||||
// 没有连接远程环境,可以重新连接
|
||||
var remoteEnvControl = new RemoteEnvControl(addres, port, token);
|
||||
|
||||
var controlConfiguration = new RemoteEnvControl.ControlConfiguration
|
||||
{
|
||||
Addres = addres,
|
||||
Port = port,
|
||||
Token = token,
|
||||
ThemeJsonKey = FlowEnvironment.ThemeKey,
|
||||
MsgIdJsonKey = FlowEnvironment.MsgIdKey,
|
||||
DataJsonKey = FlowEnvironment.DataKey,
|
||||
};
|
||||
var remoteEnvControl = new RemoteEnvControl(controlConfiguration);
|
||||
var result = await remoteEnvControl.ConnectAsync();
|
||||
if (!result)
|
||||
{
|
||||
@@ -805,7 +807,6 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TryAddNode(nodeModel);
|
||||
nodeModel.Position = position;
|
||||
|
||||
@@ -1199,30 +1200,11 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
NodeValueChangeLogger.Add((nodeGuid, path, value));
|
||||
var setExp = $"@Set .{path} = {value}"; // 生成 set 表达式
|
||||
SerinExpressionEvaluator.Evaluate(setExp, nodeModel, out _); // 更改对应的数据
|
||||
|
||||
|
||||
|
||||
//Console.WriteLine($"本地环境收到数据更改通知:{value}");
|
||||
//var getExp = $"@Get .{path}";
|
||||
////Console.WriteLine($"取值表达式:{getExp}");
|
||||
SerinExpressionEvaluator.Evaluate(setExp, nodeModel, out _); // 更改对应的数据
|
||||
//var getResult = SerinExpressionEvaluator.Evaluate(getExp, nodeModel, out _);
|
||||
////Console.WriteLine($"原数据 :{getResult}");
|
||||
//if (getResult.Equals(value))
|
||||
//{
|
||||
// Console.WriteLine("无须修改");
|
||||
// return;
|
||||
//}
|
||||
|
||||
|
||||
//NodeValueChangeLogger.Add((nodeGuid, path, value));
|
||||
|
||||
|
||||
//var setExp = $"@Set .{path} = {value}";
|
||||
////Console.WriteLine($"设值表达式:{setExp}");
|
||||
//SerinExpressionEvaluator.Evaluate(setExp, nodeModel, out _);
|
||||
//getResult = SerinExpressionEvaluator.Evaluate(getExp, nodeModel, out _);
|
||||
//Console.WriteLine($"新数据 :{getResult}");
|
||||
//Console.WriteLine($"Set表达式:{setExp},result : {getResult}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Library.Web;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.NodeFlow.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Serein.Library;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Network.WebSocketCommunication;
|
||||
using Serein.Library.Network.WebSocketCommunication.Handle;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
@@ -17,33 +12,43 @@ namespace Serein.NodeFlow.Env
|
||||
/// 客户端的消息管理(用于处理服务端的响应)
|
||||
/// </summary>
|
||||
|
||||
[AutoSocketModule(ThemeKey = FlowEnvironment.ThemeKey, DataKey = FlowEnvironment.DataKey)]
|
||||
[AutoSocketModule(ThemeKey = FlowEnvironment.ThemeKey,
|
||||
DataKey = FlowEnvironment.DataKey,
|
||||
MsgIdKey = FlowEnvironment.MsgIdKey)]
|
||||
public class MsgControllerOfClient : ISocketHandleModule
|
||||
{
|
||||
public Guid HandleGuid => new Guid();
|
||||
private readonly Func<string, object?, Task> SendCommandAsync;
|
||||
|
||||
// 消息主题,data - task等待
|
||||
private readonly Func<string, string, object?, Task> SendCommandFunc;
|
||||
private readonly RemoteFlowEnvironment remoteFlowEnvironment;
|
||||
|
||||
public MsgControllerOfClient(RemoteFlowEnvironment remoteFlowEnvironment, Func<string, object?, Task> func)
|
||||
public MsgControllerOfClient(RemoteFlowEnvironment remoteFlowEnvironment, Func<string, string, object?, Task> func)
|
||||
{
|
||||
this.remoteFlowEnvironment = remoteFlowEnvironment;
|
||||
SendCommandAsync = func;
|
||||
SendCommandFunc = func;
|
||||
}
|
||||
private async Task SendCommandAsync(string msgId, string theme, object? data)
|
||||
{
|
||||
await SendCommandFunc.Invoke(msgId, theme, data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送请求并等待远程环境响应
|
||||
/// 发送请求
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException">超时触发</exception>
|
||||
public async Task SendAsync(string signal, object? sendData = null, int overtimeInMs = 100)
|
||||
public async Task SendAsync(string signal, object? data = null, int overtimeInMs = 100)
|
||||
{
|
||||
//Console.WriteLine($"指令[{signal}],value:{JsonConvert.SerializeObject(sendData)}");
|
||||
if (!DebounceHelper.CanExecute(signal, overtimeInMs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
await SendCommandAsync.Invoke(signal, sendData);
|
||||
var msgId = MsgIdHelper.GenerateId().ToString();
|
||||
await SendCommandAsync(msgId, signal, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,11 +56,13 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException">超时触发</exception>
|
||||
public async Task<TResult> SendAndWaitDataAsync<TResult>(string signal, object? sendData = null, int overtimeInMs = 50)
|
||||
public async Task<TResult> SendAndWaitDataAsync<TResult>(string theme, object? data = null, int overtimeInMs = 50)
|
||||
{
|
||||
//Console.WriteLine($"指令[{signal}],value:{JsonConvert.SerializeObject(sendData)}");
|
||||
_ = SendCommandAsync.Invoke(signal, sendData);
|
||||
return await remoteFlowEnvironment.WaitData<TResult>(signal);
|
||||
|
||||
var msgId = MsgIdHelper.GenerateId().ToString();
|
||||
_ = SendCommandAsync(msgId, theme, data);
|
||||
return await remoteFlowEnvironment.WaitData<TResult>(msgId);
|
||||
|
||||
//if (DebounceHelper.CanExecute(signal, overtimeInMs))
|
||||
//{
|
||||
@@ -86,63 +93,63 @@ namespace Serein.NodeFlow.Env
|
||||
/// <summary>
|
||||
/// 远程环境发来项目信息
|
||||
/// </summary>
|
||||
/// <param name="msgId"></param>
|
||||
/// <param name="flowEnvInfo"></param>
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.GetEnvInfo)]
|
||||
public void GetEnvInfo([UseMsgData] FlowEnvInfo flowEnvInfo)
|
||||
public void GetEnvInfo([UseMsgId] string msgId, [UseData] FlowEnvInfo flowEnvInfo)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.GetEnvInfo, flowEnvInfo);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, flowEnvInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 远程环境发来项目信息
|
||||
/// </summary>
|
||||
/// <param name="msgId"></param>
|
||||
/// <param name="sereinProjectData"></param>
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.GetProjectInfo)]
|
||||
public void GetProjectInfo([UseMsgData] SereinProjectData sereinProjectData)
|
||||
public void GetProjectInfo([UseMsgId] string msgId, [UseData] SereinProjectData sereinProjectData)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.GetProjectInfo, sereinProjectData);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, sereinProjectData);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.SetNodeInterrupt)]
|
||||
public void SetNodeInterrupt()
|
||||
public void SetNodeInterrupt([UseMsgId] string msgId)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.GetProjectInfo, null);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, null);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.AddInterruptExpression)]
|
||||
public void AddInterruptExpression()
|
||||
public void AddInterruptExpression([UseMsgId] string msgId)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.AddInterruptExpression, null);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.CreateNode)]
|
||||
public void CreateNode([UseMsgData] NodeInfo nodeInfo)
|
||||
public void CreateNode([UseMsgId] string msgId, [UseData] NodeInfo nodeInfo)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.CreateNode, nodeInfo);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, nodeInfo);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.RemoveNode)]
|
||||
public void RemoveNode(bool state)
|
||||
public void RemoveNode([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.RemoveNode, state);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
}
|
||||
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.ConnectNode)]
|
||||
public void ConnectNode(bool state)
|
||||
public void ConnectNode([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.ConnectNode, state);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
}
|
||||
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.RemoveConnect)]
|
||||
public void RemoveConnect(bool state)
|
||||
public void RemoveConnect([UseMsgId] string msgId, bool state)
|
||||
{
|
||||
remoteFlowEnvironment.TriggerSignal(EnvMsgTheme.RemoveConnect, state);
|
||||
remoteFlowEnvironment.TriggerSignal(msgId, state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Network.WebSocketCommunication;
|
||||
using Serein.Library.Network.WebSocketCommunication.Handle;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务端的消息管理(用于处理客户端的请求)
|
||||
/// </summary>
|
||||
[AutoSocketModule(ThemeKey = FlowEnvironment.ThemeKey, DataKey = FlowEnvironment.DataKey)]
|
||||
[AutoSocketModule(ThemeKey = FlowEnvironment.ThemeKey,
|
||||
DataKey = FlowEnvironment.DataKey,
|
||||
MsgIdKey = FlowEnvironment.MsgIdKey)]
|
||||
public class MsgControllerOfServer : ISocketHandleModule
|
||||
{
|
||||
/// <summary>
|
||||
@@ -225,7 +221,7 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前环境信息(远程连接)
|
||||
/// 获取当前环境信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.GetEnvInfo)]
|
||||
@@ -316,6 +312,7 @@ namespace Serein.NodeFlow.Env
|
||||
var nodeInfo = await environment.CreateNodeAsync(nodeControlType, position, mdInfo); // 监听到客户端创建节点的请求
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从远程环境移除节点
|
||||
/// </summary>
|
||||
@@ -464,10 +461,6 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Serein.NodeFlow.Env
|
||||
{
|
||||
@@ -104,9 +102,8 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public void LoadProject(FlowEnvInfo flowEnvInfo, string filePath)
|
||||
{
|
||||
Console.WriteLine("远程环境尚未实现的接口:LoadProject");
|
||||
//Console.WriteLine("远程环境尚未实现的接口:LoadProject");
|
||||
|
||||
|
||||
// dll面板
|
||||
var libmds = flowEnvInfo.LibraryMds;
|
||||
foreach (var lib in libmds)
|
||||
@@ -143,8 +140,11 @@ namespace Serein.NodeFlow.Env
|
||||
else
|
||||
{
|
||||
|
||||
MethodDetails? methodDetails;
|
||||
MethodDetailss.TryGetValue(nodeInfo.MethodName, out methodDetails);// 尝试获取方法信息
|
||||
MethodDetails? methodDetails = null;
|
||||
if (!string.IsNullOrEmpty(nodeInfo.MethodName))
|
||||
{
|
||||
MethodDetailss.TryGetValue(nodeInfo.MethodName, out methodDetails);// 加载远程环境时尝试获取方法信息
|
||||
}
|
||||
|
||||
var nodeModel = FlowFunc.CreateNode(this, controlType, methodDetails); // 加载远程项目时创建节点
|
||||
nodeModel.LoadInfo(nodeInfo); // 创建节点model
|
||||
@@ -160,7 +160,6 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
regionChildNodes.Add((nodeModel, nodeInfo.ChildNodeGuids));
|
||||
UIContextOperation?.Invoke(() => OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, nodeInfo.Position)));
|
||||
//OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, nodeInfo.Position));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,7 +180,6 @@ namespace Serein.NodeFlow.Env
|
||||
continue;
|
||||
}
|
||||
// 存在节点
|
||||
//OnNodeCreate?.Invoke(new NodeCreateEventArgs(childNode, true, item.region.Guid));
|
||||
UIContextOperation?.Invoke(() => OnNodeCreate?.Invoke(new NodeCreateEventArgs(childNode, true, item.region.Guid)));
|
||||
}
|
||||
}
|
||||
@@ -252,7 +250,10 @@ namespace Serein.NodeFlow.Env
|
||||
});
|
||||
|
||||
SetStartNode(projectData.StartNode);
|
||||
OnProjectLoaded?.Invoke(new ProjectLoadedEventArgs());
|
||||
UIContextOperation?.Invoke(() =>
|
||||
{
|
||||
OnProjectLoaded?.Invoke(new ProjectLoadedEventArgs());
|
||||
});
|
||||
|
||||
}
|
||||
private bool TryAddNode(NodeModelBase nodeModel)
|
||||
@@ -394,7 +395,10 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public void MoveNode(string nodeGuid, double x, double y)
|
||||
{
|
||||
OnNodeMoved.Invoke(new NodeMovedEventArgs(nodeGuid, x, y));
|
||||
UIContextOperation.Invoke(() =>
|
||||
{
|
||||
OnNodeMoved.Invoke(new NodeMovedEventArgs(nodeGuid, x, y));
|
||||
});
|
||||
_ = msgClient.SendAsync(EnvMsgTheme.MoveNode,
|
||||
new
|
||||
{
|
||||
@@ -404,13 +408,14 @@ namespace Serein.NodeFlow.Env
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void SetStartNode(string nodeGuid)
|
||||
{
|
||||
_ = msgClient.SendAsync(EnvMsgTheme.SetStartNode, new
|
||||
{
|
||||
nodeGuid
|
||||
});
|
||||
// UIContextOperation?.Invoke(() => OnStartNodeChange?.Invoke(new StartNodeChangeEventArgs(oldNodeGuid, StartNode.Guid)));
|
||||
//UIContextOperation?.Invoke(() => OnStartNodeChange?.Invoke(new StartNodeChangeEventArgs(nodeGuid,nodeGuid)));
|
||||
}
|
||||
|
||||
public async Task<bool> ConnectNodeAsync(string fromNodeGuid, string toNodeGuid, ConnectionType connectionType)
|
||||
@@ -440,13 +445,22 @@ namespace Serein.NodeFlow.Env
|
||||
mdInfo = methodDetailsInfo,
|
||||
});
|
||||
|
||||
MethodDetailss.TryGetValue(methodDetailsInfo.MethodName, out var methodDetails);// 加载项目时尝试获取方法信息
|
||||
MethodDetails? methodDetails = null;
|
||||
if (!string.IsNullOrEmpty(nodeInfo.MethodName))
|
||||
{
|
||||
MethodDetailss.TryGetValue(nodeInfo.MethodName, out methodDetails);// 加载远程环境时尝试获取方法信息
|
||||
}
|
||||
|
||||
//MethodDetailss.TryGetValue(methodDetailsInfo.MethodName, out var methodDetails);// 加载项目时尝试获取方法信息
|
||||
var nodeModel = FlowFunc.CreateNode(this, nodeControlType, methodDetails); // 远程环境下加载节点
|
||||
nodeModel.LoadInfo(nodeInfo);
|
||||
TryAddNode(nodeModel);
|
||||
|
||||
// 通知UI更改
|
||||
OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, position));
|
||||
UIContextOperation.Invoke(() =>
|
||||
{
|
||||
OnNodeCreate?.Invoke(new NodeCreateEventArgs(nodeModel, position));
|
||||
});
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
@@ -460,10 +474,13 @@ namespace Serein.NodeFlow.Env
|
||||
});
|
||||
if (result)
|
||||
{
|
||||
OnNodeConnectChange?.Invoke(new NodeConnectChangeEventArgs(fromNodeGuid,
|
||||
UIContextOperation.Invoke(() =>
|
||||
{
|
||||
OnNodeConnectChange?.Invoke(new NodeConnectChangeEventArgs(fromNodeGuid,
|
||||
toNodeGuid,
|
||||
connectionType,
|
||||
NodeConnectChangeEventArgs.ConnectChangeType.Remote));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -476,7 +493,10 @@ namespace Serein.NodeFlow.Env
|
||||
});
|
||||
if (result)
|
||||
{
|
||||
OnNodeRemove?.Invoke(new NodeRemoveEventArgs(nodeGuid));
|
||||
UIContextOperation.Invoke(() =>
|
||||
{
|
||||
OnNodeRemove?.Invoke(new NodeRemoveEventArgs(nodeGuid));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,20 +4,38 @@ using Serein.Library.Api;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 组合条件节点(用于条件区域)
|
||||
/// </summary>
|
||||
public class CompositeConditionNode : NodeModelBase
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public partial class CompositeConditionNode : NodeModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件节点集合
|
||||
/// </summary>
|
||||
[PropertyInfo]
|
||||
private List<SingleConditionNode> _conditionNodes;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组合条件节点(用于条件区域)
|
||||
/// </summary>
|
||||
public partial class CompositeConditionNode : NodeModelBase
|
||||
{
|
||||
public CompositeConditionNode(IFlowEnvironment environment):base(environment)
|
||||
{
|
||||
|
||||
}
|
||||
public List<SingleConditionNode> ConditionNodes { get; } = [];
|
||||
|
||||
|
||||
public void AddNode(SingleConditionNode node)
|
||||
{
|
||||
if(ConditionNodes is null)
|
||||
{
|
||||
ConditionNodes = new List<SingleConditionNode>();
|
||||
}
|
||||
ConditionNodes.Add(node);
|
||||
MethodDetails ??= node.MethodDetails;
|
||||
}
|
||||
@@ -93,6 +111,7 @@ namespace Serein.NodeFlow.Model
|
||||
ParameterData = parameterData.ToArray(),
|
||||
ErrorNodes = errorNodes.ToArray(),
|
||||
ChildNodeGuids = ConditionNodes.Select(node => node.Guid).ToArray(),
|
||||
Position = Position,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,51 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件节点(用于条件控件)
|
||||
/// </summary>
|
||||
public class SingleConditionNode : NodeModelBase
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public partial class SingleConditionNode : NodeModelBase
|
||||
{
|
||||
public SingleConditionNode(IFlowEnvironment environment):base(environment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为自定义参数
|
||||
/// </summary>
|
||||
public bool IsCustomData { get; set; }
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private bool _isCustomData;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数值
|
||||
/// </summary>
|
||||
public object? CustomData { get; set; }
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
|
||||
private object? _customData;
|
||||
/// <summary>
|
||||
/// 条件表达式
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private string _expression;
|
||||
|
||||
public string Expression { get; set; }
|
||||
}
|
||||
|
||||
public partial class SingleConditionNode : NodeModelBase
|
||||
{
|
||||
public SingleConditionNode(IFlowEnvironment environment):base(environment)
|
||||
{
|
||||
this.IsCustomData = false;
|
||||
this.CustomData = null;
|
||||
this.Expression = "PASS";
|
||||
}
|
||||
|
||||
//public override object? Executing(IDynamicContext context)
|
||||
/// <summary>
|
||||
/// 重写节点的方法执行
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public override Task<object?> ExecutingAsync(IDynamicContext context)
|
||||
{
|
||||
// 接收上一节点参数or自定义参数内容
|
||||
@@ -94,46 +110,20 @@ namespace Serein.NodeFlow.Model
|
||||
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
var node = this;
|
||||
if (node != null)
|
||||
node.Guid = nodeInfo.Guid;
|
||||
this.Position = nodeInfo.Position;// 加载位置信息
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
node.Guid = nodeInfo.Guid;
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
Parameterdata? pd = nodeInfo.ParameterData[i];
|
||||
node.IsCustomData = pd.State;
|
||||
node.CustomData = pd.Value;
|
||||
node.Expression = pd.Expression;
|
||||
Parameterdata? pd = nodeInfo.ParameterData[i];
|
||||
node.IsCustomData = pd.State;
|
||||
node.CustomData = pd.Value;
|
||||
node.Expression = pd.Expression;
|
||||
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
//public override void Execute(DynamicContext context)
|
||||
//{
|
||||
// CurrentState = Judge(context, base.MethodDetails);
|
||||
//}
|
||||
|
||||
//private bool Judge(DynamicContext context, MethodDetails md)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// if (DelegateCache.GlobalDicDelegates.TryGetValue(md.MethodName, out Delegate del))
|
||||
// {
|
||||
// object[] parameters = GetParameters(context, md);
|
||||
// var temp = del.DynamicInvoke(parameters);
|
||||
// //context.GetData(GetDyPreviousKey());
|
||||
// return (bool)temp;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.Write(ex.Message);
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using System.Reactive;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Expression Operation - 表达式操作
|
||||
/// </summary>
|
||||
public class SingleExpOpNode : NodeModelBase
|
||||
[NodeProperty(ValuePath = NodeValuePath.Node)]
|
||||
public partial class SingleExpOpNode : NodeModelBase
|
||||
{
|
||||
public SingleExpOpNode(IFlowEnvironment environment) : base(environment)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式
|
||||
/// </summary>
|
||||
public string Expression { get; set; }
|
||||
[PropertyInfo(IsNotification = true)]
|
||||
private string _expression;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public partial class SingleExpOpNode : NodeModelBase
|
||||
{
|
||||
public SingleExpOpNode(IFlowEnvironment environment) : base(environment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//public override async Task<object?> Executing(IDynamicContext context)
|
||||
public override Task<object?> ExecutingAsync(IDynamicContext context)
|
||||
@@ -31,7 +40,7 @@ namespace Serein.NodeFlow.Model
|
||||
object? result = null;
|
||||
if (isChange)
|
||||
{
|
||||
result = newData;
|
||||
result = newData;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -52,7 +61,7 @@ namespace Serein.NodeFlow.Model
|
||||
|
||||
public override Parameterdata[] GetParameterdatas()
|
||||
{
|
||||
return [new Parameterdata{ Expression = Expression}];
|
||||
return [new Parameterdata { Expression = Expression }];
|
||||
}
|
||||
|
||||
|
||||
@@ -60,13 +69,11 @@ namespace Serein.NodeFlow.Model
|
||||
public override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
var node = this;
|
||||
if (node != null)
|
||||
this.Position = nodeInfo.Position;// 加载位置信息
|
||||
node.Guid = nodeInfo.Guid;
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
node.Guid = nodeInfo.Guid;
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
node.Expression = nodeInfo.ParameterData[i].Expression;
|
||||
}
|
||||
node.Expression = nodeInfo.ParameterData[i].Expression;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.0.16</Version>
|
||||
<Version>1.0.17</Version>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -16,7 +16,10 @@
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
|
||||
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
<CompilerGeneratedFilesOutputPath>.\obj\g</CompilerGeneratedFilesOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -63,6 +66,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Serein.Library.MyGenerator\Serein.Library.NodeGenerator.csproj" OutputItemType="Analyzer" />
|
||||
|
||||
<ProjectReference Include="..\Library.Core\Serein.Library.Core.csproj" />
|
||||
<ProjectReference Include="..\Library.Framework\Serein.Library.Framework.csproj" />
|
||||
<ProjectReference Include="..\Library\Serein.Library.csproj" />
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace Serein.NodeFlow.Tool
|
||||
{
|
||||
|
||||
public class ObjDynamicCreateHelper
|
||||
{// 类型缓存,键为类型的唯一名称(可以根据实际需求调整生成方式)
|
||||
{
|
||||
// 类型缓存,键为类型的唯一名称(可以根据实际需求调整生成方式)
|
||||
static Dictionary<string, Type> typeCache = new Dictionary<string, Type>();
|
||||
|
||||
public static object Resolve(Dictionary<string, object> properties, string typeName)
|
||||
|
||||
Reference in New Issue
Block a user