public StatusCodeResult PostClimateReading(HttpRequestMessage request) { try { // Parse data into valid XML var xdoc = XDocument.Load(request.Content.ReadAsStreamAsync().Result); // Retrieve the information from the XML using a LoRaReader var reader = new LoRaReader(xdoc); var time = reader.GetTime(); var data = reader.GetPayload(); // Send the data to the event hub var client = EventHubClient.CreateFromConnectionString(ConnectionInfo); client.Send(new EventData(Encoding.UTF8.GetBytes(data))); client.Close(); } catch (Exception ex) { // TODO : Logging Console.WriteLine(ex.InnerException); return new StatusCodeResult(HttpStatusCode.InternalServerError, this); } return new StatusCodeResult(HttpStatusCode.OK, this); }
/// <summary> /// Initializes a new instance of the <see cref="LoRaReaderTest"/> class. /// </summary> public LoRaReaderTest() { // Create a XDocument structure from the sample XML var xdoc = XDocument.Load(@"TestSample.xml"); // Initiate a new reader with the sample XML loraReader = new LoRaReader(xdoc); }