private async Task ExecuteProductionCycle() { var tasks = new List <Task> { BakeBiscuits(), StampBiscuit() }; if (!_machineTokenSource.Token.IsCancellationRequested) { tasks.Add(ExtractBiscuit()); } await Task.WhenAll(tasks); if (_machineTokenSource.Token.IsCancellationRequested && !Conveyor.Slots.Any(x => x != null)) { RaiseEvent(new ProductionFinishedEvent()); return; } if (!State.IsPaused) { await Conveyor.ReachNextPosition(); } }
protected override void InitElements() { Motor = new Motor(); Conveyor = new Conveyor(Motor); Extruder = new Extruder(); Stamper = new Stamper(); Oven = new Oven(); }
public BiscuitMachine(IOptions <BiscuitMachineOptions> options, IEventDispatcher eventDispatcher) : base(eventDispatcher) { _minOvenTemperature = options.Value.MinOvenTemperature; _maxOvenTemperature = options.Value.MaxOvenTemperature; _motorPulsesToReachPosition = options.Value.MotorPulsesToReachPosition; _biscuitBakeTimeInSeconds = options.Value.BiscuitBakeTimeInSeconds; Conveyor.SetMotorPulsesToReachPosition(_motorPulsesToReachPosition); State = BiscuitMachineState.Initial; RegisterHandlers(); }
private async Task StartOrResumeProduction() { if (State.IsProductionStarted) { await Conveyor.ReachNextPosition(); } else { State = State.StartedProduction(); await ExecuteProductionCycle(); } }
private async Task StopMachine() { if (!State.IsProductionStarted) { RaiseEvent(new ProductionFinishedEvent()); } _machineTokenSource.Cancel(); if (State.IsPaused && State.IsProductionStarted) { State = State.Resume(); await Conveyor.ReachNextPosition(); } if (State.IsProductionStarted) { State = State.TurnedOff(); } await Task.Delay(0); }
private void ResetMachine() { State = BiscuitMachineState.Initial; Conveyor.Reset(); Oven.Reset(); }
public override async Task Pause() { State = State.Pause(); await Conveyor.Stop(); }