Skip to content

Commit deffbb2

Browse files
authored
Merge pull request #1037 from Inxton/fix/various-fixies
Refactor AxoMessengerTextItem to support dynamic message and help text expressions
2 parents 28ada0a + 6bc6ae9 commit deffbb2

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/components.pneumatics/src/AXOpen.Components.Pneumatics/AxoCylinder/AxoCylinder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ private void InitializeMessenger()
2323
List<KeyValuePair<ulong, AxoMessengerTextItem>> messengerTextList = new List<KeyValuePair<ulong, AxoMessengerTextItem>>
2424
{
2525
new KeyValuePair<ulong, AxoMessengerTextItem>(0, new AxoMessengerTextItem(" ", " ")),
26-
new KeyValuePair<ulong, AxoMessengerTextItem>(1, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")),
27-
new KeyValuePair<ulong, AxoMessengerTextItem>(2, new AxoMessengerTextItem($"Movement position `{this.InLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")),
26+
new KeyValuePair<ulong, AxoMessengerTextItem>(1, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")),
27+
new KeyValuePair<ulong, AxoMessengerTextItem>(2, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` did not succeed.", "Check that cylinder is free to move, check the air pressure, and extremity sensor.")),
2828
new KeyValuePair<ulong, AxoMessengerTextItem>(3, new AxoMessengerTextItem("Both extremity sensors are active at the same time.", "Check the positions of the sensors.")),
29-
new KeyValuePair<ulong, AxoMessengerTextItem>(4, new AxoMessengerTextItem($"Movement to position `{this.OutLabel}` is temporarily suspended.", "Check the blocking condition.")),
30-
new KeyValuePair<ulong, AxoMessengerTextItem>(5, new AxoMessengerTextItem($"Movement to position `{this.InLabel}` is temporarily suspended.", "Check the blocking condition.")),
31-
new KeyValuePair<ulong, AxoMessengerTextItem>(6, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` is aborted.", "Check the blocking condition.")),
32-
new KeyValuePair<ulong, AxoMessengerTextItem>(7, new AxoMessengerTextItem($"Movement position `{this.InLabel}` is aborted.", "Check the blocking condition.")),
33-
new KeyValuePair<ulong, AxoMessengerTextItem>(8, new AxoMessengerTextItem($"Movement position `{this.InLabel}` overshot the extremity sensor.", "Check the sensor position.")),
34-
new KeyValuePair<ulong, AxoMessengerTextItem>(9, new AxoMessengerTextItem($"Movement position `{this.OutLabel}` overshot the extremity sensor.", "Check the sensor position.")),
29+
new KeyValuePair<ulong, AxoMessengerTextItem>(4, new AxoMessengerTextItem(() => $"Movement to position `{this.OutLabel}` is temporarily suspended.", "Check the blocking condition.")),
30+
new KeyValuePair<ulong, AxoMessengerTextItem>(5, new AxoMessengerTextItem(() => $"Movement to position `{this.InLabel}` is temporarily suspended.", "Check the blocking condition.")),
31+
new KeyValuePair<ulong, AxoMessengerTextItem>(6, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` is aborted.", "Check the blocking condition.")),
32+
new KeyValuePair<ulong, AxoMessengerTextItem>(7, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` is aborted.", "Check the blocking condition.")),
33+
new KeyValuePair<ulong, AxoMessengerTextItem>(8, new AxoMessengerTextItem(() => $"Movement position `{this.InLabel}` overshot the extremity sensor.", "Check the sensor position.")),
34+
new KeyValuePair<ulong, AxoMessengerTextItem>(9, new AxoMessengerTextItem(() => $"Movement position `{this.OutLabel}` overshot the extremity sensor.", "Check the sensor position.")),
3535
};
3636

3737
_Messenger.DotNetMessengerTextList = messengerTextList;

src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessenger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public Dictionary<ulong, AxoMessengerTextItem> PlcMessengerTextList
136136
private List<KeyValuePair<ulong, AxoMessengerTextItem>> dotNetMessengerTextList;
137137
public List<KeyValuePair<ulong, AxoMessengerTextItem>> DotNetMessengerTextList
138138
{
139-
get{return dotNetMessengerTextList != null ? dotNetMessengerTextList : new List<KeyValuePair<ulong, AxoMessengerTextItem>>();}
140-
set{dotNetMessengerTextList = value != null ? value : new List<KeyValuePair<ulong, AxoMessengerTextItem>>(); }
139+
get{ return dotNetMessengerTextList != null ? dotNetMessengerTextList : new List<KeyValuePair<ulong, AxoMessengerTextItem>>(); }
140+
set{ dotNetMessengerTextList = value != null ? value : new List<KeyValuePair<ulong, AxoMessengerTextItem>>(); }
141141
}
142142

143143

src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessengerTextItem.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,47 @@ namespace AXOpen.Messaging.Static;
99

1010
public class AxoMessengerTextItem
1111
{
12-
public string MessageText { get; }
13-
public string HelpText { get; }
12+
public Func<string> MessageTextExpression { get; set; }
13+
public Func<string> HelpTextExpression { get; set; }
14+
15+
private string _messageText;
16+
public string MessageText
17+
{
18+
get {
19+
if(_messageText is null && MessageTextExpression is not null)
20+
{
21+
return MessageTextExpression.Invoke();
22+
}
23+
return _messageText;
24+
}
25+
26+
private set
27+
{
28+
_messageText = value;
29+
}
30+
}
31+
32+
private string _helpText;
33+
public string HelpText { get { return _helpText; } private set { _helpText = value; } }
1434

1535
public AxoMessengerTextItem(string messageText, string helpText)
1636
{
1737
MessageText = messageText;
1838
HelpText = helpText;
1939
}
40+
41+
public AxoMessengerTextItem(Func<string> messageTextExpression, Func<string> helpTextExpression)
42+
{
43+
MessageTextExpression = messageTextExpression;
44+
HelpTextExpression = helpTextExpression;
45+
}
46+
47+
public AxoMessengerTextItem(Func<string> messageTextExpression, string helpText)
48+
{
49+
MessageTextExpression = messageTextExpression;
50+
HelpText = helpText;
51+
}
52+
2053
public AxoMessengerTextItem(string messageText)
2154
{
2255
MessageText = messageText;

0 commit comments

Comments
 (0)