示例#1
0
        private async Task HandleScanning()
        {
            _hndl = IawAppApi.RequestScanQr(
                true,
                new MatchWidthWithFixedHeightLayoutStrategy(
                    _scannerPopupHeightMm, _scannerPopupMmFromTop));

            var ended = false;

            while (!ended)
            {
                var ev = await _hndl.GetNext();

                Logger.Debug(GetType(), "got ({0}; {1})", ev.Item1, ev.Item2);

                switch (ev.Item1)
                {
                case ScanResultType.Scanned:
                    try {
                        _errorOrNull = null;
                        ScannedCode  = await _getItemByCode(ev.Item2);
                    } catch (Exception ex) {
                        _errorOrNull = ex.Message;
                    }
                    await _errorLbl.DoChange(_errorOrNull, false, this, false);

                    break;

                case ScanResultType.Paused:
                    if (_errorOrNull == null)
                    {
                        _hndl.CancelScanning();
                    }
                    else
                    {
                        //TODO extract into stylesheet
                        _view.Unpause.Widget.Style.SetProperty("display", "");
                    }
                    break;

                case ScanResultType.Disposed:
                    _hndl = null;
                    ended = true;
                    Ended?.Invoke(this,
                                  ScannedCode == null ? CompletedOrCanceled.Canceled : CompletedOrCanceled.Completed);
                    break;
                }
            }
        }