Exemplo n.º 1
0
        internal void DoTryGetDesk(CancellationToken token)
        {
            while (Desk == null &&
                   !token.IsCancellationRequested)
            {
                _logger.Information("Trying to find desk...");

                DeskDetectedEvent.WaitOne(TimeSpan.FromSeconds(1));
            }
        }
Exemplo n.º 2
0
        internal void OnDeskDetected(IDesk desk)
        {
            _logger.Information($"Detected desk {desk.Name} with " +
                                $"Bluetooth address {desk.BluetoothAddress}");

            _detector.Stop( );

            Desk = desk;

            DeskDetectedEvent.Set( );
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public async Task <(bool, IDesk)> TryGetDesk(CancellationToken token)
        {
            Desk?.Dispose( );
            Desk = null;

            try
            {
                _detector.Start( );

                await _taskRunner.Run(() => DoTryGetDesk ( token ),
                                      token);

                if (token.IsCancellationRequested)
                {
                    return(false, null);
                }

                return(Desk == null
                           ? (false, null)
                           : (true, Desk));
            }
            catch (Exception e)
            {
                if (e.IsBluetoothDisabledException( ))
                {
                    e.LogBluetoothStatusException(_logger);
                }
                else
                {
                    _logger.Error(e,
                                  "Failed to detect desk");
                }

                return(false, null);
            }
            finally
            {
                _detector.Stop( );
                DeskDetectedEvent.Reset( );
            }
        }