initial commit

This commit is contained in:
robotics_x1
2026-10-12 15:24:08 +07:00
commit 55228b3772
367 changed files with 162893 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
using System.Text;
using Microsoft.AspNetCore.SignalR;
namespace Lab505.Script;
public class RealtimeWriter : TextWriter
{
private readonly IHubContext<ScriptHub> _hub;
private readonly string? _userGroup; // "user-{uid}" — routes to all tabs of one user
public override Encoding Encoding => Encoding.UTF8;
public RealtimeWriter(IHubContext<ScriptHub> hub, string? userId = null)
{
_hub = hub;
_userGroup = userId is not null ? $"user-{userId}" : null;
}
public override void WriteLine(string? value) => Send(value ?? "");
public override void Write(string? value) => Send(value ?? "");
private void Send(string value)
{
var target = _userGroup is not null
? _hub.Clients.Group(_userGroup)
: _hub.Clients.All; // fallback only (should not happen in practice)
target.SendAsync("scriptLog", value);
}
}