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>
70 lines
2.5 KiB
C#
70 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Hi.Common.FileLines;
|
|
using Hi.Common.Messages;
|
|
using Hi.HiNcKits;
|
|
using Hi.MachiningProcs;
|
|
using Hi.MachiningSteps;
|
|
using Hi.NcParsers;
|
|
|
|
namespace Sample.Common;
|
|
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoSessionMessage.cs)]
|
|
/// </remarks>
|
|
public static class DemoSessionMessage
|
|
{
|
|
#region Demo_UseSessionMessageHost
|
|
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
|
|
{
|
|
// Session messages are partitioned by kind into three sinks on LocalProjectService:
|
|
// - ShellProgress: session-level routine / lifecycle messages
|
|
// (session-scoped: null outside BeginSession/EndSession).
|
|
// - NcDiagnosticProgress: NC-pipeline diagnostics, anchored to the NC source sentence.
|
|
// - StepDiagnosticProgress: diagnostics anchored to a motion step.
|
|
|
|
ShellProgress shellProgress = localProjectService.ShellProgress;
|
|
List<IMessage> shellMessages = shellProgress == null
|
|
? new List<IMessage>() : shellProgress.Messages.ToList();
|
|
foreach (IMessage message in shellMessages)
|
|
Console.WriteLine(
|
|
$"Shell [{message.GetSeverity()}] {message.GetId()}: {message.GetNotification()}");
|
|
|
|
foreach (NcDiagnostic diagnostic in
|
|
localProjectService.NcDiagnosticProgress.Diagnostics.ToList())
|
|
{
|
|
var ncLine = diagnostic.SentenceCarrier?.GetSentence()?.FirstIndexedFileLine;
|
|
Console.WriteLine(
|
|
$"NC [{diagnostic.GetSeverity()}] {diagnostic.GetId()}: {diagnostic.GetNotification()}; " +
|
|
$"File: {ncLine?.FilePath}; LineNo: {ncLine?.GetLineNo()}; NC: {ncLine?.Line}");
|
|
}
|
|
|
|
foreach (StepDiagnostic diagnostic in
|
|
localProjectService.StepDiagnosticProgress.Messages.ToList())
|
|
Console.WriteLine(
|
|
$"Step {diagnostic.StepIndex} [{diagnostic.GetSeverity()}] " +
|
|
$"{diagnostic.GetId()}: {diagnostic.GetNotification()}");
|
|
|
|
File.WriteAllLines("output-session-messages.txt",
|
|
shellMessages.Select(m =>
|
|
$"[{m.GetSeverity()}] {m.GetId()}: {m.GetNotification()}"));
|
|
}
|
|
#endregion
|
|
|
|
#region ShowStepPresent
|
|
internal static void ShowStepPresent(
|
|
UserService userEnv, MachiningStep machiningStep)
|
|
{
|
|
foreach (var entry in userEnv.DisplayedStepPresentAccessList)
|
|
{
|
|
var present = entry.Value.Present;
|
|
var valueText = string.Format("{0:" + present.DataFormatString + "}", entry.Value.GetValueFunc.Invoke(machiningStep));
|
|
Console.WriteLine($"{present.ShortName}: {valueText} {present.TailUnitString} ({present.Name} [{entry.Key}])");
|
|
}
|
|
}
|
|
#endregion
|
|
}
|