예제 #1
0
        private Task AddContactDeviceAsync()
        {
            var deviceId = ContactDeviceId;
            var trace    = new ContactDescriptor(deviceId, DateTime.UtcNow);

            ContactDeviceId = string.Empty;

            DeviceProcessorProvider.GetInstance().Process(trace);
            return(Task.CompletedTask);
        }
예제 #2
0
        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}.");
            }
        }