common/Production/ProductionUiCordonel/ProductionProcesses/BaseProcessStatesDef.cs
2026-04-23 17:50:07 +02:00

188 lines
8.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.Enum;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.GenericProcesses;
using Xylem.Common.Production.ProductionUiCordonel.Properties;
namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
{
/// <summary>
/// Concatenation for all production process states:
/// </summary>
/// <remarks date="2025-Apr-14" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public class BaseProcessStatesDef : IProcessStateDef
{
/// <summary>
/// Collection of state information
/// </summary>
public List<ProcessStateStruct> StateContainer { get; }
/// <summary>
/// Ctor:
/// Initialize all hidden standard generic states
/// </summary>
protected BaseProcessStatesDef()
{
StateContainer = new List<ProcessStateStruct>
{
// Waiting for any state change from external (user or program flow state change).
new ProcessStateStruct(
productionProcess: null,
processState: ProcessState.Idle,
processInfo: Resources.StrStateIdle,
productionProcessNo: null,
nextStateOnSuccess: ProcessState.Idle),
// Check if a new meter is connected to collect the according information and settings for it.
new ProcessStateStruct(
productionProcess: null,
processState: ProcessState.CheckNewMeter,
processInfo: Resources.StrProcessStateCheckNewMeter,
productionProcessNo: null,
// Repeat the detection process to initialize new objects for the new meter!
nextStateOnSuccess: ProcessState.DetectCordonel,
// Here the error will be used to fork to the next state. Meaning, this not a new meter: Connect it.
errorExitState: ProcessState.ConnectCordonel),
// Display a user control in red waiting for user input on failed production process.
new ProcessStateStruct(
productionProcess: new ErrorHandler(null),
processState: ProcessState.Error,
processInfo: Resources.StrProcessStateError,
productionProcessNo: null,
nextStateOnSuccess: ProcessState.Idle,
// Error process needs always to be started even if 'abort' is required by any state
startAlways: true),
// Kick of all tests starting with the first erroneous process.
new ProcessStateStruct(
productionProcess: null,
processState: ProcessState.RepeatFailedTests,
processInfo: Resources.StrStateRepeatFinalTest,
productionProcessNo: null,
nextStateOnSuccess: BaseProductionProcess.DoNotChangeStateAfterCompletion),
// Abort all ongoing processes and fire the cancellation event.
// The entire production process chain has to be started from the beginning.
new ProcessStateStruct(
productionProcess: null,
processState:ProcessState.AbortTest,
processInfo:Resources.StrStateSkipping,
productionProcessNo:null,
nextStateOnSuccess:ProcessState.Idle),
// Stop all processes but leave the process status list intact.
// Leave all events for those which are already running intact to force a clean stop.
new ProcessStateStruct(
productionProcess: null,
processState:ProcessState.Stop,
processInfo:Resources.StrStateUserStop,
productionProcessNo:null,
nextStateOnSuccess:ProcessState.Idle),
// Signals to the "ProductionWindow" the state change to print a report
new ProcessStateStruct(
productionProcess: null,
processState:ProcessState.PrintSuccessReport,
processInfo:Resources.StrStatePrintSuccessReport,
productionProcessNo:null,
nextStateOnSuccess:ProcessState.Idle),
// Signals to the "ProductionWindow" the state change to print a report
new ProcessStateStruct(
productionProcess: null,
processState:ProcessState.PrintReturnReport,
processInfo:Resources.StrStatePrintReturnReport,
productionProcessNo:null,
nextStateOnSuccess:ProcessState.Idle)
};
}
///<inheritdoc/>
public ProcessStateStruct GetProcessStateStructOfState(ProcessState stateMachineState)
{
return (from stateContainer in StateContainer
where stateContainer.ProcessState == stateMachineState
select stateContainer).FirstOrDefault();
}
///<inheritdoc/>
public IProductionProcess GetProcessOfState(ProcessState stateMachineState)
{
return (from stateContainer in StateContainer
where stateContainer.ProcessState == stateMachineState
select stateContainer.ProductionProcess).FirstOrDefault();
}
///<inheritdoc/>
public String GetStateInfoOfState(ProcessState? stateMachineState)
{
if (stateMachineState == null)
stateMachineState = ProcessState.Error;
return (from stateContainer in StateContainer
where stateContainer.ProcessState == stateMachineState
select stateContainer.ProcessInfo).FirstOrDefault();
}
///<inheritdoc/>
public String GetStateInfoOfProcess(IProductionProcess process)
{
return (from stateContainer in StateContainer
where stateContainer.ProductionProcess == process
select stateContainer.ProcessInfo).FirstOrDefault();
}
///<inheritdoc/>
public UInt32? GetProductionProcessNoOfProcess(IProductionProcess process)
{
return (from stateContainer in StateContainer
where stateContainer.ProductionProcess == process
select stateContainer.ProductionProcessNo).FirstOrDefault();
}
///<inheritdoc/>
public ProcessState GetStateOfFirstProcess()
{
return (from stateContainer in StateContainer
where stateContainer.ProductionProcessNo == 0
select stateContainer.ProcessState).FirstOrDefault();
}
///<inheritdoc/>
public ProcessState GetStateOfInfoText(String text)
{
return (from stateContainer in StateContainer
where stateContainer.ProcessInfo == text
select stateContainer.ProcessState).FirstOrDefault();
}
///<inheritdoc/>
public ProcessState GetStateOfProcess(IProductionProcess process)
{
return (from stateContainer in StateContainer
where stateContainer.ProductionProcess == process
select stateContainer.ProcessState).FirstOrDefault();
}
///<inheritdoc/>
public Int32 GetNumberOfInitializedProcesses()
{
return StateContainer.Count(stateContainer => stateContainer.ProductionProcessNo != null);
}
///<inheritdoc/>
public List<IProductionProcess> GetAllProductionProcesses()
{
var sortedList = StateContainer
.Where(y => y.ProductionProcessNo != null)
.OrderBy(x => x.ProductionProcessNo);
return (from state in sortedList select state.ProductionProcess).ToList();
}
}
}