Exemple #1
0
        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);
        }
Exemple #2
0
 public void Handle(RadioCreated evt)
 {
     _radioRepository.Create(evt.Name, evt.Url);
 }
Exemple #3
0
 public async Task <int> CreateRadio(Radio radio, CancellationToken token)
 {
     return(await _radioRepository.Create(radio, token));
 }