2025-05-31 00:20:29 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-07-27 23:46:26 +08:00
|
|
|
|
using Serein.Extend.NewtonsoftJson;
|
2025-05-31 00:20:29 +08:00
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using Serein.NodeFlow.Env;
|
|
|
|
|
|
using Serein.Workbench.Api;
|
|
|
|
|
|
using Serein.Workbench.Services;
|
|
|
|
|
|
using Serein.Workbench.ViewModels;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Serein.Workbench
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 注册ViewModel
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="collection"></param>
|
|
|
|
|
|
public static void AddViewModelServices(this IServiceCollection collection)
|
|
|
|
|
|
{
|
2025-06-02 16:38:37 +08:00
|
|
|
|
collection.AddSingleton<Locator>(); // 视图模型路由
|
2025-05-31 00:20:29 +08:00
|
|
|
|
|
2025-06-02 16:38:37 +08:00
|
|
|
|
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>(); // 画布视图模型
|
2025-05-31 00:20:29 +08:00
|
|
|
|
|
|
|
|
|
|
collection.AddTransient<FlowCanvasViewModel>(); // 画布
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddWorkbenchServices(this IServiceCollection collection)
|
|
|
|
|
|
{
|
|
|
|
|
|
collection.AddSingleton<IFlowEEForwardingService, FlowEEForwardingService>(); // 流程事件管理
|
|
|
|
|
|
collection.AddSingleton<IKeyEventService, KeyEventService>();// 按键事件管理
|
|
|
|
|
|
collection.AddSingleton<IWorkbenchEventService, WorkbenchEventService>(); // 流程事件管理
|
|
|
|
|
|
collection.AddSingleton<FlowProjectService>(); // 项目管理
|
|
|
|
|
|
collection.AddSingleton<FlowNodeService>(); // 节点操作管理
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 注册流程接口相关实例
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="collection"></param>
|
|
|
|
|
|
public static void AddFlowServices(this IServiceCollection collection)
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 创建实例
|
2025-07-27 23:46:26 +08:00
|
|
|
|
JsonHelper.UseJsonProvider(new NewtonsoftJsonProvider());
|
2025-06-02 16:38:37 +08:00
|
|
|
|
Func<SynchronizationContext>? getSyncContext = null;
|
2025-05-31 00:20:29 +08:00
|
|
|
|
Dispatcher.CurrentDispatcher.Invoke(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息
|
|
|
|
|
|
if (uiContext is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
getSyncContext = () => uiContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-07-06 14:34:49 +08:00
|
|
|
|
UIContextOperation? uIContextOperation = new (getSyncContext); // 封装一个调用UI线程的工具类
|
|
|
|
|
|
IFlowEnvironment flowEnvironment = new FlowEnvironment();
|
2025-06-02 16:38:37 +08:00
|
|
|
|
flowEnvironment.SetUIContextOperation(uIContextOperation);
|
2025-07-06 14:34:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-31 00:20:29 +08:00
|
|
|
|
collection.AddSingleton<UIContextOperation>(uIContextOperation); // 注册UI线程操作上下文
|
2025-06-02 16:38:37 +08:00
|
|
|
|
collection.AddSingleton<IFlowEnvironment>(flowEnvironment); // 注册运行环境
|
2025-06-02 19:17:30 +08:00
|
|
|
|
collection.AddSingleton<IFlowEnvironmentEvent>(flowEnvironment.Event); // 注册运行环境事件
|
2025-05-31 00:20:29 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|