From d3312f4989459fe99a85a7dbc627acb130d5e0be Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Sun, 29 Dec 2024 21:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=81=9C=E6=9B=B4=E6=96=B0=20Workbenc?= =?UTF-8?q?h(WPF)=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Api/IDynamicContext.cs | 3 - Library/Api/IFlowEnvironment.cs | 133 ++++++++++----------- Library/FlowNode/MethodDetailsInfo.cs | 2 +- Library/Utils/ConvertHelper.cs | 67 ++++++++++- Library/Utils/ObjectConvertHelper.cs | 10 +- Library/Utils/UIContextOperation.cs | 20 +++- NodeFlow/Env/FlowEnvironment.cs | 2 +- NodeFlow/Env/FlowEnvironmentDecorator.cs | 88 ++++++++------ NodeFlow/Env/RemoteFlowEnvironment.cs | 2 +- README.md | 3 + WorkBench/App.xaml | 3 - WorkBench/MainWindow.xaml | 2 +- WorkBench/Node/View/DllControlControl.xaml | 4 +- 13 files changed, 214 insertions(+), 125 deletions(-) diff --git a/Library/Api/IDynamicContext.cs b/Library/Api/IDynamicContext.cs index 8088ae2..9add8da 100644 --- a/Library/Api/IDynamicContext.cs +++ b/Library/Api/IDynamicContext.cs @@ -82,9 +82,6 @@ namespace Serein.Library.Api /// void Exit(); - - - /*/// /// 定时循环触发 /// diff --git a/Library/Api/IFlowEnvironment.cs b/Library/Api/IFlowEnvironment.cs index 2b45879..84f6091 100644 --- a/Library/Api/IFlowEnvironment.cs +++ b/Library/Api/IFlowEnvironment.cs @@ -296,19 +296,6 @@ namespace Serein.Library.Api this.Position = position; } - ///// - ///// 区域子项节点添加事件参数 - ///// - ///// 节点对象 - ///// 是否添加在区域中 - ///// 区域Guid - //public NodeCreateEventArgs(object nodeModel, bool isAddInRegion, string regeionGuid) - //{ - // this.NodeModel = nodeModel; - // this.RegeionGuid = regeionGuid; - // this.IsAddInRegion = isAddInRegion; - //} - /// /// 节点Model对象 /// @@ -565,69 +552,11 @@ namespace Serein.Library.Api #endregion - - /// - /// 运行环境 + /// 流程环境事件接口 /// - public interface IFlowEnvironment + public interface IFlowEnvironmentEvent { - #region 属性 - - - /// - /// 单例模式IOC容器,内部维护了一个实例字典,默认使用类型的FullName作为Key,如果以“接口-实现类”的方式注册,那么将使用接口类型的FullName作为Key。 - /// 当某个类型注册绑定成功后,将不会因为其它地方尝试注册相同类型的行为导致类型被重新创建。 - /// - ISereinIOC IOC { get; } - - - - /// - /// 环境名称 - /// - string EnvName { get; } - - /// - /// 是否全局中断 - /// - bool IsGlobalInterrupt { get; } - - /// - /// 表示是否正在控制远程 - /// Local control remote env - /// - bool IsControlRemoteEnv { get; } - - /// - /// 信息输出等级 - /// - InfoClass InfoClass { get; set; } - - /// - /// 流程运行状态 - /// - RunState FlowState { get; set; } - - /// - /// 全局触发器运行状态 - /// - RunState FlipFlopState { get; set; } - - /// - /// 表示当前环境 - /// - IFlowEnvironment CurrentEnv { get; } - - /// - /// 由运行环境提供的UI线程上下文操作,用于类库中需要在UI线程中操作视觉元素的场景 - /// - UIContextOperation UIContextOperation { get; } - - #endregion - - #region 事件 - /// /// 加载Dll /// @@ -712,6 +641,64 @@ namespace Serein.Library.Api /// 运行环境输出 /// event EnvOutHandler OnEnvOut; + } + + + /// + /// 运行环境 + /// + public interface IFlowEnvironment + { + #region 属性 + + + /// + /// 单例模式IOC容器,内部维护了一个实例字典,默认使用类型的FullName作为Key,如果以“接口-实现类”的方式注册,那么将使用接口类型的FullName作为Key。 + /// 当某个类型注册绑定成功后,将不会因为其它地方尝试注册相同类型的行为导致类型被重新创建。 + /// + ISereinIOC IOC { get; } + + /// + /// 环境名称 + /// + string EnvName { get; } + + /// + /// 是否全局中断 + /// + bool IsGlobalInterrupt { get; } + + /// + /// 表示是否正在控制远程 + /// Local control remote env + /// + bool IsControlRemoteEnv { get; } + + /// + /// 信息输出等级 + /// + InfoClass InfoClass { get; set; } + + /// + /// 流程运行状态 + /// + RunState FlowState { get; set; } + + /// + /// 全局触发器运行状态 + /// + RunState FlipFlopState { get; set; } + + /// + /// 表示当前环境 + /// + IFlowEnvironment CurrentEnv { get; } + + /// + /// 由运行环境提供的UI线程上下文操作,用于类库中需要在UI线程中操作视觉元素的场景 + /// + UIContextOperation UIContextOperation { get; } + #endregion #region 基本接口 diff --git a/Library/FlowNode/MethodDetailsInfo.cs b/Library/FlowNode/MethodDetailsInfo.cs index 2d484ea..64bb13f 100644 --- a/Library/FlowNode/MethodDetailsInfo.cs +++ b/Library/FlowNode/MethodDetailsInfo.cs @@ -9,7 +9,7 @@ namespace Serein.Library /// /// 方法描述信息 /// - public class MethodDetailsInfo + public class MethodDetailsInfo { /// /// 属于哪个程序集 diff --git a/Library/Utils/ConvertHelper.cs b/Library/Utils/ConvertHelper.cs index 85e51a2..8dca4b8 100644 --- a/Library/Utils/ConvertHelper.cs +++ b/Library/Utils/ConvertHelper.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -14,7 +15,43 @@ namespace Serein.Library.Utils public static class ConvertHelper { + /// + /// 对象转JSON文本 + /// + /// + /// + public static string ToJsonText(this object obj) + { + var jsonText = JsonConvert.SerializeObject(obj, Formatting.Indented); + return jsonText; + } + /// + /// JSON文本转对象 + /// + /// 转换类型 + /// JSON文本 + /// + public static T ToJsonObject(this string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (Exception) + { + return default(T); + } + } + + + + /// + /// 对象转换(好像没啥用) + /// + /// + /// + /// public static TResult ToConvert(this object data) { var type = typeof(TResult); @@ -25,6 +62,14 @@ namespace Serein.Library.Utils return (TResult)data.ToConvert(type); } + + + /// + /// 对象转换(好像没啥用) + /// + /// + /// + /// public static object ToConvert(this object data, Type type) { if (type.IsValueType) @@ -44,12 +89,24 @@ namespace Serein.Library.Utils + /// + /// 文本 + /// + /// + /// + /// public static T ValueParse(object value) where T : struct, IComparable { string valueStr = value.ToString(); return valueStr.ToValueData() ; } + /// + /// 文本转换数值 + /// + /// + /// + /// public static object ValueParse(Type type, object value) { string valueStr = value.ToString(); @@ -57,7 +114,13 @@ namespace Serein.Library.Utils } - + /// + /// 文本转换值对象 + /// + /// + /// + /// + /// public static T ToValueData(this string valueStr) where T : struct, IComparable { if (string.IsNullOrEmpty(valueStr)) diff --git a/Library/Utils/ObjectConvertHelper.cs b/Library/Utils/ObjectConvertHelper.cs index 2aa566d..8892cc6 100644 --- a/Library/Utils/ObjectConvertHelper.cs +++ b/Library/Utils/ObjectConvertHelper.cs @@ -1,4 +1,7 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -7,8 +10,13 @@ using System.Threading.Tasks; namespace Serein.Library.Utils { + /// + /// 对象转换工具类 + /// public static class ObjectConvertHelper { + + /// /// 父类转为子类 /// diff --git a/Library/Utils/UIContextOperation.cs b/Library/Utils/UIContextOperation.cs index 74f7c9a..53d4b28 100644 --- a/Library/Utils/UIContextOperation.cs +++ b/Library/Utils/UIContextOperation.cs @@ -15,7 +15,8 @@ namespace Serein.Library.Utils /// public class UIContextOperation { - private readonly SynchronizationContext context; + private SynchronizationContext context; + private readonly Func getUiContext = null; static UIContextOperation() { @@ -42,12 +43,25 @@ namespace Serein.Library.Utils this.context = synchronizationContext; } + /// + /// 传入UI线程上下文 + /// + /// 线程上下文 + public UIContextOperation(Func getUiContext) + { + this.getUiContext = getUiContext; + } + /// /// 同步方式进行调用方法 /// /// 要执行的UI操作 public void Invoke(Action uiAction) { + if(context is null && getUiContext != null) + { + context = getUiContext.Invoke(); + } context?.Post(state => { uiAction?.Invoke(); @@ -61,6 +75,10 @@ namespace Serein.Library.Utils /// public Task InvokeAsync(Action uiAction) { + if (context is null && getUiContext != null) + { + context = getUiContext.Invoke(); + } var tcs = new TaskCompletionSource(); context?.Post(state => diff --git a/NodeFlow/Env/FlowEnvironment.cs b/NodeFlow/Env/FlowEnvironment.cs index 23e4e23..25e570b 100644 --- a/NodeFlow/Env/FlowEnvironment.cs +++ b/NodeFlow/Env/FlowEnvironment.cs @@ -31,7 +31,7 @@ namespace Serein.NodeFlow.Env /// /// 运行环境 /// - public class FlowEnvironment : IFlowEnvironment, ISereinIOC + public class FlowEnvironment : IFlowEnvironment, IFlowEnvironmentEvent , ISereinIOC { /// /// 节点的命名空间 diff --git a/NodeFlow/Env/FlowEnvironmentDecorator.cs b/NodeFlow/Env/FlowEnvironmentDecorator.cs index 2a8685a..bb0d442 100644 --- a/NodeFlow/Env/FlowEnvironmentDecorator.cs +++ b/NodeFlow/Env/FlowEnvironmentDecorator.cs @@ -10,14 +10,14 @@ namespace Serein.NodeFlow.Env /// /// 自动管理本地与远程的环境 /// - public class FlowEnvironmentDecorator : IFlowEnvironment, ISereinIOC + public class FlowEnvironmentDecorator : IFlowEnvironment, IFlowEnvironmentEvent, ISereinIOC { public FlowEnvironmentDecorator(UIContextOperation uiContextOperation) { flowEnvironment = new FlowEnvironment(uiContextOperation); // 默认使用本地环境 currentFlowEnvironment = flowEnvironment; - + currentFlowEnvironmentEvent = flowEnvironment; SereinEnv.SetEnv(currentFlowEnvironment); } @@ -31,12 +31,28 @@ namespace Serein.NodeFlow.Env /// private RemoteFlowEnvironment remoteFlowEnvironment; + /// + /// 本地环境事件 + /// + private readonly IFlowEnvironmentEvent flowEnvironmentEvent; + + /// + /// 远程环境事件 + /// + private IFlowEnvironmentEvent remoteFlowEnvironmentEvent; + + /// /// 管理当前环境 /// private IFlowEnvironment currentFlowEnvironment; + /// + /// 管理当前环境事件 + /// + private IFlowEnvironmentEvent currentFlowEnvironmentEvent; + private int _loadingProjectFlag = 0; // 使用原子自增代替锁 @@ -84,14 +100,14 @@ namespace Serein.NodeFlow.Env public RunState FlipFlopState { get => currentFlowEnvironment.FlipFlopState; set => currentFlowEnvironment.FlipFlopState = value; } public event LoadDllHandler OnDllLoad { - add { currentFlowEnvironment.OnDllLoad += value; } - remove { currentFlowEnvironment.OnDllLoad -= value; } + add { currentFlowEnvironmentEvent.OnDllLoad += value; } + remove { currentFlowEnvironmentEvent.OnDllLoad -= value; } } public event ProjectLoadedHandler OnProjectLoaded { - add { currentFlowEnvironment.OnProjectLoaded += value; } - remove { currentFlowEnvironment.OnProjectLoaded -= value; } + add { currentFlowEnvironmentEvent.OnProjectLoaded += value; } + remove { currentFlowEnvironmentEvent.OnProjectLoaded -= value; } } /// @@ -99,93 +115,93 @@ namespace Serein.NodeFlow.Env /// public event ProjectSavingHandler? OnProjectSaving { - add { currentFlowEnvironment.OnProjectSaving += value; } - remove { currentFlowEnvironment.OnProjectSaving -= value; } + add { currentFlowEnvironmentEvent.OnProjectSaving += value; } + remove { currentFlowEnvironmentEvent.OnProjectSaving -= value; } } public event NodeConnectChangeHandler OnNodeConnectChange { - add { currentFlowEnvironment.OnNodeConnectChange += value; } - remove { currentFlowEnvironment.OnNodeConnectChange -= value; } + add { currentFlowEnvironmentEvent.OnNodeConnectChange += value; } + remove { currentFlowEnvironmentEvent.OnNodeConnectChange -= value; } } public event NodeCreateHandler OnNodeCreate { - add { currentFlowEnvironment.OnNodeCreate += value; } - remove { currentFlowEnvironment.OnNodeCreate -= value; } + add { currentFlowEnvironmentEvent.OnNodeCreate += value; } + remove { currentFlowEnvironmentEvent.OnNodeCreate -= value; } } public event NodeRemoveHandler OnNodeRemove { - add { currentFlowEnvironment.OnNodeRemove += value; } - remove { currentFlowEnvironment.OnNodeRemove -= value; } + add { currentFlowEnvironmentEvent.OnNodeRemove += value; } + remove { currentFlowEnvironmentEvent.OnNodeRemove -= value; } } public event NodePlaceHandler OnNodePlace { - add { currentFlowEnvironment.OnNodePlace += value; } - remove { currentFlowEnvironment.OnNodePlace -= value; } + add { currentFlowEnvironmentEvent.OnNodePlace += value; } + remove { currentFlowEnvironmentEvent.OnNodePlace -= value; } } public event NodeTakeOutHandler OnNodeTakeOut { - add { currentFlowEnvironment.OnNodeTakeOut += value; } - remove { currentFlowEnvironment.OnNodeTakeOut -= value; } + add { currentFlowEnvironmentEvent.OnNodeTakeOut += value; } + remove { currentFlowEnvironmentEvent.OnNodeTakeOut -= value; } } public event StartNodeChangeHandler OnStartNodeChange { - add { currentFlowEnvironment.OnStartNodeChange += value; } - remove { currentFlowEnvironment.OnStartNodeChange -= value; } + add { currentFlowEnvironmentEvent.OnStartNodeChange += value; } + remove { currentFlowEnvironmentEvent.OnStartNodeChange -= value; } } public event FlowRunCompleteHandler OnFlowRunComplete { - add { currentFlowEnvironment.OnFlowRunComplete += value; } - remove { currentFlowEnvironment.OnFlowRunComplete -= value; } + add { currentFlowEnvironmentEvent.OnFlowRunComplete += value; } + remove { currentFlowEnvironmentEvent.OnFlowRunComplete -= value; } } public event MonitorObjectChangeHandler OnMonitorObjectChange { - add { currentFlowEnvironment.OnMonitorObjectChange += value; } - remove { currentFlowEnvironment.OnMonitorObjectChange -= value; } + add { currentFlowEnvironmentEvent.OnMonitorObjectChange += value; } + remove { currentFlowEnvironmentEvent.OnMonitorObjectChange -= value; } } public event NodeInterruptStateChangeHandler OnNodeInterruptStateChange { - add { currentFlowEnvironment.OnNodeInterruptStateChange += value; } - remove { currentFlowEnvironment.OnNodeInterruptStateChange -= value; } + add { currentFlowEnvironmentEvent.OnNodeInterruptStateChange += value; } + remove { currentFlowEnvironmentEvent.OnNodeInterruptStateChange -= value; } } public event ExpInterruptTriggerHandler OnInterruptTrigger { - add { currentFlowEnvironment.OnInterruptTrigger += value; } - remove { currentFlowEnvironment.OnInterruptTrigger -= value; } + add { currentFlowEnvironmentEvent.OnInterruptTrigger += value; } + remove { currentFlowEnvironmentEvent.OnInterruptTrigger -= value; } } public event IOCMembersChangedHandler OnIOCMembersChanged { - add { currentFlowEnvironment.OnIOCMembersChanged += value; } - remove { currentFlowEnvironment.OnIOCMembersChanged -= value; } + add { currentFlowEnvironmentEvent.OnIOCMembersChanged += value; } + remove { currentFlowEnvironmentEvent.OnIOCMembersChanged -= value; } } public event NodeLocatedHandler OnNodeLocated { - add { currentFlowEnvironment.OnNodeLocated += value; } - remove { currentFlowEnvironment.OnNodeLocated -= value; } + add { currentFlowEnvironmentEvent.OnNodeLocated += value; } + remove { currentFlowEnvironmentEvent.OnNodeLocated -= value; } } public event NodeMovedHandler OnNodeMoved { - add { currentFlowEnvironment.OnNodeMoved += value; } - remove { currentFlowEnvironment.OnNodeMoved -= value; } + add { currentFlowEnvironmentEvent.OnNodeMoved += value; } + remove { currentFlowEnvironmentEvent.OnNodeMoved -= value; } } public event EnvOutHandler OnEnvOut { - add { currentFlowEnvironment.OnEnvOut += value; } - remove { currentFlowEnvironment.OnEnvOut -= value; } + add { currentFlowEnvironmentEvent.OnEnvOut += value; } + remove { currentFlowEnvironmentEvent.OnEnvOut -= value; } } diff --git a/NodeFlow/Env/RemoteFlowEnvironment.cs b/NodeFlow/Env/RemoteFlowEnvironment.cs index 13878d6..c9da35f 100644 --- a/NodeFlow/Env/RemoteFlowEnvironment.cs +++ b/NodeFlow/Env/RemoteFlowEnvironment.cs @@ -15,7 +15,7 @@ namespace Serein.NodeFlow.Env /// /// 远程流程环境 /// - public class RemoteFlowEnvironment : ChannelFlowTrigger, IFlowEnvironment + public class RemoteFlowEnvironment : ChannelFlowTrigger, IFlowEnvironment , IFlowEnvironmentEvent { /// /// 连接到远程环境后切换到的环境接口实现 diff --git a/README.md b/README.md index 102143f..40bde3b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ 基于WPF(Dotnet 8)的流程可视化编辑器,需二次开发。 不定期在Bilibili个人空间上更新相关的视频。 https://space.bilibili.com/33526379 + +# 暂停更新 Workbench(WPF)项目 +* 正在使用 Avalonia UI 重写该项目,Library 相关接口可能随时变动,重写进展不定时在个人空间更新。 # 计划任务 2024年10月28日更新 * 重新完善远程管理与远程客户端的功能(目前仅支持远程修改节点属性、添加/移除节点、启动流程、停止流程) * 重新完善节点树视图、IOC容器对象视图(目前残废版) diff --git a/WorkBench/App.xaml b/WorkBench/App.xaml index fe41f68..baa41de 100644 --- a/WorkBench/App.xaml +++ b/WorkBench/App.xaml @@ -9,9 +9,6 @@ - - -