mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
refactor (env) : 修复了运行环境构建顺序,以及同步上下文在内置ioc中传递的问题
This commit is contained in:
@@ -21,25 +21,23 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
private readonly IFlowEnvironment flowEnvironment;
|
||||
private readonly IFlowEnvironmentEvent flowEnvironmentEvent;
|
||||
private readonly FlowLibraryService flowLibraryService;
|
||||
private readonly IFlowLibraryService flowLibraryService;
|
||||
private readonly FlowOperationService flowOperationService;
|
||||
private readonly FlowModelService flowModelService;
|
||||
private readonly UIContextOperation uiContextOperation;
|
||||
private readonly Lazy<UIContextOperation> uiContextOperation;
|
||||
|
||||
public FlowControl(IFlowEnvironment flowEnvironment,
|
||||
IFlowEnvironmentEvent flowEnvironmentEvent,
|
||||
FlowLibraryService flowLibraryService,
|
||||
IFlowLibraryService flowLibraryService,
|
||||
FlowOperationService flowOperationService,
|
||||
FlowModelService flowModelService,
|
||||
UIContextOperation uiContextOperation)
|
||||
FlowModelService flowModelService)
|
||||
{
|
||||
this.flowEnvironment = flowEnvironment;
|
||||
this.flowEnvironmentEvent = flowEnvironmentEvent;
|
||||
this.flowLibraryService = flowLibraryService;
|
||||
this.flowOperationService = flowOperationService;
|
||||
this.flowModelService = flowModelService;
|
||||
this.uiContextOperation = uiContextOperation;
|
||||
|
||||
uiContextOperation = new Lazy<UIContextOperation>(() => flowEnvironment.IOC.Get<UIContextOperation>());
|
||||
contexts = new ObjectPool<IFlowContext>(() => new FlowContext(flowEnvironment), context => context.Reset());
|
||||
flowTaskOptions = new FlowWorkOptions
|
||||
{
|
||||
@@ -340,7 +338,7 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
flowWorkManagement.Exit();
|
||||
}
|
||||
uiContextOperation?.Invoke(() => flowEnvironmentEvent.OnFlowRunComplete(new FlowEventArgs()));
|
||||
uiContextOperation.Value.Invoke(() => flowEnvironmentEvent.OnFlowRunComplete(new FlowEventArgs()));
|
||||
IOC.Reset();
|
||||
GC.Collect();
|
||||
return Task.FromResult(true);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
public FlowEdit(IFlowEnvironment flowEnvironment,
|
||||
IFlowEnvironmentEvent flowEnvironmentEvent,
|
||||
FlowLibraryService flowLibraryManagement,
|
||||
IFlowLibraryService flowLibraryManagement,
|
||||
FlowOperationService flowOperationService,
|
||||
FlowModelService flowModelService,
|
||||
UIContextOperation UIContextOperation,
|
||||
@@ -45,7 +45,7 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
private readonly IFlowEnvironment flowEnvironment;
|
||||
private readonly IFlowEnvironmentEvent flowEnvironmentEvent;
|
||||
private readonly FlowLibraryService flowLibraryManagement;
|
||||
private readonly IFlowLibraryService flowLibraryManagement;
|
||||
private readonly FlowOperationService flowOperationService;
|
||||
private readonly FlowModelService flowModelService;
|
||||
|
||||
|
||||
@@ -49,11 +49,46 @@ namespace Serein.NodeFlow.Env
|
||||
public FlowEnvironment()
|
||||
{
|
||||
ISereinIOC ioc = new SereinIOC();
|
||||
ioc.Register<ISereinIOC>(()=> ioc) // IOC容器接口
|
||||
ioc.Register<ISereinIOC>(() => ioc) // IOC容器接口
|
||||
.Register<IFlowEnvironment>(() => this) // 流程环境接口
|
||||
.Register<IFlowEnvironmentEvent, FlowEnvironmentEvent>() // 流程环境事件接口
|
||||
.Register<IFlowEdit, FlowEdit>() // 流程编辑接口
|
||||
.Register<IFlowControl, FlowControl>() // 流程控制接口
|
||||
.Register<IFlowLibraryService, FlowLibraryService>() // 流程库服务
|
||||
.Register<LocalFlowEnvironment>() // 本地环境
|
||||
.Register<FlowModelService>() // 节点/画布模型服务
|
||||
.Register<FlowCoreGenerateService>() // 代码生成
|
||||
.Register<FlowOperationService>() // 流程操作
|
||||
.Register<NodeMVVMService>() // 节点MVVM服务
|
||||
.Build();
|
||||
|
||||
// 设置JSON解析器
|
||||
if (JsonHelper.Provider is null)
|
||||
{
|
||||
JsonHelper.UseJsonProvider(new NewtonsoftJsonProvider());
|
||||
}
|
||||
|
||||
// 默认使用本地环境
|
||||
localFlowEnvironment = ioc.Get<LocalFlowEnvironment>();
|
||||
currentFlowEnvironmentEvent = ioc.Get<IFlowEnvironmentEvent>();
|
||||
currentFlowEnvironment = localFlowEnvironment;
|
||||
SereinEnv.SetEnv(localFlowEnvironment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供上下文操作进行调用
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
public FlowEnvironment(UIContextOperation operation)
|
||||
{
|
||||
ISereinIOC ioc = new SereinIOC();
|
||||
ioc.Register<ISereinIOC>(() => ioc) // IOC容器接口
|
||||
.Register<IFlowEnvironment>(() => this) // 流程环境接口
|
||||
.Register<IFlowEnvironmentEvent, FlowEnvironmentEvent>() // 流程环境事件接口
|
||||
.Register<IFlowLibraryService, FlowLibraryService>()
|
||||
.Register<UIContextOperation>(() => operation) // 流程环境接口
|
||||
.Register<IFlowEdit, FlowEdit>() // 流程编辑接口
|
||||
.Register<IFlowControl, FlowControl>() // 流程控制接口
|
||||
.Register<LocalFlowEnvironment>() // 本地环境
|
||||
.Register<FlowModelService>() // 节点/画布模型服务
|
||||
.Register<FlowLibraryService>() // 流程库服务
|
||||
@@ -67,56 +102,19 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
JsonHelper.UseJsonProvider(new NewtonsoftJsonProvider());
|
||||
}
|
||||
|
||||
|
||||
// 默认使用本地环境
|
||||
currentFlowEnvironment = ioc.Get<LocalFlowEnvironment>();
|
||||
localFlowEnvironment = ioc.Get<LocalFlowEnvironment>();
|
||||
currentFlowEnvironmentEvent = ioc.Get<IFlowEnvironmentEvent>();
|
||||
SereinEnv.SetEnv(currentFlowEnvironment);
|
||||
currentFlowEnvironment = localFlowEnvironment;
|
||||
SereinEnv.SetEnv(localFlowEnvironment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供上下文操作进行调用
|
||||
/// 管理当前环境
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
public FlowEnvironment(UIContextOperation operation)
|
||||
{
|
||||
ISereinIOC ioc = new SereinIOC();
|
||||
ioc.Register<ISereinIOC>(()=> ioc) // IOC容器接口
|
||||
.Register<UIContextOperation>(() => operation) // 流程环境接口
|
||||
.Register<IFlowEnvironment>(() => this) // 流程环境接口
|
||||
.Register<IFlowEnvironmentEvent, FlowEnvironmentEvent>() // 流程环境事件接口
|
||||
.Register<IFlowEdit, FlowEdit>() // 流程编辑接口
|
||||
.Register<IFlowControl, FlowControl>() // 流程控制接口
|
||||
.Register<LocalFlowEnvironment>() // 本地环境
|
||||
.Register<FlowModelService>() // 节点/画布模型服务
|
||||
.Register<FlowLibraryService>() // 流程库服务
|
||||
.Register<FlowCoreGenerateService>() // 代码生成
|
||||
.Register<FlowOperationService>() // 流程操作
|
||||
.Register<NodeMVVMService>() // 节点MVVM服务
|
||||
.Build();
|
||||
|
||||
// 设置JSON解析器
|
||||
if (JsonHelper.Provider is null)
|
||||
{
|
||||
JsonHelper.UseJsonProvider(new NewtonsoftJsonProvider());
|
||||
}
|
||||
|
||||
// 默认使用本地环境
|
||||
currentFlowEnvironment = ioc.Get<LocalFlowEnvironment>();
|
||||
currentFlowEnvironmentEvent = ioc.Get<IFlowEnvironmentEvent>();
|
||||
SereinEnv.SetEnv(currentFlowEnvironment);
|
||||
}
|
||||
/*
|
||||
/// <summary>
|
||||
/// 本地环境事件
|
||||
/// </summary>
|
||||
private readonly IFlowEnvironmentEvent flowEnvironmentEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 远程环境事件
|
||||
/// </summary>
|
||||
private IFlowEnvironmentEvent remoteFlowEnvironmentEvent;
|
||||
*/
|
||||
private LocalFlowEnvironment localFlowEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// 管理当前环境
|
||||
@@ -129,8 +127,6 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
private IFlowEnvironmentEvent currentFlowEnvironmentEvent;
|
||||
|
||||
|
||||
|
||||
private int _loadingProjectFlag = 0; // 使用原子自增代替锁
|
||||
/// <summary>
|
||||
/// 传入false时,将停止数据通知。传入true时,
|
||||
@@ -159,6 +155,9 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IFlowControl FlowControl => currentFlowEnvironment.FlowControl;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IFlowLibraryService FlowLibraryService => currentFlowEnvironment.FlowLibraryService;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ISereinIOC IOC => currentFlowEnvironment.IOC;
|
||||
@@ -259,12 +258,6 @@ namespace Serein.NodeFlow.Env
|
||||
SetProjectLoadingFlag(true);
|
||||
}
|
||||
|
||||
/* /// <inheritdoc/>
|
||||
public void MonitorObjectNotification(string nodeGuid, object monitorData, MonitorObjectEventArgs.ObjSourceType sourceType)
|
||||
{
|
||||
currentFlowEnvironment.FlowControl.MonitorObjectNotification(nodeGuid, monitorData, sourceType);
|
||||
}*/
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TryUnloadLibrary(string assemblyName)
|
||||
{
|
||||
@@ -312,43 +305,14 @@ namespace Serein.NodeFlow.Env
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
/*
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<bool> StartFlowAsync(string[] canvasGuids)
|
||||
public Task StartRemoteServerAsync(int port = 7525)
|
||||
{
|
||||
return await currentFlowEnvironment.FlowControl.StartFlowAsync(canvasGuids);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<TResult> StartFlowAsync<TResult>(string startNodeGuid)
|
||||
{
|
||||
return await currentFlowEnvironment.FlowControl.StartFlowAsync<TResult>(startNodeGuid);
|
||||
}*/
|
||||
|
||||
/* /// <inheritdoc/>
|
||||
public async Task StartRemoteServerAsync(int port = 7525)
|
||||
{
|
||||
await currentFlowEnvironment.StartRemoteServerAsync(port);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void StopRemoteServer()
|
||||
{
|
||||
currentFlowEnvironment.StopRemoteServer();
|
||||
}*/
|
||||
/*
|
||||
/// <inheritdoc/>
|
||||
public void TerminateFlipflopNode(string nodeGuid)
|
||||
{
|
||||
currentFlowEnvironment.FlowControl.TerminateFlipflopNode(nodeGuid);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void TriggerInterrupt(string nodeGuid, string expression, InterruptTriggerEventArgs.InterruptTriggerType type)
|
||||
{
|
||||
currentFlowEnvironment.FlowControl.TriggerInterrupt(nodeGuid, expression, type);
|
||||
}*/
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SetUIContextOperation(UIContextOperation uiContextOperation)
|
||||
@@ -356,12 +320,6 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
currentFlowEnvironment.SetUIContextOperation(uiContextOperation);
|
||||
}
|
||||
/*
|
||||
/// <inheritdoc/>
|
||||
public void UseExternalIOC(ISereinIOC ioc)
|
||||
{
|
||||
currentFlowEnvironment.FlowControl.UseExternalIOC(ioc);
|
||||
}*/
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TryGetNodeModel(string nodeGuid, out IFlowNode nodeModel)
|
||||
@@ -408,6 +366,7 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
currentFlowEnvironment.LoadAllNativeLibraryOfRuning(path,isRecurrence);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ namespace Serein.NodeFlow.Services
|
||||
public class FlowCoreGenerateService
|
||||
{
|
||||
private readonly FlowModelService flowModelService;
|
||||
private readonly FlowLibraryService flowLibraryService;
|
||||
private readonly IFlowLibraryService flowLibraryService;
|
||||
|
||||
/// <summary>
|
||||
/// 流程代码生成服务
|
||||
/// </summary>
|
||||
/// <param name="flowModelService"></param>
|
||||
/// <param name="flowLibraryService"></param>
|
||||
public FlowCoreGenerateService(FlowModelService flowModelService ,FlowLibraryService flowLibraryService )
|
||||
public FlowCoreGenerateService(FlowModelService flowModelService ,IFlowLibraryService flowLibraryService )
|
||||
{
|
||||
this.flowModelService = flowModelService;
|
||||
this.flowLibraryService = flowLibraryService;
|
||||
|
||||
@@ -9,10 +9,11 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Serein.NodeFlow.Services
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 管理加载在运行环境中的外部程序集
|
||||
/// </summary>
|
||||
public class FlowLibraryService
|
||||
public class FlowLibraryService : IFlowLibraryService
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否加载过基础依赖
|
||||
@@ -49,7 +50,7 @@ namespace Serein.NodeFlow.Services
|
||||
private bool CheckBaseLibrary(string libraryfilePath, out string baseLibraryPath)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(libraryfilePath); // 获取目录路径
|
||||
ArgumentNullException.ThrowIfNullOrWhiteSpace(dir);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(dir);
|
||||
var sereinFlowBaseLibraryPath = Path.Combine(dir, SereinBaseLibrary);
|
||||
if (!Path.Exists(sereinFlowBaseLibraryPath))
|
||||
{
|
||||
|
||||
@@ -7,19 +7,19 @@ using System.Diagnostics.CodeAnalysis;
|
||||
namespace Serein.NodeFlow.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程模型服务
|
||||
/// 流程画布/节点数据实体服务
|
||||
/// </summary>
|
||||
public class FlowModelService
|
||||
{
|
||||
private readonly IFlowEnvironment environment;
|
||||
private readonly FlowLibraryService flowLibraryService;
|
||||
private readonly IFlowLibraryService flowLibraryService;
|
||||
|
||||
/// <summary>
|
||||
/// 流程模型服务构造函数
|
||||
/// </summary>
|
||||
/// <param name="environment"></param>
|
||||
/// <param name="flowLibraryService"></param>
|
||||
public FlowModelService(IFlowEnvironment environment, FlowLibraryService flowLibraryService)
|
||||
public FlowModelService(IFlowEnvironment environment, IFlowLibraryService flowLibraryService)
|
||||
{
|
||||
this.environment = environment;
|
||||
this.flowLibraryService = flowLibraryService;
|
||||
|
||||
@@ -8,6 +8,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程操作
|
||||
/// </summary>
|
||||
internal class FlowOperationService
|
||||
{
|
||||
private readonly ISereinIOC sereinIOC;
|
||||
|
||||
Reference in New Issue
Block a user