Created
May 26, 2018 15:21
-
-
Save mabbotts9797/b01910a441f2d920045c733c16a7d072 to your computer and use it in GitHub Desktop.
Retrieves sensor readings from CosmosDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, IEnumerable<AirData> documents) | |
{ | |
List<AirData> docsToReturn = new List<AirData>(); | |
string numberOfDocs = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "fetchno", true) == 0) | |
.Value; | |
int docsAsInt; | |
if(Int32.TryParse(numberOfDocs, out docsAsInt)){ | |
docsToReturn = new List<AirData>(documents.OrderByDescending(x => x.RequestDateTime).Take(docsAsInt)); | |
return await Task.Run(() => req.CreateResponse(HttpStatusCode.OK, docsToReturn)); | |
} | |
docsToReturn = new List<AirData>(documents.OrderByDescending(x => x.RequestDateTime)); | |
return await Task.Run(() => req.CreateResponse(HttpStatusCode.OK, docsToReturn)); | |
} | |
public class AirData { | |
public string Longitude { get; set; } | |
public string Latitude { get; set; } | |
public string Ppm { get; set; } | |
public DateTime RequestDateTime { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment