Ejemplo n.º 1
0
        public async Task <StartPrintResult> Execute(CancellationToken token)
        {
            _logger.LogInformation($"Executing scenario {nameof(PreheatAndPrint)}");
            if (_preheat.HasValue)
            {
                var preheat = _preheat.Value;
                _logger.LogInformation($"Preheating bed to {preheat.ToString("F0")}...");

                await SetBedTemperature(preheat)
                .ConfigureAwait(false);

                CancellationCheck(token);

                var cts = new CancellationTokenSource();

                double lastReportedTemperature = 0.0;
                double reportThreshold         = 30;

                await foreach (var state in _migo.GetStateStream(cts.Token))
                {
                    CancellationCheck(token);

                    double temperature = state.BedTemp;
                    if (state.BedTemp > preheat - Tolerance)
                    {
                        cts.Cancel();
                    }

                    if (temperature - lastReportedTemperature < reportThreshold)
                    {
                        continue;
                    }

                    double target = preheat - Tolerance;
                    _logger.LogInformation($"{temperature.ToString("F0")} of {target.ToString("F0")}");
                    lastReportedTemperature = temperature;

                    if (temperature > 100)
                    {
                        reportThreshold = 5;
                    }
                }

                _logger.LogInformation("Preheating completed");
            }

            _logger.LogInformation($"Starting print of {_fileName} ...");

            CancellationCheck(token);

            var result = await _migo.StartPrint(_fileName)
                         .ConfigureAwait(false);

            _logger.LogInformation("Scenario completed");

            return(result);
        }
Ejemplo n.º 2
0
        public async Task Should_receive_state_stream_of_known_size()
        {
            var stream = _migo.GetStateStream(_tokenSource.Token);

            var counter = await RunStreamTest(stream)
                          .ConfigureAwait(false);

            counter.Should().Be(TestStreamSize);
        }
Ejemplo n.º 3
0
        public IAsyncEnumerable <MigoStateModel> GetStateStream(CancellationToken token)
        {
            try
            {
                return(_migo.GetStateStream(token));
            }
            catch (TaskCanceledException _)
            {
                // ignore
            }

            return(default !);
Ejemplo n.º 4
0
 private async Task CheckStream(Migo migo, CancellationToken token)
 {
     try
     {
         await foreach (var _ in migo.GetStateStream(token))
         {
             // nop
         }
     }
     catch (TaskCanceledException _)
     {
         // ignore
     }
 }