// Incoming request public async Task <HesResponse <HwVaultShortInfoFromHesDto> > GetHwVaultInfoBySerialNo(string serialNo) { try { await ValidateConnectionAsync(); var vault = await _hardwareVaultService .VaultQuery() .Include(d => d.Employee) .AsNoTracking() .FirstOrDefaultAsync(d => d.Id == serialNo); var info = new HwVaultShortInfoFromHesDto() { OwnerName = vault.Employee?.FullName, OwnerEmail = vault.Employee?.Email, VaultMac = vault.MAC, VaultSerialNo = vault.Id, VaultRfid = vault.RFID }; return(new HesResponse <HwVaultShortInfoFromHesDto>(info)); } catch (HideezException ex) { _logger.LogInformation($"[{serialNo}] {ex.Message}"); return(new HesResponse <HwVaultShortInfoFromHesDto>(ex)); } catch (Exception ex) { _logger.LogError(ex.Message); return(new HesResponse <HwVaultShortInfoFromHesDto>(ex)); } }
internal Task <HwVaultShortInfoFromHesDto> Run() { Task.Run(async() => { try { HwVaultShortInfoFromHesDto info = null; if (_hesConnection.State == HesConnectionState.Connected) { info = await _hesConnection.GetHwVaultInfoByMac(_mac, _ct); IsSuccessful = true; } else { //todo - load device info from the local cache (file) info = new HwVaultShortInfoFromHesDto(); IsSuccessful = false; } _tcs.TrySetResult(info); } catch (Exception ex) { _tcs.TrySetException(ex); } }); return(_tcs.Task); }
async Task UnlockByRfid(string rfid) { if (!isRunning) { return; } if (!_rfidSettingsManager.Settings.IsRfidEnabled) { return; } if (Interlocked.CompareExchange(ref _isConnecting, 1, 1) == 1) { return; } HwVaultShortInfoFromHesDto info = null; try { _screenActivator?.ActivateScreen(); if (_hesConnection == null) { throw new Exception(TranslationSource.Instance["ConnectionFlow.RfidConnection.Error.NotConnectedToHes"]); } // get MAC address from the HES info = await _hesConnection.GetHwVaultInfoByRfid(rfid); await _clientUiManager.SendNotification(TranslationSource.Instance["ConnectionFlow.RfidConnection.ContactingHesMessage"], info.VaultMac); if (Interlocked.CompareExchange(ref _isConnecting, 1, 0) == 0) { try { await _connectionFlowProcessor.ConnectAndUnlock(info.VaultMac, 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 rfid // and prevents the repeated call of this method await Task.Delay(SdkConfig.DelayAfterMainWorkflow); Interlocked.Exchange(ref _isConnecting, 0); } } } catch (Exception ex) { WriteLine(ex); await _clientUiManager.SendError(HideezExceptionLocalization.GetErrorAsString(ex), info?.VaultMac); } }
public LocalDeviceInfo(HwVaultShortInfoFromHesDto dto) { SerialNo = dto.VaultSerialNo; Mac = dto.VaultMac; // TODO: Add RFID to device info cache OwnerName = dto.OwnerName; OwnerEmail = dto.OwnerEmail; }