using System; using System.Threading; using ProductionUiCordonelLegacy.Data; using Xylem.Common.Utils.ProcessExec.EventArguments; namespace ProductionUiCordonelLegacy.Model { /// /// Final test model preparing the Cordonel for shipping: /// - Setup device with standard parameters covered by the VAKO or customer specific CSD, /// - If radio is installed: radio test, /// - Requiring radio key from LuDB, /// - Requiring 7 passwords for the Cordonel access levels, /// - Building the password file (Level 3 is the modified skeleton key), /// - Store all configurations, /// - Reboot the Cordonel to load all settings from FLASH to RAM, /// - Configuration check of all parameters defined by VAKO and CSD. /// class FinalTestModel { #region Variables /// /// Port scan result event for message dispatcher to caller /// public event EventHandler OnProcessUpdate; // Text for caller to inform about actual process being carried out private String _actualOperation; // states of the state machine, the backup state locks against repeated execution private FinalTestState _finalTestState; private FinalTestState _finalTestBackupState; // Process counter for caller to monitor actual progress private Int32 _overallProcessedStepsCtr; private Int32 _singleProcessedStepsCtr; // maximum processing steps for calculation of progress bar private const Int32 MaxOverallProcessSteps = 20; private Int32 _maxSingleProcessSteps; // processing retries private const Int32 MaxProcessRetries = 2; private Int32 _processRetryCtr; #endregion #region Events /// /// Process event /// /// /// /// /// - Initial /// public virtual void ProcessUpdate_Event(Object sender, ProcessExecEventArgs e) { // copy text from overall messages to actual, because this is from sub-routine OnProcessUpdate?.Invoke(this, new ProcessExecEventArgs(GetActualStateText(), OverallProcessPercent, _actualOperation, e.OverallProcessPercent)); } #endregion #region ProcessInformation /// /// Process counter in percent /// /// /// - Initial /// public Double OverallProcessPercent => 100.0d * (_overallProcessedStepsCtr + _singleProcessedStepsCtr) / MaxOverallProcessSteps; /// /// Single file process counter in percent /// /// /// - Initial /// public Double SingleFileProcessPercent => 100.0d * _singleProcessedStepsCtr / _maxSingleProcessSteps; /// /// Returns the final test state text information for display /// /// /// /// - Initial /// public String GetActualStateText() { // search text assigned to current state var text = FinalTestStateInfo.GetTextFromState(_finalTestState); if (_finalTestState == FinalTestState.Idle) { return text; } text += _processRetryCtr > 0 ? $"{_processRetryCtr}" : ""; if (_overallProcessedStepsCtr > 0) { text += $"{_overallProcessedStepsCtr}/{MaxOverallProcessSteps}"; } return text; } #endregion #region CtorAssignment /// /// Ctor /// /// /// - Initial /// public FinalTestModel() { } /// /// Dispose /// public void Dispose() { } #endregion #region StateMachine /// /// State machine of FinalTestModel. /// /// /// - Initial /// public void StateMachine() { // avoid repeated execution of the state machine of identical state if (_finalTestState == _finalTestBackupState) { Thread.Sleep(1); } else { // remind backup state to avoid repeated execution and side effects _finalTestBackupState = _finalTestState; switch (_finalTestState) { case FinalTestState.Idle: break; case FinalTestState.StartInitial: _overallProcessedStepsCtr = 0; _singleProcessedStepsCtr = 0; _finalTestState = FinalTestState.Idle; break; case FinalTestState.StepFailed: _finalTestState = _processRetryCtr++ < MaxProcessRetries ? FinalTestState.RepeatFinalTest : FinalTestState.FinalTestFailed; break; case FinalTestState.RepeatFinalTest: _overallProcessedStepsCtr = 0; _singleProcessedStepsCtr = 0; _finalTestState = FinalTestState.Idle; break; default: _finalTestState = FinalTestState.Idle; break; } }// lock repeated execution of identical state #endregion } } }