public IActionResult PostTelemetry([FromBody, BindRequired] BoschIoTSuiteTelmetry body, [FromRoute, BindRequired] string gatewayId = null) { var measure = _measures.PostMeasure(body.Value.Status).Result; return(new ObjectResult(measure.Value) { StatusCode = StatusCodes.Status201Created }); }
private async static Task <bool> ProcessEnergyMonitor(Guid thingId, byte[] message) { var _context = _serviceScopeFactory.CreateScope().ServiceProvider.GetRequiredService <ApplicationDbContext>(); var _measures = new MeasuresController(_context, _hubContext); var thing = _context.Thing.AsNoTracking().Where(thing => thing.ThingId.Equals(thingId)).FirstOrDefault(); MeasureDTO measure; try { Stream measureStream = new MemoryStream(message); var options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; options.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); measure = await JsonSerializer.DeserializeAsync <MeasureDTO>(measureStream, options); measure.ThingId = thingId; } catch (JsonException ex) { _logger.LogError(ex.Message); return(false); } if (thing == null) { _logger.LogWarning($"Thing with Id {thingId} not found"); return(false); } else if (!thing.Features.ToString().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList().Contains(measure.Type.ToString().Trim())) { _logger.LogWarning($"Thing with Id {thingId} does not have the specified feature {measure.Type}"); return(false); } try { await _measures.PostMeasure(measure); } catch (DbUpdateException ex) { _logger.LogError(ex.Message); return(false); } return(true); }