Skip to content

Commit e8f81ba

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents d566a5b + 085aa1e commit e8f81ba

File tree

5 files changed

+111
-8
lines changed

5 files changed

+111
-8
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.4.0
1+
8.4.1

src/Moryx.ControlSystem/Processes/IProcessExtensions.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using Moryx.AbstractionLayer.Products;
1+
using System;
22
using Moryx.AbstractionLayer;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Text;
3+
using Moryx.AbstractionLayer.Products;
4+
using Moryx.ControlSystem.Recipes;
65

76
namespace Moryx.ControlSystem.Processes
87
{
@@ -66,5 +65,37 @@ public static bool TryModifyProductInstance<TInstance>(this IProcess process, Ac
6665
setter.Invoke(instance);
6766
return true;
6867
}
68+
69+
/// <summary>
70+
/// Returns <see cref="IOrderBasedRecipe.OrderNumber"/> on the <see cref="IProcess"/> using the given <paramref name="process"/>.
71+
/// </summary>
72+
/// <param name="process">The process holding the order number</param>
73+
/// <example>
74+
/// <code>
75+
/// <![CDATA[
76+
/// process.GetOrderNumber()
77+
/// ]]>
78+
/// </code>
79+
/// </example>
80+
public static string GetOrderNumber(this IProcess process)
81+
{
82+
return (process.Recipe as IOrderBasedRecipe)?.OrderNumber;
83+
}
84+
85+
/// <summary>
86+
/// Returns <see cref="IOrderBasedRecipe.OperationNumber"/> on the <see cref="IProcess"/> using the given <paramref name="process"/>.
87+
/// </summary>
88+
/// <param name="process">The process holding the operation number</param>
89+
/// <example>
90+
/// <code>
91+
/// <![CDATA[
92+
/// process.GetOperationNumber()
93+
/// ]]>
94+
/// </code>
95+
/// </example>
96+
public static string GetOperationNumber(this IProcess process)
97+
{
98+
return (process.Recipe as IOrderBasedRecipe)?.OperationNumber;
99+
}
69100
}
70101
}

src/Moryx.ControlSystem/VisualInstructions/EnumInstructionResult.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using System.Globalization;
89

910
namespace Moryx.ControlSystem.VisualInstructions
1011
{
@@ -24,15 +25,28 @@ public static IReadOnlyList<string> PossibleResults(Type resultEnum, params stri
2425
/// <summary>
2526
/// Determine possible string buttons from enum result
2627
/// </summary>
28+
[Obsolete("Use the 'InstructionResults' method instead!'")]
2729
public static IReadOnlyList<InstructionResult> PossibleInstructionResults(Type resultEnum, params string[] exceptions)
2830
{
2931
return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult
3032
{
31-
Key = pair.Value.ToString("D"),
33+
Key = pair.Value.ToString("D", CultureInfo.InvariantCulture),
3234
DisplayValue = pair.Key
3335
}).ToList();
3436
}
3537

38+
/// <summary>
39+
/// Determine possible string buttons from enum result
40+
/// </summary>
41+
public static InstructionResult[] InstructionResults(Type resultEnum, params string[] exceptions)
42+
{
43+
return ParseEnum(resultEnum, exceptions).Select(pair => new InstructionResult
44+
{
45+
Key = pair.Value.ToString("D", CultureInfo.InvariantCulture),
46+
DisplayValue = pair.Key
47+
}).ToArray();
48+
}
49+
3650
/// <summary>
3751
/// Parse the given result back to an enum value
3852
/// </summary>
@@ -46,7 +60,7 @@ public static int ResultToEnumValue(Type resultEnum, string result)
4660
/// </summary>
4761
public static int ResultToEnumValue(Type resultEnum, InstructionResult result)
4862
{
49-
return int.Parse(result.Key);
63+
return int.Parse(result.Key, CultureInfo.InvariantCulture);
5064
}
5165

5266
/// <summary>
@@ -79,7 +93,7 @@ public static TEnum ResultToGenericEnumValue<TEnum>(string result)
7993
public static TEnum ResultToGenericEnumValue<TEnum>(InstructionResult result)
8094
where TEnum : Enum
8195
{
82-
var numeric = int.Parse(result.Key);
96+
var numeric = int.Parse(result.Key, CultureInfo.InvariantCulture);
8397
return (TEnum)Enum.ToObject(typeof(TEnum), numeric);
8498
}
8599

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
2+
3+
using Moryx.AbstractionLayer.Recipes;
4+
using Moryx.ControlSystem.Recipes;
5+
6+
namespace Moryx.ControlSystem.Tests.Mocks
7+
{
8+
public class DummyRecipe : ProductionRecipe, IOrderBasedRecipe
9+
{
10+
public string OrderNumber { get; set; }
11+
public string OperationNumber { get; set; }
12+
13+
public DummyRecipe()
14+
{
15+
}
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
2+
3+
using Moryx.AbstractionLayer;
4+
using Moryx.ControlSystem.Processes;
5+
using Moryx.ControlSystem.Tests.Mocks;
6+
using NUnit.Framework;
7+
8+
namespace Moryx.ControlSystem.Tests
9+
{
10+
[TestFixture]
11+
internal class ProcessExtensionsTest
12+
{
13+
[Test]
14+
public void ShouldReturnOrderNumber()
15+
{
16+
// Arrange
17+
var recipe = new DummyRecipe { OrderNumber = "O10", OperationNumber = "Op082" };
18+
var process = new Process { Recipe = recipe };
19+
20+
// Act
21+
var orderNumber = process?.GetOrderNumber();
22+
23+
// Assert
24+
Assert.That(orderNumber, Is.EqualTo(recipe.OrderNumber));
25+
}
26+
27+
[Test]
28+
public void ShouldReturnOperationNumber()
29+
{
30+
// Arrange
31+
var recipe = new DummyRecipe { OrderNumber = "O10", OperationNumber = "Op082" };
32+
var process = new Process { Recipe = recipe };
33+
34+
// Act
35+
var operationNumber = process?.GetOperationNumber();
36+
37+
// Assert
38+
Assert.That(operationNumber, Is.EqualTo(recipe.OperationNumber));
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)