From 70cbad8a4cb78010aba1f213fbef84d174fd7c18 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Thu, 3 Nov 2022 23:51:21 +0100 Subject: [PATCH 01/31] Move Prop files to Deploy --- .github/workflows/pre-release.yml | 6 +++--- OpenPackML.props => Deploy/OpenPackML.props | 2 +- OpenPackMLPrefab.props => Deploy/OpenPackMLPrefab.props | 2 +- OpenPackMLTags.props => Deploy/OpenPackMLTags.props | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename OpenPackML.props => Deploy/OpenPackML.props (97%) rename OpenPackMLPrefab.props => Deploy/OpenPackMLPrefab.props (97%) rename OpenPackMLTags.props => Deploy/OpenPackMLTags.props (97%) diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 10d3a79..d4add06 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -26,7 +26,7 @@ jobs: with: PROJECT_FILE_PATH: Open.PackML/Open.PackML.csproj NUGET_KEY: ${{secrets.NUGET_KEY}} - VERSION_FILE_PATH: OpenPackML.props + VERSION_FILE_PATH: Deploy/OpenPackML.props INCLUDE_SYMBOLS: true NO_BUILD: true - name: Publish Open PackML Tags to NuGet @@ -36,7 +36,7 @@ jobs: with: PROJECT_FILE_PATH: Open.PackML.Tags/Open.PackML.Tags.csproj NUGET_KEY: ${{secrets.NUGET_KEY}} - VERSION_FILE_PATH: OpenPackMLTags.props + VERSION_FILE_PATH: Deploy/OpenPackMLTags.props INCLUDE_SYMBOLS: true NO_BUILD: true - name: Publish Open PackML PRefabs to NuGet @@ -46,6 +46,6 @@ jobs: with: PROJECT_FILE_PATH: Open.PackML.Prefab/Open.PackML.Prefab.csproj NUGET_KEY: ${{secrets.NUGET_KEY}} - VERSION_FILE_PATH: OpenPackMLPrefab.props + VERSION_FILE_PATH: Deploy/OpenPackMLPrefab.props INCLUDE_SYMBOLS: true NO_BUILD: true diff --git a/OpenPackML.props b/Deploy/OpenPackML.props similarity index 97% rename from OpenPackML.props rename to Deploy/OpenPackML.props index e9a5ab3..9fd3be6 100644 --- a/OpenPackML.props +++ b/Deploy/OpenPackML.props @@ -7,7 +7,7 @@ https://github.com/peacefighter1996/Open.PackML git MIT - 0.4.0-Beta + 0.4.1-Beta true true diff --git a/OpenPackMLPrefab.props b/Deploy/OpenPackMLPrefab.props similarity index 97% rename from OpenPackMLPrefab.props rename to Deploy/OpenPackMLPrefab.props index 6b52cca..f7166cd 100644 --- a/OpenPackMLPrefab.props +++ b/Deploy/OpenPackMLPrefab.props @@ -8,7 +8,7 @@ https://github.com/peacefighter1996/Open.PackML git MIT - 0.4.0-Beta + 0.4.1-Beta true true diff --git a/OpenPackMLTags.props b/Deploy/OpenPackMLTags.props similarity index 97% rename from OpenPackMLTags.props rename to Deploy/OpenPackMLTags.props index c27a0c2..853fe9d 100644 --- a/OpenPackMLTags.props +++ b/Deploy/OpenPackMLTags.props @@ -8,7 +8,7 @@ https://github.com/peacefighter1996/Open.PackML git MIT - 0.4.0-Beta + 0.4.1-Beta true true From 5d3742bf9a74b22ebcf87a38881404e0e7d9f9b6 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Thu, 3 Nov 2022 23:55:28 +0100 Subject: [PATCH 02/31] format non primitives to string --- Autabee.Utility/ValidationResult.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Autabee.Utility/ValidationResult.cs b/Autabee.Utility/ValidationResult.cs index e637dc5..d4060c7 100644 --- a/Autabee.Utility/ValidationResult.cs +++ b/Autabee.Utility/ValidationResult.cs @@ -16,6 +16,13 @@ public ValidationResult(bool success = true, string unSuccessfulText = "", param FailInfo = new List<(string, object[])>(); if (!string.IsNullOrWhiteSpace(unSuccessfulText)) { + for (int i = 0; i < formatObjects.Length; i++) + { + if (!formatObjects[i].GetType().IsPrimitive) + { + formatObjects[i] = formatObjects[i].ToString(); + } + } FailInfo.Add((unSuccessfulText, formatObjects)); } } From c10afc2ce0f66d1b5bedf1ac70d537b398c4c055 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 00:03:14 +0100 Subject: [PATCH 03/31] proj prop Move to deploy --- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 4 ++-- Open.PackML.Tags/Open.PackML.Tags.csproj | 2 +- Open.PackML/Open.PackML.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index 2d831ac..ac3237e 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,5 +1,5 @@ - + netstandard2.0;net6.0;net48 @@ -10,7 +10,7 @@ \ - + diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index 3435923..a2d9067 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -1,5 +1,5 @@  - + netstandard2.0;net6.0;net48 readme.md diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index 998142f..d7c8358 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -1,5 +1,5 @@  - + netstandard2.0;net6.0;net48 readme.md From 0f18abec83f8d7baf7649726f51bbb9bd81f9eed Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 00:05:08 +0100 Subject: [PATCH 04/31] Test in all framworks --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 2 +- Open.PackMLTests/Open.PackMLTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index d02ee50..84e67e9 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.0;net6.0;net48 false diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 7ea5a6b..c731007 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net6.0 + netstandard2.0;net6.0;net48 false From 2a9087e6d2a82118db8b7a59f59a31b8ec8d236a Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 00:07:48 +0100 Subject: [PATCH 05/31] Add Cancelation Token --- Open.PackML/Interfaces/IPmlController.cs | 11 +-- Open.PackML/Prefab/PmlGuardController.cs | 68 ++++--------------- Open.PackML/Prefab/PmlOemGuardController.cs | 53 +++++++++++++++ .../TestObjects/TestPmlController.cs | 11 +-- 4 files changed, 79 insertions(+), 64 deletions(-) create mode 100644 Open.PackML/Prefab/PmlOemGuardController.cs diff --git a/Open.PackML/Interfaces/IPmlController.cs b/Open.PackML/Interfaces/IPmlController.cs index 1ebbf53..547324d 100644 --- a/Open.PackML/Interfaces/IPmlController.cs +++ b/Open.PackML/Interfaces/IPmlController.cs @@ -1,5 +1,6 @@ using Autabee.Utility; using System; +using System.Threading; using System.Threading.Tasks; namespace Open.PackML @@ -15,15 +16,15 @@ public interface IPmlController: IPmlMachineController PmlMode RetrieveCurrentPackMLMode(); //Deep Async - Task RetrieveCurrentPackMLStateAsync(); - Task RetrieveCurrentPackMLModeAsync(); + Task RetrieveCurrentPackMLStateAsync(CancellationToken cancellationToken); + Task RetrieveCurrentPackMLModeAsync(CancellationToken cancellationToken); //Send PackML Function ValidationResult SendPmlCommand(PmlCommand packMLCommand); ValidationResult UpdatePmlMode(PmlMode packMLMode); ValidationResult UpdatePmlMode(int packMLMode); - Task SendPackMLCommandAsync(PmlCommand packMLCommand); - Task UpdatePackMLModeAsync(PmlMode packMLMode); - Task UpdatePackMLModeAsync(int packMLMode); + Task SendPackMLCommandAsync(PmlCommand packMLCommand, CancellationToken cancellationToken); + Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken cancellationToken); + Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken); } } diff --git a/Open.PackML/Prefab/PmlGuardController.cs b/Open.PackML/Prefab/PmlGuardController.cs index 89e96e1..5821138 100644 --- a/Open.PackML/Prefab/PmlGuardController.cs +++ b/Open.PackML/Prefab/PmlGuardController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using System.Threading; namespace Open.PackML.Prefab { @@ -67,10 +68,11 @@ public ValidationResult UpdatePmlMode(PmlMode packMLMode) if (temp.Success) temp.AddResult(controller.UpdatePmlMode(packMLMode)); return temp; } - public async Task UpdatePackMLModeAsync(PmlMode packMLMode) + public async Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); - if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode).ConfigureAwait(true)); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); return temp; } @@ -81,10 +83,11 @@ public virtual ValidationResult SendPmlCommand(PmlCommand command) return temp; } - public virtual async Task SendPackMLCommandAsync(PmlCommand command) + public virtual async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckTransition(command, currentState, currentMode); - if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command).ConfigureAwait(true)); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command, cancellationToken).ConfigureAwait(true)); return temp; } @@ -122,15 +125,15 @@ public PmlMode RetrieveCurrentPackMLMode() currentMode = controller.RetrieveCurrentPackMLMode(); return currentMode; } - public async Task RetrieveCurrentPackMLStateAsync() + public async Task RetrieveCurrentPackMLStateAsync(CancellationToken cancellationToken) { - currentState = await controller.RetrieveCurrentPackMLStateAsync().ConfigureAwait(true); + currentState = await controller.RetrieveCurrentPackMLStateAsync(cancellationToken).ConfigureAwait(true); return currentState; } - public async Task RetrieveCurrentPackMLModeAsync() + public async Task RetrieveCurrentPackMLModeAsync(CancellationToken cancellationToken) { - currentMode = await controller.RetrieveCurrentPackMLModeAsync().ConfigureAwait(true); + currentMode = await controller.RetrieveCurrentPackMLModeAsync(cancellationToken).ConfigureAwait(true); return currentMode; } @@ -146,11 +149,12 @@ public virtual ValidationResult UpdatePmlMode(int packMLMode) } } - public virtual async Task UpdatePackMLModeAsync(int packMLMode) + public virtual async Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken) { if (Enum.IsDefined(typeof(PmlMode), packMLMode)) { - return await UpdatePackMLModeAsync((PmlMode)packMLMode); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + return await UpdatePackMLModeAsync((PmlMode)packMLMode, cancellationToken).ConfigureAwait(true); } else { @@ -158,48 +162,4 @@ public virtual async Task UpdatePackMLModeAsync(int packMLMode } } } - - public class PmlOemGuardController : PmlGuardController - { - - protected new int currentMode = 0; - private IPmlOemTransitionCheck oemTransitionCheck; - - public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStore, IPmlOemTransitionCheck pmlOemTransitionCheck) : base(controller, eventStore) - { - oemTransitionCheck = pmlOemTransitionCheck ?? throw new ArgumentNullException(nameof(pmlOemTransitionCheck)); - } - - public new ValidationResult UpdatePmlMode(int packMLMode) - { - var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); - if (temp.Success) temp.AddResult(controller.UpdatePmlMode(packMLMode)); - - return temp; - } - public new async Task UpdatePackMLModeAsync(int packMLMode) - { - var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); - if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode).ConfigureAwait(true)); - - return temp; - } - - public new ValidationResult SendPmlCommand(PmlCommand command) - { - var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); - if (temp.Success) temp.AddResult(controller.SendPmlCommand(command)); - - return temp; - } - - public new async Task SendPackMLCommandAsync(PmlCommand command) - { - var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); - if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command).ConfigureAwait(true)); - - return temp; - } - - } } diff --git a/Open.PackML/Prefab/PmlOemGuardController.cs b/Open.PackML/Prefab/PmlOemGuardController.cs new file mode 100644 index 0000000..bbdac78 --- /dev/null +++ b/Open.PackML/Prefab/PmlOemGuardController.cs @@ -0,0 +1,53 @@ +using Autabee.Utility; +using System; +using System.Threading.Tasks; +using System.Threading; + +namespace Open.PackML.Prefab +{ + public class PmlOemGuardController : PmlGuardController + { + + protected new int currentMode = 0; + private IPmlOemTransitionCheck oemTransitionCheck; + + public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStore, IPmlOemTransitionCheck pmlOemTransitionCheck) : base(controller, eventStore) + { + oemTransitionCheck = pmlOemTransitionCheck ?? throw new ArgumentNullException(nameof(pmlOemTransitionCheck)); + } + + public new ValidationResult UpdatePmlMode(int packMLMode) + { + var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); + if (temp.Success) temp.AddResult(controller.UpdatePmlMode(packMLMode)); + + return temp; + } + public new async Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken) + { + var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); + + return temp; + } + + public new ValidationResult SendPmlCommand(PmlCommand command) + { + var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); + if (temp.Success) temp.AddResult(controller.SendPmlCommand(command)); + + return temp; + } + + public new async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) + { + var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command, cancellationToken).ConfigureAwait(true)); + + return temp; + } + + } +} diff --git a/Open.PackMLTests/TestObjects/TestPmlController.cs b/Open.PackMLTests/TestObjects/TestPmlController.cs index 75d1e3c..a4a894e 100644 --- a/Open.PackMLTests/TestObjects/TestPmlController.cs +++ b/Open.PackMLTests/TestObjects/TestPmlController.cs @@ -4,6 +4,7 @@ using Open.PackML.Interfaces; using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace Open.PackMLTests.TestObjects @@ -30,7 +31,7 @@ public PmlMode RetrieveCurrentPackMLMode() throw new NotImplementedException(); } - public Task RetrieveCurrentPackMLModeAsync() + public Task RetrieveCurrentPackMLModeAsync(CancellationToken token) { throw new NotImplementedException(); } @@ -47,12 +48,12 @@ public PmlState RetrieveCurrentPackMLState() throw new NotImplementedException(); } - public Task RetrieveCurrentPackMLStateAsync() + public Task RetrieveCurrentPackMLStateAsync(CancellationToken token) { throw new NotImplementedException(); } - public async Task SendPackMLCommandAsync(PmlCommand packMLCommand) => SendPmlCommand(packMLCommand); + public async Task SendPackMLCommandAsync(PmlCommand packMLCommand, CancellationToken token) => SendPmlCommand(packMLCommand); public ValidationResult SendPmlCommand(PmlCommand packMLCommand) { @@ -83,7 +84,7 @@ public ValidationResult SendPmlCommand(PmlCommand packMLCommand) } - public async Task UpdatePackMLModeAsync(PmlMode packMLMode) => UpdatePmlMode(packMLMode); + public async Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken token) => UpdatePmlMode(packMLMode); public ValidationResult UpdatePmlMode(PmlMode packMLMode) { @@ -95,7 +96,7 @@ public ValidationResult UpdatePmlMode(int packMLMode) throw new NotImplementedException(); } - public Task UpdatePackMLModeAsync(int packMLMode) + public Task UpdatePackMLModeAsync(int packMLMode, CancellationToken token) { throw new NotImplementedException(); } From 053818250800c008e242e4fc3ebc1b359b2a904b Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 00:08:56 +0100 Subject: [PATCH 06/31] move PmlEquipmentInterlock --- Open.PackML.Prefab/PmlEquipmentInterlock.cs | 13 +++++++++++++ Open.PackML.Prefab/PmlTr88Controller.cs | 11 ----------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 Open.PackML.Prefab/PmlEquipmentInterlock.cs diff --git a/Open.PackML.Prefab/PmlEquipmentInterlock.cs b/Open.PackML.Prefab/PmlEquipmentInterlock.cs new file mode 100644 index 0000000..c552069 --- /dev/null +++ b/Open.PackML.Prefab/PmlEquipmentInterlock.cs @@ -0,0 +1,13 @@ +using Open.PackML.Tags.Attributes; + +namespace Open.PackML.Prefab +{ + public class PmlEquipmentInterlock + { + [TagEndUserTerm("Blockage")] + public bool Blocker { get; set; } + + [TagEndUserTerm("Starvation")] + public bool Starve { get; set; } + } +} diff --git a/Open.PackML.Prefab/PmlTr88Controller.cs b/Open.PackML.Prefab/PmlTr88Controller.cs index 597dc3f..bb1b90c 100644 --- a/Open.PackML.Prefab/PmlTr88Controller.cs +++ b/Open.PackML.Prefab/PmlTr88Controller.cs @@ -4,9 +4,6 @@ using Open.PackML.Tags; using Open.PackML.Tags.Attributes; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Open.PackML.Prefab { @@ -78,12 +75,4 @@ public bool CmdChangeRequest } } - public class PmlEquipmentInterlock - { - [TagEndUserTerm("Blockage")] - public bool Blocker { get; set; } - - [TagEndUserTerm("Starvation")] - public bool Starve { get; set; } - } } From 6b0555010536af4c58d30f3397b9070fd55e196a Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 01:21:20 +0100 Subject: [PATCH 07/31] Fix Browse Depth and Update style points --- ...Utility.IEC61131TypeConversionTests.csproj | 18 +++-- .../IecTypeConvertorTests.cs | 3 - Open.PackML.Tags/Interfaces/ITagStore.cs | 2 +- Open.PackML.Tags/Open.PackML.Tags.csproj | 3 + Open.PackML.Tags/Prefab/TagController.cs | 16 +++-- Open.PackML/PmlTransitionCheck.cs | 2 +- Open.PackMLTests/Open.PackMLTests.csproj | 18 +++-- Open.PackMLTests/PmlGuardControllerTests.cs | 4 +- Open.PackMLTests/PmlTransitionCheckTests.cs | 7 +- Open.PackMLTests/Prefab/BuildTagTreeTests.cs | 3 + Open.PackMLTests/Prefab/TagControllerTests.cs | 67 ++++++++++++++++--- Open.PackMLTests/Prefab/Tr88TagsTest.cs | 6 +- 12 files changed, 105 insertions(+), 44 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 84e67e9..919082d 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -6,12 +6,18 @@ - - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs index 1b834dd..77bb9e2 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs @@ -5,9 +5,6 @@ using System.Collections; using System.Linq; using Xunit.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; -using System.Net.Sockets; -using System.Windows.Markup; using Autabee.Utility.IEC61131TypeConversion; using Autabee.Utility.IEC61131TypeConversionTests.TestObjects; diff --git a/Open.PackML.Tags/Interfaces/ITagStore.cs b/Open.PackML.Tags/Interfaces/ITagStore.cs index b730471..6887ca7 100644 --- a/Open.PackML.Tags/Interfaces/ITagStore.cs +++ b/Open.PackML.Tags/Interfaces/ITagStore.cs @@ -7,6 +7,6 @@ namespace Open.PackML.Interfaces public interface ITagStore { ValidationResult Browse(string Orgin); - ValidationResult Browse(string Orgin, int Depth = 1); + ValidationResult Browse(string Orgin, uint Depth); } } \ No newline at end of file diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index a2d9067..1b0f54e 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -10,6 +10,9 @@ \ + + + diff --git a/Open.PackML.Tags/Prefab/TagController.cs b/Open.PackML.Tags/Prefab/TagController.cs index 1cdbf62..2e02f1d 100644 --- a/Open.PackML.Tags/Prefab/TagController.cs +++ b/Open.PackML.Tags/Prefab/TagController.cs @@ -96,24 +96,28 @@ public ValidationResult Browse(string name) return new ValidationResult(true, ((TagDetail)tagDetail).ChildTags); } - public ValidationResult Browse(string name, int Depth = 1) + public ValidationResult Browse(string name, uint Depth = 1) { if (!tagTable.TryGetValue(TagConfig.TagStringToSearch(name), out TagConfig tagDetail)) return new ValidationResult(false, unSuccesfullText: "Tag {0} not found", formatObjects: name); - var result = GetChildren(((TagDetail)tagDetail),Depth); + var result = GetChildren(((TagDetail)tagDetail),Depth).ToArray(); - return new ValidationResult(true, ((TagDetail)tagDetail).ChildTags); + return new ValidationResult(true, result); } - internal static TagConfig[] GetChildren(TagDetail tagDetail, int Depth = 1) + internal static IEnumerable GetChildren(TagDetail tagDetail, uint Depth) { - if (Depth == 0) return tagDetail.ChildTags; + if (Depth <= 1) + return tagDetail.ChildTags; + var childeren = new List(); foreach (var child in tagDetail.ChildTags) { childeren.AddRange(GetChildren(child, Depth - 1)); + } - return childeren.ToArray(); + childeren.AddRange(tagDetail.ChildTags); + return childeren; } public ValidationResult ExecutePackTagCommand(string name, params object[] args) diff --git a/Open.PackML/PmlTransitionCheck.cs b/Open.PackML/PmlTransitionCheck.cs index a132f62..4aa5b1d 100644 --- a/Open.PackML/PmlTransitionCheck.cs +++ b/Open.PackML/PmlTransitionCheck.cs @@ -140,7 +140,7 @@ public static ValidationResult CheckModeUpdate(PmlMode currentMode, PmlMode pack } if (currentMode == packMLMode) { - return new ValidationResult(false, string.Format("PmlState already {0}", packMLMode)); + return new ValidationResult(false, "PmlState already {0}", packMLMode); } if (currentState == PmlState.Aborted || currentState == PmlState.Idle diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index c731007..4267b06 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -17,13 +17,19 @@ - + - - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Open.PackMLTests/PmlGuardControllerTests.cs b/Open.PackMLTests/PmlGuardControllerTests.cs index 2a1bd33..25b3428 100644 --- a/Open.PackMLTests/PmlGuardControllerTests.cs +++ b/Open.PackMLTests/PmlGuardControllerTests.cs @@ -71,7 +71,7 @@ public class PmlGuardControllerTests public void UpdatePackMLModeTest(PmlState state, PmlMode mode, PmlMode newMode, bool succes) { var passedInternal = false; - var catchFunc = delegate () + Action catchFunc = delegate () { passedInternal = true; }; @@ -110,7 +110,7 @@ public void UpdatePackMLModeTest(PmlState state, PmlMode mode, PmlMode newMode, public void UpdatePackMLModeTestFail(PmlMode mode, PmlMode newMode) { bool passedInternal; - var catchFunc = delegate () + Action catchFunc = delegate () { passedInternal = true; }; diff --git a/Open.PackMLTests/PmlTransitionCheckTests.cs b/Open.PackMLTests/PmlTransitionCheckTests.cs index e4b3583..429f03f 100644 --- a/Open.PackMLTests/PmlTransitionCheckTests.cs +++ b/Open.PackMLTests/PmlTransitionCheckTests.cs @@ -4,12 +4,7 @@ using Autabee.Utility; namespace Open.PackMLTests -{ - public enum OemSpecified : int - { - } - - +{ public class PmlTransitionCheckTests { [Theory] diff --git a/Open.PackMLTests/Prefab/BuildTagTreeTests.cs b/Open.PackMLTests/Prefab/BuildTagTreeTests.cs index ed1e9b4..9322a37 100644 --- a/Open.PackMLTests/Prefab/BuildTagTreeTests.cs +++ b/Open.PackMLTests/Prefab/BuildTagTreeTests.cs @@ -13,6 +13,7 @@ using Open.PackML; using Open.PackML.Prefab; using Open.PackMLTests.TestObjects; +using Open.PackML.Tags.Prefab; namespace Open.PackMLTests.Prefab { @@ -49,6 +50,7 @@ public void GetTreeTest1() } + [Fact] public void GetTreeTestTr88() { @@ -57,6 +59,7 @@ public void GetTreeTestTr88() var temp = TagTreeBuilder.GetTree("", new PmlTr88Controller(moqController.Object, eventStore, new PmlOemTransitionCheck())); logger.WriteLine(temp.BuildTable().GetTagTablePrint()); } + [Fact] public void GetTreeTestTr88Filtered() { diff --git a/Open.PackMLTests/Prefab/TagControllerTests.cs b/Open.PackMLTests/Prefab/TagControllerTests.cs index daee332..13583a5 100644 --- a/Open.PackMLTests/Prefab/TagControllerTests.cs +++ b/Open.PackMLTests/Prefab/TagControllerTests.cs @@ -1,21 +1,23 @@ using Xunit; using Open.PackML.Tags.Prefab; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Moq; using Open.PackML.Prefab; using Open.PackML; -using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; using Open.PackML.Tags; using Open.PackMLTests.TestObjects; +using Xunit.Abstractions; namespace Open.PackMLTests.Prefab { public class TagControllerTests { + readonly ITestOutputHelper logger; + public TagControllerTests(ITestOutputHelper output) + { + this.logger = output; + } [Fact()] public void GetTagDataTest() @@ -166,15 +168,15 @@ public void CallListIntFunction() public void GetSetBatch() { var calls = new List<(string, object)>() { - new ("Machine1.IntegerArray2[0]", 45), - new ("Machine1.IntegerArray1[0]", 45), - new ("Machine1.IntegerArray2[1]", 125) + ("Machine1.IntegerArray2[0]", 45), + ("Machine1.IntegerArray1[0]", 45), + ("Machine1.IntegerArray2[1]", 125) }; var calls2 = new List() { - new ("Machine1.IntegerArray2[0]"), - new ("Machine1.IntegerArray1[0]"), - new ("Machine1.IntegerArray2[1]") + "Machine1.IntegerArray2[0]", + "Machine1.IntegerArray1[0]", + "Machine1.IntegerArray2[1]" }; TagController controller = GetTestController(); @@ -230,6 +232,51 @@ public void CallBatchTagTypeFunction() } + [Fact()] + public void BrowseTagDepth1Function() + { + TagController controller = GetTestController(); + + var temp = controller.Browse("Machine1",1); + string tmp; + foreach (var item in temp.Object) + { + tmp = item.ToIecString(); + logger.WriteLine(tmp); + Assert.NotEqual(tmp, "Undefined,Machine1.ObjectArray[#].ExecuteObjects[#],,,UDT_Open_PackMLTests_Prefab_ExecuteObject[]"); + } + } + [Fact()] + public void BrowseTagDepthFunction() + { + TagController controller = GetTestController(); + + var temp = controller.Browse("Machine1"); + string tmp; + foreach (var item in temp.Object) + { + tmp = item.ToIecString(); + logger.WriteLine(tmp); + Assert.NotEqual(tmp, "Undefined,Machine1.ObjectArray[#].ExecuteObjects[#],,,UDT_Open_PackMLTests_Prefab_ExecuteObject[]"); + } + } + + + [Fact()] + public void BrowseTagDepth2Function() + { + TagController controller = GetTestController(); + + var temp = controller.Browse("Machine1", 2); + string tmp; + foreach (var item in temp.Object) + { + tmp = item.ToIecString(); + logger.WriteLine(tmp); + Assert.NotEqual(tmp, "Undefined,Machine1.ObjectArray[#].ExecuteObjects[#].Integer1,,,DINT"); + } + } + private static TagController GetDefaultcontroller() { var moqController = new Mock(); diff --git a/Open.PackMLTests/Prefab/Tr88TagsTest.cs b/Open.PackMLTests/Prefab/Tr88TagsTest.cs index d00b82d..0bf93dc 100644 --- a/Open.PackMLTests/Prefab/Tr88TagsTest.cs +++ b/Open.PackMLTests/Prefab/Tr88TagsTest.cs @@ -35,12 +35,12 @@ public TagConfig[] GetTagConfigList(bool tr88) { var tagConfig = new TagConfig(); var tagArray = tag.Split(','); - if (tagArray[4] != "X" && tr88) + if (string.Compare(tagArray[4], "X", StringComparison.Ordinal) != 0 && tr88) { continue; } string tagtypestring = string.Join(", ",tagArray[0].Split('/')); - tagConfig.TagType = Enum.Parse(tagtypestring); + tagConfig.TagType = (TagType)Enum.Parse(typeof(TagType),tagtypestring); tagConfig.Name = tagArray[1]; tagConfig.EndUserTerm = tagArray[2]; @@ -51,7 +51,7 @@ public TagConfig[] GetTagConfigList(bool tr88) if (lastPart.Contains("[") && lastPart.Contains("]")) { var number = lastPart.Split('[')[1].Split(']')[0]; - collectiontype = number == "#" ? typeof(List<>) : typeof(Array); + collectiontype = string.Compare(number, "#", StringComparison.Ordinal) == 0 ? typeof(List<>) : typeof(Array); } tagConfig.DataType = IecTypeConvertor.GetCsharpType(tagArray[3],collectiontype, Assembly.GetAssembly(typeof(PmlTr88Controller))); From f8cf4227fb04c55067c0a854962c54f8fd06ef62 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 01:53:36 +0100 Subject: [PATCH 08/31] Remove netstandard --- ...Utility.IEC61131TypeConversionTests.csproj | 27 ++++++++++++ ...Utility.IEC61131TypeConversionTests.csproj | 6 +-- ...abee.Utility.IEC61131TypeConversion.csproj | 2 +- Autabee.Utility/Autabee.Utility.csproj | 2 +- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 2 +- Open.PackML.Tags/Open.PackML.Tags.csproj | 2 +- Open.PackML/Open.PackML.csproj | 2 +- .../Open - Backup.PackMLTests.csproj | 42 +++++++++++++++++++ Open.PackMLTests/Open.PackMLTests.csproj | 4 +- 9 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj create mode 100644 Open.PackMLTests/Open - Backup.PackMLTests.csproj diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj new file mode 100644 index 0000000..30668e6 --- /dev/null +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj @@ -0,0 +1,27 @@ + + + + net6.0;net48 + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 919082d..0e46469 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@ - + - netstandard2.0;net6.0;net48 + net6.0;net48 false @@ -14,7 +14,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj b/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj index 2a4a9b7..0362804 100644 --- a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj +++ b/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net48 + net6.0;net48 readme.md diff --git a/Autabee.Utility/Autabee.Utility.csproj b/Autabee.Utility/Autabee.Utility.csproj index 3bfe640..41b4c57 100644 --- a/Autabee.Utility/Autabee.Utility.csproj +++ b/Autabee.Utility/Autabee.Utility.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net48 + net6.0;net48 readme.md diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index ac3237e..a04bf1a 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net48 + net6.0;net48 diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index 1b0f54e..a06b7eb 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net6.0;net48 + net6.0;net48 readme.md diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index d7c8358..80f493f 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net6.0;net48 + net6.0;net48 readme.md diff --git a/Open.PackMLTests/Open - Backup.PackMLTests.csproj b/Open.PackMLTests/Open - Backup.PackMLTests.csproj new file mode 100644 index 0000000..90cf71d --- /dev/null +++ b/Open.PackMLTests/Open - Backup.PackMLTests.csproj @@ -0,0 +1,42 @@ + + + + net6.0;net48 + + false + + + + + + + + + Always + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 4267b06..954c68e 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net6.0;net48 + net6.0;net48 false @@ -26,7 +26,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From c9c8e2738ff23e713cc5b14752ca188da44bb3ec Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 01:59:33 +0100 Subject: [PATCH 09/31] try fix testing at github --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 10 ++-------- Open.PackMLTests/Open.PackMLTests.csproj | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 0e46469..dc97a5e 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -9,15 +9,9 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 954c68e..ed24af2 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -21,15 +21,9 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + From 1fc22e7b1b27c552fbba8ec2dc42ec4d5b4a9978 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 02:04:34 +0100 Subject: [PATCH 10/31] test in net6 --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 2 +- Open.PackMLTests/Open.PackMLTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index dc97a5e..62f0e95 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@  - net6.0;net48 + net6.0 false diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index ed24af2..3f1609f 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net6.0;net48 + net6.0 false From 7f0bc0138129e22be639c81903b2e1f0bb752566 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 02:27:35 +0100 Subject: [PATCH 11/31] fix namingscheme --- Open.PackML/Interfaces/IPmlController.cs | 14 +++---- Open.PackML/Prefab/PmlGuardController.cs | 38 ++++++++++++------- Open.PackML/Prefab/PmlOemGuardController.cs | 8 +--- .../TestObjects/TestPmlController.cs | 14 +++---- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Open.PackML/Interfaces/IPmlController.cs b/Open.PackML/Interfaces/IPmlController.cs index 547324d..b63b210 100644 --- a/Open.PackML/Interfaces/IPmlController.cs +++ b/Open.PackML/Interfaces/IPmlController.cs @@ -12,19 +12,19 @@ public interface IPmlController: IPmlMachineController PmlMode CurrentPmlMode(); //Deep Synced - PmlState RetrieveCurrentPackMLState(); - PmlMode RetrieveCurrentPackMLMode(); + PmlState RetrieveCurrentPmlState(); + PmlMode RetrieveCurrentPmlMode(); //Deep Async - Task RetrieveCurrentPackMLStateAsync(CancellationToken cancellationToken); - Task RetrieveCurrentPackMLModeAsync(CancellationToken cancellationToken); + Task RetrieveCurrentPmlStateAsync(CancellationToken cancellationToken); + Task RetrieveCurrentPmlModeAsync(CancellationToken cancellationToken); //Send PackML Function ValidationResult SendPmlCommand(PmlCommand packMLCommand); ValidationResult UpdatePmlMode(PmlMode packMLMode); ValidationResult UpdatePmlMode(int packMLMode); - Task SendPackMLCommandAsync(PmlCommand packMLCommand, CancellationToken cancellationToken); - Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken cancellationToken); - Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken); + Task SendPmlCommandAsync(PmlCommand packMLCommand, CancellationToken cancellationToken); + Task UpdatePmlModeAsync(PmlMode packMLMode, CancellationToken cancellationToken); + Task UpdatePmlModeAsync(int packMLMode, CancellationToken cancellationToken); } } diff --git a/Open.PackML/Prefab/PmlGuardController.cs b/Open.PackML/Prefab/PmlGuardController.cs index 5821138..56fc90c 100644 --- a/Open.PackML/Prefab/PmlGuardController.cs +++ b/Open.PackML/Prefab/PmlGuardController.cs @@ -68,11 +68,16 @@ public ValidationResult UpdatePmlMode(PmlMode packMLMode) if (temp.Success) temp.AddResult(controller.UpdatePmlMode(packMLMode)); return temp; } - public async Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken cancellationToken) + public async Task UpdatePmlModeAsync(PmlMode packMLMode, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); + return await TrySendPmlMode(packMLMode, temp, cancellationToken); + } + + private async Task TrySendPmlMode(PmlMode packMLMode, ValidationResult temp, CancellationToken cancellationToken) + { if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); + if (temp.Success) temp.AddResult(await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); return temp; } @@ -83,11 +88,16 @@ public virtual ValidationResult SendPmlCommand(PmlCommand command) return temp; } - public virtual async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) + public virtual async Task SendPmlCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckTransition(command, currentState, currentMode); + return await TrySendCommandAsync(command, temp, cancellationToken); + } + + internal async Task TrySendCommandAsync(PmlCommand command, ValidationResult temp, CancellationToken cancellationToken) + { if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command, cancellationToken).ConfigureAwait(true)); + if (temp.Success) temp.AddResult(await controller.SendPmlCommandAsync(command, cancellationToken).ConfigureAwait(true)); return temp; } @@ -115,25 +125,25 @@ private void Controller_MachineEvent(object sender, PmlMachineEventArgs e) public PmlState CurrentPmlState() => currentState; public PmlMode CurrentPmlMode() => currentMode; - public PmlState RetrieveCurrentPackMLState() + public PmlState RetrieveCurrentPmlState() { - currentState = controller.RetrieveCurrentPackMLState(); + currentState = controller.RetrieveCurrentPmlState(); return currentState; } - public PmlMode RetrieveCurrentPackMLMode() + public PmlMode RetrieveCurrentPmlMode() { - currentMode = controller.RetrieveCurrentPackMLMode(); + currentMode = controller.RetrieveCurrentPmlMode(); return currentMode; } - public async Task RetrieveCurrentPackMLStateAsync(CancellationToken cancellationToken) + public async Task RetrieveCurrentPmlStateAsync(CancellationToken cancellationToken) { - currentState = await controller.RetrieveCurrentPackMLStateAsync(cancellationToken).ConfigureAwait(true); + currentState = await controller.RetrieveCurrentPmlStateAsync(cancellationToken).ConfigureAwait(true); return currentState; } - public async Task RetrieveCurrentPackMLModeAsync(CancellationToken cancellationToken) + public async Task RetrieveCurrentPmlModeAsync(CancellationToken cancellationToken) { - currentMode = await controller.RetrieveCurrentPackMLModeAsync(cancellationToken).ConfigureAwait(true); + currentMode = await controller.RetrieveCurrentPmlModeAsync(cancellationToken).ConfigureAwait(true); return currentMode; } @@ -149,12 +159,12 @@ public virtual ValidationResult UpdatePmlMode(int packMLMode) } } - public virtual async Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken) + public virtual async Task UpdatePmlModeAsync(int packMLMode, CancellationToken cancellationToken) { if (Enum.IsDefined(typeof(PmlMode), packMLMode)) { if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - return await UpdatePackMLModeAsync((PmlMode)packMLMode, cancellationToken).ConfigureAwait(true); + return await UpdatePmlModeAsync((PmlMode)packMLMode, cancellationToken).ConfigureAwait(true); } else { diff --git a/Open.PackML/Prefab/PmlOemGuardController.cs b/Open.PackML/Prefab/PmlOemGuardController.cs index bbdac78..23fb6d2 100644 --- a/Open.PackML/Prefab/PmlOemGuardController.cs +++ b/Open.PackML/Prefab/PmlOemGuardController.cs @@ -27,7 +27,7 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor { var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.UpdatePackMLModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); + if (temp.Success) temp.AddResult(await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); return temp; } @@ -36,17 +36,13 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor { var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); if (temp.Success) temp.AddResult(controller.SendPmlCommand(command)); - return temp; } public new async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); - if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.SendPackMLCommandAsync(command, cancellationToken).ConfigureAwait(true)); - - return temp; + return await TrySendCommandAsync(command, temp, cancellationToken); } } diff --git a/Open.PackMLTests/TestObjects/TestPmlController.cs b/Open.PackMLTests/TestObjects/TestPmlController.cs index a4a894e..dc026ab 100644 --- a/Open.PackMLTests/TestObjects/TestPmlController.cs +++ b/Open.PackMLTests/TestObjects/TestPmlController.cs @@ -26,12 +26,12 @@ public PmlState CurrentPmlState() return CurrentState; } - public PmlMode RetrieveCurrentPackMLMode() + public PmlMode RetrieveCurrentPmlMode() { throw new NotImplementedException(); } - public Task RetrieveCurrentPackMLModeAsync(CancellationToken token) + public Task RetrieveCurrentPmlModeAsync(CancellationToken token) { throw new NotImplementedException(); } @@ -43,17 +43,17 @@ public void InvokeEvent(Enum @enum) } - public PmlState RetrieveCurrentPackMLState() + public PmlState RetrieveCurrentPmlState() { throw new NotImplementedException(); } - public Task RetrieveCurrentPackMLStateAsync(CancellationToken token) + public Task RetrieveCurrentPmlStateAsync(CancellationToken token) { throw new NotImplementedException(); } - public async Task SendPackMLCommandAsync(PmlCommand packMLCommand, CancellationToken token) => SendPmlCommand(packMLCommand); + public async Task SendPmlCommandAsync(PmlCommand packMLCommand, CancellationToken token) => SendPmlCommand(packMLCommand); public ValidationResult SendPmlCommand(PmlCommand packMLCommand) { @@ -84,7 +84,7 @@ public ValidationResult SendPmlCommand(PmlCommand packMLCommand) } - public async Task UpdatePackMLModeAsync(PmlMode packMLMode, CancellationToken token) => UpdatePmlMode(packMLMode); + public async Task UpdatePmlModeAsync(PmlMode packMLMode, CancellationToken token) => UpdatePmlMode(packMLMode); public ValidationResult UpdatePmlMode(PmlMode packMLMode) { @@ -96,7 +96,7 @@ public ValidationResult UpdatePmlMode(int packMLMode) throw new NotImplementedException(); } - public Task UpdatePackMLModeAsync(int packMLMode, CancellationToken token) + public Task UpdatePmlModeAsync(int packMLMode, CancellationToken token) { throw new NotImplementedException(); } From bee9412a76367d857567e66cd54ff76a08a56727 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 17:38:22 +0100 Subject: [PATCH 12/31] Add net48 testing --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 2 +- Open.PackMLTests/Open.PackMLTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 62f0e95..5b578bd 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net48;net6.0 false diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 3f1609f..7db6d24 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net48;net6.0 false From ba08ba039696641b93cd6578b226e9a4155ccafe Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 17:41:21 +0100 Subject: [PATCH 13/31] Reintroduce netstandard2.0 --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 2 +- .../Autabee.Utility.IEC61131TypeConversion.csproj | 2 +- Autabee.Utility/Autabee.Utility.csproj | 2 +- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 2 +- Open.PackML.Tags/Open.PackML.Tags.csproj | 2 +- Open.PackML/Open.PackML.csproj | 2 +- Open.PackMLTests/Open.PackMLTests.csproj | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 5b578bd..d96c5e0 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@  - net48;net6.0 + net48;netstandard2.0;net6.0 false diff --git a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj b/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj index 0362804..dd1422a 100644 --- a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj +++ b/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj @@ -1,7 +1,7 @@ - net6.0;net48 + net48;netstandard2.0;net6.0 readme.md diff --git a/Autabee.Utility/Autabee.Utility.csproj b/Autabee.Utility/Autabee.Utility.csproj index 41b4c57..8c11a14 100644 --- a/Autabee.Utility/Autabee.Utility.csproj +++ b/Autabee.Utility/Autabee.Utility.csproj @@ -1,7 +1,7 @@ - net6.0;net48 + net48;netstandard2.0;net6.0 readme.md diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index a04bf1a..c4e0f26 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,7 +1,7 @@ - net6.0;net48 + net48;netstandard2.0;net6.0 diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index a06b7eb..cd8ba34 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -1,7 +1,7 @@  - net6.0;net48 + net48;netstandard2.0;net6.0 readme.md diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index 80f493f..5d4d03c 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -1,7 +1,7 @@  - net6.0;net48 + net48;netstandard2.0;net6.0;netstandard2.0 readme.md diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 7db6d24..02b0863 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net48;net6.0 + net48;netstandard2.0;net6.0 false From 2d08a5073290170e237a4ffff361824ee96c1362 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:06:22 +0100 Subject: [PATCH 14/31] fix double framework --- Autabee.Utility/Autabee.Utility.csproj | 2 +- Open.PackML/Open.PackML.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Autabee.Utility/Autabee.Utility.csproj b/Autabee.Utility/Autabee.Utility.csproj index 8c11a14..3bfe640 100644 --- a/Autabee.Utility/Autabee.Utility.csproj +++ b/Autabee.Utility/Autabee.Utility.csproj @@ -1,7 +1,7 @@ - net48;netstandard2.0;net6.0 + netstandard2.0;net6.0;net48 readme.md diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index 5d4d03c..43e56d1 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -1,7 +1,7 @@  - net48;netstandard2.0;net6.0;netstandard2.0 + net48;netstandard2.0;net6.0 readme.md From ee4709dd209a7848a74a594bf46308784ab115be Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:06:29 +0100 Subject: [PATCH 15/31] part 2 --- Autabee.Utility/Autabee.Utility.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Autabee.Utility/Autabee.Utility.csproj b/Autabee.Utility/Autabee.Utility.csproj index 3bfe640..8c11a14 100644 --- a/Autabee.Utility/Autabee.Utility.csproj +++ b/Autabee.Utility/Autabee.Utility.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net48 + net48;netstandard2.0;net6.0 readme.md From 616577c5e6fcb7397c67de0e66e313c3a080bd74 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:07:36 +0100 Subject: [PATCH 16/31] Cleanup Guards --- Open.PackML/Prefab/PmlGuardController.cs | 16 ++++------------ Open.PackML/Prefab/PmlOemGuardController.cs | 7 ++++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Open.PackML/Prefab/PmlGuardController.cs b/Open.PackML/Prefab/PmlGuardController.cs index 56fc90c..7a720e5 100644 --- a/Open.PackML/Prefab/PmlGuardController.cs +++ b/Open.PackML/Prefab/PmlGuardController.cs @@ -71,16 +71,13 @@ public ValidationResult UpdatePmlMode(PmlMode packMLMode) public async Task UpdatePmlModeAsync(PmlMode packMLMode, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); - return await TrySendPmlMode(packMLMode, temp, cancellationToken); - } - - private async Task TrySendPmlMode(PmlMode packMLMode, ValidationResult temp, CancellationToken cancellationToken) - { if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); + if (temp.Success) return await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true); return temp; } + + public virtual ValidationResult SendPmlCommand(PmlCommand command) { var temp = PmlTransitionCheck.CheckTransition(command, currentState, currentMode); @@ -91,13 +88,8 @@ public virtual ValidationResult SendPmlCommand(PmlCommand command) public virtual async Task SendPmlCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = PmlTransitionCheck.CheckTransition(command, currentState, currentMode); - return await TrySendCommandAsync(command, temp, cancellationToken); - } - - internal async Task TrySendCommandAsync(PmlCommand command, ValidationResult temp, CancellationToken cancellationToken) - { if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.SendPmlCommandAsync(command, cancellationToken).ConfigureAwait(true)); + if (temp.Success) return await controller.SendPmlCommandAsync(command, cancellationToken).ConfigureAwait(true); return temp; } diff --git a/Open.PackML/Prefab/PmlOemGuardController.cs b/Open.PackML/Prefab/PmlOemGuardController.cs index 23fb6d2..af5a2f9 100644 --- a/Open.PackML/Prefab/PmlOemGuardController.cs +++ b/Open.PackML/Prefab/PmlOemGuardController.cs @@ -27,8 +27,7 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor { var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); - if (temp.Success) temp.AddResult(await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true)); - + if (temp.Success) return await controller.UpdatePmlModeAsync(packMLMode, cancellationToken).ConfigureAwait(true); return temp; } @@ -42,7 +41,9 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor public new async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); - return await TrySendCommandAsync(command, temp, cancellationToken); + if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); + if (temp.Success) return await controller.SendPmlCommandAsync(command, cancellationToken).ConfigureAwait(true); + return temp; } } From 5d0ca04b9b619ec2b2b769a6857757df7c04b7f9 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:08:07 +0100 Subject: [PATCH 17/31] inititialize Interlock --- Open.PackML.Prefab/PmlTr88Controller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Open.PackML.Prefab/PmlTr88Controller.cs b/Open.PackML.Prefab/PmlTr88Controller.cs index bb1b90c..2a52dea 100644 --- a/Open.PackML.Prefab/PmlTr88Controller.cs +++ b/Open.PackML.Prefab/PmlTr88Controller.cs @@ -43,7 +43,7 @@ public PmlTr88Controller(IPmlController controller, IPmlEventStore eventStore, I public PmlStopReason StopReason { get; protected set; } = new PmlStopReason(); [TagType(TagType.Status)] - public PmlEquipmentInterlock EquipmentInterlock { get; } + public PmlEquipmentInterlock EquipmentInterlock { get; protected set; } = new PmlEquipmentInterlock(); [TagType(TagType.Command)] [TagEndUserTerm("Command")] From 9761204c8ac396bc38e9368429ef34322b69fa63 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:29:13 +0100 Subject: [PATCH 18/31] Change Test Frameworks --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 6 +++--- Open.PackMLTests/Open.PackMLTests.csproj | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index d96c5e0..13044f9 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -9,9 +9,9 @@ - - - + + + diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 02b0863..2e98965 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net48;netstandard2.0;net6.0 + net48;net6.0 false @@ -21,9 +21,12 @@ - + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From d092ace3d5680ec6a188341b74c2a2b3c99fe2a4 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:29:34 +0100 Subject: [PATCH 19/31] Cleanup TagTreeBuilder --- Open.PackML.Tags/ArrayTagDetail.cs | 20 -- Open.PackML.Tags/Builders/TagTableBuilder.cs | 2 +- Open.PackML.Tags/Builders/TagTreeBuilder.cs | 283 ++++++++++-------- .../Builders/TagTreeBuilderProcessData.cs | 25 ++ Open.PackML.Tags/TagDetail.cs | 171 ++++++----- Open.PackMLTests/Prefab/BuildTagTreeTests.cs | 4 +- Open.PackMLTests/Prefab/TagControllerTests.cs | 3 +- Open.PackMLTests/Prefab/Tr88TagsTest.cs | 20 +- 8 files changed, 304 insertions(+), 224 deletions(-) delete mode 100644 Open.PackML.Tags/ArrayTagDetail.cs create mode 100644 Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs diff --git a/Open.PackML.Tags/ArrayTagDetail.cs b/Open.PackML.Tags/ArrayTagDetail.cs deleted file mode 100644 index 92b1fde..0000000 --- a/Open.PackML.Tags/ArrayTagDetail.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; - -namespace Open.PackML.Tags -{ - internal class ArrayTagDetail : TagDetail - { - internal ArrayTagDetail( - TagConfig config, - object baseObject, - TagDetail[] childTags, - int length, - MemberInfo[] propertyInfos, - bool[] arrayType) : base(config, baseObject, childTags, propertyInfos, arrayType) - { Length = length; } - - public int Length { get; } - } -} \ No newline at end of file diff --git a/Open.PackML.Tags/Builders/TagTableBuilder.cs b/Open.PackML.Tags/Builders/TagTableBuilder.cs index 1ecb1aa..cf8975f 100644 --- a/Open.PackML.Tags/Builders/TagTableBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTableBuilder.cs @@ -4,7 +4,7 @@ namespace Open.PackML.Tags.Builders { - + public static class TagTableBuilder { public static TagTable BuildTagTable(Dictionary collection) diff --git a/Open.PackML.Tags/Builders/TagTreeBuilder.cs b/Open.PackML.Tags/Builders/TagTreeBuilder.cs index 7c29e32..66e27a7 100644 --- a/Open.PackML.Tags/Builders/TagTreeBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTreeBuilder.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Reflection; @@ -29,7 +28,7 @@ internal static TagDetail GetTree(string root, object obj, string description = { Type type = obj.GetType(); if ((type.IsArray - || type.GetInterfaces().Contains(typeof(IEnumerable)))) + || type.GetInterfaces().Contains(typeof(IEnumerable)))) throw new ArgumentException("Cannot create a tag tree from an array or IEnumerable"); TagConfig conf = new TagConfig() @@ -40,134 +39,131 @@ internal static TagDetail GetTree(string root, object obj, string description = Description = description, EndUserTerm = endUserTerm }; - - return GetTree(conf, type, obj, new List() { type }, TagType.Undefined, new List(), new List() { }, Iec); + TagTreeBuilderProcessData tagbuilder = new TagTreeBuilderProcessData(Iec, obj); + tagbuilder.TypesChain.Add(type); + return GetTree(conf, type, tagbuilder, TagType.Undefined); } private static TagDetail GetTree(TagConfig root, Type objType, - object baseObject, - List types, - TagType TagTypeCarry, - List propertyChain, - List arraytree, - bool Iec) + TagTreeBuilderProcessData tagBuilder, + TagType TagTypeCarry) { List Children = new List(); - foreach (var property in objType.GetProperties()) - { - if (property.GetCustomAttribute(typeof(TagIgnoreAttribute)) != null) continue; - - if (!(property.CanRead || property.CanWrite)) continue; - - var config = GetPropertyTagConfig(property, root.Name, TagTypeCarry); - propertyChain.Add(property); - if ((config.DataType.IsArray - || config.DataType.GetInterfaces().Contains(typeof(IEnumerable))) - && config.DataType != typeof(string) - && !types.Contains(config.DataType)) - { - Type elementType; - if (config.DataType.IsArray) - { - elementType = config.DataType.GetElementType(); - } - else - { - if (config.DataType.GenericTypeArguments.Count() > 0) - elementType = config.DataType.GenericTypeArguments[0]; - else continue; - } - - int lenght = -1; - string arrayRoot = string.IsNullOrWhiteSpace(root.Name) ? root.Name : root.Name + '.'; - var fixedSizeAttribute = property.GetCustomAttribute(typeof(TagFixedSizeAttribute)) as TagFixedSizeAttribute; - if (config.DataType != typeof(char[]) - && fixedSizeAttribute != null - && fixedSizeAttribute.Size >= 0 ) - { - config.Name = arrayRoot + property.Name + $"[0..{fixedSizeAttribute.Size}]"; - lenght = fixedSizeAttribute.Size; - } - if (config.DataType == typeof(char[]) - && fixedSizeAttribute != null - && fixedSizeAttribute.Size >= 0) - { - config.Name = arrayRoot + property.Name; - lenght = fixedSizeAttribute.Size; - } - else - { - config.Name = arrayRoot + property.Name + $"[#]"; - } - types.Add(config.DataType); - arraytree.Add(true); - var tree = GetTree(config, - elementType, - baseObject, - types, - config.TagType, - propertyChain, - arraytree, Iec - ); - - Children.Add(new ArrayTagDetail( - config, - baseObject, - tree.ChildTags.ToArray(), - lenght, - propertyChain.ToArray(), - arraytree.ToArray())); - arraytree.RemoveAt(arraytree.Count - 1); - types.Remove(config.DataType); - } - else if ((config.DataType.IsInterface - || config.DataType.IsClass - || config.DataType.IsValueType) - && !config.DataType.IsPrimitive - && config.DataType != typeof(string) - && config.DataType != typeof(DateTime) - && config.DataType != typeof(TimeSpan) - && !config.DataType.IsEnum - && !types.Contains(config.DataType) // prevent circular references - ) - { - types.Add(config.DataType); - arraytree.Add(false); - Children.Add(GetTree(config, - property.PropertyType, - baseObject, - types, - config.TagType, - propertyChain, - arraytree,Iec - )); - arraytree.RemoveAt(arraytree.Count - 1); - types.Remove(config.DataType); - } - else - { - arraytree.Add(false); - Children.Add(new TagDetail(config, baseObject, new TagDetail[0], propertyChain.ToArray(),arraytree.ToArray())); - arraytree.RemoveAt(arraytree.Count - 1); - } - propertyChain.RemoveAt(propertyChain.Count - 1); - } + Children.AddRange(objType.GetProperties() + .Select(o => ProcessProperty(root, tagBuilder, TagTypeCarry, o)) + .Where(o => o != null)); foreach (var method in objType.GetMethods()) { - arraytree.Add(false); if (method.GetCustomAttribute(typeof(TagTypeAttribute)) is TagTypeAttribute attribute) { - var config = GetMethodeTagConfig(method, root.Name, attribute.TagType, Iec); - propertyChain.Add(method); - Children.Add(new TagDetail(config, baseObject, new TagDetail[0], propertyChain.ToArray(), arraytree.ToArray())); - propertyChain.Remove(method); + Children.Add(ProcessMethode(root, tagBuilder, Children, method, attribute)); } - arraytree.RemoveAt(arraytree.Count - 1); + + } + return new TagDetail(root, tagBuilder, Children.ToArray()); + } + + private static TagDetail ProcessMethode(TagConfig root, TagTreeBuilderProcessData tagBuilder, List Children, MethodInfo method, TagTypeAttribute attribute) + { + var config = GetMethodeTagConfig(method, root.Name, attribute.TagType, tagBuilder.iec); + tagBuilder.ArrayChain.Add(false); + tagBuilder.PropertyChain.Add(method); + var tmp = new TagDetail(config, tagBuilder, new TagDetail[0]); + tagBuilder.PropertyChain.RemoveLast(); + tagBuilder.ArrayChain.RemoveLast(); + return tmp; + } + + private static TagDetail ProcessProperty(TagConfig root, TagTreeBuilderProcessData tagBuilder, TagType TagTypeCarry, PropertyInfo property) + { + if (property.GetCustomAttribute(typeof(TagIgnoreAttribute)) != null) return null; + + if (!(property.CanRead || property.CanWrite)) return null; + + var config = GetPropertyTagConfig(property, root.Name, TagTypeCarry); + tagBuilder.PropertyChain.Add(property); + TagDetail result; + if (config.IsCollection(tagBuilder.TypesChain)) + { + result = ProcessCollection(root, tagBuilder, property, config); + } + else if (config.IsObject(tagBuilder.TypesChain)) + { + result = ProcessObject(tagBuilder, property, config); } + else + { + result = ProcessValue(tagBuilder, config); + } + tagBuilder.PropertyChain.RemoveLast(); + return result; + } + private static TagDetail ProcessValue(TagTreeBuilderProcessData tagBuilder, TagConfig config) + { + tagBuilder.ArrayChain.Add(false); + var tmp = new TagDetail(config, tagBuilder, new TagDetail[0]); + tagBuilder.ArrayChain.RemoveLast(); + return tmp; + } - return new TagDetail(root, baseObject, Children.ToArray(), propertyChain.ToArray(), arraytree.ToArray()); + private static TagDetail ProcessObject(TagTreeBuilderProcessData tagBuilder, PropertyInfo property, TagConfig config) + { + tagBuilder.PrepareDive(config, false); + var tmp = GetTree(config, + property.PropertyType, + tagBuilder, + config.TagType + ); + tagBuilder.Surface(); + return tmp; + } + + private static TagDetail ProcessCollection(TagConfig root, TagTreeBuilderProcessData tagBuilder, PropertyInfo property, TagConfig config) + { + Type elementType = config.GetElementType(); + (int lenght, config.Name) = GetNameAndLenght(root, property); + tagBuilder.PrepareDive(config, true); + var tree = GetTree(config, + elementType, + tagBuilder, + config.TagType + ); + + var temp = (new TagDetail( + config, + tagBuilder, + tree.ChildTags.ToArray(), + lenght)); + tagBuilder.Surface(); + return temp; + } + + private static void Surface(this TagTreeBuilderProcessData tagBuilder) + { + tagBuilder.ArrayChain.RemoveLast(); + tagBuilder.TypesChain.RemoveLast(); + } + + private static void RemoveLast(this List ts) => ts.RemoveAt(ts.Count - 1); + + + private static void PrepareDive(this TagTreeBuilderProcessData tagBuilder, TagConfig config, bool array) + { + tagBuilder.TypesChain.Add(config.DataType); + tagBuilder.ArrayChain.Add(array); + } + + private static Type GetElementType(this TagConfig config) + { + Type elementType; + if (config.DataType.IsArray) + elementType = config.DataType.GetElementType(); + else if (config.DataType.GenericTypeArguments.Count() > 0) + elementType = config.DataType.GenericTypeArguments[0]; + else throw new Exception($"Unhandled Elementtype of collection type {config.DataType}"); + return elementType; } private static TagConfig GetPropertyTagConfig(PropertyInfo property, string root, TagType TagCarry) @@ -190,8 +186,8 @@ private static TagConfig GetPropertyTagConfig(PropertyInfo property, string root private static TagConfig GetMethodeTagConfig(MethodInfo property, string root, TagType TagCarry, bool Iec) { - var paramters = property.GetParameters().Aggregate("", (accumulator, item) => - accumulator += (Iec?item.ParameterType.GetIecTypeString(): item.ParameterType.ToString()) + var paramters = property.GetParameters().Aggregate("", (accumulator, item) => + accumulator += (Iec ? item.ParameterType.GetIecTypeString() : item.ParameterType.ToString()) + " " + item.Name + ",").TrimEnd(','); TagConfig config = new TagConfig() { @@ -206,7 +202,58 @@ private static TagConfig GetMethodeTagConfig(MethodInfo property, string root, T }; + return config; } + private static (int, string) GetNameAndLenght(TagConfig root, PropertyInfo property) + { + int length; + string name = string.Empty; + string arrayRoot = string.IsNullOrWhiteSpace(root.Name) ? root.Name : root.Name + '.'; + var fixedSizeAttribute = property.GetCustomAttribute(typeof(TagFixedSizeAttribute)) as TagFixedSizeAttribute; + + if (fixedSizeAttribute != null && fixedSizeAttribute.Size >= 0) + { + if (property.PropertyType == typeof(char[])) + { + name = arrayRoot + property.Name; // + $"[{fixedSizeAttribute.Size}]"; + length = fixedSizeAttribute.Size; + } + else + { + name = arrayRoot + property.Name + $"[0..{fixedSizeAttribute.Size}]"; + length = fixedSizeAttribute.Size; + } + } + else + { + name = arrayRoot + property.Name + $"[#]"; + length = -1; + } + + return (length, name); + } + + private static bool IsObject(this TagConfig config, IEnumerable types) + { + return (config.DataType.IsInterface + || config.DataType.IsClass + || config.DataType.IsValueType) + && !config.DataType.IsPrimitive + && config.DataType != typeof(string) + && config.DataType != typeof(DateTime) + && config.DataType != typeof(TimeSpan) + && !config.DataType.IsEnum + && !types.Contains(config.DataType); + } + + private static bool IsCollection(this TagConfig config, IEnumerable types) + { + return (config.DataType.IsArray + || config.DataType.GetInterfaces().Contains(typeof(IEnumerable))) + && config.DataType != typeof(string) + && !types.Contains(config.DataType); + } + } } diff --git a/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs b/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs new file mode 100644 index 0000000..e983c2c --- /dev/null +++ b/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Open.PackMLTests")] +namespace Open.PackML.Tags.Builders +{ + internal class TagTreeBuilderProcessData + { + internal readonly object baseObject; + internal readonly bool iec; + + internal List TypesChain { get; } = new List(); + internal List PropertyChain { get; } = new List(); + internal List ArrayChain { get; } = new List(); + + internal TagTreeBuilderProcessData(bool Iec, object BaseObject) + { + baseObject = BaseObject; + iec = Iec; + } + } +} diff --git a/Open.PackML.Tags/TagDetail.cs b/Open.PackML.Tags/TagDetail.cs index e1a856f..7cd2f88 100644 --- a/Open.PackML.Tags/TagDetail.cs +++ b/Open.PackML.Tags/TagDetail.cs @@ -1,4 +1,16 @@ using Autabee.Utility; + +/* Unmerged change from project 'Open.PackML.Tags (net6.0)' +Before: +using Open.PackML.Tags.Builders; +After: +using Open; +using Open.PackML; +using Open.PackML.Tags; +using Open.PackML.PackML.Tags.Builders; +*/ + +using Open.PackML.Tags.Builders; using System; using System.Collections; using System.Collections.Generic; @@ -24,18 +36,18 @@ internal class TagDetail : TagConfig private ParameterInfo[] parameters; private MethodInfo setMethod; - public TagDetail(TagConfig config, object baseObject, TagDetail[] childTags, MemberInfo[] memberInfos, bool[] arrayType) : base(config) + internal TagDetail(TagConfig config, TagTreeBuilderProcessData tagBuilder, TagDetail[] childTags, int length =-1) : base(config) { - if (baseObject == null) + if (tagBuilder.baseObject == null) { - throw new ArgumentNullException(nameof(baseObject)); + throw new ArgumentNullException(nameof(tagBuilder.baseObject)); } - this.baseObject = baseObject; + baseObject = tagBuilder.baseObject; if (childTags != null) ChildTags = childTags; else ChildTags = new TagDetail[0]; - memberInfo = memberInfos; - if (memberInfos.Length >= 1) + memberInfo = tagBuilder.PropertyChain.ToArray(); + if (memberInfo.Length >= 1) { last = memberInfo[memberInfo.Length - 1]; if (last is PropertyInfo propertyInfo) @@ -50,15 +62,18 @@ public TagDetail(TagConfig config, object baseObject, TagDetail[] childTags, Mem parameters = methodInfo.GetParameters(); } } - ArrayType = arrayType; + ArrayType = tagBuilder.ArrayChain.ToArray(); arrayTreeCount = Name.Count(o => o == '['); + Length = length; } - private bool IsMethod { get => last is MethodInfo; } private bool IsProperty { get => last is PropertyInfo; } - private bool Readable { get => (getMethod != null && getMethod.IsPublic); } - private bool Writable { get => (setMethod != null && setMethod.IsPublic); } + private bool Readable { get => getMethod != null && getMethod.IsPublic; } + private bool Writable { get => setMethod != null && setMethod.IsPublic; } + + private bool IsArray { get => DataType.IsArray; } + public int Length { get; private set; } public ValidationResult Execute(Queue queue, object[] args) { @@ -68,15 +83,7 @@ public ValidationResult Execute(Queue queue, object[] args) if (args == null) args = Array.Empty(); if (args.Length != parameters.Length) validation.AddResult(false, "tyring to call a function with {0} parmeters with {1}", formatObjects: new object[] { parameters.Length, args.Length }); if (!validation.Success) return validation; - for (int i = 0; i < parameters.Length; i++) - { - var parType = parameters[i].ParameterType; - if (args == null && parType.IsClass) continue; - else if (args[i].GetType() == parType) continue; - else if (args[i].GetType().GetNestedTypes().Contains(parType)) continue; - else if (args[i].GetType().GetInterfaces().Contains(parType)) continue; - validation.AddResult(false, "Parameter {0} is not of type {1}", i, parType.Name); - } + CheckPameters(args, validation); if (!validation.Success) return validation; validation = MoveToLastBase(queue); @@ -95,13 +102,26 @@ public ValidationResult Execute(Queue queue, object[] args) return new ValidationResult(Object: result); } + private void CheckPameters(object[] args, ValidationResult validation) + { + for (int i = 0; i < parameters.Length; i++) + { + var parType = parameters[i].ParameterType; + if (args == null && parType.IsClass) continue; + else if (args[i].GetType() == parType) continue; + else if (args[i].GetType().GetNestedTypes().Contains(parType)) continue; + else if (args[i].GetType().GetInterfaces().Contains(parType)) continue; + validation.AddResult(false, "Parameter {0} is not of type {1}", i, parType.Name); + } + } + private ValidationResult MoveToLastBase(Queue queue) { object result = baseObject; for (int i = 0; i < memberInfo.Length - 1; i++) { result = GetNextObject(ArrayType[i], (PropertyInfo)memberInfo[i], result, queue); - if (result == null) return ObjectNotFound(TagAddress,i); + if (result == null) return ObjectNotFound(TagAddress, i); } return new ValidationResult(Object: result); } @@ -111,7 +131,7 @@ private static object GetNextObject(bool arraytype, PropertyInfo info, object ob if (arraytype) { - switch ((info).GetValue(obj)) + switch (info.GetValue(obj)) { case Array a: return a.GetValue(queue.Dequeue()); @@ -124,6 +144,27 @@ private static object GetNextObject(bool arraytype, PropertyInfo info, object ob return info.GetValue(obj); } + private static bool SetValue(bool arraytype, PropertyInfo info, object baseObj, object value, Queue queue) + { + if (arraytype) + { + switch (info.GetValue(baseObj)) + { + case Array a: + a.SetValue(value, queue.Dequeue()); + break; + case IList b: + b[queue.Dequeue()] = value; + break; + default: + return false; + }; + } + else + info.SetValue(baseObj, value); + return true; + } + private static ValidationResult ObjectNotFound(string tagName) { return new ValidationResult(false, null, "Object not found at {0}", tagName); @@ -141,28 +182,14 @@ private static ValidationResult ObjectNotFound(string[] address, int i) public ValidationResult GetValue(Queue queue) { - var validation = new ValidationResult(); - if (!Readable)validation.AddResult(false, null, "Object not readable"); - if (!IsProperty) validation.AddResult(false, null, "Tag not a property"); - if (!validation.Success) return validation; - - validation = MoveToLastBase(queue); - if (!validation.Success) return validation;; + if (!Readable) return TagNotReadable(); + if (!IsProperty) return TagNotAProperty(); + var validation = MoveToLastBase(queue); + if (!validation.Success) return validation; PropertyInfo info = (PropertyInfo)last; - - if (info.PropertyType.IsArray && queue.Count == 1) - switch (info.GetValue(validation.Object)) - { - case Array a: - return new ValidationResult(Object: a.GetValue(queue.Dequeue())); - case IList b: - return new ValidationResult(Object: b[queue.Dequeue()]); - default: - return null; - } - else - return new ValidationResult(Object: info.GetValue(validation.Object)); + return new ValidationResult(Object: GetNextObject( + info.PropertyType.IsArray && queue.Count == 1, info, validation.Object, queue)); } @@ -190,47 +217,47 @@ public ValidationResult GetValue(Queue queue) public ValidationResult SetValue(Queue queue, object obj) { Type type = obj.GetType(); - if (!Writable && !DataType.IsArray) return ObjectNotWritable(Name); - if (!IsProperty) return new ValidationResult(false, "Tag not a property"); - if ((type.IsArray && base.DataType.IsArray && base.DataType != type) - || (!type.IsArray && base.DataType.IsArray && base.DataType.GetElementType() != type) - || (!base.DataType.IsArray && base.DataType != type)) - return ObjectTypeMisMatch(base.DataType, type); - + var InsertElement = arrayTreeCount == queue.Count; + if (!IsProperty) + return TagNotAProperty(); + if (!Writable && (!IsArray || !InsertElement)) + return ObjectNotWritable(Name); + if (CheckTyping(type, InsertElement)) + return ObjectTypeMisMatch(DataType, type); + var validation = MoveToLastBase(queue); if (!validation.Success) return validation; - - if (last is PropertyInfo info) - { - if (info.PropertyType.IsArray && queue.Count == 1) - { - switch (info.GetValue(validation.Object)) - { - case Array a: - a.SetValue(obj, queue.Dequeue()); - break; - case IList b: - b[queue.Dequeue()] = obj; - break; - default: - return new ValidationResult(false, "Failed To write Array"); - }; - } - else if (!Writable) return ObjectNotWritable(Name); - else - (info).SetValue(validation.Object, obj); - } + + PropertyInfo info = (PropertyInfo)last; + SetValue(info.PropertyType.IsArray && queue.Count == 1, info, validation.Object, obj, queue); + return new ValidationResult(); } - private static ValidationResult ObjectNotWritable(string TagName) + + + private bool CheckTyping(Type type, bool InsertElement) + { + return IsArray && (!InsertElement && DataType != type + || InsertElement && DataType.GetElementType() != type + ) || !IsArray && DataType != type; + + } + private ValidationResult TagNotReadable() { + return new ValidationResult(false, null, "Object not readable"); + } + private ValidationResult TagNotAProperty() + { + return new ValidationResult(false,null, "Tag {0} is not a property", Name); + } + private static ValidationResult ObjectNotWritable(string TagName) { - return new ValidationResult(false, "{0} not writable", TagName); + return new ValidationResult(false, "{0} not writable", TagName); } - private static ValidationResult ObjectTypeMisMatch(Type expected, Type actually) => new ValidationResult(false, "Object type mismatch. Expected {0} but got {1}", expected.Name, actually.Name); + private static ValidationResult ObjectTypeMisMatch(Type expected, Type actually) => new ValidationResult(false, "Object type mismatch. Expected {0} but got {1}", expected.Name, actually.Name); public TagDetail[] ChildTags { get; } } diff --git a/Open.PackMLTests/Prefab/BuildTagTreeTests.cs b/Open.PackMLTests/Prefab/BuildTagTreeTests.cs index 9322a37..c43385e 100644 --- a/Open.PackMLTests/Prefab/BuildTagTreeTests.cs +++ b/Open.PackMLTests/Prefab/BuildTagTreeTests.cs @@ -1,5 +1,4 @@ -using Open.PackML.Tags; -using Xunit; +using Xunit; using System; using System.Collections.Generic; using System.Linq; @@ -14,6 +13,7 @@ using Open.PackML.Prefab; using Open.PackMLTests.TestObjects; using Open.PackML.Tags.Prefab; +using Open.PackML.Tags; namespace Open.PackMLTests.Prefab { diff --git a/Open.PackMLTests/Prefab/TagControllerTests.cs b/Open.PackMLTests/Prefab/TagControllerTests.cs index 13583a5..7c4bcab 100644 --- a/Open.PackMLTests/Prefab/TagControllerTests.cs +++ b/Open.PackMLTests/Prefab/TagControllerTests.cs @@ -8,6 +8,7 @@ using Open.PackML.Tags; using Open.PackMLTests.TestObjects; using Xunit.Abstractions; +using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; namespace Open.PackMLTests.Prefab { @@ -277,7 +278,7 @@ public void BrowseTagDepth2Function() } } - private static TagController GetDefaultcontroller() + private TagController GetDefaultcontroller() { var moqController = new Mock(); var eventStore = new PmlEventStore(); diff --git a/Open.PackMLTests/Prefab/Tr88TagsTest.cs b/Open.PackMLTests/Prefab/Tr88TagsTest.cs index 0bf93dc..3416775 100644 --- a/Open.PackMLTests/Prefab/Tr88TagsTest.cs +++ b/Open.PackMLTests/Prefab/Tr88TagsTest.cs @@ -17,7 +17,7 @@ namespace Open.PackMLTests.Prefab { - + public class Tr88TagsTest { ITestOutputHelper logger; @@ -39,8 +39,8 @@ public TagConfig[] GetTagConfigList(bool tr88) { continue; } - string tagtypestring = string.Join(", ",tagArray[0].Split('/')); - tagConfig.TagType = (TagType)Enum.Parse(typeof(TagType),tagtypestring); + string tagtypestring = string.Join(", ", tagArray[0].Split('/')); + tagConfig.TagType = (TagType)Enum.Parse(typeof(TagType), tagtypestring); tagConfig.Name = tagArray[1]; tagConfig.EndUserTerm = tagArray[2]; @@ -53,13 +53,13 @@ public TagConfig[] GetTagConfigList(bool tr88) var number = lastPart.Split('[')[1].Split(']')[0]; collectiontype = string.Compare(number, "#", StringComparison.Ordinal) == 0 ? typeof(List<>) : typeof(Array); } - - tagConfig.DataType = IecTypeConvertor.GetCsharpType(tagArray[3],collectiontype, Assembly.GetAssembly(typeof(PmlTr88Controller))); + + tagConfig.DataType = IecTypeConvertor.GetCsharpType(tagArray[3], collectiontype, Assembly.GetAssembly(typeof(PmlTr88Controller))); tagConfigList.Add(tagConfig); } return tagConfigList.ToArray(); } - + //Test if when a tagcontroller uses the Tr88 controller, has all the tags specified by PackML Implementation Guide [Fact()] public void TestTr88Tags() @@ -72,12 +72,12 @@ public void TestTr88Tags() { if (table.TryGetValue(tag.Name, out TagConfig data)) { - if((tag.Name.Equals(data.Name)) + if ((tag.Name.Equals(data.Name)) && (tag.EndUserTerm.Equals(data.EndUserTerm)) && (tag.TagType.Equals(data.TagType)) && (tag.DataType.Equals(data.DataType))) { - + Assert.True(true); } else @@ -91,7 +91,7 @@ public void TestTr88Tags() } - + } } @@ -117,7 +117,7 @@ public void TestEumTags() } else { - result.AddResult(false,$"tag does not match: [{tag.Name}]==[{data.Name}], [{tag.EndUserTerm}]==[{data.EndUserTerm}], [{tag.TagType}]==[{data.TagType}], [{tag.DataType}]==[{data.DataType}]"); + result.AddResult(false, $"tag does not match: [{tag.Name}]==[{data.Name}], [{tag.EndUserTerm}]==[{data.EndUserTerm}], [{tag.TagType}]==[{data.TagType}], [{tag.DataType}]==[{data.DataType}]"); } } else From 96e53b2fa661b6e1c71e3f640c429b01c4a5bfb6 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:33:42 +0100 Subject: [PATCH 20/31] Update Autabee.Utility.IEC61131TypeConversionTests.csproj remove stdnet2.0 --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 13044f9..111fa4e 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -1,7 +1,7 @@  - net48;netstandard2.0;net6.0 + net48;net6.0 false From 0dd09f5aaf48264e50f655bd52d52045ba874dab Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:37:19 +0100 Subject: [PATCH 21/31] reintall xunit --- .../Autabee.Utility.IEC61131TypeConversionTests.csproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj index 111fa4e..939689c 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj @@ -10,8 +10,11 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 9663e30e09b8edb6259945608798c5bca4c0b06b Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 18:53:15 +0100 Subject: [PATCH 22/31] test on windows --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9313070..cac54dd 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v3 From 93fffe2acb3e43316161a033dfc35df973f7c4d1 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 19:03:14 +0100 Subject: [PATCH 23/31] Update pre-release.yml --- .github/workflows/pre-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index d4add06..c69720f 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -1,4 +1,4 @@ -name: .NET +name: pre-release check on: push: From 3c7f5121df9ae27b9d7ee30da8cf9262d95c2817 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Fri, 4 Nov 2022 19:03:41 +0100 Subject: [PATCH 24/31] Update dotnet.yml --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9313070..adc7891 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,4 +1,4 @@ -name: .NET +name: main-pull on: push: From d282f9d6f031f8075bb06a9d818adceee445cbfd Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Thu, 10 Nov 2022 23:50:55 +0100 Subject: [PATCH 25/31] cleanup and extend descriptions --- .../IecTypeConvertorTests.cs | 8 +- .../IECType.cs | 8 +- .../IecTypeConvertor.cs | 15 +- Autabee.Utility/ValidationResult.cs | 8 +- Open.PackML.Prefab/PmlEumController.cs | 3 +- Open.PackML.Prefab/PmlTr88Controller.cs | 9 +- Open.PackML.Prefab/readme.md | 2 +- .../Attributes/TagEndUserTermAttribute.cs | 7 +- .../Attributes/TagFixedSizeAttribute.cs | 3 +- .../Attributes/TagIgnoreAttribute.cs | 4 + .../Attributes/TagTypeAttribute.cs | 6 +- Open.PackML.Tags/Builders/TagTableBuilder.cs | 55 ++- Open.PackML.Tags/Builders/TagTreeBuilder.cs | 71 ++-- .../Builders/TagTreeBuilderProcessData.cs | 3 + Open.PackML.Tags/Interfaces/ITagController.cs | 25 +- Open.PackML.Tags/Interfaces/ITagFactory.cs | 4 +- Open.PackML.Tags/Interfaces/ITagStore.cs | 7 +- Open.PackML.Tags/Prefab/DefaultTagStore.cs | 7 +- Open.PackML.Tags/Prefab/TagController.cs | 23 +- Open.PackML.Tags/Prefab/TagFactory.cs | 2 - Open.PackML.Tags/Tag.cs | 110 ------ Open.PackML.Tags/TagCall.cs | 39 ++- Open.PackML.Tags/TagConfig.cs | 54 ++- Open.PackML.Tags/TagDetail.cs | 30 +- Open.PackML.Tags/TagTable.cs | 44 ++- Open.PackML.Tags/TagType.cs | 2 +- Open.PackML.Tags/readme.md | 2 +- Open.PackML/Interfaces/IPmlController.cs | 2 +- Open.PackML/Interfaces/IPmlEventStore.cs | 4 +- Open.PackML/PmlOemTransitionCheck.cs | 4 - Open.PackML/PmlTransitionCheck.cs | 10 +- Open.PackML/Prefab/PmlEventStore.cs | 30 +- Open.PackML/Prefab/PmlGuardController.cs | 16 +- Open.PackML/Prefab/PmlOemGuardController.cs | 6 +- Open.PackMLTests/PmlGuardControllerTests.cs | 17 +- Open.PackMLTests/PmlTransitionCheckTests.cs | 324 +++++++++--------- Open.PackMLTests/Prefab/BuildTagTreeTests.cs | 30 +- .../Prefab/DefaultEventStoreTests.cs | 12 +- Open.PackMLTests/Prefab/TagControllerTests.cs | 19 +- Open.PackMLTests/Prefab/Tr88TagsTest.cs | 7 +- Open.PackMLTests/TagConfigTests.cs | 7 +- .../TestObjects/TestPmlController.cs | 1 - 42 files changed, 506 insertions(+), 534 deletions(-) delete mode 100644 Open.PackML.Tags/Tag.cs diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs index 77bb9e2..350f7b9 100644 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs +++ b/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs @@ -1,12 +1,10 @@ -using Xunit; +using Autabee.Utility.IEC61131TypeConversion; +using Autabee.Utility.IEC61131TypeConversionTests.TestObjects; using System; -using System.Collections.Generic; -using System.Text; using System.Collections; using System.Linq; +using Xunit; using Xunit.Abstractions; -using Autabee.Utility.IEC61131TypeConversion; -using Autabee.Utility.IEC61131TypeConversionTests.TestObjects; namespace Autabee.Utility.IEC61131TypeConversionTests { diff --git a/Autabee.Utility.IEC61131TypeConversion/IECType.cs b/Autabee.Utility.IEC61131TypeConversion/IECType.cs index 53f422b..bf16a4b 100644 --- a/Autabee.Utility.IEC61131TypeConversion/IECType.cs +++ b/Autabee.Utility.IEC61131TypeConversion/IECType.cs @@ -2,6 +2,9 @@ namespace Autabee.Utility.IEC61131TypeConversion { + /// + /// IEC61131 Type strings + /// public static class IECType { private static string[] DefaultTypes { get; } = @@ -57,9 +60,10 @@ public static class IECType public static string ArrayOf(string type) => $"{type}[]"; - public static bool ContainsType(string type) { + public static bool ContainsType(string type) + { type = type.ToUpper(); - + if (DefaultTypes.Contains(type) || type.StartsWith("UDT_")) return true; if (type.EndsWith("]")) return ContainsType(type.Substring(0, type.IndexOf('['))); return false; diff --git a/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs b/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs index 11e0ede..6e218e1 100644 --- a/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs +++ b/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs @@ -1,16 +1,14 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; using System.Linq; using System.Reflection; -using System.Text.RegularExpressions; using System.Xml; -using System.Xml.Linq; namespace Autabee.Utility.IEC61131TypeConversion { + /// + /// Converter switching between IEC61131 types and C# types + /// public static class IecTypeConvertor { // source https://www.plcnext.help/te/Programming/Csharp/Csharp_programming/Csharp_Supported_data_types.htm @@ -18,7 +16,6 @@ public static string GetIecTypeString(this T value) { Type type = value.GetType(); return GetIecTypeString(type); - } public static string GetIecTypeString(this Type type) { @@ -34,8 +31,8 @@ public static string GetIecTypeString(this Type type) return result; } } - else if (type.GetInterfaces().Contains(typeof(IEnumerable)) - && type != typeof(string) + else if (type.GetInterfaces().Contains(typeof(IEnumerable)) + && type != typeof(string) && type != typeof(BitArray)) { var result = GetIecTypeString(type.GenericTypeArguments[0]) + "[]"; @@ -149,7 +146,7 @@ public static Type GetCsharpType(string typeString, Type collectionType, Assembl { if (typeString.Contains("[")) { - var elementType = GetCsharpType(typeString.Replace("[]", ""), null, executingAssembly); + var elementType = GetCsharpType(typeString.Replace("[]", string.Empty), null, executingAssembly); if (collectionType.IsGenericType) { collectionType = collectionType.MakeGenericType(elementType); diff --git a/Autabee.Utility/ValidationResult.cs b/Autabee.Utility/ValidationResult.cs index d4060c7..0904836 100644 --- a/Autabee.Utility/ValidationResult.cs +++ b/Autabee.Utility/ValidationResult.cs @@ -12,7 +12,7 @@ public class ValidationResult { public ValidationResult(bool success = true, string unSuccessfulText = "", params object[] formatObjects) { - this.Success = success; + Success = success; FailInfo = new List<(string, object[])>(); if (!string.IsNullOrWhiteSpace(unSuccessfulText)) { @@ -28,8 +28,8 @@ public ValidationResult(bool success = true, string unSuccessfulText = "", param } public ValidationResult(bool success = true, List<(string, object[])> failInfo = default) { - this.Success = success; - this.FailInfo = failInfo ?? new List<(string, object[])>(); + Success = success; + FailInfo = failInfo ?? new List<(string, object[])>(); } public void AddResult(ValidationResult validationResult) @@ -50,7 +50,7 @@ public void AddResult(bool succes, string failText, params object[] formatObject } public string FailString() { - string failString = FailInfo.Aggregate("", (accumulator, fail) => accumulator += string.Format(fail.Item1, fail.Item2) + Environment.NewLine); + string failString = FailInfo.Aggregate(string.Empty, (accumulator, fail) => accumulator += string.Format(fail.Item1, fail.Item2) + Environment.NewLine); return failString; } diff --git a/Open.PackML.Prefab/PmlEumController.cs b/Open.PackML.Prefab/PmlEumController.cs index 0e9f574..39dc6f3 100644 --- a/Open.PackML.Prefab/PmlEumController.cs +++ b/Open.PackML.Prefab/PmlEumController.cs @@ -1,5 +1,4 @@ -using Open.PackML.Interfaces; -using Open.PackML.Tags; +using Open.PackML.Tags; using Open.PackML.Tags.Attributes; using System; using System.Collections.Generic; diff --git a/Open.PackML.Prefab/PmlTr88Controller.cs b/Open.PackML.Prefab/PmlTr88Controller.cs index 2a52dea..b5be3c1 100644 --- a/Open.PackML.Prefab/PmlTr88Controller.cs +++ b/Open.PackML.Prefab/PmlTr88Controller.cs @@ -1,7 +1,4 @@ -using Autabee.Utility; -using Open.PackML.EventArguments; -using Open.PackML.Interfaces; -using Open.PackML.Tags; +using Open.PackML.Tags; using Open.PackML.Tags.Attributes; using System; @@ -21,7 +18,7 @@ public PmlTr88Controller(IPmlController controller, IPmlEventStore eventStore, I [TagEndUserTerm("Mode")] [TagType(TagType.Status)] - public int UnitModeCurrent { get => (int)currentMode; } + public int UnitModeCurrent { get => currentMode; } [TagEndUserTerm("Nominal Speed")] @@ -66,7 +63,7 @@ public PmlTr88Controller(IPmlController controller, IPmlEventStore eventStore, I [TagEndUserTerm("Change command")] public bool CmdChangeRequest { - get => false; + get => false; set { if (Enum.IsDefined(typeof(PmlCommand), CntrlCmd)) diff --git a/Open.PackML.Prefab/readme.md b/Open.PackML.Prefab/readme.md index 9aa2152..a214e7e 100644 --- a/Open.PackML.Prefab/readme.md +++ b/Open.PackML.Prefab/readme.md @@ -3,4 +3,4 @@ ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/Open.PackML.Prefab) ![GitHub](https://img.shields.io/github/license/peacefighter1996/Open.PackML) -Extending Open PackML and adding the Tag control feature. \ No newline at end of file +Pre build base controlls that can be extended. \ No newline at end of file diff --git a/Open.PackML.Tags/Attributes/TagEndUserTermAttribute.cs b/Open.PackML.Tags/Attributes/TagEndUserTermAttribute.cs index b11f4da..e543580 100644 --- a/Open.PackML.Tags/Attributes/TagEndUserTermAttribute.cs +++ b/Open.PackML.Tags/Attributes/TagEndUserTermAttribute.cs @@ -3,10 +3,11 @@ namespace Open.PackML.Tags.Attributes { - [AttributeUsage(AttributeTargets.Class | - AttributeTargets.Struct + [AttributeUsage( + AttributeTargets.Class + | AttributeTargets.Struct | AttributeTargets.Property) -] + ] public class TagEndUserTermAttribute : Attribute { public string EndUserTerm { get; } diff --git a/Open.PackML.Tags/Attributes/TagFixedSizeAttribute.cs b/Open.PackML.Tags/Attributes/TagFixedSizeAttribute.cs index b345b8d..f002ea2 100644 --- a/Open.PackML.Tags/Attributes/TagFixedSizeAttribute.cs +++ b/Open.PackML.Tags/Attributes/TagFixedSizeAttribute.cs @@ -2,6 +2,7 @@ namespace Open.PackML.Tags.Attributes { + [AttributeUsage(AttributeTargets.Property)] public class TagFixedSizeAttribute : Attribute { public int Size { get; } @@ -10,7 +11,7 @@ public TagFixedSizeAttribute(int size) this.Size = size; } } - + //public class TagFixedInstanceAttribute : Attribute //{ // public bool Value { get; } diff --git a/Open.PackML.Tags/Attributes/TagIgnoreAttribute.cs b/Open.PackML.Tags/Attributes/TagIgnoreAttribute.cs index 7e9f9d9..f9aa1ba 100644 --- a/Open.PackML.Tags/Attributes/TagIgnoreAttribute.cs +++ b/Open.PackML.Tags/Attributes/TagIgnoreAttribute.cs @@ -3,5 +3,9 @@ namespace Open.PackML.Tags.Attributes { + [AttributeUsage( + AttributeTargets.Method + | AttributeTargets.Property) + ] public class TagIgnoreAttribute : Attribute { }; } diff --git a/Open.PackML.Tags/Attributes/TagTypeAttribute.cs b/Open.PackML.Tags/Attributes/TagTypeAttribute.cs index 65ea668..1aedc4b 100644 --- a/Open.PackML.Tags/Attributes/TagTypeAttribute.cs +++ b/Open.PackML.Tags/Attributes/TagTypeAttribute.cs @@ -4,9 +4,9 @@ namespace Open.PackML.Tags.Attributes { [AttributeUsage( - AttributeTargets.Property - | AttributeTargets.Method) -] + AttributeTargets.Method + | AttributeTargets.Property) + ] public class TagTypeAttribute : Attribute { public TagType TagType { get; } diff --git a/Open.PackML.Tags/Builders/TagTableBuilder.cs b/Open.PackML.Tags/Builders/TagTableBuilder.cs index cf8975f..8457d2b 100644 --- a/Open.PackML.Tags/Builders/TagTableBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTableBuilder.cs @@ -4,27 +4,38 @@ namespace Open.PackML.Tags.Builders { - + /// + /// Build a TagTable from a given object + /// public static class TagTableBuilder { - public static TagTable BuildTagTable(Dictionary collection) + public static TagTable BuildTagTable(string TagName, object obj) + { + var table = new TagTable(); + + table.ExtendTableAtRoot(TagTreeBuilder.GetTree(TagName, obj), false); + + table.GenerateArray(); + table.GenerateOnUpdate = true; + return table; + } + public static TagTable BuildTagTable(Dictionary collection) { var table = new TagTable(); foreach (var item in collection) { - BuildTable(TagTreeBuilder.GetTree(item.Key, item.Value), table); + table.ExtendTableAtRoot(TagTreeBuilder.GetTree(item.Key, item.Value), false); } table.GenerateArray(); table.GenerateOnUpdate = true; return table; } - internal static TagTable BuildTable(IEnumerable tagDetails) { - var table = new TagTable(); + var table = new TagTable(tagDetails.ToArray()); foreach (var tagDetail in tagDetails) { - tagDetail.BuildTable(table); + table.ExtendTable(tagDetail, false); } table.GenerateArray(); table.GenerateOnUpdate = true; @@ -33,19 +44,39 @@ internal static TagTable BuildTable(IEnumerable tagDetails) [assembly: InternalVisibleTo("Open.PackMLTests")] internal static TagTable BuildTable(this TagDetail tagDetails) { - var table = new TagTable(); - tagDetails.BuildTable(table); + var table = new TagTable(new TagDetail[] { tagDetails }); + table.ExtendTable(tagDetails, false); table.GenerateArray(); table.GenerateOnUpdate = true; return table; } + [assembly: InternalVisibleTo("Open.PackMLTests")] - internal static void BuildTable(this TagDetail tagDetails, TagTable table) + internal static void ExtendTable(this TagTable table, TagDetail tagDetails, bool update = true) { + if (update) table.GenerateOnUpdate = false; table.Add(tagDetails.SearchString, tagDetails); - //tagDetails.TagNameUpdate += table.TagUpdated; - foreach (TagDetail tagtree in tagDetails.ChildTags) - tagtree.BuildTable(table); + for (int i = 0; i < tagDetails.ChildTags.Length; i++) + table.ExtendTable(tagDetails.ChildTags[i], false); + if (update) + { + table.GenerateArray(); + table.GenerateOnUpdate = true; + } + } + [assembly: InternalVisibleTo("Open.PackMLTests")] + internal static void ExtendTableAtRoot(this TagTable table, TagDetail tagDetails, bool update = true) + { + if (update) table.GenerateOnUpdate = false; + table.AddRoot(tagDetails.SearchString, tagDetails); + for (int i = 0; i < tagDetails.ChildTags.Length; i++) + table.ExtendTable(tagDetails.ChildTags[i], false); + if (update) + { + table.GenerateArray(); + table.GenerateOnUpdate = true; + } } + } } diff --git a/Open.PackML.Tags/Builders/TagTreeBuilder.cs b/Open.PackML.Tags/Builders/TagTreeBuilder.cs index 66e27a7..ddaa463 100644 --- a/Open.PackML.Tags/Builders/TagTreeBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTreeBuilder.cs @@ -18,19 +18,18 @@ internal static class TagTreeBuilder /// Builds a TagTree from a base object /// /// Root object name - /// Object for which the tree needs to be build - /// - /// - /// + /// Object for which the tree needs to be build from + /// Description of the obj + /// Simplyfied term for enduser + /// Type of tag that is used to set the typing of the propeties that are being scanned /// - /// + /// Does not allow a collection to be used as base object. internal static TagDetail GetTree(string root, object obj, string description = "", string endUserTerm = "", TagType StartTagType = TagType.Undefined, bool Iec = false) { Type type = obj.GetType(); - if ((type.IsArray - || type.GetInterfaces().Contains(typeof(IEnumerable)))) + if (type.IsArray + || type.GetInterfaces().Contains(typeof(IEnumerable))) throw new ArgumentException("Cannot create a tag tree from an array or IEnumerable"); - TagConfig conf = new TagConfig() { Name = root, @@ -57,22 +56,22 @@ private static TagDetail GetTree(TagConfig root, { if (method.GetCustomAttribute(typeof(TagTypeAttribute)) is TagTypeAttribute attribute) { - Children.Add(ProcessMethode(root, tagBuilder, Children, method, attribute)); + Children.Add(ProcessMethode(root, tagBuilder, method, attribute)); } - } + return new TagDetail(root, tagBuilder, Children.ToArray()); } - private static TagDetail ProcessMethode(TagConfig root, TagTreeBuilderProcessData tagBuilder, List Children, MethodInfo method, TagTypeAttribute attribute) + private static TagDetail ProcessMethode(TagConfig root, TagTreeBuilderProcessData tagBuilder, MethodInfo method, TagTypeAttribute attribute) { var config = GetMethodeTagConfig(method, root.Name, attribute.TagType, tagBuilder.iec); tagBuilder.ArrayChain.Add(false); tagBuilder.PropertyChain.Add(method); - var tmp = new TagDetail(config, tagBuilder, new TagDetail[0]); + var result = new TagDetail(config, tagBuilder, new TagDetail[0]); tagBuilder.PropertyChain.RemoveLast(); tagBuilder.ArrayChain.RemoveLast(); - return tmp; + return result; } private static TagDetail ProcessProperty(TagConfig root, TagTreeBuilderProcessData tagBuilder, TagType TagTypeCarry, PropertyInfo property) @@ -103,21 +102,21 @@ private static TagDetail ProcessProperty(TagConfig root, TagTreeBuilderProcessDa private static TagDetail ProcessValue(TagTreeBuilderProcessData tagBuilder, TagConfig config) { tagBuilder.ArrayChain.Add(false); - var tmp = new TagDetail(config, tagBuilder, new TagDetail[0]); + var result = new TagDetail(config, tagBuilder, new TagDetail[0]); tagBuilder.ArrayChain.RemoveLast(); - return tmp; + return result; } private static TagDetail ProcessObject(TagTreeBuilderProcessData tagBuilder, PropertyInfo property, TagConfig config) { tagBuilder.PrepareDive(config, false); - var tmp = GetTree(config, + var result = GetTree(config, property.PropertyType, tagBuilder, config.TagType ); tagBuilder.Surface(); - return tmp; + return result; } private static TagDetail ProcessCollection(TagConfig root, TagTreeBuilderProcessData tagBuilder, PropertyInfo property, TagConfig config) @@ -186,7 +185,7 @@ private static TagConfig GetPropertyTagConfig(PropertyInfo property, string root private static TagConfig GetMethodeTagConfig(MethodInfo property, string root, TagType TagCarry, bool Iec) { - var paramters = property.GetParameters().Aggregate("", (accumulator, item) => + var paramters = property.GetParameters().Aggregate(string.Empty, (accumulator, item) => accumulator += (Iec ? item.ParameterType.GetIecTypeString() : item.ParameterType.ToString()) + " " + item.Name + ",").TrimEnd(','); TagConfig config = new TagConfig() @@ -233,26 +232,34 @@ private static (int, string) GetNameAndLenght(TagConfig root, PropertyInfo prope return (length, name); } - private static bool IsObject(this TagConfig config, IEnumerable types) { - return (config.DataType.IsInterface - || config.DataType.IsClass - || config.DataType.IsValueType) - && !config.DataType.IsPrimitive - && config.DataType != typeof(string) - && config.DataType != typeof(DateTime) - && config.DataType != typeof(TimeSpan) - && !config.DataType.IsEnum - && !types.Contains(config.DataType); + return config.DataType.IsObject(types); + } + private static bool IsObject(this Type type, IEnumerable types) + { + return (type.IsInterface + || type.IsClass + || type.IsValueType) + && !type.IsPrimitive + && type != typeof(string) + && type != typeof(DateTime) + && type != typeof(TimeSpan) + && !type.IsEnum + && !types.Contains(type); } private static bool IsCollection(this TagConfig config, IEnumerable types) { - return (config.DataType.IsArray - || config.DataType.GetInterfaces().Contains(typeof(IEnumerable))) - && config.DataType != typeof(string) - && !types.Contains(config.DataType); + return config.DataType.IsCollection(types); + } + + private static bool IsCollection(this Type type, IEnumerable types) + { + return (type.IsArray + || type.GetInterfaces().Contains(typeof(IEnumerable))) + && type != typeof(string) + && !types.Contains(type); } } diff --git a/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs b/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs index e983c2c..4964fbc 100644 --- a/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs +++ b/Open.PackML.Tags/Builders/TagTreeBuilderProcessData.cs @@ -7,6 +7,9 @@ [assembly: InternalsVisibleTo("Open.PackMLTests")] namespace Open.PackML.Tags.Builders { + /// + /// Proccess data for the TagTreeBuilder + /// internal class TagTreeBuilderProcessData { internal readonly object baseObject; diff --git a/Open.PackML.Tags/Interfaces/ITagController.cs b/Open.PackML.Tags/Interfaces/ITagController.cs index 3e29c3f..f8345ec 100644 --- a/Open.PackML.Tags/Interfaces/ITagController.cs +++ b/Open.PackML.Tags/Interfaces/ITagController.cs @@ -1,32 +1,31 @@ using Autabee.Utility; using Open.PackML.Tags; -using Open.PackML.Tags.Prefab; using System; using System.Collections.Generic; -using System.Threading.Tasks; namespace Open.PackML.Interfaces { public interface ITagController { - //Task> AsyncExecutePackTagCommand(string name, params object[] args); + //Task> AsyncExecutePackTagCommand(string tagName, params object[] args); - - ValidationResult ExecutePackTagCommand(string name, params object[] args); + + ValidationResult ExecutePackTagCommand(string tagName, params object[] args); ValidationResult[] ExecutePackTagCommand(List<(string, object[])> data); - - ValidationResult GetTagData(string name); - ValidationResult GetTagData(string name); - - ValidationResult SetTagData(string name, object data); - ValidationResult SetTagData(string name, T data); - + + ValidationResult GetTagData(string tagName); + ValidationResult GetTagData(string tagName); + + ValidationResult SetTagData(string tagName, object data); + ValidationResult SetTagData(string tagName, T data); + ValidationResult TagCall(TagCall tagCall); ValidationResult[] BatchSetTagData(List<(string, object)> data); - ValidationResult[] BatchGetTagData(List name); + ValidationResult[] BatchGetTagData(List tagName); ValidationResult[] BatchCall(List tagCalls); + //ValidationResult[] BatchCall(BatchTagCall tagCalls); } } diff --git a/Open.PackML.Tags/Interfaces/ITagFactory.cs b/Open.PackML.Tags/Interfaces/ITagFactory.cs index 217eee6..286bff6 100644 --- a/Open.PackML.Tags/Interfaces/ITagFactory.cs +++ b/Open.PackML.Tags/Interfaces/ITagFactory.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Open.PackML.Interfaces { @@ -14,6 +12,6 @@ namespace Open.PackML.Interfaces //{ // TagConfig GenerateTagConfig(Tag tagConfig); // IEnumerable GenerateTagConfig(IEnumerable> tagConfig); - + //} } diff --git a/Open.PackML.Tags/Interfaces/ITagStore.cs b/Open.PackML.Tags/Interfaces/ITagStore.cs index 6887ca7..d62f36b 100644 --- a/Open.PackML.Tags/Interfaces/ITagStore.cs +++ b/Open.PackML.Tags/Interfaces/ITagStore.cs @@ -1,12 +1,13 @@ using Autabee.Utility; using Open.PackML.Tags; -using System.Collections.Generic; namespace Open.PackML.Interfaces { public interface ITagStore { - ValidationResult Browse(string Orgin); - ValidationResult Browse(string Orgin, uint Depth); + ValidationResult BrowseRoot(); + ValidationResult BrowseAll(); + ValidationResult Browse(string baseTagName); + ValidationResult Browse(string baseTagName, uint Depth); } } \ No newline at end of file diff --git a/Open.PackML.Tags/Prefab/DefaultTagStore.cs b/Open.PackML.Tags/Prefab/DefaultTagStore.cs index 0600a20..1041126 100644 --- a/Open.PackML.Tags/Prefab/DefaultTagStore.cs +++ b/Open.PackML.Tags/Prefab/DefaultTagStore.cs @@ -1,10 +1,5 @@ -using Autabee.Utility; -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; +using System; using System.Linq; -using System.Reflection; namespace Open.PackML.Prefab { diff --git a/Open.PackML.Tags/Prefab/TagController.cs b/Open.PackML.Tags/Prefab/TagController.cs index 2e02f1d..27e3c84 100644 --- a/Open.PackML.Tags/Prefab/TagController.cs +++ b/Open.PackML.Tags/Prefab/TagController.cs @@ -2,13 +2,8 @@ using Open.PackML.Interfaces; using Open.PackML.Tags.Builders; using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Runtime.InteropServices; -using System.Xml.Linq; namespace Open.PackML.Tags.Prefab { @@ -87,8 +82,14 @@ ValidationResult> GetTagArrayIndexes(string name) // else return new ValidationResult(false, unSuccesfullText: "Tag {0} not found", formatObjects: name); //} - - + public ValidationResult BrowseAll() + { + return new ValidationResult(true, tagTable.GetTags); + } + public ValidationResult BrowseRoot() + { + return new ValidationResult(true, tagTable.GetRoots); + } public ValidationResult Browse(string name) { if (!tagTable.TryGetValue(TagConfig.TagStringToSearch(name), out TagConfig tagDetail)) @@ -100,21 +101,21 @@ public ValidationResult Browse(string name, uint Depth = 1) { if (!tagTable.TryGetValue(TagConfig.TagStringToSearch(name), out TagConfig tagDetail)) return new ValidationResult(false, unSuccesfullText: "Tag {0} not found", formatObjects: name); - var result = GetChildren(((TagDetail)tagDetail),Depth).ToArray(); + var result = GetChildren(((TagDetail)tagDetail), Depth).ToArray(); return new ValidationResult(true, result); } internal static IEnumerable GetChildren(TagDetail tagDetail, uint Depth) { - if (Depth <= 1) + if (Depth <= 1) return tagDetail.ChildTags; - + var childeren = new List(); foreach (var child in tagDetail.ChildTags) { childeren.AddRange(GetChildren(child, Depth - 1)); - + } childeren.AddRange(tagDetail.ChildTags); return childeren; diff --git a/Open.PackML.Tags/Prefab/TagFactory.cs b/Open.PackML.Tags/Prefab/TagFactory.cs index d6224ec..86376ce 100644 --- a/Open.PackML.Tags/Prefab/TagFactory.cs +++ b/Open.PackML.Tags/Prefab/TagFactory.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Open.PackML.Prefab { diff --git a/Open.PackML.Tags/Tag.cs b/Open.PackML.Tags/Tag.cs deleted file mode 100644 index 3a8eeac..0000000 --- a/Open.PackML.Tags/Tag.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace Open.PackML.Tags -{ - //public abstract class Tag : TagConfig - //{ - // public Tag(TagConfig tagConfig) : base(tagConfig) - // { - // DataType = typeof(T); - // } - - //} - - //public class StatusTag : DataTag where T : IComparable - //{ - // public StatusTag(DataTagConfig dataTagConfig) : base(dataTagConfig) - // { - // } - - // public override TagType TagType => TagType.Status; - //} - - //public class AdminTag : DataTag where T : IComparable - //{ - // public AdminTag(DataTagConfig dataTagConfig) : base(dataTagConfig) - // { - // } - - // public override TagType TagType => TagType.Admin; - //} - - //public class DataTagConfig : TagConfig - //{ - // public object DefaultValue; - //} - - //public class DataTag : Tag where T : IComparable - //{ - // private T tagValue; - - - // public DataTag(DataTagConfig dataTagConfig) : base(dataTagConfig) - // { - // tagValue = default; - // } - - - // public DataTag(DataTagConfig config, T Initvalue) : base(config) - // { - // tagValue = Initvalue; - // } - - // public T Value - // { - // get => tagValue; set - // { - // if (tagValue.CompareTo(value) != 0) - // { - // tagValue = value; - // ValueUpdated?.BeginInvoke(this, value, null, new object()); - // } - // } - // } - - // public override TagType TagType => throw new NotImplementedException(); - - // public event EventHandler ValueUpdated; - - //} - - //public class CommandTagConfig : TagConfig - //{ - // public Type EnumType; - // public object value; - //} - - //public class FunctionCommandTag : Tag - //{ - // private readonly object baseObject; - - // public FunctionCommandTag(object baseObject, TagConfig tagConfig) : base(tagConfig) - // { - // this.baseObject = baseObject; - // } - - // public override TagType TagType => TagType.Command; - - // public void Execute(T data) - // { - // //MachineController.ExecutePackTagCommand(Name, data); - // } - // public async Task ExecuteAsync(T data) - // { - // // await MachineController.AsyncExecutePackTagCommand(Name, data); - // } - //} - - //public class DataCommandTag : DataTag where K : Enum where T : IComparable - //{ - // public DataCommandTag(IPmlController machineController, DataTagConfig tagConfig) : base(tagConfig) - // { - // MachineController = machineController; - // } - - // private IPmlController MachineController; - - // public override TagType TagType => TagType.Command; - //} -} diff --git a/Open.PackML.Tags/TagCall.cs b/Open.PackML.Tags/TagCall.cs index eb27ea5..ecfbf83 100644 --- a/Open.PackML.Tags/TagCall.cs +++ b/Open.PackML.Tags/TagCall.cs @@ -3,10 +3,14 @@ namespace Open.PackML.Tags { + /// + /// A tag call is a request to do something with a tag. + /// public class TagCall { public TagCall() { + } public TagCall(TagCallType tagCallType, string tagName, object data = null) { @@ -15,8 +19,41 @@ public TagCall(TagCallType tagCallType, string tagName, object data = null) Data = data; } - public TagCallType TagCallType { get; set; } + /// + /// Data as input or set value data + /// public object Data { get; set; } + + /// + /// The type of tag call. + /// + public TagCallType TagCallType { get; set; } + /// + /// Name of the tag being called + /// public string TagName { get; set; } } + + + + //public class BatchTagCall: Dictionary> + //{ + // public bool allowAsyncCalls; + //} + // + //public static class TagCallBuilder + //{ + // public static TagCall MethodCall(string tagName, object[] inputArguments) + // { + // return new TagCall(TagCallType.Execute, tagName, inputArguments); + // } + // public static TagCall GetCall(string tagName) + // { + // return new TagCall(TagCallType.Get, tagName); + // } + // public static TagCall SetCall(string tagName) + // { + // return new TagCall(TagCallType.Set, tagName); + // } + //} } \ No newline at end of file diff --git a/Open.PackML.Tags/TagConfig.cs b/Open.PackML.Tags/TagConfig.cs index ab8edee..2bc662b 100644 --- a/Open.PackML.Tags/TagConfig.cs +++ b/Open.PackML.Tags/TagConfig.cs @@ -1,10 +1,14 @@ using Autabee.Utility.IEC61131TypeConversion; using System; using System.Linq; +#if (NET6_0_OR_GREATER) +using System.Text.Json.Serialization; +#endif using System.Xml.Serialization; namespace Open.PackML.Tags { + [Serializable] public class TagConfig { string tagName; @@ -13,28 +17,40 @@ public string Name { get => tagName; set { - if (value != string.Empty && string.IsNullOrWhiteSpace(value)) Name = string.Empty; - if (value.Equals(Name)) return; - if (value == string.Empty) + + if (value == null) { - tagName = value; - SearchString = value; - TagTail = value; - TagAddress = new string[1] { value }; - //SearchHash = 0; + UpdateTagName(string.Empty); + return; } - else - { + value = value.Trim(); + if (value.Equals(Name)) return; + UpdateTagName(value); + } + } - tagName = value; - SearchString = TagStringToSearch(value); - //SearchHash = SearchString.GetHashCode(); - TagAddress = SearchString.Split('.'); - TagTail = TagAddress.Last(); - } - TagNameUpdate?.Invoke(this, EventArgs.Empty); + private void UpdateTagName(string value) + { + if (value == string.Empty) + { + tagName = value; + SearchString = value; + TagTail = value; + TagAddress = new string[1] { value }; + //SearchHash = 0; + } + else + { + + tagName = value; + SearchString = TagStringToSearch(value); + //SearchHash = SearchString.GetHashCode(); + TagAddress = SearchString.Split('.'); + TagTail = TagAddress.Last(); } + TagNameUpdate?.Invoke(this, EventArgs.Empty); } + [XmlIgnore] public string TagTail { get; private set; } [XmlIgnore] @@ -43,7 +59,9 @@ public string Name public string Description { get; set; } public virtual TagType TagType { get; set; } public virtual Type DataType { get; set; } - +#if (NET6_0_OR_GREATER) + [JsonIgnore] +#endif [XmlIgnore] public string[] TagAddress { get; private set; } diff --git a/Open.PackML.Tags/TagDetail.cs b/Open.PackML.Tags/TagDetail.cs index 7cd2f88..aa4af43 100644 --- a/Open.PackML.Tags/TagDetail.cs +++ b/Open.PackML.Tags/TagDetail.cs @@ -1,25 +1,10 @@ using Autabee.Utility; - -/* Unmerged change from project 'Open.PackML.Tags (net6.0)' -Before: -using Open.PackML.Tags.Builders; -After: -using Open; -using Open.PackML; -using Open.PackML.Tags; -using Open.PackML.PackML.Tags.Builders; -*/ - using Open.PackML.Tags.Builders; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Security.Cryptography.X509Certificates; -using System.Threading.Tasks; -using System.Xml.Linq; -using System.Xml.Serialization; namespace Open.PackML.Tags { @@ -36,7 +21,7 @@ internal class TagDetail : TagConfig private ParameterInfo[] parameters; private MethodInfo setMethod; - internal TagDetail(TagConfig config, TagTreeBuilderProcessData tagBuilder, TagDetail[] childTags, int length =-1) : base(config) + internal TagDetail(TagConfig config, TagTreeBuilderProcessData tagBuilder, TagDetail[] childTags, int length = -1) : base(config) { if (tagBuilder.baseObject == null) { @@ -224,7 +209,7 @@ public ValidationResult SetValue(Queue queue, object obj) return ObjectNotWritable(Name); if (CheckTyping(type, InsertElement)) return ObjectTypeMisMatch(DataType, type); - + var validation = MoveToLastBase(queue); if (!validation.Success) return validation; @@ -236,7 +221,7 @@ public ValidationResult SetValue(Queue queue, object obj) } - + private bool CheckTyping(Type type, bool InsertElement) { @@ -245,12 +230,13 @@ private bool CheckTyping(Type type, bool InsertElement) ) || !IsArray && DataType != type; } - private ValidationResult TagNotReadable() { - return new ValidationResult(false, null, "Object not readable"); - } + private ValidationResult TagNotReadable() + { + return new ValidationResult(false, null, "Object not readable"); + } private ValidationResult TagNotAProperty() { - return new ValidationResult(false,null, "Tag {0} is not a property", Name); + return new ValidationResult(false, null, "Tag {0} is not a property", Name); } private static ValidationResult ObjectNotWritable(string TagName) { diff --git a/Open.PackML.Tags/TagTable.cs b/Open.PackML.Tags/TagTable.cs index 71fd971..a84d320 100644 --- a/Open.PackML.Tags/TagTable.cs +++ b/Open.PackML.Tags/TagTable.cs @@ -4,17 +4,26 @@ namespace Open.PackML.Tags { + /// + /// This class is used to store all the tags that are used in a given controller. + /// public class TagTable : Dictionary { - TagConfig[] array; + private TagConfig[] roots; + private TagConfig[] array; private bool generateOnUpdate; public TagTable() : base() { } - public TagTable(TagConfig[] tags) : base() + public TagTable(TagConfig[] roots) : base() { + this.roots = roots; + } + public TagTable(TagConfig[] roots, TagConfig[] tags) : base() + { + this.roots = roots; foreach (var tag in tags) { Add(tag.Name, tag); @@ -25,7 +34,7 @@ public string GetTagTablePrint(bool filterUndifined = false, bool Iec = false) IEnumerable temp = array; if (filterUndifined) temp = temp.Where(o => o.TagType != TagType.Undefined); return array - .Aggregate("", (accumulator, item) => accumulator += (Iec ? item.ToIecString() : item.ToString()) + Environment.NewLine); + .Aggregate(string.Empty, (accumulator, item) => accumulator += (Iec ? item.ToIecString() : item.ToString()) + Environment.NewLine); } public void TagNameUpdated(object sender, EventArgs e) { @@ -42,7 +51,6 @@ public bool GenerateOnUpdate { if (value == generateOnUpdate) return; generateOnUpdate = true; - GenerateArray(); } } @@ -50,7 +58,26 @@ public bool GenerateOnUpdate { base.Add(key, value); value.TagNameUpdate += TagNameUpdated; - if (generateOnUpdate) GenerateArray(); + if (generateOnUpdate) UpdateArray(value); + } + + + + public void AddRoot(string key, TagConfig value) + { + base.Add(key, value); + UpdateRootArray(value); + value.TagNameUpdate += TagNameUpdated; + if (generateOnUpdate) UpdateArray(value); + } + + private void UpdateArray(TagConfig config) + { + array = array.Append(config).OrderBy(o => o.TagAddress).ToArray(); + } + private void UpdateRootArray(TagConfig config) + { + roots = roots.Append(config).OrderBy(o => o.TagAddress).ToArray(); } public void GenerateArray() @@ -58,6 +85,13 @@ public void GenerateArray() array = this.Select(o => o.Value).ToArray(); } + /// + /// Pre generated array of all the tags in the table + /// public TagConfig[] GetTags { get => array == null ? Array.Empty() : array; } + /// + /// tags that are on the top level of managed objects + /// + public TagConfig[] GetRoots { get => roots == null ? Array.Empty() : roots; } } } diff --git a/Open.PackML.Tags/TagType.cs b/Open.PackML.Tags/TagType.cs index 30544f1..564f51d 100644 --- a/Open.PackML.Tags/TagType.cs +++ b/Open.PackML.Tags/TagType.cs @@ -5,7 +5,7 @@ namespace Open.PackML.Tags [Flags] public enum TagType { - Undefined = 0 , + Undefined = 0, Status = 1, Command = 2, // performance information diff --git a/Open.PackML.Tags/readme.md b/Open.PackML.Tags/readme.md index 1c3df0a..2d5d6be 100644 --- a/Open.PackML.Tags/readme.md +++ b/Open.PackML.Tags/readme.md @@ -3,4 +3,4 @@ ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/Open.PackML.Tags) ![GitHub](https://img.shields.io/github/license/peacefighter1996/Open.PackML) -Extending Open PackML and adding the Tag control feature described by OMAC. \ No newline at end of file +Extending Open PackML libary with the Tag control feature described by OMAC. \ No newline at end of file diff --git a/Open.PackML/Interfaces/IPmlController.cs b/Open.PackML/Interfaces/IPmlController.cs index b63b210..1cb6fcf 100644 --- a/Open.PackML/Interfaces/IPmlController.cs +++ b/Open.PackML/Interfaces/IPmlController.cs @@ -5,7 +5,7 @@ namespace Open.PackML { - public interface IPmlController: IPmlMachineController + public interface IPmlController : IPmlMachineController { //local PmlState CurrentPmlState(); diff --git a/Open.PackML/Interfaces/IPmlEventStore.cs b/Open.PackML/Interfaces/IPmlEventStore.cs index 997cce6..76a04bb 100644 --- a/Open.PackML/Interfaces/IPmlEventStore.cs +++ b/Open.PackML/Interfaces/IPmlEventStore.cs @@ -1,12 +1,10 @@ using Autabee.Utility; using System; -using System.Collections.Generic; namespace Open.PackML { public interface IPmlEventStore { - ValidationResult ProcessEvent(Enum MachineEventId); - PmlEventReaction GetMachineEvent(Enum @event); + ValidationResult GetMachineEvent(Enum MachineEventId); } } \ No newline at end of file diff --git a/Open.PackML/PmlOemTransitionCheck.cs b/Open.PackML/PmlOemTransitionCheck.cs index 38f3246..c50db64 100644 --- a/Open.PackML/PmlOemTransitionCheck.cs +++ b/Open.PackML/PmlOemTransitionCheck.cs @@ -1,11 +1,7 @@ using Autabee.Utility; -using Open.PackML; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; -using System.Security.Cryptography; -using System.Xml; namespace Open.PackML { diff --git a/Open.PackML/PmlTransitionCheck.cs b/Open.PackML/PmlTransitionCheck.cs index 4aa5b1d..af79294 100644 --- a/Open.PackML/PmlTransitionCheck.cs +++ b/Open.PackML/PmlTransitionCheck.cs @@ -1,12 +1,10 @@ using Autabee.Utility; -using System.Collections.ObjectModel; -using System.Security.Cryptography; namespace Open.PackML { public static class PmlTransitionCheck { - + public static ValidationResult CheckTransition(PmlCommand PmlCommand, PmlState currentState, PmlMode currentMode) { return PmlCommand switch @@ -49,13 +47,13 @@ public static ValidationResult Stop(PmlState currentPackMLState, PmlMode packMLM case PmlState.Completing: return new ValidationResult(true); default: - return new ValidationResult(false, "Unkown current state"); + return new ValidationResult(false, "Unkown current state"); } } public static ValidationResult Abort(PmlState currentPackMLState, PmlMode packMLMode = PmlMode.Production) { - if (currentPackMLState == PmlState.Aborted + if (currentPackMLState == PmlState.Aborted || currentPackMLState == PmlState.Aborting) { return new ValidationResult(false, "Already aborted or aborting"); @@ -112,7 +110,7 @@ public static ValidationResult UnHold(PmlState currentPackMLState, PmlMode packM { if (packMLMode == PmlMode.Undefined) return new ValidationResult(false, "Current mode is undefined"); return currentPackMLState == PmlState.Held - ? new ValidationResult() + ? new ValidationResult() : new ValidationResult(false, "Current PackML state not in held."); } diff --git a/Open.PackML/Prefab/PmlEventStore.cs b/Open.PackML/Prefab/PmlEventStore.cs index 7992b69..2a12617 100644 --- a/Open.PackML/Prefab/PmlEventStore.cs +++ b/Open.PackML/Prefab/PmlEventStore.cs @@ -1,12 +1,13 @@ using Autabee.Utility; -using Open.PackML; using System; using System.Collections.Generic; -using static System.Collections.Specialized.BitVector32; namespace Open.PackML.Prefab { - public class PmlEventStore: Dictionary, IPmlEventStore + /// + /// Collections of machine events to update the state machine + /// + public class PmlEventStore : Dictionary, IPmlEventStore { public PmlEventStore() { } public PmlEventStore(List eventReactions) @@ -17,12 +18,16 @@ public PmlEventStore(List eventReactions) } } - - public ValidationResult ProcessEvent(Enum @event) + /// + /// trys to get the event reaction for the given event id + /// + /// + /// + public ValidationResult GetMachineEvent(Enum @event) { - if (ContainsKey(@event)) + if (this.TryGetValue(@event, out var value)) { - return new ValidationResult(true, this[@event].StateChangeId); + return new ValidationResult(true, value.StateChangeId); } else { @@ -30,17 +35,6 @@ public ValidationResult ProcessEvent(Enum @event) } } - public PmlEventReaction GetMachineEvent(Enum @event) - { - if (this.TryGetValue(@event, out PmlEventReaction value)) - { - return value; - } - else - { - return null; - } - } public void Add(PmlEventReaction pmlEventReaction) { this.Add(pmlEventReaction.MachineEventId, pmlEventReaction); diff --git a/Open.PackML/Prefab/PmlGuardController.cs b/Open.PackML/Prefab/PmlGuardController.cs index 7a720e5..1934417 100644 --- a/Open.PackML/Prefab/PmlGuardController.cs +++ b/Open.PackML/Prefab/PmlGuardController.cs @@ -1,16 +1,14 @@ using Autabee.Utility; using Open.PackML.EventArguments; -using Open.PackML; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; using System.Threading; +using System.Threading.Tasks; namespace Open.PackML.Prefab { - public class PmlGuardController : IPmlController + public class PmlGuardController : IPmlController { protected PmlState currentState = PmlState.Undefined; @@ -23,6 +21,12 @@ public class PmlGuardController : IPmlController public event EventHandler UpdateCurrentState; public event EventHandler MachineEvent; + /// + /// Creates a new instance of the PmlGuardController + /// + /// Internal machine + /// Events connected with this machine + /// public PmlGuardController(IPmlController controller, IPmlEventStore eventStore) { //Guard Check null @@ -76,7 +80,7 @@ public async Task UpdatePmlModeAsync(PmlMode packMLMode, Cance return temp; } - + public virtual ValidationResult SendPmlCommand(PmlCommand command) { @@ -96,7 +100,7 @@ public virtual async Task SendPmlCommandAsync(PmlCommand comma private void Controller_MachineEvent(object sender, PmlMachineEventArgs e) { //Prcesses the event - var result = eventStore.ProcessEvent(e.@enum); + var result = eventStore.GetMachineEvent(e.@enum); if (result.Success && (lastTransition < e.DateTime)) { diff --git a/Open.PackML/Prefab/PmlOemGuardController.cs b/Open.PackML/Prefab/PmlOemGuardController.cs index af5a2f9..f1cb153 100644 --- a/Open.PackML/Prefab/PmlOemGuardController.cs +++ b/Open.PackML/Prefab/PmlOemGuardController.cs @@ -1,7 +1,7 @@ using Autabee.Utility; using System; -using System.Threading.Tasks; using System.Threading; +using System.Threading.Tasks; namespace Open.PackML.Prefab { @@ -23,7 +23,7 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor return temp; } - public new async Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken) + public async Task UpdatePackMLModeAsync(int packMLMode, CancellationToken cancellationToken) { var temp = oemTransitionCheck.CheckModeUpdate(currentMode, packMLMode, currentState); if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); @@ -38,7 +38,7 @@ public PmlOemGuardController(IPmlController controller, IPmlEventStore eventStor return temp; } - public new async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) + public async Task SendPackMLCommandAsync(PmlCommand command, CancellationToken cancellationToken) { var temp = oemTransitionCheck.CheckTransition(command, currentState, currentMode); if (cancellationToken.IsCancellationRequested) return new ValidationResult(false, "Operation cancelled"); diff --git a/Open.PackMLTests/PmlGuardControllerTests.cs b/Open.PackMLTests/PmlGuardControllerTests.cs index 25b3428..f89db56 100644 --- a/Open.PackMLTests/PmlGuardControllerTests.cs +++ b/Open.PackMLTests/PmlGuardControllerTests.cs @@ -1,16 +1,13 @@ -using Xunit; +using Autabee.Utility; +using Moq; +using Open.PackML; +using Open.PackML.EventArguments; using Open.PackML.Prefab; +using Open.PackMLTests.TestObjects; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Open.PackML.Interfaces; -using Open.PackML.EventArguments; -using Autabee.Utility; -using Moq; -using Open.PackML; -using Open.PackMLTests.TestObjects; +using Xunit; namespace Open.PackMLTests { @@ -186,7 +183,7 @@ public void MachineEvent() testController.CurrentMode = PmlMode.Manual; var eventStore = new PmlEventStore(); eventStore.Add(EventHanderEnum1.id1, new PmlEventReaction(EventHanderEnum1.id1, PmlState.Stopping)); - + var controller = new PmlGuardController(testController, eventStore); testController.InvokeEvent(EventHanderEnum1.id1); //var result = controller.SendPmlCommand(PmlCommand.Abort); diff --git a/Open.PackMLTests/PmlTransitionCheckTests.cs b/Open.PackMLTests/PmlTransitionCheckTests.cs index 429f03f..ec3e00a 100644 --- a/Open.PackMLTests/PmlTransitionCheckTests.cs +++ b/Open.PackMLTests/PmlTransitionCheckTests.cs @@ -1,31 +1,31 @@ -using Xunit; +using Autabee.Utility; using Open.PackML; using System; -using Autabee.Utility; +using Xunit; namespace Open.PackMLTests -{ +{ public class PmlTransitionCheckTests { [Theory] - [InlineData(PmlState.Undefined, true, true, true, true)] - [InlineData(PmlState.Aborting, false, false, false, false)] - [InlineData(PmlState.Aborted, false, false, false, false)] - [InlineData(PmlState.Clearing, true, true, true, true)] - [InlineData(PmlState.Stopping, true, true, true, true)] - [InlineData(PmlState.Stopped, true, true, true, true)] - [InlineData(PmlState.Resetting, true, true, true, true)] - [InlineData(PmlState.Idle, true, true, true, true)] - [InlineData(PmlState.Starting, true, true, true, true)] - [InlineData(PmlState.Execute, true, true, true, true)] - [InlineData(PmlState.Held, true, true, true, true)] - [InlineData(PmlState.Holding, true, true, true, true)] - [InlineData(PmlState.UnHolding, true, true, true, true)] - [InlineData(PmlState.Suspending, true, true, true, true)] - [InlineData(PmlState.Suspended, true, true, true, true)] - [InlineData(PmlState.UnSuspending, true, true, true, true)] - [InlineData(PmlState.Completing, true, true, true, true)] - [InlineData(PmlState.Completed, true, true, true, true)] + [InlineData(PmlState.Undefined, true, true, true, true)] + [InlineData(PmlState.Aborting, false, false, false, false)] + [InlineData(PmlState.Aborted, false, false, false, false)] + [InlineData(PmlState.Clearing, true, true, true, true)] + [InlineData(PmlState.Stopping, true, true, true, true)] + [InlineData(PmlState.Stopped, true, true, true, true)] + [InlineData(PmlState.Resetting, true, true, true, true)] + [InlineData(PmlState.Idle, true, true, true, true)] + [InlineData(PmlState.Starting, true, true, true, true)] + [InlineData(PmlState.Execute, true, true, true, true)] + [InlineData(PmlState.Held, true, true, true, true)] + [InlineData(PmlState.Holding, true, true, true, true)] + [InlineData(PmlState.UnHolding, true, true, true, true)] + [InlineData(PmlState.Suspending, true, true, true, true)] + [InlineData(PmlState.Suspended, true, true, true, true)] + [InlineData(PmlState.UnSuspending, true, true, true, true)] + [InlineData(PmlState.Completing, true, true, true, true)] + [InlineData(PmlState.Completed, true, true, true, true)] public void AbortTest(PmlState state, params bool[] args) @@ -39,197 +39,197 @@ private static void CheckModes(PmlState state, bool[] args, Func(); var eventStore = new PmlEventStore(); - var temp = TagTreeBuilder.GetTree("", new PmlTr88Controller(moqController.Object, eventStore, new PmlOemTransitionCheck())); + var temp = TagTreeBuilder.GetTree(string.Empty, new PmlTr88Controller(moqController.Object, eventStore, new PmlOemTransitionCheck())); logger.WriteLine(temp.BuildTable().GetTagTablePrint()); } @@ -65,7 +59,7 @@ public void GetTreeTestTr88Filtered() { var moqController = new Mock(); var eventStore = new PmlEventStore(); - var temp = TagTreeBuilder.GetTree("", new PmlTr88Controller(moqController.Object, eventStore, new PmlOemTransitionCheck())); + var temp = TagTreeBuilder.GetTree(string.Empty, new PmlTr88Controller(moqController.Object, eventStore, new PmlOemTransitionCheck())); logger.WriteLine(temp.BuildTable().GetTagTablePrint(true)); } @@ -74,7 +68,7 @@ public void GetTreeTestEumFiltered() { var moqController = new Mock(); var eventStore = new PmlEventStore(); - var temp = TagTreeBuilder.GetTree("", new PmlEumController(moqController.Object, eventStore, new PmlOemTransitionCheck())); + var temp = TagTreeBuilder.GetTree(string.Empty, new PmlEumController(moqController.Object, eventStore, new PmlOemTransitionCheck())); logger.WriteLine(temp.BuildTable().GetTagTablePrint(true)); } diff --git a/Open.PackMLTests/Prefab/DefaultEventStoreTests.cs b/Open.PackMLTests/Prefab/DefaultEventStoreTests.cs index 29720d9..322739c 100644 --- a/Open.PackMLTests/Prefab/DefaultEventStoreTests.cs +++ b/Open.PackMLTests/Prefab/DefaultEventStoreTests.cs @@ -1,8 +1,8 @@ -using System; -using Xunit; -using Open.PackML; +using Open.PackML; using Open.PackML.Prefab; using Open.PackMLTests.TestObjects; +using System; +using Xunit; namespace Open.PackMLTests.Prefab { @@ -12,7 +12,7 @@ public class DefaultEventStoreTests public DefaultEventStoreTests() { - this.eventStore = new PmlEventStore(); + eventStore = new PmlEventStore(); eventStore.Add(new PmlEventReaction(EventHanderEnum1.id1, PmlState.Idle)); eventStore.Add(new PmlEventReaction(EventHanderEnum1.id2, PmlState.Aborted)); eventStore.Add(new PmlEventReaction(EventHanderEnum2.id1, PmlState.Clearing)); @@ -26,7 +26,7 @@ public DefaultEventStoreTests() [InlineData(EventHanderEnum2.id2, PmlState.Held)] public void ProcessEventTest(Enum arg, PmlState expectation) { - var newState = eventStore.ProcessEvent(arg); + var newState = eventStore.GetMachineEvent(arg); Assert.Equal(expectation, newState.Object); } @@ -35,7 +35,7 @@ public void ProcessEventTest(Enum arg, PmlState expectation) [InlineData(EventHanderEnum2.id3)] public void FailProcessEventTest(Enum arg) { - Assert.Equal(null, eventStore.GetMachineEvent(arg)); + Assert.False(eventStore.GetMachineEvent(arg).Success) ; } } } \ No newline at end of file diff --git a/Open.PackMLTests/Prefab/TagControllerTests.cs b/Open.PackMLTests/Prefab/TagControllerTests.cs index 7c4bcab..20e76e3 100644 --- a/Open.PackMLTests/Prefab/TagControllerTests.cs +++ b/Open.PackMLTests/Prefab/TagControllerTests.cs @@ -1,14 +1,13 @@ -using Xunit; -using Open.PackML.Tags.Prefab; -using System.Collections.Generic; -using System.Linq; -using Moq; -using Open.PackML.Prefab; +using Moq; using Open.PackML; +using Open.PackML.Prefab; using Open.PackML.Tags; +using Open.PackML.Tags.Prefab; using Open.PackMLTests.TestObjects; +using System.Collections.Generic; +using System.Linq; +using Xunit; using Xunit.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; namespace Open.PackMLTests.Prefab { @@ -31,7 +30,7 @@ public void GetTagDataTest() var controller = new TagController(new Dictionary() - {{"", eumController }}); + {{ string.Empty, eumController }}); var value = controller.GetTagData("ProdDefectiveCount"); @@ -238,7 +237,7 @@ public void BrowseTagDepth1Function() { TagController controller = GetTestController(); - var temp = controller.Browse("Machine1",1); + var temp = controller.Browse("Machine1", 1); string tmp; foreach (var item in temp.Object) { @@ -283,7 +282,7 @@ private TagController GetDefaultcontroller() var moqController = new Mock(); var eventStore = new PmlEventStore(); var eumController = new PmlEumController(moqController.Object, eventStore, new PmlOemTransitionCheck()); - var controller = new TagController(new Dictionary() { { "", eumController } }); + var controller = new TagController(new Dictionary() { { string.Empty, eumController } }); return controller; } diff --git a/Open.PackMLTests/Prefab/Tr88TagsTest.cs b/Open.PackMLTests/Prefab/Tr88TagsTest.cs index 3416775..6ab4606 100644 --- a/Open.PackMLTests/Prefab/Tr88TagsTest.cs +++ b/Open.PackMLTests/Prefab/Tr88TagsTest.cs @@ -1,6 +1,5 @@ using Autabee.Utility; using Autabee.Utility.IEC61131TypeConversion; -using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; using Moq; using Open.PackML; using Open.PackML.Prefab; @@ -10,8 +9,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; @@ -65,7 +62,7 @@ public TagConfig[] GetTagConfigList(bool tr88) public void TestTr88Tags() { var moqController = new Mock(); - var table = TagTreeBuilder.GetTree("", new PmlTr88Controller(moqController.Object, new PmlEventStore(), new PmlOemTransitionCheck())).BuildTable(); + var table = TagTreeBuilder.GetTree(string.Empty, new PmlTr88Controller(moqController.Object, new PmlEventStore(), new PmlOemTransitionCheck())).BuildTable(); //var tags = table.GetTags; logger.WriteLine(table.GetTagTablePrint()); foreach (var tag in GetTagConfigList(true)) @@ -99,7 +96,7 @@ public void TestTr88Tags() public void TestEumTags() { var moqController = new Mock(); - var table = TagTreeBuilder.GetTree("", new PmlEumController(moqController.Object, new PmlEventStore(), new PmlOemTransitionCheck()), Iec: true).BuildTable(); + var table = TagTreeBuilder.GetTree(string.Empty, new PmlEumController(moqController.Object, new PmlEventStore(), new PmlOemTransitionCheck()), Iec: true).BuildTable(); //var tags = table.GetTags; logger.WriteLine(table.GetTagTablePrint(Iec: true)); var result = new ValidationResult(); diff --git a/Open.PackMLTests/TagConfigTests.cs b/Open.PackMLTests/TagConfigTests.cs index fff85ee..3602c65 100644 --- a/Open.PackMLTests/TagConfigTests.cs +++ b/Open.PackMLTests/TagConfigTests.cs @@ -1,10 +1,7 @@ -using Xunit; -using Open.PackML.Tags; +using Open.PackML.Tags; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Xunit; namespace Open.PackMLTests { diff --git a/Open.PackMLTests/TestObjects/TestPmlController.cs b/Open.PackMLTests/TestObjects/TestPmlController.cs index dc026ab..458b2b9 100644 --- a/Open.PackMLTests/TestObjects/TestPmlController.cs +++ b/Open.PackMLTests/TestObjects/TestPmlController.cs @@ -1,7 +1,6 @@ using Autabee.Utility; using Open.PackML; using Open.PackML.EventArguments; -using Open.PackML.Interfaces; using System; using System.Linq; using System.Threading; From f731fbaceb185151419a718979833ccc65213f65 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Thu, 26 Jan 2023 15:10:05 +0100 Subject: [PATCH 26/31] move common properties --- Common.props | 32 +++++++++++++++++++++++++++++ Deploy/OpenPackML.props | 37 ---------------------------------- Deploy/OpenPackMLPrefab.props | 38 ----------------------------------- Deploy/OpenPackMLTags.props | 38 ----------------------------------- 4 files changed, 32 insertions(+), 113 deletions(-) create mode 100644 Common.props delete mode 100644 Deploy/OpenPackML.props delete mode 100644 Deploy/OpenPackMLPrefab.props delete mode 100644 Deploy/OpenPackMLTags.props diff --git a/Common.props b/Common.props new file mode 100644 index 0000000..202082a --- /dev/null +++ b/Common.props @@ -0,0 +1,32 @@ + + + git + MIT + https://github.com/peacefighter1996/Open.PackML + https://github.com/peacefighter1996/Open.PackML + true + true + true + true + snupkg + true + + false + false + + true + false + latest + + + + true + + + + + + + readme.md + + \ No newline at end of file diff --git a/Deploy/OpenPackML.props b/Deploy/OpenPackML.props deleted file mode 100644 index 9fd3be6..0000000 --- a/Deploy/OpenPackML.props +++ /dev/null @@ -1,37 +0,0 @@ - - - Ian Arbouw - Open Library for development of PackML/ISA88 control systems. - packml;industrial-automation;ISA;ISA88;88 - https://github.com/peacefighter1996/Open.PackML - https://github.com/peacefighter1996/Open.PackML - git - MIT - 0.4.1-Beta - - true - true - true - true - snupkg - true - - false - false - - true - false - latest - - - - true - - - - - - - readme.md - - diff --git a/Deploy/OpenPackMLPrefab.props b/Deploy/OpenPackMLPrefab.props deleted file mode 100644 index f7166cd..0000000 --- a/Deploy/OpenPackMLPrefab.props +++ /dev/null @@ -1,38 +0,0 @@ - - - - Ian Arbouw - Default Implementations for the TR 88.00.02 and End user Minimum - packml;industrial-automation;ISA;ISA88;88;tags - https://github.com/peacefighter1996/Open.PackML - https://github.com/peacefighter1996/Open.PackML - git - MIT - 0.4.1-Beta - - true - true - true - true - snupkg - true - - false - false - - true - false - latest - - - - true - - - - - - - readme.md - - diff --git a/Deploy/OpenPackMLTags.props b/Deploy/OpenPackMLTags.props deleted file mode 100644 index 853fe9d..0000000 --- a/Deploy/OpenPackMLTags.props +++ /dev/null @@ -1,38 +0,0 @@ - - - - Ian Arbouw - Base package for Open Packml implementation of the tag system - packml;industrial-automation;ISA;ISA88;88;tags - https://github.com/peacefighter1996/Open.PackML - https://github.com/peacefighter1996/Open.PackML - git - MIT - 0.4.1-Beta - - true - true - true - true - snupkg - true - - false - false - - true - false - latest - - - - true - - - - - - - readme.md - - From 52ba1f9cb1861916a250307144a60d6883b2e5f2 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Thu, 26 Jan 2023 15:12:36 +0100 Subject: [PATCH 27/31] Cleanup add documentation move to use auatbee packages --- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 8 +- Open.PackML.Prefab/PmlTr88Controller.cs | 4 +- Open.PackML.Tags/Builders/TagTableBuilder.cs | 10 +- Open.PackML.Tags/Builders/TagTreeBuilder.cs | 10 +- Open.PackML.Tags/Interfaces/ITagController.cs | 1 + Open.PackML.Tags/Interfaces/ITagStore.cs | 2 +- Open.PackML.Tags/Open.PackML.Tags.csproj | 15 +- Open.PackML.Tags/Prefab/TagController.cs | 7 +- Open.PackML.Tags/TagCall.cs | 37 ++-- Open.PackML.Tags/TagCallType.cs | 1 + Open.PackML.Tags/TagConfig.cs | 100 +++++----- Open.PackML.Tags/TagDetail.cs | 171 ++++++++---------- Open.PackML.sln | 25 --- Open.PackML/Interfaces/IPmlEventStore.cs | 2 +- Open.PackML/Open.PackML.csproj | 10 +- Open.PackML/Prefab/PmlEventStore.cs | 1 + Open.PackMLTests/Open.PackMLTests.csproj | 1 - Open.PackMLTests/PmlGuardControllerTests.cs | 6 +- Open.PackMLTests/PmlTransitionCheckTests.cs | 2 +- Open.PackMLTests/Prefab/TagControllerTests.cs | 38 ++-- Open.PackMLTests/Prefab/Tr88TagsTest.cs | 4 +- 21 files changed, 211 insertions(+), 244 deletions(-) diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index c4e0f26..ef3c349 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,5 +1,11 @@ - + + + Ian Arbouw + Default Implementations for the TR 88.00.02 and End user Minimum + packml;industrial-automation;ISA;ISA88;88;tags + 0.4.2-Beta + net48;netstandard2.0;net6.0 diff --git a/Open.PackML.Prefab/PmlTr88Controller.cs b/Open.PackML.Prefab/PmlTr88Controller.cs index b5be3c1..180dbdc 100644 --- a/Open.PackML.Prefab/PmlTr88Controller.cs +++ b/Open.PackML.Prefab/PmlTr88Controller.cs @@ -10,8 +10,8 @@ public PmlTr88Controller(IPmlController controller, IPmlEventStore eventStore, I { } - - + + [TagEndUserTerm("State")] [TagType(TagType.Status)] public int StateCurrent { get => (int)currentState; } diff --git a/Open.PackML.Tags/Builders/TagTableBuilder.cs b/Open.PackML.Tags/Builders/TagTableBuilder.cs index 8457d2b..918b91d 100644 --- a/Open.PackML.Tags/Builders/TagTableBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTableBuilder.cs @@ -5,10 +5,13 @@ namespace Open.PackML.Tags.Builders { /// - /// Build a TagTable from a given object + /// This class builds a table of tags for a given object. /// public static class TagTableBuilder { + // Generates a TagTable for a given object + // TagName: base name of the tag + // obj: Object to generate the TagTable for public static TagTable BuildTagTable(string TagName, object obj) { var table = new TagTable(); @@ -19,6 +22,11 @@ public static TagTable BuildTagTable(string TagName, object obj) table.GenerateOnUpdate = true; return table; } + /// + /// This code creates a new tag table for a given collection. using the key as the + /// tag table base name. This is used for the PackML state machine. + /// + /// collection of (tag base name, object) public static TagTable BuildTagTable(Dictionary collection) { var table = new TagTable(); diff --git a/Open.PackML.Tags/Builders/TagTreeBuilder.cs b/Open.PackML.Tags/Builders/TagTreeBuilder.cs index ddaa463..1092c6c 100644 --- a/Open.PackML.Tags/Builders/TagTreeBuilder.cs +++ b/Open.PackML.Tags/Builders/TagTreeBuilder.cs @@ -1,5 +1,5 @@  -using Autabee.Utility.IEC61131TypeConversion; +using Autabee.Utility.IEC61131StringTypeConversion; using Open.PackML.Tags.Attributes; using System; using System.Collections; @@ -15,14 +15,14 @@ namespace Open.PackML.Tags.Builders internal static class TagTreeBuilder { /// - /// Builds a TagTree from a base object + /// This function builds a tree of tags for a given object. /// /// Root object name /// Object for which the tree needs to be build from /// Description of the obj - /// Simplyfied term for enduser + /// Simplyfied term for enduser for the root tag /// Type of tag that is used to set the typing of the propeties that are being scanned - /// + /// TagDetail /// Does not allow a collection to be used as base object. internal static TagDetail GetTree(string root, object obj, string description = "", string endUserTerm = "", TagType StartTagType = TagType.Undefined, bool Iec = false) { @@ -61,7 +61,7 @@ private static TagDetail GetTree(TagConfig root, } return new TagDetail(root, tagBuilder, Children.ToArray()); - } + } private static TagDetail ProcessMethode(TagConfig root, TagTreeBuilderProcessData tagBuilder, MethodInfo method, TagTypeAttribute attribute) { diff --git a/Open.PackML.Tags/Interfaces/ITagController.cs b/Open.PackML.Tags/Interfaces/ITagController.cs index f8345ec..73c3f3b 100644 --- a/Open.PackML.Tags/Interfaces/ITagController.cs +++ b/Open.PackML.Tags/Interfaces/ITagController.cs @@ -1,4 +1,5 @@ using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using Open.PackML.Tags; using System; using System.Collections.Generic; diff --git a/Open.PackML.Tags/Interfaces/ITagStore.cs b/Open.PackML.Tags/Interfaces/ITagStore.cs index d62f36b..42ca19b 100644 --- a/Open.PackML.Tags/Interfaces/ITagStore.cs +++ b/Open.PackML.Tags/Interfaces/ITagStore.cs @@ -1,4 +1,4 @@ -using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using Open.PackML.Tags; namespace Open.PackML.Interfaces diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index cd8ba34..d9dba19 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -1,5 +1,11 @@  - + + + Ian Arbouw + Base package for Open Packml implementation of the tag system + packml;industrial-automation;ISA;ISA88;88;tags + 0.4.2-Beta + net48;netstandard2.0;net6.0 readme.md @@ -11,11 +17,8 @@ + + - - - - - diff --git a/Open.PackML.Tags/Prefab/TagController.cs b/Open.PackML.Tags/Prefab/TagController.cs index 27e3c84..e988e6d 100644 --- a/Open.PackML.Tags/Prefab/TagController.cs +++ b/Open.PackML.Tags/Prefab/TagController.cs @@ -1,4 +1,5 @@ using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using Open.PackML.Interfaces; using Open.PackML.Tags.Builders; using System; @@ -126,7 +127,7 @@ public ValidationResult ExecutePackTagCommand(string name, params object if (tagTable.TryGetValue(TagConfig.TagStringToSearch(name), out TagConfig tagDetail)) { var queue = GetTagArrayIndexes(name); - if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailString()); + if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailInfo); return ((TagDetail)tagDetail).Execute(queue.Object, args); } else @@ -149,7 +150,7 @@ public ValidationResult GetTagData(string name) out TagConfig tagDetails)) { var queue = GetTagArrayIndexes(name); - if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailString()); + if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailInfo); return ((TagDetail)tagDetails).GetValue(queue.Object); } @@ -168,7 +169,7 @@ public ValidationResult SetTagData(string name, object data) out TagConfig tagDetails)) { var queue = GetTagArrayIndexes(name); - if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailString()); + if (!queue.Success) return new ValidationResult(false, unSuccesfullText: "Array number parsing failure: {0}", formatObjects: queue.FailInfo); return ((TagDetail)tagDetails).SetValue(queue.Object, data); } return new ValidationResult(false, unSuccesfullText: "Tag {0} not found", formatObjects: name); diff --git a/Open.PackML.Tags/TagCall.cs b/Open.PackML.Tags/TagCall.cs index ecfbf83..3ffde5a 100644 --- a/Open.PackML.Tags/TagCall.cs +++ b/Open.PackML.Tags/TagCall.cs @@ -8,17 +8,27 @@ namespace Open.PackML.Tags /// public class TagCall { + /// + /// Creates a new tag call + /// public TagCall() { - + Data = null; + TagCallType = TagCallType.None; + TagName = string.Empty; } + /// + /// Creates a new tag call + /// + /// The type of tag call. + /// Name of the tag being called + /// Data as input or set value data public TagCall(TagCallType tagCallType, string tagName, object data = null) { TagCallType = tagCallType; TagName = tagName; Data = data; } - /// /// Data as input or set value data /// @@ -33,27 +43,4 @@ public TagCall(TagCallType tagCallType, string tagName, object data = null) /// public string TagName { get; set; } } - - - - //public class BatchTagCall: Dictionary> - //{ - // public bool allowAsyncCalls; - //} - // - //public static class TagCallBuilder - //{ - // public static TagCall MethodCall(string tagName, object[] inputArguments) - // { - // return new TagCall(TagCallType.Execute, tagName, inputArguments); - // } - // public static TagCall GetCall(string tagName) - // { - // return new TagCall(TagCallType.Get, tagName); - // } - // public static TagCall SetCall(string tagName) - // { - // return new TagCall(TagCallType.Set, tagName); - // } - //} } \ No newline at end of file diff --git a/Open.PackML.Tags/TagCallType.cs b/Open.PackML.Tags/TagCallType.cs index 6a90496..057b585 100644 --- a/Open.PackML.Tags/TagCallType.cs +++ b/Open.PackML.Tags/TagCallType.cs @@ -5,6 +5,7 @@ namespace Open.PackML.Tags { public enum TagCallType { + None, Get, Set, Execute diff --git a/Open.PackML.Tags/TagConfig.cs b/Open.PackML.Tags/TagConfig.cs index 2bc662b..c1cc286 100644 --- a/Open.PackML.Tags/TagConfig.cs +++ b/Open.PackML.Tags/TagConfig.cs @@ -1,4 +1,4 @@ -using Autabee.Utility.IEC61131TypeConversion; +using Autabee.Utility.IEC61131StringTypeConversion; using System; using System.Linq; #if (NET6_0_OR_GREATER) @@ -12,23 +12,24 @@ namespace Open.PackML.Tags public class TagConfig { string tagName; - public event EventHandler TagNameUpdate; - public string Name + + public TagConfig() { } + + public TagConfig(TagConfig tagConfig) : this(tagConfig.Name, tagConfig.EndUserTerm, tagConfig.Description, tagConfig.TagType, tagConfig.DataType) { - get => tagName; set - { + } - if (value == null) - { - UpdateTagName(string.Empty); - return; - } - value = value.Trim(); - if (value.Equals(Name)) return; - UpdateTagName(value); - } + public TagConfig(string name, string endUserTerm, string description, TagType tagType, Type dataType) + { + Name = name; + EndUserTerm = endUserTerm; + Description = description; + TagType = tagType; + DataType = dataType; } + public event EventHandler TagNameUpdate; + private void UpdateTagName(string value) { if (value == string.Empty) @@ -51,33 +52,20 @@ private void UpdateTagName(string value) TagNameUpdate?.Invoke(this, EventArgs.Empty); } - [XmlIgnore] - public string TagTail { get; private set; } - [XmlIgnore] - public string SearchString { get; private set; } - public string EndUserTerm { get; set; } - public string Description { get; set; } - public virtual TagType TagType { get; set; } - public virtual Type DataType { get; set; } -#if (NET6_0_OR_GREATER) - [JsonIgnore] -#endif - [XmlIgnore] - public string[] TagAddress { get; private set; } + public static string TagStringToSearch(string name) + { + if (name == string.Empty) return string.Empty; + var searchname = name; + var i = searchname.IndexOf('[', 0); + while (i != -1) + { - public TagConfig() { } + searchname = searchname.Substring(0, i) + searchname.Substring(searchname.IndexOf(']', i) + 1); - public TagConfig(string name, string endUserTerm, string description, TagType tagType, Type dataType) - { - Name = name; - EndUserTerm = endUserTerm; - Description = description; - TagType = tagType; - DataType = dataType; - } + i = searchname.IndexOf('[', 0); - public TagConfig(TagConfig tagConfig) : this(tagConfig.Name, tagConfig.EndUserTerm, tagConfig.Description, tagConfig.TagType, tagConfig.DataType) - { + } + return searchname; } public string ToIecString() { @@ -87,20 +75,36 @@ public override string ToString() { return string.Format("{0},{1},{2},{3},{4}", TagType.ToString(), Name, EndUserTerm, Description, DataType.ToString()); } - public static string TagStringToSearch(string name) + + public virtual Type DataType { get; set; } + public string Description { get; set; } + public string EndUserTerm { get; set; } + public string Name { - if (name == string.Empty) return string.Empty; - var searchname = name; - var i = searchname.IndexOf('[', 0); - while (i != -1) + get => tagName; set { - searchname = searchname.Substring(0, i) + searchname.Substring(searchname.IndexOf(']', i) + 1); - - i = searchname.IndexOf('[', 0); - + if (value == null) + { + UpdateTagName(string.Empty); + return; + } + value = value.Trim(); + if (value.Equals(Name)) return; + UpdateTagName(value); } - return searchname; } + [XmlIgnore] + public string SearchString { get; private set; } + + [XmlIgnore] + public string TagTail { get; private set; } + public virtual TagType TagType { get; set; } + +#if (NET6_0_OR_GREATER) + [JsonIgnore] +#endif + [XmlIgnore] + public string[] TagAddress { get; private set; } } } \ No newline at end of file diff --git a/Open.PackML.Tags/TagDetail.cs b/Open.PackML.Tags/TagDetail.cs index aa4af43..86660e8 100644 --- a/Open.PackML.Tags/TagDetail.cs +++ b/Open.PackML.Tags/TagDetail.cs @@ -1,4 +1,5 @@ using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using Open.PackML.Tags.Builders; using System; using System.Collections; @@ -52,40 +53,6 @@ internal TagDetail(TagConfig config, TagTreeBuilderProcessData tagBuilder, TagDe arrayTreeCount = Name.Count(o => o == '['); Length = length; } - private bool IsMethod { get => last is MethodInfo; } - private bool IsProperty { get => last is PropertyInfo; } - private bool Readable { get => getMethod != null && getMethod.IsPublic; } - private bool Writable { get => setMethod != null && setMethod.IsPublic; } - - private bool IsArray { get => DataType.IsArray; } - public int Length { get; private set; } - - public ValidationResult Execute(Queue queue, object[] args) - { - var validation = new ValidationResult(); - if (queue.Count() != arrayTreeCount) validation.AddResult(false, "Array chain mismatch"); - if (!IsMethod) validation.AddResult(false, "Not a method"); - if (args == null) args = Array.Empty(); - if (args.Length != parameters.Length) validation.AddResult(false, "tyring to call a function with {0} parmeters with {1}", formatObjects: new object[] { parameters.Length, args.Length }); - if (!validation.Success) return validation; - CheckPameters(args, validation); - if (!validation.Success) return validation; - - validation = MoveToLastBase(queue); - if (!validation.Success) return validation; - object result = validation.Object; - - try - { - result = ((MethodInfo)last).Invoke(result, args); - if (DataType != typeof(void) && result == null) return ObjectNotFound(Name); - } - catch (Exception e) - { - return new ValidationResult(false, null, e.Message); - } - return new ValidationResult(Object: result); - } private void CheckPameters(object[] args, ValidationResult validation) { @@ -99,16 +66,13 @@ private void CheckPameters(object[] args, ValidationResult validation) validation.AddResult(false, "Parameter {0} is not of type {1}", i, parType.Name); } } - - private ValidationResult MoveToLastBase(Queue queue) + + private bool CheckTyping(Type type, bool InsertElement) { - object result = baseObject; - for (int i = 0; i < memberInfo.Length - 1; i++) - { - result = GetNextObject(ArrayType[i], (PropertyInfo)memberInfo[i], result, queue); - if (result == null) return ObjectNotFound(TagAddress, i); - } - return new ValidationResult(Object: result); + return IsArray && (!InsertElement && DataType != type + || InsertElement && DataType.GetElementType() != type + ) || !IsArray && DataType != type; + } private static object GetNextObject(bool arraytype, PropertyInfo info, object obj, Queue queue) @@ -129,6 +93,33 @@ private static object GetNextObject(bool arraytype, PropertyInfo info, object ob return info.GetValue(obj); } + private ValidationResult MoveToLastBase(Queue queue) + { + object result = baseObject; + for (int i = 0; i < memberInfo.Length - 1; i++) + { + result = GetNextObject(ArrayType[i], (PropertyInfo)memberInfo[i], result, queue); + if (result == null) return ObjectNotFound(TagAddress, i); + } + return new ValidationResult(Object: result); + } + + private static ValidationResult ObjectNotFound(string tagName) + { + return new ValidationResult(false, null, "Object not found at {0}", tagName); + } + private static ValidationResult ObjectNotFound(string[] address, int i) + { + address = address.Take(i + 1).ToArray(); + return new ValidationResult(false, null, "Object not found at {0}", string.Join(".", address)); + } + private static ValidationResult ObjectNotWritable(string TagName) + { + return new ValidationResult(false, "{0} not writable", TagName); + } + + private static ValidationResult ObjectTypeMisMatch(Type expected, Type actually) => new ValidationResult(false, "Object type mismatch. Expected {0} but got {1}", expected.Name, actually.Name); + private static bool SetValue(bool arraytype, PropertyInfo info, object baseObj, object value, Queue queue) { if (arraytype) @@ -149,21 +140,49 @@ private static bool SetValue(bool arraytype, PropertyInfo info, object baseObj, info.SetValue(baseObj, value); return true; } - - private static ValidationResult ObjectNotFound(string tagName) + private ValidationResult TagNotAProperty() { - return new ValidationResult(false, null, "Object not found at {0}", tagName); + return new ValidationResult(false, null, "Tag {0} is not a property", Name); } - private static ValidationResult ObjectNotFound(string[] address, int i) + private ValidationResult TagNotReadable() { - address = address.Take(i + 1).ToArray(); - return new ValidationResult(false, null, "Object not found at {0}", string.Join(".", address)); + return new ValidationResult(false, null, "Object not readable"); + } + + private bool IsArray { get => DataType.IsArray; } + private bool IsMethod { get => last is MethodInfo; } + private bool IsProperty { get => last is PropertyInfo; } + private bool Readable { get => getMethod != null && getMethod.IsPublic; } + private bool Writable { get => setMethod != null && setMethod.IsPublic; } + + public ValidationResult Execute(Queue queue, object[] args) + { + var validation = new ValidationResult(); + if (queue.Count() != arrayTreeCount) validation.AddResult(false, "Array chain mismatch"); + if (!IsMethod) validation.AddResult(false, "Not a method"); + if (args == null) args = Array.Empty(); + if (args.Length != parameters.Length) validation.AddResult(false, "tyring to call a function with {0} parmeters with {1}", formatObjects: new object[] { parameters.Length, args.Length }); + if (!validation.Success) return validation; + CheckPameters(args, validation); + if (!validation.Success) return validation; + + validation = MoveToLastBase(queue); + if (!validation.Success) return validation; + object result = validation.Object; + + try + { + result = ((MethodInfo)last).Invoke(result, args); + if (DataType != typeof(void) && result == null) return ObjectNotFound(Name); + } + catch (Exception e) + { + return new ValidationResult(false, null, e.Message); + } + return new ValidationResult(Object: result); } - //public Task> ExecuteAsync(Queue queue, object[] args) - //{ - // return new Task>(delegate { return Execute(queue, args); }); - //} + public ValidationResult GetValue(Queue queue) { @@ -178,27 +197,6 @@ public ValidationResult GetValue(Queue queue) } - //public ValidationResult GetValueIsUpdated() - //{ - // var result = GetValue(); - // if (result.Success) - // { - // if (lastData == result.Object) - // { - // return new ValidationResult(false, null, "Data not updated"); - // } - // else - // { - // lastData = result.Object; - // return new ValidationResult(true, result.Object); - // } - // } - // else - // { - // return result; - // } - //} - public ValidationResult SetValue(Queue queue, object obj) { Type type = obj.GetType(); @@ -221,30 +219,7 @@ public ValidationResult SetValue(Queue queue, object obj) } - - - private bool CheckTyping(Type type, bool InsertElement) - { - return IsArray && (!InsertElement && DataType != type - || InsertElement && DataType.GetElementType() != type - ) || !IsArray && DataType != type; - - } - private ValidationResult TagNotReadable() - { - return new ValidationResult(false, null, "Object not readable"); - } - private ValidationResult TagNotAProperty() - { - return new ValidationResult(false, null, "Tag {0} is not a property", Name); - } - private static ValidationResult ObjectNotWritable(string TagName) - { - return new ValidationResult(false, "{0} not writable", TagName); - } - - private static ValidationResult ObjectTypeMisMatch(Type expected, Type actually) => new ValidationResult(false, "Object type mismatch. Expected {0} but got {1}", expected.Name, actually.Name); - public TagDetail[] ChildTags { get; } + public int Length { get; private set; } } } \ No newline at end of file diff --git a/Open.PackML.sln b/Open.PackML.sln index f5fca80..d2c8676 100644 --- a/Open.PackML.sln +++ b/Open.PackML.sln @@ -7,18 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.PackML", "Open.PackML\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.PackMLTests", "Open.PackMLTests\Open.PackMLTests.csproj", "{A6FE6E93-42AF-4E36-8A05-E1108E8FBC07}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autabee.Utility.IEC61131TypeConversion", "Autabee.Utility.IEC61131TypeConversion\Autabee.Utility.IEC61131TypeConversion.csproj", "{D96C5069-1885-4B22-A01E-B4F372119AA8}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autabee.Utility.IEC61131TypeConversionTests", "Autabee.Automation.Utility.IEC61131TypeConversionTests\Autabee.Utility.IEC61131TypeConversionTests.csproj", "{0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.PackML.Tags", "Open.PackML.Tags\Open.PackML.Tags.csproj", "{862C1E05-87A4-4E50-81D0-9185DD4C5B5A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autabee.Utility", "Autabee.Utility\Autabee.Utility.csproj", "{8C6B09BA-47F1-4952-A7EF-7862F181D979}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.PackML.Prefab", "Open.PackML.Prefab\Open.PackML.Prefab.csproj", "{45C563AA-FCE6-45B1-9CFD-E9210D844ED7}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AutabeeDependencies", "AutabeeDependencies", "{6A4D79EC-04BD-46B7-A5FE-C8C9103F518E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,22 +25,10 @@ Global {A6FE6E93-42AF-4E36-8A05-E1108E8FBC07}.Debug|Any CPU.Build.0 = Debug|Any CPU {A6FE6E93-42AF-4E36-8A05-E1108E8FBC07}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6FE6E93-42AF-4E36-8A05-E1108E8FBC07}.Release|Any CPU.Build.0 = Release|Any CPU - {D96C5069-1885-4B22-A01E-B4F372119AA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D96C5069-1885-4B22-A01E-B4F372119AA8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D96C5069-1885-4B22-A01E-B4F372119AA8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D96C5069-1885-4B22-A01E-B4F372119AA8}.Release|Any CPU.Build.0 = Release|Any CPU - {0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689}.Release|Any CPU.Build.0 = Release|Any CPU {862C1E05-87A4-4E50-81D0-9185DD4C5B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {862C1E05-87A4-4E50-81D0-9185DD4C5B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU {862C1E05-87A4-4E50-81D0-9185DD4C5B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU {862C1E05-87A4-4E50-81D0-9185DD4C5B5A}.Release|Any CPU.Build.0 = Release|Any CPU - {8C6B09BA-47F1-4952-A7EF-7862F181D979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8C6B09BA-47F1-4952-A7EF-7862F181D979}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8C6B09BA-47F1-4952-A7EF-7862F181D979}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8C6B09BA-47F1-4952-A7EF-7862F181D979}.Release|Any CPU.Build.0 = Release|Any CPU {45C563AA-FCE6-45B1-9CFD-E9210D844ED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {45C563AA-FCE6-45B1-9CFD-E9210D844ED7}.Debug|Any CPU.Build.0 = Debug|Any CPU {45C563AA-FCE6-45B1-9CFD-E9210D844ED7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -57,11 +37,6 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {D96C5069-1885-4B22-A01E-B4F372119AA8} = {6A4D79EC-04BD-46B7-A5FE-C8C9103F518E} - {0EEC3E68-F3A9-4B59-BB1E-21E3BCD6C689} = {6A4D79EC-04BD-46B7-A5FE-C8C9103F518E} - {8C6B09BA-47F1-4952-A7EF-7862F181D979} = {6A4D79EC-04BD-46B7-A5FE-C8C9103F518E} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1B2671C5-EE40-498F-AD8B-7B795BA54B9E} EndGlobalSection diff --git a/Open.PackML/Interfaces/IPmlEventStore.cs b/Open.PackML/Interfaces/IPmlEventStore.cs index 76a04bb..49190fe 100644 --- a/Open.PackML/Interfaces/IPmlEventStore.cs +++ b/Open.PackML/Interfaces/IPmlEventStore.cs @@ -1,4 +1,4 @@ -using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using System; namespace Open.PackML diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index 43e56d1..d52f3d0 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -1,5 +1,11 @@  - + + Ian Arbouw + Open Library for development of PackML/ISA88 control systems. + packml;industrial-automation;ISA;ISA88;88 + 0.4.2-Beta + + net48;netstandard2.0;net6.0 readme.md @@ -11,6 +17,6 @@ - + diff --git a/Open.PackML/Prefab/PmlEventStore.cs b/Open.PackML/Prefab/PmlEventStore.cs index 2a12617..e58dbe7 100644 --- a/Open.PackML/Prefab/PmlEventStore.cs +++ b/Open.PackML/Prefab/PmlEventStore.cs @@ -1,4 +1,5 @@ using Autabee.Utility; +using Autabee.Utility.Messaging.Validation; using System; using System.Collections.Generic; diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index 2e98965..b466a6a 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -30,7 +30,6 @@ - diff --git a/Open.PackMLTests/PmlGuardControllerTests.cs b/Open.PackMLTests/PmlGuardControllerTests.cs index f89db56..35870ad 100644 --- a/Open.PackMLTests/PmlGuardControllerTests.cs +++ b/Open.PackMLTests/PmlGuardControllerTests.cs @@ -166,11 +166,11 @@ void Controller_UpdateCurrentState(object sender, PmlStateChangeEventArg e) controller.UpdateCurrentState += Controller_UpdateCurrentState; //var result = controller.SendPmlCommand(PmlCommand.Abort); - //Assert.True(result.Success, result.FailString()); + //Assert.True(result.Success, result.ToString()); //controller.UpdatePmlMode(PmlMode.Production); var result = controller.SendPmlCommand(PmlCommand.Clear); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); Assert.Equal(PmlState.Clearing, catchStates[0]); Assert.Equal(PmlState.Stopped, catchStates[1]); } @@ -187,7 +187,7 @@ public void MachineEvent() var controller = new PmlGuardController(testController, eventStore); testController.InvokeEvent(EventHanderEnum1.id1); //var result = controller.SendPmlCommand(PmlCommand.Abort); - //Assert.True(result.Success, result.FailString()); + //Assert.True(result.Success, result.ToString()); //controller.UpdatePmlMode(PmlMode.Production); Assert.Equal(PmlState.Stopping, controller.CurrentPmlState()); diff --git a/Open.PackMLTests/PmlTransitionCheckTests.cs b/Open.PackMLTests/PmlTransitionCheckTests.cs index ec3e00a..1d2742b 100644 --- a/Open.PackMLTests/PmlTransitionCheckTests.cs +++ b/Open.PackMLTests/PmlTransitionCheckTests.cs @@ -39,7 +39,7 @@ private static void CheckModes(PmlState state, bool[] args, Func("StopReason.ID"); Assert.Equal(45, value.Object); } @@ -57,7 +57,7 @@ public void FailSetTagDataTest() { TagController controller = GetDefaultcontroller(); var result = controller.SetTagData("StopReason", new PmlStopReason(45, 100)); - Assert.False(result.Success, result.FailString()); + Assert.False(result.Success, result.ToString()); } [Theory] @@ -68,9 +68,9 @@ public void SetArrayValueTagDataTest(string tagName, T tagValue) { TagController controller = GetTestController(); var result = controller.SetTagData(tagName, tagValue); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); var value = controller.GetTagData(tagName); - Assert.True(value.Success, value.FailString()); + Assert.True(value.Success, value.ToString()); Assert.Equal(tagValue, value.Object); } @@ -81,16 +81,16 @@ public void SetArrayTagDataTest1FailWrite() { TagController controller = GetTestController(); var result = controller.SetTagData("Machine1.IntegerArray1", new int[] { 112, 25564 }); - Assert.False(result.Success, result.FailString()); + Assert.False(result.Success, result.ToString()); } [Fact()] public void SetArrayTagDataTest2() { TagController controller = GetTestController(); var result = controller.SetTagData("Machine1.IntegerArray2", new int[] { 112, 25564 }); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); var value = controller.GetTagData("Machine1.IntegerArray2"); - Assert.True(value.Success, value.FailString()); + Assert.True(value.Success, value.ToString()); Assert.Equal(new int[] { 112, 25564 }, value.Object); } @@ -101,9 +101,9 @@ public void CallFunction() { TagController controller = GetTestController(); var result = controller.ExecutePackTagCommand("Machine1.SetValue(DINT value1)", 45); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); var value = controller.GetTagData("Machine1.Integer1"); - Assert.True(value.Success, value.FailString()); + Assert.True(value.Success, value.ToString()); Assert.Equal(45, value.Object); } @@ -115,9 +115,9 @@ public void CallArrayVoidFunction() for (int i = 0; i < 4; i++) { var result = controller.ExecutePackTagCommand($"Machine1.ExecuteObjects[{i}].SetValue(DINT value1)", 45); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); var value = controller.GetTagData($"Machine1.ExecuteObjects[{i}].Integer1"); - Assert.True(value.Success, value.FailString()); + Assert.True(value.Success, value.ToString()); Assert.Equal(45, value.Object); } @@ -131,7 +131,7 @@ public void CallArrayIntFunction() for (int i = 0; i < 4; i++) { var result = controller.ExecutePackTagCommand($"Machine1.ExecuteObjects[{i}].PlusOne(DINT value1)", 45); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); Assert.Equal(result.Object, 46); } } @@ -144,9 +144,9 @@ public void CallListVoidFunction() for (int i = 0; i < 3; i++) { var result = controller.ExecutePackTagCommand($"Machine2.ExecuteObjects[{i}].SetValue(DINT value1)", 45); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); var value = controller.GetTagData($"Machine2.ExecuteObjects[{i}].Integer1"); - Assert.True(value.Success, value.FailString()); + Assert.True(value.Success, value.ToString()); Assert.Equal(45, value.Object); } } @@ -159,7 +159,7 @@ public void CallListIntFunction() for (int i = 0; i < 3; i++) { var result = controller.ExecutePackTagCommand($"Machine2.ExecuteObjects[{i}].PlusOne(DINT value1)", 45); - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); Assert.Equal(result.Object, 46); } } @@ -219,14 +219,14 @@ public void CallBatchTagTypeFunction() new TagCall(TagCallType.Get, "Machine1.IntegerArray1[1]") }); - Assert.True(result[0].Success, result[0].FailString()); + Assert.True(result[0].Success, result[0].ToString()); Assert.Equal(result[0].Object, 46); - Assert.True(result[1].Success, result[1].FailString()); + Assert.True(result[1].Success, result[1].ToString()); Assert.Null(result[1].Object); - Assert.True(result[2].Success, result[2].FailString()); - Assert.True(result[3].Success, result[3].FailString()); + Assert.True(result[2].Success, result[2].ToString()); + Assert.True(result[3].Success, result[3].ToString()); Assert.Equal(451, result[3].Object); } diff --git a/Open.PackMLTests/Prefab/Tr88TagsTest.cs b/Open.PackMLTests/Prefab/Tr88TagsTest.cs index 6ab4606..6c2cc10 100644 --- a/Open.PackMLTests/Prefab/Tr88TagsTest.cs +++ b/Open.PackMLTests/Prefab/Tr88TagsTest.cs @@ -1,5 +1,5 @@ using Autabee.Utility; -using Autabee.Utility.IEC61131TypeConversion; +using Autabee.Utility.IEC61131StringTypeConversion; using Moq; using Open.PackML; using Open.PackML.Prefab; @@ -122,7 +122,7 @@ public void TestEumTags() result.AddResult(false, $"Tag [{tag.Name}] does not Exist"); } } - Assert.True(result.Success, result.FailString()); + Assert.True(result.Success, result.ToString()); } } } From 424b664aa734fb3c42f6aa42e654eec2422740b2 Mon Sep 17 00:00:00 2001 From: "I. Arbouw" Date: Wed, 22 Mar 2023 10:29:51 +0100 Subject: [PATCH 28/31] move utility --- ...Utility.IEC61131TypeConversionTests.csproj | 27 --- ...Utility.IEC61131TypeConversionTests.csproj | 24 -- .../IecTypeConvertorTests.cs | 90 -------- .../TestObjects/Address.cs | 8 - .../TestObjects/GpsCoordinates.cs | 8 - .../TestObjects/Person.cs | 9 - ...abee.Utility.IEC61131TypeConversion.csproj | 14 -- .../IECType.cs | 72 ------ .../IecTypeConvertor.cs | 211 ------------------ .../readme.md | 3 - Autabee.Utility/Autabee.Utility.csproj | 8 - Autabee.Utility/ValidationResult.cs | 61 ----- Autabee.Utility/ValidationResult`1.cs | 29 --- 13 files changed, 564 deletions(-) delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Address.cs delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/GpsCoordinates.cs delete mode 100644 Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Person.cs delete mode 100644 Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj delete mode 100644 Autabee.Utility.IEC61131TypeConversion/IECType.cs delete mode 100644 Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs delete mode 100644 Autabee.Utility.IEC61131TypeConversion/readme.md delete mode 100644 Autabee.Utility/Autabee.Utility.csproj delete mode 100644 Autabee.Utility/ValidationResult.cs delete mode 100644 Autabee.Utility/ValidationResult`1.cs diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj deleted file mode 100644 index 30668e6..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee - Backup.Utility.IEC61131TypeConversionTests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - net6.0;net48 - false - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj b/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj deleted file mode 100644 index 939689c..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/Autabee.Utility.IEC61131TypeConversionTests.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net48;net6.0 - false - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs deleted file mode 100644 index 350f7b9..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/IecTypeConvertorTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Autabee.Utility.IEC61131TypeConversion; -using Autabee.Utility.IEC61131TypeConversionTests.TestObjects; -using System; -using System.Collections; -using System.Linq; -using Xunit; -using Xunit.Abstractions; - -namespace Autabee.Utility.IEC61131TypeConversionTests -{ - public class IecTypeConvertorTests - { - ITestOutputHelper logger; - public IecTypeConvertorTests(ITestOutputHelper output) - { - logger = output; - } - - //[Theory] - //[InlineData(1, "BOOL")] - //[InlineData(8, "BYTE")] - //[InlineData(16, "WORD")] - //[InlineData(32, "DWORD")] - //[InlineData(64, "LWORD")] - //public void GetIecBitArraysTest(int i, string expected) - //{ - - // Assert.Equal(expected, IecTypeConvertor.GetIecTypeString(new BitArray(i, false))); - - //} - [Fact] - public void GetIecBitArrayTest() - { - for (var j = 0; j < 100; j++) - { - Assert.Equal($"BOOL[]", IecTypeConvertor.GetIecTypeString(new BitArray(j, false))); - } - - } - [Fact()] - public void GetIecByteArrayTest() - { - Assert.Equal("STRING[]", IecTypeConvertor.GetIecTypeString(new char[3])); - - } - - - - - [Fact()] - public void GetIecArrayTest() - { - - Assert.Equal("DINT[]", IecTypeConvertor.GetIecTypeString(new int[3])); - - } - - [Theory] - [InlineData(false, "BOOL")] - [InlineData(true, "BOOL")] - [InlineData((byte.MaxValue), "USINT")] - [InlineData((ushort.MaxValue), "UINT")] - [InlineData((uint.MaxValue), "UDINT")] - [InlineData((ulong.MaxValue), "ULINT")] - - public void GetIecTypeTest(T obj, string expectedResult) - { - Assert.Equal(expectedResult, IecTypeConvertor.GetIecTypeString(obj)); - } - - [Fact()] - public void GetIecObjectTypeTest() - { - Guid guid = new Guid(); - var person = new Person() { Name = guid.ToString(), PasswordHash = guid.GetHashCode() }; - Assert.Equal("UDT_Autabee_Utility_IEC61131TypeConversionTests_TestObjects_Person", person.GetIecTypeString()); - } - - - [Fact()] - public void GetIecObjectTypeStructureTest() - { - Guid guid = new Guid(); - var person = new Person() { Name = guid.ToString(), PasswordHash = guid.GetHashCode() }; - logger.WriteLine(person.GetIecTypeStructure(5).OuterXml); - } - } - - -} \ No newline at end of file diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Address.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Address.cs deleted file mode 100644 index d62c8fd..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Address.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Autabee.Utility.IEC61131TypeConversionTests.TestObjects -{ - class Address - { - public string Postcode { get; set; } - public GpsCoordinates GPS { get; set; } - } -} \ No newline at end of file diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/GpsCoordinates.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/GpsCoordinates.cs deleted file mode 100644 index 9a2cb62..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/GpsCoordinates.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Autabee.Utility.IEC61131TypeConversionTests.TestObjects -{ - class GpsCoordinates - { - public double Longitude { get; set; } - public double Latitude { get; set; } - } -} \ No newline at end of file diff --git a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Person.cs b/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Person.cs deleted file mode 100644 index 5d58b7f..0000000 --- a/Autabee.Automation.Utility.IEC61131TypeConversionTests/TestObjects/Person.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Autabee.Utility.IEC61131TypeConversionTests.TestObjects -{ - class Person - { - public string Name { get; set; } - public int PasswordHash { get; set; } - public Address Address { get; set; } - } -} \ No newline at end of file diff --git a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj b/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj deleted file mode 100644 index dd1422a..0000000 --- a/Autabee.Utility.IEC61131TypeConversion/Autabee.Utility.IEC61131TypeConversion.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net48;netstandard2.0;net6.0 - readme.md - - - - True - \ - - - - diff --git a/Autabee.Utility.IEC61131TypeConversion/IECType.cs b/Autabee.Utility.IEC61131TypeConversion/IECType.cs deleted file mode 100644 index bf16a4b..0000000 --- a/Autabee.Utility.IEC61131TypeConversion/IECType.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Linq; - -namespace Autabee.Utility.IEC61131TypeConversion -{ - /// - /// IEC61131 Type strings - /// - public static class IECType - { - private static string[] DefaultTypes { get; } = - { - "BOOL", - "BYTE", - "WORD", - "DWORD", - "LWORD", - "STRING", - "WSTRING", - "CHAR", - "SINT", - "INT", - "DINT", - "USINT", - "UINT", - "UDINT", - "ULINT", - "REAL", - "LREAL", - "DATE", - "LTIME", - "OBJECT" - }; - - public static string BOOL { get => "BOOL"; } - public static string BYTE { get => "BYTE"; } - public static string WORD { get => "WORD"; } - public static string DWORD { get => "DWORD"; } - public static string LWORD { get => "LWORD"; } - - public static string STRING { get => "STRING"; } - public static string WSTRING { get => "WSTRING"; } - public static string CHAR { get => "CHAR"; } - - public static string SINT { get => "SINT"; } - public static string INT { get => "INT"; } - public static string DINT { get => "DINT"; } - public static string LINT { get => "LINT"; } - - public static string USINT { get => "USINT"; } - public static string UINT { get => "UINT"; } - public static string UDINT { get => "UDINT"; } - public static string ULINT { get => "ULINT"; } - - public static string REAL { get => "REAL"; } - public static string LREAL { get => "LREAL"; } - - public static string DATE { get => "DATE"; } - public static string LTIME { get => "LTIME"; } - public static string OBJECT { get => "OBJECT"; } - - public static string ArrayOf(string type) => $"{type}[]"; - - public static bool ContainsType(string type) - { - type = type.ToUpper(); - - if (DefaultTypes.Contains(type) || type.StartsWith("UDT_")) return true; - if (type.EndsWith("]")) return ContainsType(type.Substring(0, type.IndexOf('['))); - return false; - } - } -} diff --git a/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs b/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs deleted file mode 100644 index 6e218e1..0000000 --- a/Autabee.Utility.IEC61131TypeConversion/IecTypeConvertor.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Collections; -using System.Linq; -using System.Reflection; -using System.Xml; - -namespace Autabee.Utility.IEC61131TypeConversion -{ - /// - /// Converter switching between IEC61131 types and C# types - /// - public static class IecTypeConvertor - { - // source https://www.plcnext.help/te/Programming/Csharp/Csharp_programming/Csharp_Supported_data_types.htm - public static string GetIecTypeString(this T value) - { - Type type = value.GetType(); - return GetIecTypeString(type); - } - public static string GetIecTypeString(this Type type) - { - if (type.IsArray) - { - var result = GetIecTypeString(type.GetElementType()) + "[]"; - if (string.Equals(result, "CHAR[]")) - { - return IECType.STRING + "[]"; - } - else - { - return result; - } - } - else if (type.GetInterfaces().Contains(typeof(IEnumerable)) - && type != typeof(string) - && type != typeof(BitArray)) - { - var result = GetIecTypeString(type.GenericTypeArguments[0]) + "[]"; - - return result; - - - - } - else - { - switch (type.FullName) - { - case "System.Boolean": - return IECType.BOOL; - - //unsigned Integers - case "System.Byte": - return IECType.USINT; - case "System.UInt16": - return IECType.UINT; - case "System.UInt32": - return IECType.UDINT; - case "System.UInt64": - return IECType.ULINT; - - //signed Integers - case "System.SByte": - return IECType.SINT; - case "System.Int16": - return IECType.INT; - case "System.Int32": - return IECType.DINT; - case "System.Int64": - return IECType.LINT; - - //Floating Points - case "System.Float": - return IECType.REAL; - case "System.Double": - return IECType.LREAL; - - //Duration - case "System.TimeSpan": - return IECType.LTIME; - case "System.Date": - return IECType.DATE; - - case "System.Char": - return IECType.CHAR; - case "System.String": - return IECType.WSTRING; - case "System.Collections.BitArray": - return IECType.BOOL + "[]"; - default: - return "UDT_" + type.FullName.Replace('.', '_'); - } - } - - } - public static Type GetCsharpType(string typeString, Type collectionType, Assembly executingAssembly) - { - return GetCsharpType(typeString, collectionType, new Assembly[] { executingAssembly }); - } - public static Type GetCsharpType(string typeString, Type collectionType, Assembly[] executingAssembly) - { - switch (typeString.ToUpper()) - { - case "BOOL": - return typeof(bool); - case "USINT": - return typeof(byte); - case "BYTE": - case "WORD": - case "DWORD": - case "LWORD": - case "BOOL[]": - return typeof(BitArray); - case "UINT": - return typeof(ushort); - case "UDINT": - return typeof(uint); - case "ULINT": - return typeof(ulong); - case "SINT": - return typeof(sbyte); - case "INT": - return typeof(short); - case "DINT": - return typeof(int); - case "LINT": - return typeof(long); - case "REAL": - return typeof(float); - case "LREAL": - return typeof(double); - case "LTIME": - return typeof(TimeSpan); - case "DATE": - return typeof(DateTime); - case "CHAR": - return typeof(char); - case "STRING": - return typeof(string); - case "STRING[]": - return typeof(char[]); - case "OBJECT": - return typeof(object); - default: - if (typeString.StartsWith("UDT")) - { - if (typeString.Contains("[")) - { - var elementType = GetCsharpType(typeString.Replace("[]", string.Empty), null, executingAssembly); - if (collectionType.IsGenericType) - { - collectionType = collectionType.MakeGenericType(elementType); - return collectionType; - } - else - { - var arrayType = elementType.MakeArrayType(); - return arrayType; - } - } - else - { - var typeName = typeString.Substring(4).Replace('_', '.'); - var assemby = executingAssembly.FirstOrDefault(o => o.GetType(typeName) != null); - if (assemby == null) throw new Exception("Unkown or Forbidden UDT"); - - return assemby.GetType(typeName); - } - } - if (typeString.StartsWith("STRING[")) - { - return typeof(char[]); - } - else - { - throw new ArgumentException($"Unable to convert {typeString} to c# type"); - } - } - } - - - public static XmlDocument GetIecTypeStructure(this T value, int depth = 1) - { - var item = new XmlDocument(); - item.NameTable.Add(value.GetType().Namespace); - var node = item.CreateElement(value.GetIecTypeString()); - //node.SetAttribute("type", value.GetIecTypeString()); - item.AppendChild(node); - AddSubNodes(value.GetType(), item, node, depth - 1); - return item; - } - - private static void AddSubNodes(Type value, XmlDocument item, XmlNode baseNode, int depth) - { - foreach (var property in value.GetProperties()) - { - var node = item.CreateElement(property.Name); - node.SetAttribute("type", property.PropertyType.GetIecTypeString()); - baseNode.AppendChild(node); - if (depth > 0 && node.Attributes[0].Value.Substring(0, 3).Equals("UDT")) - { - AddSubNodes(property.PropertyType, item, node, depth - 1); - } - } - } - } - - - - -} diff --git a/Autabee.Utility.IEC61131TypeConversion/readme.md b/Autabee.Utility.IEC61131TypeConversion/readme.md deleted file mode 100644 index bdc1d87..0000000 --- a/Autabee.Utility.IEC61131TypeConversion/readme.md +++ /dev/null @@ -1,3 +0,0 @@ - - -- [1] [PlcNext Supported data types in C#](https://www.plcnext.help/te/Programming/Csharp/Csharp_programming/Csharp_Supported_data_types.htm) \ No newline at end of file diff --git a/Autabee.Utility/Autabee.Utility.csproj b/Autabee.Utility/Autabee.Utility.csproj deleted file mode 100644 index 8c11a14..0000000 --- a/Autabee.Utility/Autabee.Utility.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - net48;netstandard2.0;net6.0 - readme.md - - - diff --git a/Autabee.Utility/ValidationResult.cs b/Autabee.Utility/ValidationResult.cs deleted file mode 100644 index 0904836..0000000 --- a/Autabee.Utility/ValidationResult.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Autabee.Utility -{ -#if(NET6_0_OR_GREATER) - public record ValidationResult -#else - public class ValidationResult -#endif - { - public ValidationResult(bool success = true, string unSuccessfulText = "", params object[] formatObjects) - { - Success = success; - FailInfo = new List<(string, object[])>(); - if (!string.IsNullOrWhiteSpace(unSuccessfulText)) - { - for (int i = 0; i < formatObjects.Length; i++) - { - if (!formatObjects[i].GetType().IsPrimitive) - { - formatObjects[i] = formatObjects[i].ToString(); - } - } - FailInfo.Add((unSuccessfulText, formatObjects)); - } - } - public ValidationResult(bool success = true, List<(string, object[])> failInfo = default) - { - Success = success; - FailInfo = failInfo ?? new List<(string, object[])>(); - } - - public void AddResult(ValidationResult validationResult) - { - if (validationResult.Success == false) - { - Success = false; - FailInfo.AddRange(validationResult.FailInfo); - } - } - public void AddResult(bool succes, string failText, params object[] formatObjects) - { - Success &= succes; - if (!string.IsNullOrWhiteSpace(failText)) - { - FailInfo.Add((failText, formatObjects)); - } - } - public string FailString() - { - string failString = FailInfo.Aggregate(string.Empty, (accumulator, fail) => accumulator += string.Format(fail.Item1, fail.Item2) + Environment.NewLine); - return failString; - } - - public List<(string, object[])> FailInfo { get; } - - public bool Success { get; private set; } - } -} \ No newline at end of file diff --git a/Autabee.Utility/ValidationResult`1.cs b/Autabee.Utility/ValidationResult`1.cs deleted file mode 100644 index e982fa7..0000000 --- a/Autabee.Utility/ValidationResult`1.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Autabee.Utility -{ -#if(NET6_0_OR_GREATER) - public record ValidationResult : ValidationResult -#else - public class ValidationResult : ValidationResult -#endif - { - public ValidationResult(bool success = true, T Object = default, string unSuccesfullText = "", params object[] formatObjects) : base(success, unSuccesfullText, formatObjects) - { - this.Object = Object; - } - - public ValidationResult(bool success = true, T Object = default, List<(string, object[])> failInfo = default) : base(success, failInfo) - { - this.Object = Object; - } - - public ValidationResult(ValidationResult result) : base(result.Success, result.FailInfo) - { - Object = default; - } - public T Object { get; } - } -} \ No newline at end of file From 964251ef450e18633a327a8f8e624835efc576d7 Mon Sep 17 00:00:00 2001 From: peacefighter1996 Date: Tue, 14 May 2024 23:21:59 +0200 Subject: [PATCH 29/31] net8 --- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 4 +- Open.PackML.Tags/Open.PackML.Tags.csproj | 2 +- .../Open - Backup.PackMLTests.csproj | 42 ------------------- Open.PackMLTests/Open.PackMLTests.csproj | 2 +- 4 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 Open.PackMLTests/Open - Backup.PackMLTests.csproj diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index ef3c349..c9bfb4a 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,4 +1,4 @@ - + Ian Arbouw @@ -7,7 +7,7 @@ 0.4.2-Beta - net48;netstandard2.0;net6.0 + net48;netstandard2.0;net6.0;net8 diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index d9dba19..f6e7ecd 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -7,7 +7,7 @@ 0.4.2-Beta - net48;netstandard2.0;net6.0 + net48;netstandard2.0;net6.0;net8 readme.md diff --git a/Open.PackMLTests/Open - Backup.PackMLTests.csproj b/Open.PackMLTests/Open - Backup.PackMLTests.csproj deleted file mode 100644 index 90cf71d..0000000 --- a/Open.PackMLTests/Open - Backup.PackMLTests.csproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - net6.0;net48 - - false - - - - - - - - - Always - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - diff --git a/Open.PackMLTests/Open.PackMLTests.csproj b/Open.PackMLTests/Open.PackMLTests.csproj index b466a6a..5360c1d 100644 --- a/Open.PackMLTests/Open.PackMLTests.csproj +++ b/Open.PackMLTests/Open.PackMLTests.csproj @@ -1,7 +1,7 @@  - net48;net6.0 + net48;net6.0;net8 false From ef1f653f50910f2d2751c6fecfaef5a5c4216f63 Mon Sep 17 00:00:00 2001 From: peacefighter1996 Date: Tue, 14 May 2024 23:26:33 +0200 Subject: [PATCH 30/31] update version --- Open.PackML.Prefab/Open.PackML.Prefab.csproj | 40 ++++++++++---------- Open.PackML.Tags/Open.PackML.Tags.csproj | 2 +- Open.PackML/Open.PackML.csproj | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Open.PackML.Prefab/Open.PackML.Prefab.csproj b/Open.PackML.Prefab/Open.PackML.Prefab.csproj index c9bfb4a..d970b4c 100644 --- a/Open.PackML.Prefab/Open.PackML.Prefab.csproj +++ b/Open.PackML.Prefab/Open.PackML.Prefab.csproj @@ -1,25 +1,25 @@  - - - Ian Arbouw - Default Implementations for the TR 88.00.02 and End user Minimum - packml;industrial-automation;ISA;ISA88;88;tags - 0.4.2-Beta - - - net48;netstandard2.0;net6.0;net8 - + + + Ian Arbouw + Default Implementations for the TR 88.00.02 and End user Minimum + packml;industrial-automation;ISA;ISA88;88;tags + 0.4.2 + + + net48;netstandard2.0;net6.0;net8 + - - - True - \ - - + + + True + \ + + - - - - + + + + diff --git a/Open.PackML.Tags/Open.PackML.Tags.csproj b/Open.PackML.Tags/Open.PackML.Tags.csproj index f6e7ecd..49e89a2 100644 --- a/Open.PackML.Tags/Open.PackML.Tags.csproj +++ b/Open.PackML.Tags/Open.PackML.Tags.csproj @@ -4,7 +4,7 @@ Ian Arbouw Base package for Open Packml implementation of the tag system packml;industrial-automation;ISA;ISA88;88;tags - 0.4.2-Beta + 0.4.2 net48;netstandard2.0;net6.0;net8 diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index d52f3d0..961af06 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -3,7 +3,7 @@ Ian Arbouw Open Library for development of PackML/ISA88 control systems. packml;industrial-automation;ISA;ISA88;88 - 0.4.2-Beta + 0.4.2 From 01ac99d2211619a6437b7eb6d44e55800fd18b0a Mon Sep 17 00:00:00 2001 From: peacefighter1996 Date: Tue, 14 May 2024 23:27:19 +0200 Subject: [PATCH 31/31] net8 --- Open.PackML/Open.PackML.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Open.PackML/Open.PackML.csproj b/Open.PackML/Open.PackML.csproj index 961af06..7b53b3f 100644 --- a/Open.PackML/Open.PackML.csproj +++ b/Open.PackML/Open.PackML.csproj @@ -7,7 +7,7 @@ - net48;netstandard2.0;net6.0 + net48;netstandard2.0;net6.0;net8 readme.md