// ============================================================================= // DEE Action: ASA_Scenario2_RegisterMolderUpdateInERP // Scenario: 2 — Controller Version Update with Fixed Validity Window // Stage: Post-Action Validation (second validation, after MaxStartupTime) // // Purpose: // After MoldingController B/4 has been updated to B/5, register the completed // maintenance event as a traceable record in the ERP system. If the ERP is // unreachable or rejects the record, return false so the task is marked // ValidationFailed. // // Simulation: // ERP availability is controlled by a MES Configuration Entry so the scenario // can be toggled from the MES UI without redeploying code: // // Path : /Cmf/Tutorials/AutomationScheduleAction/Scenario2/ErpRegistrationEnabled // Type : Boolean // Value: true → ERP accepts the record → ProcessedSuccess // false → ERP rejects the record → ValidationFailed // // Set the entry to false to demonstrate a ValidationFailed outcome after // the controller update has already been applied. // // DEE Contract: // Input - Task : AutomationScheduledActionTask (current task context) // Output - Result : Boolean (true = record registered, false = registration failed) // // 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_Scenario2_RegisterMolderUpdateInERP : 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(); // In production this is where the ERP integration call would go // For simulation, we just read the config value to determine success or failure const string configParentPath = "/Cmf/Tutorials/AutomationScheduleAction/Scenario2"; const string configName = "ErpRegistrationEnabled"; const string configPath = $"{configParentPath}/{configName}"; IConfig erpConfig = _entFactory.Create(); if (!erpConfig.TryLoad(configPath)) { erpConfig.Name = configName; erpConfig.ValueType = "System.Boolean"; erpConfig.Value = false; erpConfig.Create(configParentPath); } bool erpEnabled = erpConfig.GetConfigValue(); Input["Result"] = erpEnabled; //---End DEE Code--- return Input; } } }