暂停更新 Workbench(WPF)项目

This commit is contained in:
fengjiayi
2024-12-29 21:26:03 +08:00
parent 93d202974f
commit d3312f4989
13 changed files with 214 additions and 125 deletions

View File

@@ -82,9 +82,6 @@ namespace Serein.Library.Api
/// </summary> /// </summary>
void Exit(); void Exit();
/*/// <summary> /*/// <summary>
/// 定时循环触发 /// 定时循环触发
/// </summary> /// </summary>

View File

@@ -296,19 +296,6 @@ namespace Serein.Library.Api
this.Position = position; this.Position = position;
} }
///// <summary>
///// 区域子项节点添加事件参数
///// </summary>
///// <param name="nodeModel">节点对象</param>
///// <param name="isAddInRegion">是否添加在区域中</param>
///// <param name="regeionGuid">区域Guid</param>
//public NodeCreateEventArgs(object nodeModel, bool isAddInRegion, string regeionGuid)
//{
// this.NodeModel = nodeModel;
// this.RegeionGuid = regeionGuid;
// this.IsAddInRegion = isAddInRegion;
//}
/// <summary> /// <summary>
/// 节点Model对象 /// 节点Model对象
/// </summary> /// </summary>
@@ -565,69 +552,11 @@ namespace Serein.Library.Api
#endregion #endregion
/// <summary> /// <summary>
/// 运行环境 /// 流程环境事件接口
/// </summary> /// </summary>
public interface IFlowEnvironment public interface IFlowEnvironmentEvent
{ {
#region
/// <summary>
/// <para>单例模式IOC容器内部维护了一个实例字典默认使用类型的FullName作为Key如果以“接口-实现类”的方式注册那么将使用接口类型的FullName作为Key。</para>
/// <para>当某个类型注册绑定成功后,将不会因为其它地方尝试注册相同类型的行为导致类型被重新创建。</para>
/// </summary>
ISereinIOC IOC { get; }
/// <summary>
/// 环境名称
/// </summary>
string EnvName { get; }
/// <summary>
/// 是否全局中断
/// </summary>
bool IsGlobalInterrupt { get; }
/// <summary>
/// <para>表示是否正在控制远程</para>
/// <para>Local control remote env</para>
/// </summary>
bool IsControlRemoteEnv { get; }
/// <summary>
/// 信息输出等级
/// </summary>
InfoClass InfoClass { get; set; }
/// <summary>
/// 流程运行状态
/// </summary>
RunState FlowState { get; set; }
/// <summary>
/// 全局触发器运行状态
/// </summary>
RunState FlipFlopState { get; set; }
/// <summary>
/// 表示当前环境
/// </summary>
IFlowEnvironment CurrentEnv { get; }
/// <summary>
/// 由运行环境提供的UI线程上下文操作用于类库中需要在UI线程中操作视觉元素的场景
/// </summary>
UIContextOperation UIContextOperation { get; }
#endregion
#region
/// <summary> /// <summary>
/// 加载Dll /// 加载Dll
/// </summary> /// </summary>
@@ -712,6 +641,64 @@ namespace Serein.Library.Api
/// 运行环境输出 /// 运行环境输出
/// </summary> /// </summary>
event EnvOutHandler OnEnvOut; event EnvOutHandler OnEnvOut;
}
/// <summary>
/// 运行环境
/// </summary>
public interface IFlowEnvironment
{
#region
/// <summary>
/// <para>单例模式IOC容器内部维护了一个实例字典默认使用类型的FullName作为Key如果以“接口-实现类”的方式注册那么将使用接口类型的FullName作为Key。</para>
/// <para>当某个类型注册绑定成功后,将不会因为其它地方尝试注册相同类型的行为导致类型被重新创建。</para>
/// </summary>
ISereinIOC IOC { get; }
/// <summary>
/// 环境名称
/// </summary>
string EnvName { get; }
/// <summary>
/// 是否全局中断
/// </summary>
bool IsGlobalInterrupt { get; }
/// <summary>
/// <para>表示是否正在控制远程</para>
/// <para>Local control remote env</para>
/// </summary>
bool IsControlRemoteEnv { get; }
/// <summary>
/// 信息输出等级
/// </summary>
InfoClass InfoClass { get; set; }
/// <summary>
/// 流程运行状态
/// </summary>
RunState FlowState { get; set; }
/// <summary>
/// 全局触发器运行状态
/// </summary>
RunState FlipFlopState { get; set; }
/// <summary>
/// 表示当前环境
/// </summary>
IFlowEnvironment CurrentEnv { get; }
/// <summary>
/// 由运行环境提供的UI线程上下文操作用于类库中需要在UI线程中操作视觉元素的场景
/// </summary>
UIContextOperation UIContextOperation { get; }
#endregion #endregion
#region #region

View File

@@ -9,7 +9,7 @@ namespace Serein.Library
/// <summary> /// <summary>
/// 方法描述信息 /// 方法描述信息
/// </summary> /// </summary>
public class MethodDetailsInfo public class MethodDetailsInfo
{ {
/// <summary> /// <summary>
/// 属于哪个程序集 /// 属于哪个程序集

View File

@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@@ -14,7 +15,43 @@ namespace Serein.Library.Utils
public static class ConvertHelper public static class ConvertHelper
{ {
/// <summary>
/// 对象转JSON文本
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string ToJsonText(this object obj)
{
var jsonText = JsonConvert.SerializeObject(obj, Formatting.Indented);
return jsonText;
}
/// <summary>
/// JSON文本转对象
/// </summary>
/// <typeparam name="T">转换类型</typeparam>
/// <param name="json">JSON文本</param>
/// <returns></returns>
public static T ToJsonObject<T>(this string json)
{
try
{
return JsonConvert.DeserializeObject<T>(json);
}
catch (Exception)
{
return default(T);
}
}
/// <summary>
/// 对象转换(好像没啥用)
/// </summary>
/// <typeparam name="TResult"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
public static TResult ToConvert<TResult>(this object data) public static TResult ToConvert<TResult>(this object data)
{ {
var type = typeof(TResult); var type = typeof(TResult);
@@ -25,6 +62,14 @@ namespace Serein.Library.Utils
return (TResult)data.ToConvert(type); return (TResult)data.ToConvert(type);
} }
/// <summary>
/// 对象转换(好像没啥用)
/// </summary>
/// <param name="data"></param>
/// <param name="type"></param>
/// <returns></returns>
public static object ToConvert(this object data, Type type) public static object ToConvert(this object data, Type type)
{ {
if (type.IsValueType) if (type.IsValueType)
@@ -44,12 +89,24 @@ namespace Serein.Library.Utils
/// <summary>
/// 文本
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T ValueParse<T>(object value) where T : struct, IComparable<T> public static T ValueParse<T>(object value) where T : struct, IComparable<T>
{ {
string valueStr = value.ToString(); string valueStr = value.ToString();
return valueStr.ToValueData<T>() ; return valueStr.ToValueData<T>() ;
} }
/// <summary>
/// 文本转换数值
/// </summary>
/// <param name="type"></param>
/// <param name="value"></param>
/// <returns></returns>
public static object ValueParse(Type type, object value) public static object ValueParse(Type type, object value)
{ {
string valueStr = value.ToString(); string valueStr = value.ToString();
@@ -57,7 +114,13 @@ namespace Serein.Library.Utils
} }
/// <summary>
/// 文本转换值对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="valueStr"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static T ToValueData<T>(this string valueStr) where T : struct, IComparable<T> public static T ToValueData<T>(this string valueStr) where T : struct, IComparable<T>
{ {
if (string.IsNullOrEmpty(valueStr)) if (string.IsNullOrEmpty(valueStr))

View File

@@ -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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -7,8 +10,13 @@ using System.Threading.Tasks;
namespace Serein.Library.Utils namespace Serein.Library.Utils
{ {
/// <summary>
/// 对象转换工具类
/// </summary>
public static class ObjectConvertHelper public static class ObjectConvertHelper
{ {
/// <summary> /// <summary>
/// 父类转为子类 /// 父类转为子类
/// </summary> /// </summary>

View File

@@ -15,7 +15,8 @@ namespace Serein.Library.Utils
/// </summary> /// </summary>
public class UIContextOperation public class UIContextOperation
{ {
private readonly SynchronizationContext context; private SynchronizationContext context;
private readonly Func<SynchronizationContext> getUiContext = null;
static UIContextOperation() static UIContextOperation()
{ {
@@ -42,12 +43,25 @@ namespace Serein.Library.Utils
this.context = synchronizationContext; this.context = synchronizationContext;
} }
/// <summary>
/// 传入UI线程上下文
/// </summary>
/// <param name="synchronizationContext">线程上下文</param>
public UIContextOperation(Func<SynchronizationContext> getUiContext)
{
this.getUiContext = getUiContext;
}
/// <summary> /// <summary>
/// 同步方式进行调用方法 /// 同步方式进行调用方法
/// </summary> /// </summary>
/// <param name="uiAction">要执行的UI操作</param> /// <param name="uiAction">要执行的UI操作</param>
public void Invoke(Action uiAction) public void Invoke(Action uiAction)
{ {
if(context is null && getUiContext != null)
{
context = getUiContext.Invoke();
}
context?.Post(state => context?.Post(state =>
{ {
uiAction?.Invoke(); uiAction?.Invoke();
@@ -61,6 +75,10 @@ namespace Serein.Library.Utils
/// <returns></returns> /// <returns></returns>
public Task InvokeAsync(Action uiAction) public Task InvokeAsync(Action uiAction)
{ {
if (context is null && getUiContext != null)
{
context = getUiContext.Invoke();
}
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
context?.Post(state => context?.Post(state =>

View File

@@ -31,7 +31,7 @@ namespace Serein.NodeFlow.Env
/// <summary> /// <summary>
/// 运行环境 /// 运行环境
/// </summary> /// </summary>
public class FlowEnvironment : IFlowEnvironment, ISereinIOC public class FlowEnvironment : IFlowEnvironment, IFlowEnvironmentEvent , ISereinIOC
{ {
/// <summary> /// <summary>
/// 节点的命名空间 /// 节点的命名空间

View File

@@ -10,14 +10,14 @@ namespace Serein.NodeFlow.Env
/// <summary> /// <summary>
/// 自动管理本地与远程的环境 /// 自动管理本地与远程的环境
/// </summary> /// </summary>
public class FlowEnvironmentDecorator : IFlowEnvironment, ISereinIOC public class FlowEnvironmentDecorator : IFlowEnvironment, IFlowEnvironmentEvent, ISereinIOC
{ {
public FlowEnvironmentDecorator(UIContextOperation uiContextOperation) public FlowEnvironmentDecorator(UIContextOperation uiContextOperation)
{ {
flowEnvironment = new FlowEnvironment(uiContextOperation); flowEnvironment = new FlowEnvironment(uiContextOperation);
// 默认使用本地环境 // 默认使用本地环境
currentFlowEnvironment = flowEnvironment; currentFlowEnvironment = flowEnvironment;
currentFlowEnvironmentEvent = flowEnvironment;
SereinEnv.SetEnv(currentFlowEnvironment); SereinEnv.SetEnv(currentFlowEnvironment);
} }
@@ -31,12 +31,28 @@ namespace Serein.NodeFlow.Env
/// </summary> /// </summary>
private RemoteFlowEnvironment remoteFlowEnvironment; private RemoteFlowEnvironment remoteFlowEnvironment;
/// <summary>
/// 本地环境事件
/// </summary>
private readonly IFlowEnvironmentEvent flowEnvironmentEvent;
/// <summary>
/// 远程环境事件
/// </summary>
private IFlowEnvironmentEvent remoteFlowEnvironmentEvent;
/// <summary> /// <summary>
/// 管理当前环境 /// 管理当前环境
/// </summary> /// </summary>
private IFlowEnvironment currentFlowEnvironment; private IFlowEnvironment currentFlowEnvironment;
/// <summary>
/// 管理当前环境事件
/// </summary>
private IFlowEnvironmentEvent currentFlowEnvironmentEvent;
private int _loadingProjectFlag = 0; // 使用原子自增代替锁 private int _loadingProjectFlag = 0; // 使用原子自增代替锁
@@ -84,14 +100,14 @@ namespace Serein.NodeFlow.Env
public RunState FlipFlopState { get => currentFlowEnvironment.FlipFlopState; set => currentFlowEnvironment.FlipFlopState = value; } public RunState FlipFlopState { get => currentFlowEnvironment.FlipFlopState; set => currentFlowEnvironment.FlipFlopState = value; }
public event LoadDllHandler OnDllLoad { public event LoadDllHandler OnDllLoad {
add { currentFlowEnvironment.OnDllLoad += value; } add { currentFlowEnvironmentEvent.OnDllLoad += value; }
remove { currentFlowEnvironment.OnDllLoad -= value; } remove { currentFlowEnvironmentEvent.OnDllLoad -= value; }
} }
public event ProjectLoadedHandler OnProjectLoaded public event ProjectLoadedHandler OnProjectLoaded
{ {
add { currentFlowEnvironment.OnProjectLoaded += value; } add { currentFlowEnvironmentEvent.OnProjectLoaded += value; }
remove { currentFlowEnvironment.OnProjectLoaded -= value; } remove { currentFlowEnvironmentEvent.OnProjectLoaded -= value; }
} }
/// <summary> /// <summary>
@@ -99,93 +115,93 @@ namespace Serein.NodeFlow.Env
/// </summary> /// </summary>
public event ProjectSavingHandler? OnProjectSaving public event ProjectSavingHandler? OnProjectSaving
{ {
add { currentFlowEnvironment.OnProjectSaving += value; } add { currentFlowEnvironmentEvent.OnProjectSaving += value; }
remove { currentFlowEnvironment.OnProjectSaving -= value; } remove { currentFlowEnvironmentEvent.OnProjectSaving -= value; }
} }
public event NodeConnectChangeHandler OnNodeConnectChange public event NodeConnectChangeHandler OnNodeConnectChange
{ {
add { currentFlowEnvironment.OnNodeConnectChange += value; } add { currentFlowEnvironmentEvent.OnNodeConnectChange += value; }
remove { currentFlowEnvironment.OnNodeConnectChange -= value; } remove { currentFlowEnvironmentEvent.OnNodeConnectChange -= value; }
} }
public event NodeCreateHandler OnNodeCreate public event NodeCreateHandler OnNodeCreate
{ {
add { currentFlowEnvironment.OnNodeCreate += value; } add { currentFlowEnvironmentEvent.OnNodeCreate += value; }
remove { currentFlowEnvironment.OnNodeCreate -= value; } remove { currentFlowEnvironmentEvent.OnNodeCreate -= value; }
} }
public event NodeRemoveHandler OnNodeRemove public event NodeRemoveHandler OnNodeRemove
{ {
add { currentFlowEnvironment.OnNodeRemove += value; } add { currentFlowEnvironmentEvent.OnNodeRemove += value; }
remove { currentFlowEnvironment.OnNodeRemove -= value; } remove { currentFlowEnvironmentEvent.OnNodeRemove -= value; }
} }
public event NodePlaceHandler OnNodePlace public event NodePlaceHandler OnNodePlace
{ {
add { currentFlowEnvironment.OnNodePlace += value; } add { currentFlowEnvironmentEvent.OnNodePlace += value; }
remove { currentFlowEnvironment.OnNodePlace -= value; } remove { currentFlowEnvironmentEvent.OnNodePlace -= value; }
} }
public event NodeTakeOutHandler OnNodeTakeOut public event NodeTakeOutHandler OnNodeTakeOut
{ {
add { currentFlowEnvironment.OnNodeTakeOut += value; } add { currentFlowEnvironmentEvent.OnNodeTakeOut += value; }
remove { currentFlowEnvironment.OnNodeTakeOut -= value; } remove { currentFlowEnvironmentEvent.OnNodeTakeOut -= value; }
} }
public event StartNodeChangeHandler OnStartNodeChange public event StartNodeChangeHandler OnStartNodeChange
{ {
add { currentFlowEnvironment.OnStartNodeChange += value; } add { currentFlowEnvironmentEvent.OnStartNodeChange += value; }
remove { currentFlowEnvironment.OnStartNodeChange -= value; } remove { currentFlowEnvironmentEvent.OnStartNodeChange -= value; }
} }
public event FlowRunCompleteHandler OnFlowRunComplete public event FlowRunCompleteHandler OnFlowRunComplete
{ {
add { currentFlowEnvironment.OnFlowRunComplete += value; } add { currentFlowEnvironmentEvent.OnFlowRunComplete += value; }
remove { currentFlowEnvironment.OnFlowRunComplete -= value; } remove { currentFlowEnvironmentEvent.OnFlowRunComplete -= value; }
} }
public event MonitorObjectChangeHandler OnMonitorObjectChange public event MonitorObjectChangeHandler OnMonitorObjectChange
{ {
add { currentFlowEnvironment.OnMonitorObjectChange += value; } add { currentFlowEnvironmentEvent.OnMonitorObjectChange += value; }
remove { currentFlowEnvironment.OnMonitorObjectChange -= value; } remove { currentFlowEnvironmentEvent.OnMonitorObjectChange -= value; }
} }
public event NodeInterruptStateChangeHandler OnNodeInterruptStateChange public event NodeInterruptStateChangeHandler OnNodeInterruptStateChange
{ {
add { currentFlowEnvironment.OnNodeInterruptStateChange += value; } add { currentFlowEnvironmentEvent.OnNodeInterruptStateChange += value; }
remove { currentFlowEnvironment.OnNodeInterruptStateChange -= value; } remove { currentFlowEnvironmentEvent.OnNodeInterruptStateChange -= value; }
} }
public event ExpInterruptTriggerHandler OnInterruptTrigger public event ExpInterruptTriggerHandler OnInterruptTrigger
{ {
add { currentFlowEnvironment.OnInterruptTrigger += value; } add { currentFlowEnvironmentEvent.OnInterruptTrigger += value; }
remove { currentFlowEnvironment.OnInterruptTrigger -= value; } remove { currentFlowEnvironmentEvent.OnInterruptTrigger -= value; }
} }
public event IOCMembersChangedHandler OnIOCMembersChanged public event IOCMembersChangedHandler OnIOCMembersChanged
{ {
add { currentFlowEnvironment.OnIOCMembersChanged += value; } add { currentFlowEnvironmentEvent.OnIOCMembersChanged += value; }
remove { currentFlowEnvironment.OnIOCMembersChanged -= value; } remove { currentFlowEnvironmentEvent.OnIOCMembersChanged -= value; }
} }
public event NodeLocatedHandler OnNodeLocated public event NodeLocatedHandler OnNodeLocated
{ {
add { currentFlowEnvironment.OnNodeLocated += value; } add { currentFlowEnvironmentEvent.OnNodeLocated += value; }
remove { currentFlowEnvironment.OnNodeLocated -= value; } remove { currentFlowEnvironmentEvent.OnNodeLocated -= value; }
} }
public event NodeMovedHandler OnNodeMoved public event NodeMovedHandler OnNodeMoved
{ {
add { currentFlowEnvironment.OnNodeMoved += value; } add { currentFlowEnvironmentEvent.OnNodeMoved += value; }
remove { currentFlowEnvironment.OnNodeMoved -= value; } remove { currentFlowEnvironmentEvent.OnNodeMoved -= value; }
} }
public event EnvOutHandler OnEnvOut public event EnvOutHandler OnEnvOut
{ {
add { currentFlowEnvironment.OnEnvOut += value; } add { currentFlowEnvironmentEvent.OnEnvOut += value; }
remove { currentFlowEnvironment.OnEnvOut -= value; } remove { currentFlowEnvironmentEvent.OnEnvOut -= value; }
} }

View File

@@ -15,7 +15,7 @@ namespace Serein.NodeFlow.Env
/// <summary> /// <summary>
/// 远程流程环境 /// 远程流程环境
/// </summary> /// </summary>
public class RemoteFlowEnvironment : ChannelFlowTrigger<string>, IFlowEnvironment public class RemoteFlowEnvironment : ChannelFlowTrigger<string>, IFlowEnvironment , IFlowEnvironmentEvent
{ {
/// <summary> /// <summary>
/// 连接到远程环境后切换到的环境接口实现 /// 连接到远程环境后切换到的环境接口实现

View File

@@ -2,6 +2,9 @@
基于WPFDotnet 8的流程可视化编辑器需二次开发。 基于WPFDotnet 8的流程可视化编辑器需二次开发。
不定期在Bilibili个人空间上更新相关的视频。 不定期在Bilibili个人空间上更新相关的视频。
https://space.bilibili.com/33526379 https://space.bilibili.com/33526379
# 暂停更新 Workbench(WPF)项目
* 正在使用 Avalonia UI 重写该项目Library 相关接口可能随时变动,重写进展不定时在个人空间更新。
# 计划任务 2024年10月28日更新 # 计划任务 2024年10月28日更新
* 重新完善远程管理与远程客户端的功能(目前仅支持远程修改节点属性、添加/移除节点、启动流程、停止流程) * 重新完善远程管理与远程客户端的功能(目前仅支持远程修改节点属性、添加/移除节点、启动流程、停止流程)
* 重新完善节点树视图、IOC容器对象视图目前残废版 * 重新完善节点树视图、IOC容器对象视图目前残废版

View File

@@ -9,9 +9,6 @@
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="/Themes/ExplicitDataControl.xaml" />--> <!--<ResourceDictionary Source="/Themes/ExplicitDataControl.xaml" />-->
<ResourceDictionary Source="/Themes/MethodDetailsControl.xaml" /> <ResourceDictionary Source="/Themes/MethodDetailsControl.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type TextBlock }"> <Style TargetType="{x:Type TextBlock }">

View File

@@ -68,7 +68,7 @@
</MenuItem> </MenuItem>
<!--<MenuItem Header="说明"></MenuItem>--> <!--<MenuItem Header="说明"></MenuItem>-->
</Menu> </Menu>
<DockPanel Grid.Row="1" Grid.Column="0" Background="#F5F5F5"> <DockPanel Grid.Row="1" Grid.Column="0" Background="#F5F5F5">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View File

@@ -20,10 +20,10 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<GroupBox x:Name="ActionNodeGroupBox" Grid.Row="0" Header="动作" Margin="5" Visibility="Collapsed"> <GroupBox x:Name="ActionNodeGroupBox" Grid.Row="0" Header="动作" Margin="5" >
<ListBox x:Name="ActionsListBox" Background="#D0F1F9"/> <ListBox x:Name="ActionsListBox" Background="#D0F1F9"/>
</GroupBox> </GroupBox>
<GroupBox x:Name="FlipflopNodeGroupBox" Grid.Row="1" Header="触发器" Margin="5" Visibility="Collapsed"> <GroupBox x:Name="FlipflopNodeGroupBox" Grid.Row="1" Header="触发器" Margin="5">
<ListBox x:Name="FlipflopsListBox" Background="#FACFC1"/> <ListBox x:Name="FlipflopsListBox" Background="#FACFC1"/>
</GroupBox> </GroupBox>
</Grid> </Grid>