mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-11 20:19:24 +08:00
使用异步重构了节点执行方法,将触发器节点与其他节点统一。使用Channel代替Tcs更改了信号触发,使其符合异步编程的习惯。增加了节点是否启用勾选框、参数遮罩勾选框,节点右键面板增加中断功能(试验)。增加了选择后被选择的节点的视觉效果。更改平移缩放逻辑,使其更加符合一般的使用习惯。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Serein.WorkBench.tool
|
||||
@@ -6,10 +7,24 @@ namespace Serein.WorkBench.tool
|
||||
/// <summary>
|
||||
/// 可以捕获类库输出的打印输出
|
||||
/// </summary>
|
||||
public class LogTextWriter(Action<string> logAction) : TextWriter
|
||||
public class LogTextWriter : TextWriter
|
||||
{
|
||||
private readonly Action<string> logAction = logAction;
|
||||
private readonly Action<string> logAction;
|
||||
private readonly StringWriter stringWriter = new();
|
||||
private readonly BlockingCollection<string> logQueue = new();
|
||||
private readonly Task logTask;
|
||||
|
||||
// 用于计数的字段
|
||||
private int writeCount = 0;
|
||||
private const int maxWrites = 500;
|
||||
private readonly Action clearTextBoxAction;
|
||||
|
||||
public LogTextWriter(Action<string> logAction, Action clearTextBoxAction)
|
||||
{
|
||||
this.logAction = logAction;
|
||||
this.clearTextBoxAction = clearTextBoxAction;
|
||||
logTask = Task.Run(ProcessLogQueue); // 异步处理日志
|
||||
}
|
||||
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
|
||||
@@ -18,28 +33,60 @@ namespace Serein.WorkBench.tool
|
||||
stringWriter.Write(value);
|
||||
if (value == '\n')
|
||||
{
|
||||
logAction(stringWriter.ToString());
|
||||
stringWriter.GetStringBuilder().Clear();
|
||||
EnqueueLog();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(string? value)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(value)) { return; }
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
stringWriter.Write(value);
|
||||
if (value.Contains('\n'))
|
||||
{
|
||||
logAction(stringWriter.ToString());
|
||||
stringWriter.GetStringBuilder().Clear();
|
||||
EnqueueLog();
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteLine(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) { return; }
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
stringWriter.WriteLine(value);
|
||||
logAction(stringWriter.ToString());
|
||||
EnqueueLog();
|
||||
}
|
||||
|
||||
private void EnqueueLog()
|
||||
{
|
||||
logQueue.Add(stringWriter.ToString());
|
||||
stringWriter.GetStringBuilder().Clear();
|
||||
}
|
||||
|
||||
private async Task ProcessLogQueue()
|
||||
{
|
||||
foreach (var log in logQueue.GetConsumingEnumerable())
|
||||
{
|
||||
// 异步执行日志输出操作
|
||||
await Task.Run(() =>
|
||||
{
|
||||
logAction(log);
|
||||
|
||||
// 计数器增加
|
||||
writeCount++;
|
||||
if (writeCount >= maxWrites)
|
||||
{
|
||||
// 计数器达到50,清空文本框
|
||||
clearTextBoxAction?.Invoke();
|
||||
writeCount = 0; // 重置计数器
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
logQueue.CompleteAdding();
|
||||
logTask.Wait();
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user