public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function [GetTempHumidity] processed a request."); using (var analytic = new AnalyticService(new RequestTelemetry { Name = nameof(GetTempHumidity) })) { try { var kvps = req.GetQueryNameValuePairs(); var tempHumidity = CosmosDataService.Instance("TempHumidityCollection").GetTempHumidityModel(); if (tempHumidity.Count == 0) { return(req.CreateErrorResponse(HttpStatusCode.NoContent, "No results found.")); } return(req.CreateResponse(HttpStatusCode.OK, tempHumidity)); } catch (Exception e) { // track exceptions that occur analytic.TrackException(e); return(req.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message, e)); } } }
public static void Run([EventHubTrigger("razzpi", Connection = "EventHub")] string myEventHubMessage, TraceWriter log) { log.Info($"C# Hub trigger function [TempHumidityEventTrigger] processed a message: {myEventHubMessage}"); TempHumidityModel data = JsonConvert.DeserializeObject <TempHumidityModel>(myEventHubMessage); // JSON looks like: {"deviceId": "Raspberry Pi - Python","externalTemp": 66.058200,"humidity": 77.534756,"internalTemp": 64.736600, "timeOfReading": "2018-08-27 08:21:13.733881"} try { var uploadData = CosmosDataService.Instance("TempHumidityCollection").InsertItemAsync(data); } catch (Exception e) { //TODO: Implement analytics service Console.WriteLine(e); } }
public static async Task InsertBags(Flight f) { // create bags for (int i = 0; i < 10; i++) { var bag = new BaggageItem() { //Set properties on bags at checkin FlightNumber = f.FlightNumber, BaggageId = i.ToString(), Weight = BagWeight + Rand.NextDouble() * 15, Status = "Checked In", LastScanned = DateTime.Now, LastKnownLocation = "SFO", Destination = "SEA", Departure = "SFO" }; await CosmosDataService.Instance("BagCollection").InsertItemAsync(bag); } }
public static async Task InsertFlights() { var dummyFlights = new DummyData.DummyData().CreateFlights(); var existingFlights = CosmosDataService.Instance("FlightCollection").GetFlights(); // Get current list of flights in DB. // If they match the dummy data, do nothing. If they don't create the dummy data. // This was done in case we want to let people create their own flights later. foreach (var f in dummyFlights) { // Check if dummy flight is already in DB var matches = existingFlights.Where(b => String.Equals(b.FlightNumber, f.FlightNumber)).ToList(); // If not in DB, create it. if ((matches.Count == 0) || (matches == null)) { await CosmosDataService.Instance("FlightCollection").InsertItemAsync(f); } else { return; } } }