From 192a5d87565947dc0e700a5a547d13f8f54e239c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:28:12 +0200 Subject: [PATCH] [BUG] Users are able to enter manual mode without adequate permissions, potentially leading to unauthorized actions (#143) * Create draft PR for #120 * +not possible start any modes if user dont have a proper rights to do that (also valid forcontext menu) +ReworkInstructor -added as sinbgle project , allow us find best suitable rework defined in table . * +sln file --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: peterbarancek <62284244+peterbarancek@users.noreply.github.com> --- .../x_template_x-xae/x_template_x-xae.tsproj | 2 +- .../Components/Rework/ReworkData.TcDUT | 20 + .../Rework/ReworkInstructionTask.TcPOU | 35 ++ .../Components/Rework/eReworkResults.TcDUT | 19 + .../Technology/CU00x/CU00x.TcPOU | 3 + .../CU00x/Components/CU00xComponents.TcDUT | 3 + .../CU00x/Data/CU00xProcessData.TcDUT | 3 + .../x_template_xPlc/x_template_xPlc.plcproj | 10 + .../Rework/ReworkModel.cs | 11 +- .../t/src/x_template_xHmi.Wpf/App.xaml.cs | 50 ++- .../ControlledUnits/Base/CUBaseViewModel.cs | 7 +- .../Views/Operator/OperatorView.xaml | 24 +- .../Views/Operator/OperatorViewModel.cs | 4 + .../x_template_xHmi.Wpf.csproj | 1 + .../Properties/Localizations.Designer.cs | 45 +++ .../Properties/Localizations.resx | 15 + .../Security/DefaultRoles.cs | 8 +- .../Instructor/ReworkInstructionItem.cs | 203 ++++++++++ .../Instructor/ReworkInstructionItemStatus.cs | 11 + .../Instructor/ReworkInstructorController.cs | 381 ++++++++++++++++++ .../Instructor/TransformationEntityData.cs | 138 +++++++ .../View/InstructionConfiguratorView.xaml | 70 ++++ .../View/InstructionConfiguratorView.xaml.cs | 103 +++++ .../View/ReworkInstructionView.xaml | 43 ++ .../View/ReworkInstructionView.xaml.cs | 17 + .../View/ReworkInstructionViewModel.cs | 113 ++++++ .../Properties/Resources.Designer.cs | 198 +++++++++ .../Properties/Resources.resx | 165 ++++++++ .../Properties/Resources.sk-SK.resx | 165 ++++++++ .../x_template_xReworkInstructor.csproj | 32 ++ templates/mts-s-template/t/x_template_x.sln | 23 ++ 31 files changed, 1909 insertions(+), 13 deletions(-) create mode 100644 templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkData.TcDUT create mode 100644 templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkInstructionTask.TcPOU create mode 100644 templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/eReworkResults.TcDUT create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItem.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItemStatus.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructorController.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/TransformationEntityData.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/InstructionConfiguratorView.xaml create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/InstructionConfiguratorView.xaml.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/ReworkInstructionView.xaml create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/ReworkInstructionView.xaml.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/ReworkInstructionViewModel.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Properties/Resources.Designer.cs create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Properties/Resources.resx create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/Properties/Resources.sk-SK.resx create mode 100644 templates/mts-s-template/t/src/x_template_xReworkInstructor/x_template_xReworkInstructor.csproj diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_x-xae.tsproj b/templates/mts-s-template/t/src/x_template_x-xae/x_template_x-xae.tsproj index c9642b7..021fc1b 100644 --- a/templates/mts-s-template/t/src/x_template_x-xae/x_template_x-xae.tsproj +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_x-xae.tsproj @@ -151,7 +151,7 @@ - + x_template_xPlc Instance {08500001-0000-0000-F000-000000000064} diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkData.TcDUT b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkData.TcDUT new file mode 100644 index 0000000..b2e6b2e --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkData.TcDUT @@ -0,0 +1,20 @@ + + + + "} + EntityId: STRING; + {attribute addProperty Name "<#ReworkId#>"} + ReworkId: STRING; + + {attribute addProperty Name "<#Rework Instrukcia#>"} + ReworkInstruction:STRING; + {attribute addProperty Name "<#Rework Instrukcia najdena#>"} + ReworkInstructionFound:BOOL; + +END_STRUCT +END_TYPE +]]> + + \ No newline at end of file diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkInstructionTask.TcPOU b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkInstructionTask.TcPOU new file mode 100644 index 0000000..4deecbd --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/ReworkInstructionTask.TcPOU @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/eReworkResults.TcDUT b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/eReworkResults.TcDUT new file mode 100644 index 0000000..5d64073 --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Abstractions/Components/Rework/eReworkResults.TcDUT @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/CU00x.TcPOU b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/CU00x.TcPOU index 9187661..5f750ad 100644 --- a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/CU00x.TcPOU +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/CU00x.TcPOU @@ -29,6 +29,8 @@ VAR {attribute addProperty Name "<#Test multi positions#>"} _positionsMulti : CU00xTestMultiPositions(THIS^); + + END_VAR ]]> @@ -266,6 +268,7 @@ END_VAR]]> "} + ReworkInstructionTask : ReworkInstructionTask(THISSTRUCT); {attribute wpf [Container(Layout.Stack,"DRIVES AND MANIPULATORS")]} {attribute wpf [Group(Layout.Scroll)]} {attribute addProperty Name "MultiAxis"} diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/Data/CU00xProcessData.TcDUT b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/Data/CU00xProcessData.TcDUT index 63d90f0..7351a57 100644 --- a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/Data/CU00xProcessData.TcDUT +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/Technology/CU00x/Data/CU00xProcessData.TcDUT @@ -5,8 +5,11 @@ CU00xProcessData EXTENDS CUProcessDataBase : STRUCT {attribute wpf [Container(Layout.Stack)]} + {attribute addProperty Name "Bolt present inspection"} BoltPresenceInspector : TcoInspectors.TcoDigitalInspector(THISSTRUCT); + {attribute addProperty Name "Bolt Dimension inspection"} BoltDimensionPresenceInspector : TcoInspectors.TcoAnalogueInspector(THISSTRUCT); + {attribute addProperty Name "Bolt code inspection"} BoltDatacodePresenceInspector : TcoInspectors.TcoDataInspector(THISSTRUCT); {attribute addProperty Name "Dimension inspection 1"} diff --git a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/x_template_xPlc.plcproj b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/x_template_xPlc.plcproj index f04e1cb..bc739cc 100644 --- a/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/x_template_xPlc.plcproj +++ b/templates/mts-s-template/t/src/x_template_x-xae/x_template_xPlc/x_template_xPlc.plcproj @@ -50,6 +50,15 @@ Code + + Code + + + Code + + + Code + Code @@ -373,6 +382,7 @@ + diff --git a/templates/mts-s-template/t/src/x_template_xDataMerge/Rework/ReworkModel.cs b/templates/mts-s-template/t/src/x_template_xDataMerge/Rework/ReworkModel.cs index 75fe491..3248e54 100644 --- a/templates/mts-s-template/t/src/x_template_xDataMerge/Rework/ReworkModel.cs +++ b/templates/mts-s-template/t/src/x_template_xDataMerge/Rework/ReworkModel.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq; using System.Reflection; using System.Resources; using System.Text; @@ -137,7 +138,7 @@ private IEnumerable ReqProperty(object obj) var retVal = new List(); switch (obj) { - // here you define properties witch are relevant for reqired types to change by rework + // here you define properties witch are relevant for required types to change by rework case TcoInspectors.PlainTcoDigitalInspectorData c: return PropertyHelper.GetPropertiesNames(c, p => p.RetryAttemptsCount ,p =>p.IsByPassed,p => p.IsExcluded); case TcoInspectors.PlainTcoAnalogueInspectorData c: @@ -156,7 +157,7 @@ private IEnumerable ReqProperty(object obj) private bool Exclude(object obj) { - // some special conditions to exluce + // some special conditions to exclude return false; } @@ -165,8 +166,12 @@ private bool Include(object obj) switch (obj) { // here is definitions of all types and condition witch are relevat to change by rework (source) - case TcoInspectors.PlainTcoInspectorData c: + case TcoInspectors.PlainTcoDigitalInspectorData c: + return c is TcoInspectors.PlainTcoDigitalInspectorData; + case TcoInspectors.PlainTcoAnalogueInspectorData c: return c is TcoInspectors.PlainTcoAnalogueInspectorData; + case TcoInspectors.PlainTcoDataInspectorData c: + return c is TcoInspectors.PlainTcoDataInspectorData; case PlainCuHeader c: return c is PlainCuHeader; //&& (c.NextOnPassed != 0 diff --git a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/App.xaml.cs b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/App.xaml.cs index a1f0645..a2f9b85 100644 --- a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/App.xaml.cs +++ b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/App.xaml.cs @@ -34,6 +34,8 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization; using Newtonsoft.Json; +using x_template_xReworkInstructor.Instructor; +using x_template_xReworkInstructor.Instructor.View; namespace x_template_xHmi.Wpf { @@ -368,8 +370,6 @@ private void SetUpRepositoriesUsingRavenDb() CuxInstructor = new InstructorController(_instructionPlanHandler, new InstructableSequencer(x_template_xPlc.MAIN._technology._cu00x._automatTask)); CuxParalellInstructor = new InstructorController(_instructionPlanHandler, new InstructableSequencer(x_template_xPlc.MAIN._technology._cu00x._automatTask._paralellTask)); - - } @@ -420,9 +420,52 @@ private void SetUpRepositoriesUsingMongoDb() CuxParalellInstructor = new InstructorController(_instructionPlanHandler, new InstructableSequencer(x_template_xPlc.MAIN._technology._cu00x._automatTask._paralellTask)); - + + Log.Information(@"Initialize Rework instructor repository..."); + + + + //Rework Instructor + var _reworkInstructionPlanHandler = RepositoryDataSetHandler.CreateSet(new MongoDbRepository>(new MongoDbRepositorySettings>(Entry.Settings.GetConnectionString(), Entry.Settings.DbName, "ReworkInstructions"))); + + CuxReworkInstructor = new ReworkInstructorController(_reworkInstructionPlanHandler, new MongoDbRepository(ProcessDataRepoSettings), x_template_xPlc.MAIN._technology._cu00x._processData._data); + + Action getReworkInstruction = () => GetReworkInstruction(x_template_xPlc.MAIN._technology._cu00x._components.ReworkInstructionTask,CuxReworkInstructor); + x_template_xPlc.MAIN._technology._cu00x._components.ReworkInstructionTask.InitializeExclusively(getReworkInstruction); + + Log.Information(@"Initialize Rework instructor repository... Done"); + } + private void GetReworkInstruction(ReworkInstructionTask task, ReworkInstructorController reworkInstructor) + { + try + { + task.Read(); + reworkInstructor.FindInsturction(task._data.EntityId.Cyclic); + if (string.IsNullOrEmpty(reworkInstructor.CurrentInstruction.ReworkName)) + { + task._data.ReworkId.Cyclic = ""; + task._data .ReworkInstruction.Cyclic = "AUTO REWORK NOT FOUND!"; + task._data.ReworkInstructionFound.Cyclic = false; + + } + else + { + task._data.ReworkId.Synchron = reworkInstructor.CurrentInstruction.ReworkName; + task._data.ReworkInstruction.Cyclic = "AUTO REWORK FOUND - " + reworkInstructor.CurrentInstruction.ReworkName; + task._data.ReworkInstructionFound.Cyclic = true; + + } + task.Write(); + } + catch (Exception ex) + { + + Console.WriteLine(ex.ToString()); + } + + } private void GetProductionPlan(ProductionPlaner productionPlaner) { ProductionItem item; @@ -459,6 +502,7 @@ public static x_template_xPlcTwinController x_template_xPlc public static LanguageSelectionViewModel LanguageSelectionModel { get; private set; } public static ShutdownViewModel AppShutdownModel { get; private set; } = new ShutdownViewModel(); public bool DataExchangeActive { get; private set; } = true; + public static ReworkInstructorController CuxReworkInstructor { get; private set; } /// diff --git a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/ControlledUnits/Base/CUBaseViewModel.cs b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/ControlledUnits/Base/CUBaseViewModel.cs index ee7eebc..56f8a5b 100644 --- a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/ControlledUnits/Base/CUBaseViewModel.cs +++ b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/ControlledUnits/Base/CUBaseViewModel.cs @@ -105,7 +105,8 @@ void Update() var automatTask = Component.GetType().GetProperty("_automatTask")?.GetValue(Component) as TcoTaskedSequencer; if (automatTask != null) { - automatTask._task.ExecuteDialog = () => + automatTask._task.Roles = x_template_xPlcConnector.DefaultRoles.automat_start; + automatTask._task.ExecuteDialog = () => { return MessageBox.Show(x_template_xHmi.Wpf.Properties.strings.AutomatWarning, "Automat", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes; }; @@ -114,7 +115,8 @@ void Update() var groundTask = Component.GetType().GetProperty("_groundTask")?.GetValue(Component) as TcoTaskedSequencer; if (groundTask != null) { - groundTask._task.ExecuteDialog = () => + groundTask._task.Roles = x_template_xPlcConnector.DefaultRoles.ground_position_start; + groundTask._task.ExecuteDialog = () => { return MessageBox.Show(x_template_xHmi.Wpf.Properties.strings.GroundWarning, "Ground", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes; }; @@ -123,6 +125,7 @@ void Update() var manualTask = Component.GetType().GetProperty("_manualTask")?.GetValue(Component) as TcoTaskedService; if (manualTask != null) { + manualTask.Roles = x_template_xPlcConnector.DefaultRoles.manual_start; manualTask.ExecuteDialog = () => { return MessageBox.Show(x_template_xHmi.Wpf.Properties.strings.ManualWarning, "Manual", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes; diff --git a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorView.xaml b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorView.xaml index 222e1e5..4705df4 100644 --- a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorView.xaml +++ b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorView.xaml @@ -8,7 +8,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vortex="http://vortex.mts/xaml" xmlns:vortexs="http://vortex.security.mts/xaml" xmlns:view="clr-namespace:x_template_xProductionPlaner.Planer.View;assembly=x_template_xProductionPlaner" - xmlns:x_template_xinstructor="clr-namespace:x_template_xInstructor;assembly=x_template_xInstructor" xmlns:view1="clr-namespace:x_template_xStatistic.Statistics.View;assembly=x_template_xStatistic" xmlns:view2="clr-namespace:x_template_xTagsDictionary.View;assembly=x_template_xTagsDictionary" + + xmlns:x_template_xinstructor="clr-namespace:x_template_xInstructor;assembly=x_template_xInstructor" xmlns:view1="clr-namespace:x_template_xStatistic.Statistics.View;assembly=x_template_xStatistic" xmlns:view2="clr-namespace:x_template_xTagsDictionary.View;assembly=x_template_xTagsDictionary" xmlns:view3="clr-namespace:x_template_xReworkInstructor.Instructor.View;assembly=x_template_xReworkInstructor" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> @@ -114,6 +115,27 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorViewModel.cs b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorViewModel.cs index b0c853b..d4dcb86 100644 --- a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorViewModel.cs +++ b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/Views/Operator/OperatorViewModel.cs @@ -10,6 +10,7 @@ using x_template_xStatistic.Statistics.View; using x_template_xTagsDictionary.View; using x_template_xPlcConnector; +using x_template_xReworkInstructor.Instructor.View; namespace x_template_xHmi.Wpf.Views.Operator { @@ -35,6 +36,8 @@ public OperatorViewModel() InstructorParalellViewModel = new InstructorViewModel(App.CuxParalellInstructor); StatisticViewModel = new StatisticsDataViewModel(App.CuxStatistic); TagsPairingViewModel = new TagsPairingViewModel(App.CuxTagsPairing); + ReworkInstructorViewModel = new ReworkInstructionViewModel(App.CuxReworkInstructor); + @@ -47,5 +50,6 @@ public OperatorViewModel() public InstructorViewModel InstructorParalellViewModel { get; private set; } public StatisticsDataViewModel StatisticViewModel { get; private set; } public TagsPairingViewModel TagsPairingViewModel { get; private set; } + public ReworkInstructionViewModel ReworkInstructorViewModel { get; private set; } } } diff --git a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/x_template_xHmi.Wpf.csproj b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/x_template_xHmi.Wpf.csproj index 6333110..2e0f9b5 100644 --- a/templates/mts-s-template/t/src/x_template_xHmi.Wpf/x_template_xHmi.Wpf.csproj +++ b/templates/mts-s-template/t/src/x_template_xHmi.Wpf/x_template_xHmi.Wpf.csproj @@ -69,6 +69,7 @@ + diff --git a/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.Designer.cs b/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.Designer.cs index 1005d0d..2a61a84 100644 --- a/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.Designer.cs +++ b/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.Designer.cs @@ -738,6 +738,15 @@ public static string ___Entity_header__ { } } + /// + /// Looks up a localized string similar to Entity Id. + /// + public static string ___Entity_Id__ { + get { + return ResourceManager.GetString("___Entity_Id__", resourceCulture); + } + } + /// /// Looks up a localized string similar to Error. /// @@ -1757,6 +1766,24 @@ public static string ___Rework_Count__ { } } + /// + /// Looks up a localized string similar to Rework Instrukcia. + /// + public static string ___Rework_Instrukcia__ { + get { + return ResourceManager.GetString("___Rework_Instrukcia__", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rework Instrukcia najdena. + /// + public static string ___Rework_Instrukcia_najdena__ { + get { + return ResourceManager.GetString("___Rework_Instrukcia_najdena__", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reworked. /// @@ -1766,6 +1793,24 @@ public static string ___Reworked__ { } } + /// + /// Looks up a localized string similar to ReworkId. + /// + public static string ___ReworkId__ { + get { + return ResourceManager.GetString("___ReworkId__", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ReworkInstruction. + /// + public static string ___ReworkInstruction__ { + get { + return ResourceManager.GetString("___ReworkInstruction__", resourceCulture); + } + } + /// /// Looks up a localized string similar to Safety doors OK. /// diff --git a/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.resx b/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.resx index e5c0fa4..0caa6ad 100644 --- a/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.resx +++ b/templates/mts-s-template/t/src/x_template_xPlcConnector/Properties/Localizations.resx @@ -636,6 +636,18 @@ Oddelovanie blistrov na vstupe neaktive (P10)(P10.1)je nepritomne + + Entity Id + + + ReworkId + + + Rework Instrukcia + + + Rework Instrukcia najdena + Next on Passed @@ -855,6 +867,9 @@ CU00x + + ReworkInstruction + Created diff --git a/templates/mts-s-template/t/src/x_template_xPlcConnector/Security/DefaultRoles.cs b/templates/mts-s-template/t/src/x_template_xPlcConnector/Security/DefaultRoles.cs index a569593..afe2be1 100644 --- a/templates/mts-s-template/t/src/x_template_xPlcConnector/Security/DefaultRoles.cs +++ b/templates/mts-s-template/t/src/x_template_xPlcConnector/Security/DefaultRoles.cs @@ -18,6 +18,7 @@ private DefaultRoles() SecurityManager.Manager.GetOrCreateRole(new Role(instructor_access)); SecurityManager.Manager.GetOrCreateRole(new Role(planer_access)); SecurityManager.Manager.GetOrCreateRole(new Role(statistic_access)); + SecurityManager.Manager.GetOrCreateRole(new Role(rework_instructor_access)); SecurityManager.Manager.GetOrCreateRole(new Role(technology_automat_all)); SecurityManager.Manager.GetOrCreateRole(new Role(technology_ground_all)); @@ -48,6 +49,7 @@ private DefaultRoles() public const string instructor_access = nameof(instructor_access); public const string planer_access = nameof(planer_access); public const string statistic_access = nameof(planer_access); + public const string rework_instructor_access = nameof(rework_instructor_access); public const string technology_automat_all = nameof(technology_automat_all); @@ -80,7 +82,7 @@ public static void AssignRoles() SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Administrator, new string[] { "Administrator", process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access, - instructor_access,planer_access,statistic_access, + instructor_access,planer_access,statistic_access,rework_instructor_access, technology_automat_all,technology_ground_all, ground_position_start,automat_start,manual_start, station_details,sequencer_step, @@ -90,7 +92,7 @@ public static void AssignRoles() SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Maintenance, new string[] { //process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access, - //instructor_access,planer_access,statistic_access, + //instructor_access,planer_access,statistic_access,rework_instructor_access, technology_automat_all,technology_ground_all, ground_position_start,automat_start,manual_start, station_details,sequencer_step, @@ -99,7 +101,7 @@ public static void AssignRoles() SecurityManager.RoleGroupManager.AddRolesToGroup(DefaultGroups.Operator, new string[] { //process_settings_access, process_settings_change,rework_settings_access,process_traceability_access,technology_settings_access, - //instructor_access,planer_access,statistic_access, + //instructor_access,planer_access,statistic_access,rework_instructor_access, //technology_automat_all,technology_ground_all, //ground_position_start,automat_start,manual_start, //station_details,sequencer_step, diff --git a/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItem.cs b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItem.cs new file mode 100644 index 0000000..362afd6 --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItem.cs @@ -0,0 +1,203 @@ +using System; +using System.ComponentModel; +using TcOpen.Inxton.RepositoryDataSet; + +namespace x_template_xReworkInstructor.Instructor +{ + public class ReworkInstructionItem + : INotifyPropertyChanged, IEquatable, IDataSetItems + { + + string key; + /// + /// Gets or sets the key of this instruction item. + /// + public string Key + { + get + { + return key; + } + set + { + if (key == value) + { + return; + } + + key = value; + NotifyPropertyChange(nameof(Key)); + } + } + + + /// + /// Gets or sets the key description of this instruction item. + /// + public string KeyDescription + { + get + { + return keyDescription; + } + set + { + if (keyDescription == value) + { + return; + } + + keyDescription = value; + NotifyPropertyChange(nameof(KeyDescription)); + } + } + string primaryDescription; + + /// + /// Gets or sets arbitrary description of this instruction. + /// + public string PrimaryDescription + { + get + { + return primaryDescription; + } + set + { + if (primaryDescription == value) + { + return; + } + + primaryDescription = value; + NotifyPropertyChange(nameof(PrimaryDescription)); + } + } + + /// + /// Gets or sets arbitrary description of this instruction. + /// + public string SecondaryDescription + { + get + { + return secondaryDescription; + } + set + { + if (secondaryDescription == value) + { + return; + } + + secondaryDescription = value; + NotifyPropertyChange(nameof(SecondaryDescription)); + } + } + public string ReworkName + { + get + { + return reworkName; + } + set + { + if (reworkName == value) + { + return; + } + + reworkName = value; + NotifyPropertyChange(nameof(ReworkName)); + } + } + + + + string contentSource; + private string secondaryDescription; + private ReworkInstructionItemStatus status; + private string keyDescription; + private string reworkName; + private ulong counter; + private string description; + + /// + /// Content source (path to image) of this instruction item. + /// + public string ContentSource + { + get + { + return contentSource; + } + set + { + if (contentSource == value) + { + return; + } + + contentSource = value; + NotifyPropertyChange(nameof(ContentSource)); + } + } + + + public ReworkInstructionItemStatus Status + { + get + { + return status; + } + set + { + if (status == value) + { + return; + } + + status = value; + NotifyPropertyChange(nameof(Status)); + } + } + + public string Description { get => description; set{ description = value; + NotifyPropertyChange(nameof(Description)); } } + + public event PropertyChangedEventHandler PropertyChanged; + + protected void NotifyPropertyChange(string propertyName) + { + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public bool Equals(ReworkInstructionItem other) + { + if (other == null) + return false; + + if (this.Key == other.Key) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + ReworkInstructionItem personObj = obj as ReworkInstructionItem; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.Key.GetHashCode(); + } + } +} diff --git a/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItemStatus.cs b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItemStatus.cs new file mode 100644 index 0000000..96b4e8f --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructionItemStatus.cs @@ -0,0 +1,11 @@ +namespace x_template_xReworkInstructor.Instructor +{ + public enum ReworkInstructionItemStatus + + + { + None = 0, + Active = 10, + Deleted = 20, + } +} diff --git a/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructorController.cs b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructorController.cs new file mode 100644 index 0000000..231def9 --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/ReworkInstructorController.cs @@ -0,0 +1,381 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq.Expressions; +using System.Text; +using System.Linq; + +using Vortex.Connector; +using System.Collections.ObjectModel; +using TcOpen.Inxton.Data; +using TcOpen.Inxton.RepositoryDataSet; +using x_template_xPlc; +using TcoInspectors; + +namespace x_template_xReworkInstructor.Instructor +{ + public class ReworkInstructorController + : INotifyPropertyChanged + { + + public ReworkInstructorController(RepositoryDataSetHandler instructionData, + IRepository repository, + ProcessData onlineData) + { + OnlineData = onlineData; + DataHandler = instructionData; + RewrkSetRepository = repository; + transferEntityObject = new TransformationEntityData(repository); + RepositorySource = repository; + RefreshReworkSet(repository); + + } + + + /// + /// Gets current instruction set. + /// + public EntitySet CurrentInstructionSet { get; set; } = new EntitySet(); + /// + /// Gets production of this + /// + protected RepositoryDataSetHandler DataHandler { get; } + public IRepository RewrkSetRepository { get; private set; } + + public string ConfigName { get; set; } + + /// + /// Source repository + /// + public IRepository RepositorySource { get; private set; } + + + ReworkInstructionItem currentInstruction = new ReworkInstructionItem(); + + /// + /// Gets current instruction item. + /// + public ReworkInstructionItem CurrentInstruction + { + get + { + return currentInstruction; + } + set + { + if (currentInstruction == value) + { + return; + } + + currentInstruction = value; + OnPropertyChanged(nameof(CurrentInstruction)); + } + } + + + private ReworkInstructionItem EmptyIntruction = new ReworkInstructionItem(); + + public void RefreshReworkSet() + { + RefreshReworkSet(RepositorySource); + } + private void RefreshReworkSet(IRepository repositorySource) + { + var items = repositorySource.Queryable.Select(p => p._EntityId).ToList(); + + RecipeCollection = new ObservableCollection(items); + if (!RecipeCollection.Contains(string.Empty)) + { + RecipeCollection.Add(string.Empty); + } + } + + + + + + public void FindInsturction(string entityId) + { + if (string.IsNullOrEmpty(EntityId)) + { + RefreshInstruction(null);// provide empty instruction + return; + } + var entity = transferEntityObject.GetEntityData(entityId); + + if (entity.EntityHeader.Results.Result == (short)eOverallResult.Failed) + { + collectionOfFailedCheck.Clear(); + + if (entity != null) + { + transferEntityObject.SearchPlainEntity("", entity, null, IncludeFailedInspectors); + + // first failed inspector in process data + var key = collectionOfFailedCheck[0].Key; + + if (key != null) + { + var result = CurrentInstructionSet.Items.FirstOrDefault(p => p.Key == key); + + RefreshInstruction(result.Key); + + + // this.SaveDataSet(OnlineData.HumanReadable); + + } + + } + + } + else + { + //send empty instruction + RefreshInstruction(null); + } + + } + + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + + TransformationEntityData transferEntityObject; + + + public ProcessData OnlineData { get; private set; } + + public string EntityId { get; private set; } + public string ActualResult { get; private set; } + + public ObservableCollection RecipeCollection + { + get => _recipeCollection; private set + { + _recipeCollection = value; + OnPropertyChanged(nameof(RecipeCollection)); + } + } + + + /// + /// When overriden performs update of . + /// + public void RefreshInstruction(string key =null) + { + if (key == null) + { + this.CurrentInstruction = EmptyIntruction; + return; + } + var instruction = this.CurrentInstructionSet.Items.Where(p => p.Key == key).FirstOrDefault(); + + if (instruction != null) + { + this.CurrentInstruction = instruction; + } + else + { + this.CurrentInstruction = EmptyIntruction; + } + } + /// + /// Loads items set from the repository to this controller. + /// + /// set id. + public void LoadDataSet(string setid) + { + var result = DataHandler.Repository.Queryable.FirstOrDefault(p => p._EntityId == setid); + + if (result == null) + { + DataHandler.Create(setid, CurrentInstructionSet); + } + + CurrentInstructionSet = DataHandler.Read(setid); + } + + /// + /// Saves items set from this controller to the repository. + /// + /// Instrucion set id. + public void SaveDataSet(string setId) + { + + if (!DataHandler.Repository.Queryable.Where(p => p._EntityId == setId).Any()) + { + DataHandler.Create(setId, CurrentInstructionSet); + } + DataHandler.Update(setId, CurrentInstructionSet); + + + } + + public void UpdateFromOnlineDataTemplate() + { + if (!string.IsNullOrEmpty(OnlineData.HumanReadable)) + { + collectionOfAllCheck.Clear(); + + transferEntityObject.SearchEntity( OnlineData, Include); + + + + UpdateList(collectionOfAllCheck); + // this.SaveDataSet(OnlineData.HumanReadable); + + + } + } + + + + public void UpdateList(IEnumerable templateInstructions) + { + var templateInstructionList = new List(); + + foreach (var item in templateInstructions) + { + templateInstructionList.Add(item); + } + + + foreach (var item in CurrentInstructionSet.Items) + { + item.Status = ReworkInstructionItemStatus.Deleted; + } + + CurrentInstructionSet.Items = new ObservableCollection(CurrentInstructionSet.Items.Union(templateInstructionList)); + + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentInstructionSet))); + + foreach (var item in CurrentInstructionSet.Items) + { + if (templateInstructions != null) + { + var result = templateInstructions.Where(p => p.Key == item.Key).FirstOrDefault(); + if (result != null) + { + item.Status = ReworkInstructionItemStatus.Active; + } + } + } + + + } + + + public void UpdateFromTemplate() + { + if (this.OnlineData!=null) + { + UpdateFromOnlineDataTemplate(); + } + + } + + private List collectionOfFailedCheck = new List(); + private List collectionOfAllCheck = new List(); + private ObservableCollection _recipeCollection; + + + + static string GetTextBetweenData(string inputSource,string marker) + { + + + // Find the position of the first occurrence of "_data" + int firstIndex = inputSource.IndexOf(marker); + + // If the first "_data" is found + if (firstIndex != -1) + { + // Find the position of the last occurrence of "_data" + int lastIndex = inputSource.LastIndexOf(marker); + + // Ensure the lastIndex is different from the firstIndex + if (lastIndex != -1 && lastIndex != firstIndex) + { + // Calculate the start and length for the substring + int startIndex = firstIndex + marker.Length; + int length = lastIndex - startIndex; + + // Extract the substring between the first and last "_data" + return inputSource.Substring(startIndex, length); + } + } + + + return inputSource; + } + + private bool Include( object obj) + { + const string marker = "._data"; + + switch (obj) + { + + case TcoDigitalInspectorData c: + collectionOfAllCheck.Add(new ReworkInstructionItem() { Key = GetTextBetweenData(c.Symbol, marker).TrimStart('.'), KeyDescription =$"{c.HumanReadable.TrimEnd('.').Split('.').Last()}", Status = ReworkInstructionItemStatus.Active }); + return c is TcoDigitalInspectorData; + case TcoAnalogueInspectorData c: + collectionOfAllCheck.Add(new ReworkInstructionItem() { Key = GetTextBetweenData(c.Symbol, marker).TrimStart('.'), KeyDescription = $"{c.HumanReadable.TrimEnd('.').Split('.').Last()}", Status = ReworkInstructionItemStatus.Active }); + return c is TcoAnalogueInspectorData; + case TcoDataInspectorData c: + collectionOfAllCheck.Add(new ReworkInstructionItem() { Key = GetTextBetweenData(c.Symbol, marker).TrimStart('.'), KeyDescription = $"{c.HumanReadable.TrimEnd('.').Split('.').Last()}", Status = ReworkInstructionItemStatus.Active }); + return c is TcoDataInspectorData; + + default: + break; + } + + return false; + } + + private bool IncludeFailedInspectors(string symbol, object obj) + { + var result = false; + switch (obj) + { + + case PlainTcoDigitalInspectorData c: + result = c.Result ==(short)eInspectorResult.Failed; + if (result) + { + collectionOfFailedCheck.Add(new ReworkInstructionItem() { Key = symbol, Status = ReworkInstructionItemStatus.Active }); + } + return c is PlainTcoDigitalInspectorData && result; + + case PlainTcoAnalogueInspectorData c: + result = c.Result == (short)eInspectorResult.Failed; + if (result) + { + collectionOfFailedCheck.Add(new ReworkInstructionItem() { Key = symbol, Status = ReworkInstructionItemStatus.Active }); + } + return c is PlainTcoAnalogueInspectorData && result; + + case PlainTcoDataInspectorData c: + result = c.Result == (short)eInspectorResult.Failed; + if (result) + { + collectionOfFailedCheck.Add(new ReworkInstructionItem() { Key = symbol, Status = ReworkInstructionItemStatus.Active }); + + } + return c is PlainTcoDataInspectorData && result; + + default: + break; + } + + return false; + } + + } +} diff --git a/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/TransformationEntityData.cs b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/TransformationEntityData.cs new file mode 100644 index 0000000..005aed0 --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/TransformationEntityData.cs @@ -0,0 +1,138 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using TcOpen.Inxton.Data; +using Vortex.Connector; +using x_template_xPlc; + +namespace x_template_xReworkInstructor.Instructor +{ + public class TransformationEntityData + { + private IRepository repository; + private List _collectioOfPlainReqType = new List(); + private List _collectioOfReqType = new List(); + + public TransformationEntityData(IRepository repos) + { + Repository = repos; + _collectioOfReqType.Clear(); + _collectioOfPlainReqType.Clear(); + + } + + public PlainProcessData Source { get; set; } + + public IRepository Repository { get => repository; set => repository = value; } + + public PlainProcessData GetEntityData(string id) + { + return Repository.Queryable.FirstOrDefault(p => p._EntityId == id); + } + + public IQueryable GetEntities() + { + return Repository.Queryable.Where(p => true); + } + + + public Func Exclusion { get; } + public Func Inclusion { get; } + + + public void SearchPlainEntity(string symbol, IPlain sourceObj, Func exclude = null, Func include = null) + { + + foreach (var child in sourceObj.GetType().GetProperties().Where(p => true)) + { + var obj = child.GetValue(sourceObj); + var objName = child.Name; + string path = string.Empty; + + path = $"{symbol}.{objName}"; + + + if (obj != null) + { + + if (include != null) + { + if (include(symbol, obj)) + { + + _collectioOfPlainReqType.Add((IPlain)obj); + } + + if (obj.GetType().IsArray) + { + var arrayObj = obj as Array; + + if (arrayObj != null) + for (int i = 0; i < arrayObj.Length; i++) + { + SearchPlainEntity(path, (IPlain)arrayObj.GetValue(i), exclude, include); + } + } + + if (obj is IPlain) + { + SearchPlainEntity(path, (IPlain)obj, exclude, include); + } + + } + } + } + } + + internal void SearchEntity(IVortexObject sourceObj, Func include = null) + { + + foreach (var child in sourceObj.GetChildren()) + { + + + var obj = child; + + if (obj != null) + { + + if (include != null) + { + + if (include(obj)) + { + _collectioOfReqType.Add((IVortexObject)obj); + } + else + { + + + + if (obj.GetType().IsArray) + { + var arrayObj = obj as Array; + + if (arrayObj != null) + for (int i = 0; i < arrayObj.Length; i++) + { + SearchEntity((IVortexObject)arrayObj.GetValue(i), include); + } + + } + + if (obj is IVortexObject) + { + SearchEntity((IVortexObject)obj, include); + } + } + } + } + } + } + + + + } + +} diff --git a/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/InstructionConfiguratorView.xaml b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/InstructionConfiguratorView.xaml new file mode 100644 index 0000000..243960c --- /dev/null +++ b/templates/mts-s-template/t/src/x_template_xReworkInstructor/Instructor/View/InstructionConfiguratorView.xaml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +