using Microsoft.Extensions.DependencyInjection;
using Serein.Extend.NewtonsoftJson;
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
{
///
/// 注册ViewModel
///
///
public static void AddViewModelServices(this IServiceCollection collection)
{
collection.AddSingleton(); // 视图模型路由
collection.AddSingleton();
collection.AddSingleton(); // 菜单栏视图模型
collection.AddSingleton(); // 工作台视图模型
collection.AddSingleton(); // 基础节点视图模型
collection.AddSingleton(); // 流程已加载依赖视图模型
collection.AddSingleton(); // 流程画布编辑器视图模型
collection.AddSingleton(); // 节点信息视图模型
collection.AddSingleton(); // 方法信息视图模型
collection.AddSingleton(); // 画布视图模型
collection.AddTransient(); // 画布
}
public static void AddWorkbenchServices(this IServiceCollection collection)
{
collection.AddSingleton(); // 流程事件管理
collection.AddSingleton();// 按键事件管理
collection.AddSingleton(); // 流程事件管理
collection.AddSingleton(); // 项目管理
collection.AddSingleton(); // 节点操作管理
}
///
/// 注册流程接口相关实例
///
///
public static void AddFlowServices(this IServiceCollection collection)
{
Func? getSyncContext = null;
UIContextOperation? uIContextOperation = new(getSyncContext); // 封装一个调用UI线程的工具类
IFlowEnvironment flowEnvironment = new FlowEnvironment(uIContextOperation);
Dispatcher.CurrentDispatcher.Invoke(() =>
{
if (SynchronizationContext.Current is { } uiContext)
{
// 在UI线程上获取UI线程上下文信息
getSyncContext = () => uiContext;
flowEnvironment.UIContextOperation.GetUiContext = () => uiContext;
}
});
collection.AddSingleton(uIContextOperation); // 注册UI线程操作上下文
collection.AddSingleton(flowEnvironment); // 注册运行环境
collection.AddSingleton(flowEnvironment.Event); // 注册运行环境事件
collection.AddSingleton(); // 注册工作台环境事件
//#region 创建实例
//Func? getSyncContext = null;
//Dispatcher.CurrentDispatcher.Invoke(() =>
//{
// var uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息
// if (uiContext is not null)
// {
// getSyncContext = () => uiContext;
// }
//});
//UIContextOperation? uIContextOperation = new (getSyncContext); // 封装一个调用UI线程的工具类
//IFlowEnvironment flowEnvironment = new FlowEnvironment();
//flowEnvironment.SetUIContextOperation(uIContextOperation);
//collection.AddSingleton(uIContextOperation); // 注册UI线程操作上下文
//collection.AddSingleton(flowEnvironment); // 注册运行环境
//collection.AddSingleton(flowEnvironment.Event); // 注册运行环境事件
//#endregion
}
}
}