public async static Task <bool> AsyncUpdateReading(LibreReadingModel reading) { var collection = GetReadingsCollection(); var updateFilter = Builders <LibreReadingModel> .Filter.Eq("uuid", reading.uuid); var update = Builders <LibreReadingModel> .Update.Set("result", reading.result) .Set("status", reading.status) .Set("ModifiedOn", reading.ModifiedOn) .Set("newState", reading.newState ?? "n/a"); var res = await collection.UpdateOneAsync(updateFilter, update); return(res.ModifiedCount == 1); }
public async Task <ActionResult> UploadResults(string processing_accesstoken, string uuid, string result, string newState) { if (!await this.checkProcessingPermissions(processing_accesstoken)) { return(this.Error("UploadResults Denied")); } if (string.IsNullOrWhiteSpace(uuid)) { return(this.Error("UploadResults Denied: invalid parameter uuid")); } if (string.IsNullOrWhiteSpace(result)) { return(this.Error("UploadResults Denied: invalid parameter result")); } var wasSuccessfullyModified = false; try { var reading = new LibreReadingModel { ModifiedOn = DateTime.Now, status = "complete", uuid = uuid, result = result, newState = newState }; wasSuccessfullyModified = await MongoConnection.AsyncUpdateReading(reading); } catch (Exception ex) { return(Error("UploadResults Failed: " + ex.Message)); } return(Success <string>($"Modified: {wasSuccessfullyModified}", "UploadResults")); //var content = $"processing_accesstoken: {processing_accesstoken}, uuid: {uuid}, result: {result}"; //return Content(System.Reflection.MethodBase.GetCurrentMethod().Name + " IS NOT IMPLEMENTED YET:" + content); }
public async Task <ActionResult> CreateRequestAsync(string accesstoken, string b64contents, string oldState, string sensorStartTimestamp, string sensorScanTimestamp, string currentUtcOffset) { //var permissions= await NightscoutPermissions.CheckUploadPermissions(accesstoken); //var permissions = await NightscoutPermissions.CheckProcessPermissions(accesstoken); if (!await this.checkUploadPermissions(accesstoken)) { return(this.Error("CreateRequestAsync Denied")); } long?longSensorStartTimestamp = null; long?longSensorScanTimestamp = null; long?longCurrentUtcOffset = null; if (string.IsNullOrWhiteSpace(b64contents)) { return(this.Error("CreateRequestAsync Denied: invalid parameter b64contents")); } try{ // Database expects a base64, which we already have // this is just to verify that the contents is valid as base64 System.Convert.FromBase64String(b64contents); } catch (FormatException) { return(this.Error("CreateRequestAsync Denied: invalid parameter b64contents: (not a b64string)")); } if (string.IsNullOrWhiteSpace(oldState + sensorStartTimestamp + sensorScanTimestamp + currentUtcOffset)) { //these advanced parameters are optional, and this is ok } else if (oldState?.Length > 0 && sensorStartTimestamp?.Length > 0 && sensorScanTimestamp?.Length > 0 && currentUtcOffset?.Length > 0) { try { //database expects a base64, which we already have // this is just to verify that the contents is valid as base64 System.Convert.FromBase64String(oldState); } catch (FormatException) { return(this.Error("CreateRequestAsync Denied: invalid parameter oldState: (not a b64string)")); } longSensorStartTimestamp = Int64.TryParse(sensorStartTimestamp, out var t1) ? t1 : (long?)null; longSensorScanTimestamp = Int64.TryParse(sensorScanTimestamp, out var t2) ? t2 : (long?)null; longCurrentUtcOffset = Int64.TryParse(currentUtcOffset, out var t3) ? t3 : (long?)null; if (longSensorStartTimestamp == null) { return(this.Error("CreateRequestAsync Denied: invalid parameter sensorStartTimestamp: (not a long)")); } if (longSensorScanTimestamp == null) { return(this.Error("CreateRequestAsync Denied: invalid parameter sensorScanTimestamp: (not a long)")); } if (longCurrentUtcOffset == null) { return(this.Error("CreateRequestAsync Denied: invalid parameter currentUtcOffset: (not a long)")); } } else { return(this.Error("CreateRequestAsync Denied: when speciying advanced parameters, all advanced parameters should be specified (oldState, sensorStartTimestamp, sensorScanTimestamp, currentUtcOffset)")); } var g = Guid.NewGuid().ToString(); var reading = new LibreReadingModel { CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, status = "pending", b64contents = b64contents, uuid = g, oldState = (oldState == null || oldState == "") ? null : oldState, currentUtcOffset = longCurrentUtcOffset, sensorStartTimestamp = longSensorStartTimestamp, sensorScanTimestamp = longSensorScanTimestamp, newState = null //gets updated by the algo }; //return this.Error("synthax ok"); try{ await MongoConnection.AsyncInsertReading(reading); } catch (System.TimeoutException) { return(Error("Timeout, database down?")); } return(Success <LibreReadingModel>(reading, "CreateRequestAsync")); //var content = $"accesstoken: {accesstoken}, b64contents: {b64contents}, guid: {g}"; //return Content("CreateRequestAsync IS NOT IMPLEMENTED YET:" + content); }
public async static Task AsyncInsertReading(LibreReadingModel reading) { await GetReadingsCollection().InsertOneAsync(reading); }