From 3d0ed00fbac9600bf5c4b2d1065ddb433f392e7d Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Thu, 12 Dec 2024 20:47:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E4=BA=86=20=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=99=A8=E7=A4=BA=E4=BE=8B=E5=B7=A5=E7=A8=8B=20?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowStartTool/FlowEnv.cs | 55 ++++++++++++++++++++++++++++++++++ FlowStartTool/Program.cs | 64 +++++++++++++++------------------------- 2 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 FlowStartTool/FlowEnv.cs diff --git a/FlowStartTool/FlowEnv.cs b/FlowStartTool/FlowEnv.cs new file mode 100644 index 0000000..fed72d1 --- /dev/null +++ b/FlowStartTool/FlowEnv.cs @@ -0,0 +1,55 @@ +using Serein.Library; +using Serein.Library.Api; +using Serein.Library.Utils; +using Serein.NodeFlow.Env; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Serein.FlowStartTool +{ + internal class FlowEnv + { + public IFlowEnvironment? Env; + 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线程的工具类 + + //if (OperatingSystem.IsLinux()) + //{ + + //} + + // if (uIContextOperation is null) + //{ + // throw new Exception("无法封装 UIContextOperation "); + //} + //else + //{ + // env = new FlowEnvironmentDecorator(uIContextOperation); + // this.window = window; + //} + + Env = new FlowEnvironmentDecorator(uIContextOperation); + Env.LoadProject(new FlowEnvInfo { Project = flowProjectData }, fileDataPath); // 加载项目 + + // 获取环境输出 + Env.OnEnvOut += (infoType, value) => + { + Console.WriteLine($"{DateTime.UtcNow} [{infoType}] : {value}{Environment.NewLine}"); + }; + + await Env.StartRemoteServerAsync(7525); // 启动 web socket 监听远程请求 + + //await Env.StartAsync(); + + IsRuning = false; + } + + } +} diff --git a/FlowStartTool/Program.cs b/FlowStartTool/Program.cs index 1b30d8d..3dcdc74 100644 --- a/FlowStartTool/Program.cs +++ b/FlowStartTool/Program.cs @@ -11,22 +11,28 @@ namespace Serein.FlowStartTool { public class Program { + /// + /// 运行环境 + /// + private static readonly FlowEnv flowEnv = new FlowEnv(); public static void Main(string[] args) { + + + #region 获取文件路径 #if debug args = [@"F:\临时\project\linux\project.dnf"]; #endif - - Console.WriteLine("Hello :) "); Console.WriteLine($"args : {string.Join(" , ", args)}"); + string filePath; string fileDataPath; SereinProjectData? flowProjectData; + string? assembly = Assembly.GetExecutingAssembly()?.Location; + string exeAssemblyDictPath = Path.GetDirectoryName(assembly)!; - string exeAssemblyDictPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - - if (args.Length == 1) + if (args.Length == 1) { filePath = args[0]; fileDataPath = Path.GetDirectoryName(filePath) ?? ""; @@ -35,6 +41,7 @@ namespace Serein.FlowStartTool { Console.WriteLine("loading project file data..."); filePath = Process.GetCurrentProcess().ProcessName + ".dnf"; + fileDataPath = exeAssemblyDictPath; } @@ -45,9 +52,11 @@ namespace Serein.FlowStartTool Console.WriteLine($"Current Name : {filePath}"); Console.WriteLine($"Dict Path : {fileDataPath}"); + #endregion + + #region 读取项目文件内容 try { - // 读取文件内容 string content = File.ReadAllText(filePath); // 读取整个文件内容 flowProjectData = JsonConvert.DeserializeObject(content); if (flowProjectData is null || string.IsNullOrEmpty(fileDataPath)) @@ -60,47 +69,20 @@ namespace Serein.FlowStartTool Console.WriteLine($"读取文件时发生错误:{ex.Message}"); return; } + #endregion - IsRuning = true; - _ = Task.Run(async () => await StartFlow(flowProjectData, fileDataPath)); - while (IsRuning) + #region 加载项目 + _ = Task.Run(async () => await flowEnv.StartFlow(flowProjectData, fileDataPath)); + while (flowEnv.IsRuning) { Console.ReadKey(); - } + } + #endregion + } - public static IFlowEnvironment? Env; - public static bool IsRuning; - public static async Task StartFlow(SereinProjectData flowProjectData, string fileDataPath) - { - - SynchronizationContext? uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息 - var uIContextOperation = new UIContextOperation(uiContext); // 封装一个调用UI线程的工具类 - - //if (OperatingSystem.IsLinux()) - //{ - - //} - - // if (uIContextOperation is null) - //{ - // throw new Exception("无法封装 UIContextOperation "); - //} - //else - //{ - // env = new FlowEnvironmentDecorator(uIContextOperation); - // this.window = window; - //} - - Env = new FlowEnvironmentDecorator(uIContextOperation); - Env.LoadProject(new FlowEnvInfo { Project = flowProjectData }, fileDataPath); // 加载项目 - await Env.StartRemoteServerAsync(7525); // 启动 web socket 监听远程请求 - - //await Env.StartAsync(); - - IsRuning = false; - } + } }