예제 #1
0
        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();
            }
        }
예제 #2
0
 protected override void InitElements()
 {
     Motor    = new Motor();
     Conveyor = new Conveyor(Motor);
     Extruder = new Extruder();
     Stamper  = new Stamper();
     Oven     = new Oven();
 }
예제 #3
0
 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();
 }
예제 #4
0
 private async Task StartOrResumeProduction()
 {
     if (State.IsProductionStarted)
     {
         await Conveyor.ReachNextPosition();
     }
     else
     {
         State = State.StartedProduction();
         await ExecuteProductionCycle();
     }
 }
예제 #5
0
 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);
 }
예제 #6
0
 private void ResetMachine()
 {
     State = BiscuitMachineState.Initial;
     Conveyor.Reset();
     Oven.Reset();
 }
예제 #7
0
 public override async Task Pause()
 {
     State = State.Pause();
     await Conveyor.Stop();
 }