优化了接口设计,提供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;
}