From f7cfcea4df5c99c0058c03bcc198f535dbe5916a Mon Sep 17 00:00:00 2001 From: Peter Kurhajec <61538034+PTKu@users.noreply.github.com> Date: Thu, 19 Feb 2026 12:46:24 +0100 Subject: [PATCH 1/2] Refactor AxoMessengerTextItem to support dynamic message and help text expressions --- .../AxoCylinder/AxoCylinder.cs | 16 ++++---- .../AxoMessenger/Static/AxoMessenger.cs | 4 +- .../Static/AxoMessengerTextItem.cs | 40 ++++++++++++++++++- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/components.pneumatics/src/AXOpen.Components.Pneumatics/AxoCylinder/AxoCylinder.cs b/src/components.pneumatics/src/AXOpen.Components.Pneumatics/AxoCylinder/AxoCylinder.cs index 2ce174cad..77d31a529 100644 --- a/src/components.pneumatics/src/AXOpen.Components.Pneumatics/AxoCylinder/AxoCylinder.cs +++ b/src/components.pneumatics/src/AXOpen.Components.Pneumatics/AxoCylinder/AxoCylinder.cs @@ -23,15 +23,15 @@ private void InitializeMessenger() List> messengerTextList = new List> { new KeyValuePair(0, new AxoMessengerTextItem(" ", " ")), - new KeyValuePair(1, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")), - new KeyValuePair(2, new AxoMessengerTextItem($"Movement position `{this.InLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")), + new KeyValuePair(1, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")), + new KeyValuePair(2, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")), new KeyValuePair(3, new AxoMessengerTextItem("Both extremity sensors are active at the same time.", "Check the positions of the sensors.")), - new KeyValuePair(4, new AxoMessengerTextItem($"Movement to position `{this.OutLabel}` is temporarily suspended.", "Check the blocking condition.")), - new KeyValuePair(5, new AxoMessengerTextItem($"Movement to position `{this.InLabel}` is temporarily suspended.", "Check the blocking condition.")), - new KeyValuePair(6, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` is aborted.", "Check the blocking condition.")), - new KeyValuePair(7, new AxoMessengerTextItem($"Movement position `{this.InLabel}` is aborted.", "Check the blocking condition.")), - new KeyValuePair(8, new AxoMessengerTextItem($"Movement position `{this.InLabel}` overshot the extremity sensor.", "Check the sensor position.")), - new KeyValuePair(9, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` overshot the extremity sensor.", "Check the sensor position.")), + new KeyValuePair(4, new AxoMessengerTextItem(() => $"Movement to position `{this.OutLabel}` is temporarily suspended.", "Check the blocking condition.")), + new KeyValuePair(5, new AxoMessengerTextItem(() => $"Movement to position `{this.InLabel}` is temporarily suspended.", "Check the blocking condition.")), + new KeyValuePair(6, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` is aborted.", "Check the blocking condition.")), + new KeyValuePair(7, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` is aborted.", "Check the blocking condition.")), + new KeyValuePair(8, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` overshot the extremity sensor.", "Check the sensor position.")), + new KeyValuePair(9, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` overshot the extremity sensor.", "Check the sensor position.")), }; _Messenger.DotNetMessengerTextList = messengerTextList; diff --git a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessenger.cs b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessenger.cs index 090bc5822..cf9687b90 100644 --- a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessenger.cs +++ b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessenger.cs @@ -136,8 +136,8 @@ public Dictionary PlcMessengerTextList private List> dotNetMessengerTextList; public List> DotNetMessengerTextList { - get{return dotNetMessengerTextList != null ? dotNetMessengerTextList : new List>();} - set{dotNetMessengerTextList = value != null ? value : new List>(); } + get{ return dotNetMessengerTextList != null ? dotNetMessengerTextList : new List>(); } + set{ dotNetMessengerTextList = value != null ? value : new List>(); } } diff --git a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs index 6b66b9490..cc2f3aff1 100644 --- a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs +++ b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs @@ -9,14 +9,50 @@ namespace AXOpen.Messaging.Static; public class AxoMessengerTextItem { - public string MessageText { get; } - public string HelpText { get; } + public Func MessageTextExpression { get; set; } + public Func HelpTextExpression { get; set; } + + private string _messageText; + public string MessageText + { + get { + if(_messageText is null) + { + if(MessageTextExpression is not null) + { + return MessageTextExpression.Invoke(); + } + } + return _messageText; + } + + private set + { + _messageText = value; + } + } + + private string _helpText; + public string HelpText { get { return _helpText; } private set { _helpText = value; } } public AxoMessengerTextItem(string messageText, string helpText) { MessageText = messageText; HelpText = helpText; } + + public AxoMessengerTextItem(Func messageTextExpression, Func helpTextExpression) + { + MessageTextExpression = messageTextExpression; + HelpTextExpression = helpTextExpression; + } + + public AxoMessengerTextItem(Func messageTextExpression, string helpText) + { + MessageTextExpression = messageTextExpression; + HelpText = helpText; + } + public AxoMessengerTextItem(string messageText) { MessageText = messageText; From 6bc6ae988382f4383a55610cb61634bf31083e99 Mon Sep 17 00:00:00 2001 From: Peter Kurhajec <61538034+PTKu@users.noreply.github.com> Date: Thu, 19 Feb 2026 13:08:55 +0100 Subject: [PATCH 2/2] Potential fix for pull request finding 'Nested 'if' statements can be combined' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- .../AxoMessenger/Static/AxoMessengerTextItem.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs index cc2f3aff1..114aa2403 100644 --- a/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs +++ b/src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs @@ -16,12 +16,9 @@ public class AxoMessengerTextItem public string MessageText { get { - if(_messageText is null) + if(_messageText is null && MessageTextExpression is not null) { - if(MessageTextExpression is not null) - { - return MessageTextExpression.Invoke(); - } + return MessageTextExpression.Invoke(); } return _messageText; }