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 { /// /// Concatenation for all production process states: /// /// /// - Initial /// public class BaseProcessStatesDef : IProcessStateDef { /// /// Collection of state information /// public List StateContainer { get; } /// /// Ctor: /// Initialize all hidden standard generic states /// protected BaseProcessStatesDef() { StateContainer = new List { // 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) }; } /// public ProcessStateStruct GetProcessStateStructOfState(ProcessState stateMachineState) { return (from stateContainer in StateContainer where stateContainer.ProcessState == stateMachineState select stateContainer).FirstOrDefault(); } /// public IProductionProcess GetProcessOfState(ProcessState stateMachineState) { return (from stateContainer in StateContainer where stateContainer.ProcessState == stateMachineState select stateContainer.ProductionProcess).FirstOrDefault(); } /// public String GetStateInfoOfState(ProcessState? stateMachineState) { if (stateMachineState == null) stateMachineState = ProcessState.Error; return (from stateContainer in StateContainer where stateContainer.ProcessState == stateMachineState select stateContainer.ProcessInfo).FirstOrDefault(); } /// public String GetStateInfoOfProcess(IProductionProcess process) { return (from stateContainer in StateContainer where stateContainer.ProductionProcess == process select stateContainer.ProcessInfo).FirstOrDefault(); } /// public UInt32? GetProductionProcessNoOfProcess(IProductionProcess process) { return (from stateContainer in StateContainer where stateContainer.ProductionProcess == process select stateContainer.ProductionProcessNo).FirstOrDefault(); } /// public ProcessState GetStateOfFirstProcess() { return (from stateContainer in StateContainer where stateContainer.ProductionProcessNo == 0 select stateContainer.ProcessState).FirstOrDefault(); } /// public ProcessState GetStateOfInfoText(String text) { return (from stateContainer in StateContainer where stateContainer.ProcessInfo == text select stateContainer.ProcessState).FirstOrDefault(); } /// public ProcessState GetStateOfProcess(IProductionProcess process) { return (from stateContainer in StateContainer where stateContainer.ProductionProcess == process select stateContainer.ProcessState).FirstOrDefault(); } /// public Int32 GetNumberOfInitializedProcesses() { return StateContainer.Count(stateContainer => stateContainer.ProductionProcessNo != null); } /// public List GetAllProductionProcesses() { var sortedList = StateContainer .Where(y => y.ProductionProcessNo != null) .OrderBy(x => x.ProductionProcessNo); return (from state in sortedList select state.ProductionProcess).ToList(); } } }