public static async Task <CurrentSensorDevice> FromSensorInformationAsync(SensorInformation sensorInformation, CancellationToken cancellationToken) { if (sensorInformation.Kind != SensorKind.Current) { throw new ArgumentException("Invalid sensor type"); } var deviceId = await DeviceInformation.CreateFromIdAsync(sensorInformation.LogicalDeviceId, new[] { ContainerIdProperty }); return(await FromServiceDeviceAsync(deviceId, cancellationToken)); }
public CurrentSensor(SensorInformation sensorInformation) { this.SensorInformation = sensorInformation; this.initializationCancel = new CancellationTokenSource(); this.initializationTask = Task.Run(async() => { try { this.Device = await CurrentSensorDevice.FromSensorInformationAsync(sensorInformation, this.initializationCancel.Token); this.disposables.Add(this.Device); } catch (Exception) { // Maybe the sensor device was not found. } this.SubscribeCurrent(); }, this.initializationCancel.Token); }
private CurrentSensor(SensorInformation sensorInformation, CurrentSensorDevice device) { this.SensorInformation = sensorInformation; this.Device = device; this.SubscribeCurrent(); }
public static async Task <CurrentSensor> FromSensorInformationAsync(SensorInformation sensorInformation, CancellationToken cancellationToken) { var device = await CurrentSensorDevice.FromSensorInformationAsync(sensorInformation, cancellationToken); return(new CurrentSensor(sensorInformation, device)); }
/// <summary> /// Check if a sensor is registered in this registry or not. /// </summary> /// <param name="target"></param> /// <returns></returns> public bool IsRegistered(SensorInformation target) { return(this.sensors.Any(sensor => sensor.Id == target.Id || (sensor.LogicalDeviceId == target.LogicalDeviceId && sensor.PhysicalDeviceId == target.PhysicalDeviceId))); }
/// <summary> /// Unregister a sensor to this registry. /// </summary> /// <param name="sensor"></param> /// <returns></returns> public Task UnregisterSensor(SensorInformation sensor) { this.classifiedSensors[sensor.Kind].Remove(sensor); this.sensors.Remove(sensor); return(Task.FromResult(0)); }