优化了接口设计,提供Event属性。

This commit is contained in:
fengjiayi
2025-06-02 16:45:10 +08:00
parent b1dc641c84
commit c7fbdc1cbb
5 changed files with 27 additions and 34 deletions

View File

@@ -12,48 +12,22 @@ namespace Serein.FlowStartTool
{
internal class FlowEnv
{
public IFlowEnvironment? Env;
public readonly IFlowEnvironment flowEnvironment = new FlowEnvironment();
public bool IsRuning;
public async Task StartFlow(SereinProjectData flowProjectData, string fileDataPath)
{
IsRuning = true;
SynchronizationContext? uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息
var uIContextOperation = new UIContextOperation(uiContext); // 封装一个调用UI线程的工具类
flowEnvironment.SetUIContextOperation(uIContextOperation);
flowEnvironment.LoadProject(new FlowEnvInfo { Project = flowProjectData }, fileDataPath); // 加载项目
//if (OperatingSystem.IsLinux())
//{
//}
// if (uIContextOperation is null)
//{
// throw new Exception("无法封装 UIContextOperation ");
//}
//else
//{
// env = new FlowEnvironment(uIContextOperation);
// this.window = window;
//}
Env = new FlowEnvironment();
Env.SetUIContextOperation(uIContextOperation);
Env.LoadProject(new FlowEnvInfo { Project = flowProjectData }, fileDataPath); // 加载项目
if(Env is IFlowEnvironmentEvent @event)
flowEnvironment.Event.OnEnvOut += (infoType, value) =>
{
// 获取环境输出
@event.OnEnvOut += (infoType, value) =>
{
Console.WriteLine($"{DateTime.Now} [{infoType}] : {value}{Environment.NewLine}");
};
}
await Env.StartRemoteServerAsync(7525); // 启动 web socket 监听远程请求
//await Env.StartAsync();
Console.WriteLine($"{DateTime.Now} [{infoType}] : {value}{Environment.NewLine}");
};
await flowEnvironment.StartRemoteServerAsync(7525); // 启动 web socket 监听远程请求
IsRuning = false;
}

View File

@@ -754,6 +754,12 @@ namespace Serein.Library.Api
/// </summary>
ISereinIOC IOC { get; }
/// <summary>
/// 流程事件接口
/// </summary>
IFlowEnvironmentEvent Event { get; }
/// <summary>
/// 环境名称
/// </summary>

View File

@@ -80,7 +80,11 @@ namespace Serein.NodeFlow.Env
/// <inheritdoc/>
public NodeMVVMManagement NodeMVVMManagement => currentFlowEnvironment.NodeMVVMManagement;
/// <inheritdoc/>
public ISereinIOC IOC => (ISereinIOC)currentFlowEnvironment;
public ISereinIOC IOC => currentFlowEnvironment.IOC;
/// <inheritdoc/>
public IFlowEnvironmentEvent Event => currentFlowEnvironment.Event;
/// <inheritdoc/>
public string EnvName => currentFlowEnvironment.EnvName;

View File

@@ -224,6 +224,11 @@ namespace Serein.NodeFlow.Env
/// </summary>
public IFlowEnvironment CurrentEnv { get => this; }
/// <summary>
/// 流程事件
/// </summary>
public IFlowEnvironmentEvent Event { get => this; }
/// <summary>
/// UI线程操作类
/// </summary>

View File

@@ -65,6 +65,10 @@ namespace Serein.NodeFlow.Env
public ISereinIOC IOC => throw new NotImplementedException();
/// <summary>
/// 流程事件
/// </summary>
public IFlowEnvironmentEvent Event { get => this; }
public string EnvName => LocalFlowEnvironment.SpaceName;
/// <summary>