mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
重新设计接口类,将流程运行环境和IOC解耦
This commit is contained in:
@@ -22,19 +22,19 @@ namespace Serein.Workbench
|
||||
/// <param name="collection"></param>
|
||||
public static void AddViewModelServices(this IServiceCollection collection)
|
||||
{
|
||||
collection.AddSingleton<Locator>(); // 主窗体
|
||||
collection.AddSingleton<Locator>(); // 视图模型路由
|
||||
|
||||
collection.AddSingleton<MainViewModel>();
|
||||
collection.AddSingleton<MainMenuBarViewModel>();
|
||||
collection.AddSingleton<FlowWorkbenchViewModel>();
|
||||
collection.AddSingleton<BaseNodesViewModel>();
|
||||
collection.AddSingleton<FlowLibrarysViewModel>();
|
||||
collection.AddSingleton<FlowEditViewModel>();
|
||||
collection.AddSingleton<ViewNodeInfoViewModel>();
|
||||
collection.AddSingleton<ViewNodeMethodInfoViewModel>();
|
||||
collection.AddSingleton<MainViewModel>();
|
||||
collection.AddSingleton<MainMenuBarViewModel>(); // 菜单栏视图模型
|
||||
collection.AddSingleton<FlowWorkbenchViewModel>(); // 工作台视图模型
|
||||
collection.AddSingleton<BaseNodesViewModel>(); // 基础节点视图模型
|
||||
collection.AddSingleton<FlowLibrarysViewModel>(); // 流程已加载依赖视图模型
|
||||
collection.AddSingleton<FlowEditViewModel>(); // 流程画布编辑器视图模型
|
||||
collection.AddSingleton<ViewNodeInfoViewModel>(); // 节点信息视图模型
|
||||
collection.AddSingleton<ViewNodeMethodInfoViewModel>(); // 方法信息视图模型
|
||||
collection.AddSingleton<ViewCanvasInfoViewModel>(); // 画布视图模型
|
||||
|
||||
collection.AddTransient<FlowCanvasViewModel>(); // 画布
|
||||
collection.AddTransient<ViewCanvasInfoViewModel>(); // 画布节点树视图
|
||||
}
|
||||
|
||||
public static void AddWorkbenchServices(this IServiceCollection collection)
|
||||
@@ -54,7 +54,7 @@ namespace Serein.Workbench
|
||||
public static void AddFlowServices(this IServiceCollection collection)
|
||||
{
|
||||
#region 创建实例
|
||||
Func<SynchronizationContext> getSyncContext = null;
|
||||
Func<SynchronizationContext>? getSyncContext = null;
|
||||
Dispatcher.CurrentDispatcher.Invoke(() =>
|
||||
{
|
||||
var uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息
|
||||
@@ -62,16 +62,14 @@ namespace Serein.Workbench
|
||||
{
|
||||
getSyncContext = () => uiContext;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
UIContextOperation? uIContextOperation = null;
|
||||
uIContextOperation = new UIContextOperation(getSyncContext); // 封装一个调用UI线程的工具类
|
||||
var flowEnvironmentDecorator = new FlowEnvironmentDecorator();
|
||||
flowEnvironmentDecorator.SetUIContextOperation(uIContextOperation);
|
||||
var flowEnvironment = new FlowEnvironment();
|
||||
flowEnvironment.SetUIContextOperation(uIContextOperation);
|
||||
collection.AddSingleton<UIContextOperation>(uIContextOperation); // 注册UI线程操作上下文
|
||||
collection.AddSingleton<IFlowEnvironment>(flowEnvironmentDecorator); // 注册运行环境
|
||||
collection.AddSingleton<IFlowEnvironmentEvent>(flowEnvironmentDecorator); // 注册运行环境事件
|
||||
collection.AddSingleton<IFlowEnvironment>(flowEnvironment); // 注册运行环境
|
||||
collection.AddSingleton<IFlowEnvironmentEvent>(flowEnvironment); // 注册运行环境事件
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Serein.Workbench.Services
|
||||
private void InitFlowEnvironmentEvent()
|
||||
{
|
||||
flowEnvironmentEvent.OnDllLoad += FlowEnvironment_DllLoadEvent;
|
||||
flowEnvironmentEvent.OnProjectSaving += EnvDecorator_OnProjectSaving;
|
||||
flowEnvironmentEvent.OnProjectSaving += FlowEnvironment_OnProjectSaving;
|
||||
flowEnvironmentEvent.OnProjectLoaded += FlowEnvironment_OnProjectLoaded;
|
||||
flowEnvironmentEvent.OnCanvasCreate += FlowEnvironmentEvent_OnCanvasCreate;
|
||||
flowEnvironmentEvent.OnCanvasRemove += FlowEnvironmentEvent_OnCanvasRemove;
|
||||
@@ -138,8 +138,8 @@ namespace Serein.Workbench.Services
|
||||
flowEnvironmentEvent.OnNodeConnectChange += FlowEnvironment_NodeConnectChangeEvemt;
|
||||
flowEnvironmentEvent.OnNodeCreate += FlowEnvironment_NodeCreateEvent;
|
||||
flowEnvironmentEvent.OnNodeRemove += FlowEnvironment_NodeRemoveEvent;
|
||||
flowEnvironmentEvent.OnNodePlace += EnvDecorator_OnNodePlaceEvent;
|
||||
flowEnvironmentEvent.OnNodeTakeOut += EnvDecorator_OnNodeTakeOutEvent;
|
||||
flowEnvironmentEvent.OnNodePlace += FlowEnvironment_OnNodePlaceEvent;
|
||||
flowEnvironmentEvent.OnNodeTakeOut += FlowEnvironment_OnNodeTakeOutEvent;
|
||||
flowEnvironmentEvent.OnFlowRunComplete += FlowEnvironment_OnFlowRunCompleteEvent;
|
||||
|
||||
flowEnvironmentEvent.OnMonitorObjectChange += FlowEnvironment_OnMonitorObjectChangeEvent;
|
||||
@@ -158,14 +158,14 @@ namespace Serein.Workbench.Services
|
||||
private void ResetFlowEnvironmentEvent()
|
||||
{
|
||||
flowEnvironmentEvent.OnDllLoad -= FlowEnvironment_DllLoadEvent;
|
||||
flowEnvironmentEvent.OnProjectSaving -= EnvDecorator_OnProjectSaving;
|
||||
flowEnvironmentEvent.OnProjectSaving -= FlowEnvironment_OnProjectSaving;
|
||||
flowEnvironmentEvent.OnProjectLoaded -= FlowEnvironment_OnProjectLoaded;
|
||||
flowEnvironmentEvent.OnStartNodeChange -= FlowEnvironment_StartNodeChangeEvent;
|
||||
flowEnvironmentEvent.OnNodeConnectChange -= FlowEnvironment_NodeConnectChangeEvemt;
|
||||
flowEnvironmentEvent.OnNodeCreate -= FlowEnvironment_NodeCreateEvent;
|
||||
flowEnvironmentEvent.OnNodeRemove -= FlowEnvironment_NodeRemoveEvent;
|
||||
flowEnvironmentEvent.OnNodePlace -= EnvDecorator_OnNodePlaceEvent;
|
||||
flowEnvironmentEvent.OnNodeTakeOut -= EnvDecorator_OnNodeTakeOutEvent;
|
||||
flowEnvironmentEvent.OnNodePlace -= FlowEnvironment_OnNodePlaceEvent;
|
||||
flowEnvironmentEvent.OnNodeTakeOut -= FlowEnvironment_OnNodeTakeOutEvent;
|
||||
flowEnvironmentEvent.OnFlowRunComplete -= FlowEnvironment_OnFlowRunCompleteEvent;
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void EnvDecorator_OnProjectSaving(ProjectSavingEventArgs eventArgs)
|
||||
private void FlowEnvironment_OnProjectSaving(ProjectSavingEventArgs eventArgs)
|
||||
{
|
||||
OnProjectSaving?.Invoke(eventArgs);
|
||||
}
|
||||
@@ -289,7 +289,7 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void EnvDecorator_OnNodePlaceEvent(NodePlaceEventArgs eventArgs)
|
||||
private void FlowEnvironment_OnNodePlaceEvent(NodePlaceEventArgs eventArgs)
|
||||
{
|
||||
OnNodePlace?.Invoke(eventArgs);
|
||||
}
|
||||
@@ -298,7 +298,7 @@ namespace Serein.Workbench.Services
|
||||
/// 取出一个节点
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
private void EnvDecorator_OnNodeTakeOutEvent(NodeTakeOutEventArgs eventArgs)
|
||||
private void FlowEnvironment_OnNodeTakeOutEvent(NodeTakeOutEventArgs eventArgs)
|
||||
{
|
||||
OnNodeTakeOut?.Invoke(eventArgs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user