Beispiel #1
0
 void ConnectionManager_AdvertismentReceived(object sender, AdvertismentReceivedEventArgs e)
 {
     if (e.Rssi > SdkConfig.TapProximityUnlockThreshold)
     {
         _hub.Publish(new AdvertismentReceivedEvent(e));
     }
 }
Beispiel #2
0
        void BleConnectionManager_AdvertismentReceived(object sender, AdvertismentReceivedEventArgs e)
        {
            lock (_lock)
            {
                RemoveTimedOutRecords();

                var shortMac = BleUtils.ConnectionIdToMac(e.Id);
                if (_ignoreList.Any(m => m == shortMac))
                {
                    var proximity = BleUtils.RssiToProximity(e.Rssi);

                    if (proximity > _workstationSettingsManager.Settings.LockProximity)
                    {
                        _lastAdvRecTime[shortMac] = DateTime.UtcNow;
                    }
                }
            }
        }
        async Task UnlockByTap(AdvertismentReceivedEventArgs adv)
        {
            if (!isRunning)
            {
                return;
            }

            if (adv == null)
            {
                return;
            }

            if (adv.Rssi > SdkConfig.TapProximityUnlockThreshold)
            {
                if (Interlocked.CompareExchange(ref _isConnecting, 1, 0) == 0)
                {
                    try
                    {
                        var mac = BleUtils.ConnectionIdToMac(adv.Id);
                        await _connectionFlowProcessor.ConnectAndUnlock(mac, OnUnlockAttempt);
                    }
                    catch (Exception)
                    {
                        // Silent handling. Log is already printed inside of _connectionFlowProcessor.ConnectAndUnlock()
                    }
                    finally
                    {
                        // this delay allows a user to move away the device from the dongle
                        // and prevents the repeated call of this method
                        await Task.Delay(SdkConfig.DelayAfterMainWorkflow);

                        Interlocked.Exchange(ref _isConnecting, 0);
                    }
                }
            }
        }
 public AdvertismentReceivedEvent(AdvertismentReceivedEventArgs e)
 {
     _e = e;
 }
 async void BleConnectionManager_AdvertismentReceived(object sender, AdvertismentReceivedEventArgs e)
 {
     await UnlockByTap(e);
 }
        async Task ConnectByProximity(AdvertismentReceivedEventArgs adv)
        {
            if (!isRunning)
            {
                return;
            }

            if (adv == null)
            {
                return;
            }

            if (_isConnecting == 1)
            {
                return;
            }

            if (_macListToConnect.Count == 0)
            {
                return;
            }

            var mac = BleUtils.ConnectionIdToMac(adv.Id);

            if (!_macListToConnect.Any(m => m == mac))
            {
                return;
            }

            var proximity = BleUtils.RssiToProximity(adv.Rssi);
            var settings  = _workstationSettingsManager.Settings;

            if (proximity < settings.UnlockProximity)
            {
                return;
            }

            if (_advIgnoreListMonitor.IsIgnored(mac))
            {
                return;
            }

            if (!_hesAccessManager.HasAccessKey())
            {
                return;
            }

            if (Interlocked.CompareExchange(ref _isConnecting, 1, 0) == 0)
            {
                try
                {
                    var device = _bleDeviceManager.Devices.FirstOrDefault(d => d.Mac == mac && !d.IsRemote && !d.IsBoot);

                    // Unlocked Workstation, Device not found OR Device not connected - dont add to ignore
                    if (!_workstationUnlocker.IsConnected && (device == null || (device != null && !device.IsConnected)))
                    {
                        return;
                    }

                    try
                    {
                        // Unlocked Workstation, Device connected - add to ignore
                        if (!_workstationUnlocker.IsConnected && device != null && device.IsConnected)
                        {
                            return;
                        }

                        // Locked Workstation, Device not found OR not connected - connect add to ignore
                        if (_workstationUnlocker.IsConnected && (device == null || (device != null && !device.IsConnected)))
                        {
                            await _connectionFlowProcessor.ConnectAndUnlock(mac, OnUnlockAttempt);
                        }
                    }
                    catch (Exception)
                    {
                        // Silent handling. Log is already printed inside of _connectionFlowProcessor.ConnectAndUnlock()
                    }
                    finally
                    {
                        _advIgnoreListMonitor.Ignore(mac);
                    }
                }
                finally
                {
                    Interlocked.Exchange(ref _isConnecting, 0);
                }
            }
        }
 async void BleConnectionManager_AdvertismentReceived(object sender, AdvertismentReceivedEventArgs e)
 {
     await ConnectByProximity(e);
 }