// ============================================================================= // DEE Action: ASA_Scenario5_CheckChangeApprovalRegistered // Scenario: 5 — Custom DEE Action at Every Stage // Stage: Acceptance Gate // // Purpose: // Verify that an approved change request exists in the QMS for the specific // target baking station before recalibration is allowed to proceed. // Gate semantics: if this returns false, only this oven's task is skipped — // other ovens with approved change requests continue to be evaluated. // // Simulation: // The approval state for each station is controlled by a per-resource // MES Configuration Entry, toggled independently from the MES UI: // // Path : /Cmf/Tutorials/AutomationScheduleAction/Scenario5/ChangeApprovalRegistered/{resourceName} // Type : Boolean // Value: true → approved change request found → gate passes // false → no approved request → SkippedGateFailed // // Example entries for the tutorial resources: // /Cmf/Tutorials/AutomationScheduleAction/Scenario5/ChangeApprovalRegistered/ASA Baker-01 // /Cmf/Tutorials/AutomationScheduleAction/Scenario5/ChangeApprovalRegistered/ASA Baker-02 // // Set Baker-02 to false to demonstrate that this gate blocks one oven while // Baker-01 continues to the action stage. // // DEE Contract: // Input - Task : AutomationScheduledActionTask (includes target entity via EntityName) // Output - Result : Boolean (true = approved request found, false = not found) // // Fail-closed: any exception or missing config is treated as false. // ============================================================================= using Cmf.Foundation.BusinessOrchestration.Abstractions; using Cmf.Foundation.BusinessOrchestration.ConfigurationManagement.InputObjects; using Cmf.Foundation.Common.Abstractions; using Cmf.Foundation.Configuration.Abstractions; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; namespace Cmf.Custom.Tutorials.AutomationScheduleAction.Actions { public class ASA_Scenario5_CheckChangeApprovalRegistered : DeeDevBase { public override bool DeeTestCondition(Dictionary Input) { //---Start DEE Condition Code--- return true; //---End DEE Condition Code--- } public override Dictionary DeeActionCode(Dictionary Input) { //---Start DEE Code--- UseReference("", "Cmf.Foundation.BusinessOrchestration.Abstractions"); UseReference("", "Cmf.Foundation.BusinessOrchestration.ConfigurationManagement"); UseReference("", "Cmf.Foundation.BusinessOrchestration.ConfigurationManagement.InputObjects"); IServiceProvider _svcProvider = Input["ServiceProvider"] as IServiceProvider; IEntityFactory _entFactory = _svcProvider.GetService(); //INPUT: Automation Scheduled Action Task var task = Input["Task"] as IAutomationScheduledActionTask; string resourceName = task?.EntityName ?? string.Empty; // In production this is where the QMS integration query would go // For simulation, we just read the config value to determine if an approved request is registered const string configParentPath = "/Cmf/Tutorials/AutomationScheduleAction/Scenario5/ChangeApprovalRegistered"; string configPath = $"{configParentPath}/{resourceName}"; IConfig approvalConfig = _entFactory.Create(); if (!approvalConfig.TryLoad(configPath)) { approvalConfig.Name = resourceName; approvalConfig.ValueType = "System.Boolean"; approvalConfig.Value = false; approvalConfig.Create(configParentPath); } bool approved = approvalConfig.GetConfigValue(); //OUTPUT: Boolean - true if check approved, otherwise false Input["Result"] = approved; //---End DEE Code--- return Input; } } }