Exemplo n.º 1
0
 public static IActionResult GetTemperature(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "temperature/{devicename}")] HttpRequest req,
     [CosmosDB(
          databaseName: "Devices",
          collectionName: "Temperatures",
          ConnectionStringSetting = "CosmosDBConnection",
          PartitionKey = "temperature",
          Id = "{devicename}")] TemperatureItem temperatureItem,
     ILogger log)
 {
     return(new OkObjectResult(temperatureItem));
 }
Exemplo n.º 2
0
        public static void EventHubTrigger([EventHubTrigger("samples-workitems", Connection = "ecs")] EventData message,
                                           [CosmosDB(
                                                databaseName: "Devices",
                                                collectionName: "Temperatures",
                                                ConnectionStringSetting = "CosmosDBConnection")] out TemperatureItem temperatureItem,
                                           ILogger log)
        {
            var jsonBody = Encoding.UTF8.GetString(message.Body);

            log.LogInformation($"V2 C# IoT Hub trigger function processed a message: {jsonBody}");

            dynamic data        = JsonConvert.DeserializeObject(jsonBody);
            double  temperature = data.temperature;

            log.LogInformation($"Temp: {temperature}");

            temperatureItem = new TemperatureItem
            {
                PartitionKey = "temperature",
                Id           = message.SystemProperties["iothub-connection-device-id"].ToString(),
                Temperature  = temperature
            };
        }