/// <summary> /// Stores the cert calibration date into the database so it can be used in reporting. /// </summary> /// <param name="cert">Cert.</param> private async Task <bool> UpdateLastNistDate(GaugeDeviceCalibrationCertificate cert) { var table = ion.database.Table <LoggingDeviceRow>(); var row = table.Where(ldr => ldr.serialNumber == cert.testSerialNumber.ToString()).FirstOrDefault(); if (row == null) { // The logging device row does not exist in the database for the given serial number. We will need to add it row = new LoggingDeviceRow() { serialNumber = cert.testSerialNumber.ToString(), nistDate = cert.lastTestCalibrationDate.ToShortDateString(), }; return(await ion.database.SaveAsync <LoggingDeviceRow>(row)); } else { // The logging device row exists in the database. Pull it and update the date. row.nistDate = cert.lastTestCalibrationDate.ToShortDateString(); return(await ion.database.SaveAsync <LoggingDeviceRow>(row)); } }
/// <summary> /// checking if timer error when saving /// </summary> public async void recordInterval(TimeSpan interval) { await Task.Delay(TimeSpan.FromMilliseconds(1)); while (isActive) { Log.D(this, "Logging devices"); try { var sensors = new HashSet <GaugeDeviceSensor>(); ////// pull ios sensorlist items if (ion.currentAnalyzer != null && ion.currentAnalyzer.sensorList != null) { foreach (var s in ion.currentAnalyzer.sensorList) { var gds = s as GaugeDeviceSensor; if (gds != null && gds.device.isConnected) { sensors.Add(gds); } } } //foreach (var m in ion.currentWorkbench.manifolds) { foreach (var m in ion.currentWorkbench.sensors) { //var gds = m.primarySensor as GaugeDeviceSensor; var gds = m as GaugeDeviceSensor; if (gds != null && gds.device.isConnected) { sensors.Add(gds); } } var rows = new List <SensorMeasurementRow>(); var db = ion.database; var now = DateTime.Now; foreach (var gds in sensors) { var existing = db.Query <LoggingDeviceRow>("SELECT * FROM LoggingDeviceRow WHERE serialNumber = ?", gds.device.serialNumber.ToString()); if (existing.Count == 0) { var newDevice = new LoggingDeviceRow { serialNumber = gds.device.serialNumber.ToString() }; db.Insert(newDevice); } } foreach (var gds in sensors) { // TODO [email protected]: Normalize the device unit or the resulting data backend will be funky. rows.Add(await CreateSensorMeasurement(db, gds, now)); } var inserted = db.InsertAll(rows, true); Log.D(this, "Inserting: " + inserted + " rows"); } catch (Exception e) { Log.E(this, "Failed to resolve timer callback", e); } await Task.Delay(interval); } }