refactor(demos): retarget session-message samples off MixedProgress0 to the three partitioned sinks

DemoUseSessionMessageHost now reads ShellProgress / NcDiagnosticProgress /
StepDiagnosticProgress (severity + id + notification, with the per-kind NC-line
/ step anchors). Drop DemoUseSessionMessageHost2 — its premise (reading
MachiningStep objects out of the mixed message list) dissolves under the
partition; step-data demos live in ShowStepPresent and SessionStepBuilt.
DemoUseMachiningProject's abnormal-message log now subscribes the three sinks'
MessageAdded events (shell via the OnShellMessageAdded app-lifetime bridge).

Part of MixedProgress0 retirement (migration P6). Build x64 green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 12:50:33 +08:00
co-authored by Claude Fable 5
parent 7a4d0d7999
commit 1ba32813bb
2 changed files with 45 additions and 116 deletions
+17 -11
View File
@@ -2,6 +2,7 @@
using Hi.Common.Messages;
using Hi.HiNcKits;
using Hi.MachiningProcs;
using Hi.NcParsers;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
@@ -37,17 +38,22 @@ public static class DemoUseMachiningProject
Console.WriteLine($"Set message event.");
using StreamWriter writer = new StreamWriter("msg.txt");
//show message if something abnormal.
localProjectService.MixedProgress.CollectionItemAdded += pack =>
{
if (pack.Tags.Contains(MessageFlag.Warning.ToString()) ||
pack.Tags.Contains(MessageFlag.Error.ToString()) ||
pack.Tags.Contains(MessageFlag.Exception.ToString()))
{
var sourceCommand = pack.SourceCommand;
writer.WriteLine($"{pack.Message} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
}
};
//show message if something abnormal, from each partitioned message sink:
//shell (session lifecycle), NC diagnostics, and step-anchored diagnostics.
void LogIfAbnormal(IMessage message, ISentenceCarrier sentenceCarrier)
{
var severity = message.GetSeverity();
if (severity != Severity.Warning && severity != Severity.Error)
return;
var ncLine = sentenceCarrier?.GetSentence()?.FirstIndexedFileLine;
writer.WriteLine($"{message.GetNotification()} At \"{ncLine?.FilePath}\" (Line {ncLine?.GetLineNo()}) \"{ncLine?.Line}\"");
}
localProjectService.OnShellMessageAdded += (index, message)
=> LogIfAbnormal(message, null);
localProjectService.NcDiagnosticProgress.MessageAdded += (index, diagnostic)
=> LogIfAbnormal(diagnostic, diagnostic.SentenceCarrier);
localProjectService.StepDiagnosticProgress.MessageAdded += (index, diagnostic)
=> LogIfAbnormal(diagnostic, diagnostic.SentenceCarrier);
Console.WriteLine($"Set machining step event.");
//show MRR.
localProjectService.SessionShell.SessionStepBuilt += (preStep, curStep) =>