private async Task <IRadio> GetRadio(IRadioPeripheral peripheral, CancellationToken cancellationToken) { using var lockObj = await RadioDictionaryLock.LockAsync().ConfigureAwait(true); IRadio radio = null; if (RadioDictionary.ContainsKey(peripheral.Uuid)) { radio = RadioDictionary[peripheral.Uuid]; } else { var entity = await RadioRepository.ByDeviceUuid(peripheral.Uuid); if (entity == null) { entity = RadioRepository.New(); entity.DeviceUuid = peripheral.Uuid; entity.DeviceName = peripheral.Name; await RadioRepository.Create(entity, cancellationToken).ConfigureAwait(true); } radio = Container.Resolve <IRadio>(RegistrationConstants.RileyLink); radio.Entity = entity; radio.Peripheral = peripheral; radio.Peripheral.RssiUpdateTimeSpan = radio.GetConfiguration().RssiUpdateInterval; RadioDictionary.Add(peripheral.Uuid, radio); } radio.Peripheral = peripheral; return(radio); }