private Task AddContactDeviceAsync() { var deviceId = ContactDeviceId; var trace = new ContactDescriptor(deviceId, DateTime.UtcNow); ContactDeviceId = string.Empty; DeviceProcessorProvider.GetInstance().Process(trace); return(Task.CompletedTask); }
public void HandleDeviceCommunicationDiscoveredCharacteristicRead(DeviceDescriptor descriptor, byte[] payload, Action <DeviceDescriptor> onNext = null) { try { if (_discoveredDevices.TryGetValue(descriptor.Identifier, out var deviceDescriptor)) { try { if (PayloadFormatter.TryGetValue(payload, out var packageData)) { _logger.LogDebug( $"DeviceManager - Characteristic read - processing. id: {descriptor.Identifier}."); deviceDescriptor.Context = descriptor.Context; var contact = new ContactDescriptor(packageData.DeviceId, DateTime.UtcNow); DeviceProcessorProvider.GetInstance().Process(contact); Monitor.Enter(deviceDescriptor.ProcessingLock); try { deviceDescriptor.Processed = true; } finally { Monitor.Exit(deviceDescriptor.ProcessingLock); } } } catch (Exception ex) { _logger.LogError(ex, $"DeviceManager - Characteristic read - Processing failed. id: {deviceDescriptor.Identifier}."); } // Disconnect peripheral onNext?.Invoke(deviceDescriptor); } } catch (Exception ex) { _logger.LogError(ex, $"DeviceManager - Characteristic read - Processing failed. id: {descriptor.Identifier}. Reason: {ex.Message}."); } }