Refactor: Streamline code formatting, introduce cleaner structure, and remove unused Class1. Add .editorconfig for consistent coding style.

This commit is contained in:
2026-02-02 09:45:44 +01:00
parent 7182061a5f
commit c09fe5fd36
16 changed files with 623 additions and 173 deletions

View File

@@ -45,7 +45,8 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
string corr = Guid.NewGuid().ToString("N");
await SelectedChild.SendAsync(
new IpcFrame(IpcKinds.Ping, CorrelationId: corr, Payload: IpcProtocol.ToJsonElement(new { from = "parent" })),
SelectedChild.LifetimeCts.Token);
SelectedChild.LifetimeCts.Token
);
SelectedChild.AddLog($"[parent] -> ping ({corr})");
}
@@ -62,11 +63,9 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
SelectedChild.ProgressPercent = 0;
await SelectedChild.SendAsync(
new IpcFrame(
IpcKinds.StartWork,
CorrelationId: corr,
Payload: IpcProtocol.ToJsonElement(new { steps, delayMs })),
SelectedChild.LifetimeCts.Token);
new IpcFrame(IpcKinds.StartWork, CorrelationId: corr, Payload: IpcProtocol.ToJsonElement(new { steps, delayMs })),
SelectedChild.LifetimeCts.Token
);
SelectedChild.AddLog($"[parent] -> startWork (corr={corr}, steps={steps}, delayMs={delayMs})");
}
@@ -79,9 +78,7 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
}
string corr = SelectedChild.CurrentWorkId ?? Guid.NewGuid().ToString("N");
await SelectedChild.SendAsync(
new IpcFrame(IpcKinds.CancelWork, CorrelationId: corr),
SelectedChild.LifetimeCts.Token);
await SelectedChild.SendAsync(new IpcFrame(IpcKinds.CancelWork, CorrelationId: corr), SelectedChild.LifetimeCts.Token);
SelectedChild.AddLog($"[parent] -> cancelWork (corr={corr})");
}
@@ -94,7 +91,8 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
direction: PipeDirection.InOut,
maxNumberOfServerInstances: 1,
transmissionMode: PipeTransmissionMode.Byte,
options: PipeOptions.Asynchronous);
options: PipeOptions.Asynchronous
);
Task waitForConnection = server.WaitForConnectionAsync(cancellationToken);
@@ -124,11 +122,10 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
string debugDll = Path.Combine(solutionRoot, "ChildWorker", "bin", "Debug", "net10.0", "ChildWorker.dll");
string releaseDll = Path.Combine(solutionRoot, "ChildWorker", "bin", "Release", "net10.0", "ChildWorker.dll");
string childDll = File.Exists(debugDll)
? debugDll
: File.Exists(releaseDll)
? releaseDll
: string.Empty;
string childDll =
File.Exists(debugDll) ? debugDll
: File.Exists(releaseDll) ? releaseDll
: string.Empty;
string fileName;
string arguments;
@@ -150,7 +147,7 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
FileName = fileName,
Arguments = arguments,
UseShellExecute = false,
CreateNoWindow = true
CreateNoWindow = true,
};
var p = new Process { StartInfo = psi, EnableRaisingEvents = true };
@@ -216,46 +213,46 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
switch (frame.Kind)
{
case IpcKinds.Hello:
{
var hello = IpcProtocol.FromJsonElement<HelloPayload>(frame.Payload);
session.AddLog($"[child] hello: id={hello?.ChildId}, pid={hello?.Pid}");
break;
}
{
var hello = IpcProtocol.FromJsonElement<HelloPayload>(frame.Payload);
session.AddLog($"[child] hello: id={hello?.ChildId}, pid={hello?.Pid}");
break;
}
case IpcKinds.Pong:
session.AddLog($"[child] pong ({frame.CorrelationId})");
break;
case IpcKinds.Log:
{
var log = IpcProtocol.FromJsonElement<LogPayload>(frame.Payload);
session.AddLog($"[child:{log?.Level ?? "info"}] {log?.Message}");
break;
}
{
var log = IpcProtocol.FromJsonElement<LogPayload>(frame.Payload);
session.AddLog($"[child:{log?.Level ?? "info"}] {log?.Message}");
break;
}
case IpcKinds.Progress:
{
var prog = IpcProtocol.FromJsonElement<ProgressPayload>(frame.Payload);
if (prog is not null)
{
var prog = IpcProtocol.FromJsonElement<ProgressPayload>(frame.Payload);
if (prog is not null)
{
session.ProgressPercent = prog.Percent;
session.Status = $"Working ({prog.Step}/{prog.Total})";
}
break;
session.ProgressPercent = prog.Percent;
session.Status = $"Working ({prog.Step}/{prog.Total})";
}
break;
}
case IpcKinds.Result:
{
var res = IpcProtocol.FromJsonElement<ResultPayload>(frame.Payload);
session.ProgressPercent = 100;
session.Status = "Idle";
session.AddLog($"[child] result: {res?.Message}");
break;
}
{
var res = IpcProtocol.FromJsonElement<ResultPayload>(frame.Payload);
session.ProgressPercent = 100;
session.Status = "Idle";
session.AddLog($"[child] result: {res?.Message}");
break;
}
case IpcKinds.Error:
{
var err = IpcProtocol.FromJsonElement<ErrorPayload>(frame.Payload);
session.Status = "Error";
session.AddLog($"[child] error: {err?.Message}");
break;
}
{
var err = IpcProtocol.FromJsonElement<ErrorPayload>(frame.Payload);
session.Status = "Error";
session.AddLog($"[child] error: {err?.Message}");
break;
}
default:
session.AddLog($"[child] {frame.Kind} ({frame.CorrelationId})");
break;
@@ -268,15 +265,23 @@ public sealed class MainViewModel : NotifyBase, IAsyncDisposable
foreach (var child in Children.ToArray())
{
try { await child.DisposeAsync(); } catch { }
try
{
await child.DisposeAsync();
}
catch { }
}
_shutdownCts.Dispose();
}
private sealed record HelloPayload(int ChildId, int Pid);
private sealed record LogPayload(string Level, string Message);
private sealed record ProgressPayload(int Step, int Total, double Percent);
private sealed record ResultPayload(string Message);
private sealed record ErrorPayload(string Message);
}