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:
parent
7a4d0d7999
commit
1ba32813bb
@ -2,17 +2,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using Hi.Common;
|
|
||||||
using Hi.Common.FileLines;
|
using Hi.Common.FileLines;
|
||||||
using Hi.Common.Messages;
|
using Hi.Common.Messages;
|
||||||
using Hi.Geom;
|
|
||||||
using Hi.HiNcKits;
|
using Hi.HiNcKits;
|
||||||
using Hi.MachiningProcs;
|
using Hi.MachiningProcs;
|
||||||
using Hi.MachiningSteps;
|
using Hi.MachiningSteps;
|
||||||
using Hi.Mech;
|
using Hi.NcParsers;
|
||||||
using Hi.Mech.Topo;
|
|
||||||
using Hi.Numerical;
|
|
||||||
|
|
||||||
namespace Sample.Common;
|
namespace Sample.Common;
|
||||||
|
|
||||||
@ -25,112 +20,40 @@ public static class DemoSessionMessage
|
|||||||
#region Demo_UseSessionMessageHost
|
#region Demo_UseSessionMessageHost
|
||||||
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
|
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
|
||||||
{
|
{
|
||||||
MixedProgress0 sessionMessageHost = localProjectService.MixedProgress;
|
// 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.
|
||||||
|
|
||||||
MixedProgress0.FilterFlag filterFlags =
|
ShellProgress shellProgress = localProjectService.ShellProgress;
|
||||||
MixedProgress0.FilterFlag.NC |
|
List<IMessage> shellMessages = shellProgress == null
|
||||||
MixedProgress0.FilterFlag.Progress |
|
? new List<IMessage>() : shellProgress.Messages.ToList();
|
||||||
MixedProgress0.FilterFlag.Error;
|
foreach (IMessage message in shellMessages)
|
||||||
string filterText = null;
|
Console.WriteLine(
|
||||||
var filteredSessionMessageList = sessionMessageHost
|
$"Shell [{message.GetSeverity()}] {message.GetId()}: {message.GetNotification()}");
|
||||||
.GetFliteredList(filterFlags, filterText);
|
|
||||||
|
|
||||||
foreach (var sessionMessage in filteredSessionMessageList)
|
foreach (NcDiagnostic diagnostic in
|
||||||
|
localProjectService.NcDiagnosticProgress.Diagnostics.ToList())
|
||||||
{
|
{
|
||||||
//M.I.: Message Index.
|
var ncLine = diagnostic.SentenceCarrier?.GetSentence()?.FirstIndexedFileLine;
|
||||||
Console.Write($"M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}");
|
Console.WriteLine(
|
||||||
|
$"NC [{diagnostic.GetSeverity()}] {diagnostic.GetId()}: {diagnostic.GetNotification()}; " +
|
||||||
// For SessionMessageHost.FilterFlag.NC
|
$"File: {ncLine?.FilePath}; LineNo: {ncLine?.GetLineNo()}; NC: {ncLine?.Line}");
|
||||||
var nc = sessionMessage.DirectInstantSourceCommand;
|
|
||||||
if (nc != null)
|
|
||||||
Console.Write($"Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; ");
|
|
||||||
|
|
||||||
// For SessionMessageHost.FilterFlag.Progress or Error.
|
|
||||||
if (sessionMessage.Data is IMessage message)
|
|
||||||
Console.WriteLine($"Message/NC: {message.GetNotification()}");
|
|
||||||
var exception = sessionMessage.Exception;
|
|
||||||
if (exception != null)
|
|
||||||
Console.WriteLine($"Message/NC: {exception.Message}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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",
|
File.WriteAllLines("output-session-messages.txt",
|
||||||
filteredSessionMessageList.Select(m =>
|
shellMessages.Select(m =>
|
||||||
$"Msg[{m.Index}][{m.MessageRoleText}]: {m}"));
|
$"[{m.GetSeverity()}] {m.GetId()}: {m.GetNotification()}"));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal static void DemoUseSessionMessageHost2(LocalProjectService localProjectService)
|
|
||||||
{
|
|
||||||
MixedProgress0 sessionMessageHost = localProjectService.MixedProgress;
|
|
||||||
IMachiningChain machiningChain = localProjectService.MachiningChain;
|
|
||||||
|
|
||||||
PresentAttribute mrrPresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.Mrr_mm3ds)).GetCustomAttribute<PresentAttribute>();
|
|
||||||
string mrrUnit = mrrPresent?.TailUnitString;
|
|
||||||
string mrrFormat = mrrPresent?.DataFormatString;
|
|
||||||
PresentAttribute torquePresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.AvgAbsTorque_Nm)).GetCustomAttribute<PresentAttribute>();
|
|
||||||
string torqueUnit = torquePresent?.TailUnitString;
|
|
||||||
string torqueFormat = torquePresent?.DataFormatString;
|
|
||||||
|
|
||||||
MixedProgress0.FilterFlag filterFlags =
|
|
||||||
MixedProgress0.FilterFlag.Step |
|
|
||||||
MixedProgress0.FilterFlag.NC |
|
|
||||||
MixedProgress0.FilterFlag.Progress |
|
|
||||||
MixedProgress0.FilterFlag.Error;
|
|
||||||
string filterText = null;
|
|
||||||
var filteredSessionMessageList = sessionMessageHost
|
|
||||||
.GetFliteredList(filterFlags, filterText);
|
|
||||||
|
|
||||||
foreach (var sessionMessage in filteredSessionMessageList)
|
|
||||||
{
|
|
||||||
//M.I.: Message Index.
|
|
||||||
Console.Write($"M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}");
|
|
||||||
|
|
||||||
// For SessionMessageHost.FilterFlag.Step
|
|
||||||
var step = sessionMessage.MachiningStep;
|
|
||||||
if (step != null)
|
|
||||||
{
|
|
||||||
string[] machineCoordinateValueTexts = GetMachineCoordinateValueTexts(step, machiningChain);
|
|
||||||
var machineCoordinatesText = string.Join("; ", Enumerable.Range(0, machiningChain.McCodes.Length)
|
|
||||||
.Select(i => $"MC.{machiningChain.McCodes[i]}: {machineCoordinateValueTexts[i]}"));
|
|
||||||
Console.Write($"Time: {step.EndTimecode:G}; MRR = {step.Mrr_mm3ds.ToString(mrrFormat)} {mrrUnit}; Torque = {step.AvgAbsTorque_Nm?.ToString(torqueFormat)} {torqueUnit}; {machineCoordinatesText}; ");
|
|
||||||
var nc_ = sessionMessageHost.GetSourceCommand(sessionMessage);
|
|
||||||
Console.WriteLine($"Message/NC: {nc_.Line}; File: {nc_.FilePath}; LineNo: {nc_.GetLineNo()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// For SessionMessageHost.FilterFlag.NC
|
|
||||||
var nc = sessionMessage.DirectInstantSourceCommand;
|
|
||||||
if (nc != null)
|
|
||||||
{
|
|
||||||
Console.Write($"Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; ");
|
|
||||||
if (nc is HardNcLine ncLine)
|
|
||||||
Console.WriteLine($"T: {ncLine.T}; S: {ncLine.S}; F: {ncLine.F}; NC-Flags: {ncLine.FlagsText}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// For SessionMessageHost.FilterFlag.Progress or Error.
|
|
||||||
if (sessionMessage.Data is IMessage message)
|
|
||||||
Console.WriteLine($"Message/NC: {message.GetNotification()}");
|
|
||||||
var exception = sessionMessage.Exception;
|
|
||||||
if (exception != null)
|
|
||||||
Console.WriteLine($"Message/NC: {exception.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static string[] GetMachineCoordinateValueTexts(MachiningStep step, IMachiningChain machiningChain)
|
|
||||||
{
|
|
||||||
var mcTransformers = machiningChain.McTransformers;
|
|
||||||
string[] dst = new string[mcTransformers.Length];
|
|
||||||
if (mcTransformers != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < mcTransformers.Length; i++)
|
|
||||||
{
|
|
||||||
if (mcTransformers[i] == null)
|
|
||||||
continue;
|
|
||||||
if (mcTransformers[i] is DynamicRotation)
|
|
||||||
dst[i] = MathUtil.ToDeg(step.GetMcValue(i).Value).ToString("F4");
|
|
||||||
else
|
|
||||||
dst[i] = step.GetMcValue(i)?.ToString("F5");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
#region ShowStepPresent
|
#region ShowStepPresent
|
||||||
internal static void ShowStepPresent(
|
internal static void ShowStepPresent(
|
||||||
UserService userEnv, MachiningStep machiningStep)
|
UserService userEnv, MachiningStep machiningStep)
|
||||||
@ -143,4 +66,4 @@ public static class DemoSessionMessage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using Hi.Common.Messages;
|
using Hi.Common.Messages;
|
||||||
using Hi.HiNcKits;
|
using Hi.HiNcKits;
|
||||||
using Hi.MachiningProcs;
|
using Hi.MachiningProcs;
|
||||||
|
using Hi.NcParsers;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -37,17 +38,22 @@ public static class DemoUseMachiningProject
|
|||||||
Console.WriteLine($"Set message event.");
|
Console.WriteLine($"Set message event.");
|
||||||
|
|
||||||
using StreamWriter writer = new StreamWriter("msg.txt");
|
using StreamWriter writer = new StreamWriter("msg.txt");
|
||||||
//show message if something abnormal.
|
//show message if something abnormal, from each partitioned message sink:
|
||||||
localProjectService.MixedProgress.CollectionItemAdded += pack =>
|
//shell (session lifecycle), NC diagnostics, and step-anchored diagnostics.
|
||||||
{
|
void LogIfAbnormal(IMessage message, ISentenceCarrier sentenceCarrier)
|
||||||
if (pack.Tags.Contains(MessageFlag.Warning.ToString()) ||
|
{
|
||||||
pack.Tags.Contains(MessageFlag.Error.ToString()) ||
|
var severity = message.GetSeverity();
|
||||||
pack.Tags.Contains(MessageFlag.Exception.ToString()))
|
if (severity != Severity.Warning && severity != Severity.Error)
|
||||||
{
|
return;
|
||||||
var sourceCommand = pack.SourceCommand;
|
var ncLine = sentenceCarrier?.GetSentence()?.FirstIndexedFileLine;
|
||||||
writer.WriteLine($"{pack.Message} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
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.");
|
Console.WriteLine($"Set machining step event.");
|
||||||
//show MRR.
|
//show MRR.
|
||||||
localProjectService.SessionShell.SessionStepBuilt += (preStep, curStep) =>
|
localProjectService.SessionShell.SessionStepBuilt += (preStep, curStep) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user