Exemple #1
0
        public async Task <ActionResult <ChillerMessage> > Get(string id)
        {
            ChillerMessage item = await _chillerDbService.GetMessageAsync(id);

            if (item == null)
            {
                return(NotFound());
            }
            return(item);
        }
        private async Task ProcessEventHandler(ProcessEventArgs eventArgs)
        {
            //Activity.Current.SetIdFormat(ActivityIdFormat.W3C);
            if (eventArgs.Data.SystemProperties.ContainsKey("traceparent"))
            {
                Activity.Current.SetParentId(eventArgs.Data.SystemProperties["traceparent"].ToString());
            }

            var data = Encoding.UTF8.GetString(eventArgs.Data.Body.ToArray());

            _logger.LogInformation($"Message received. Partition: '{eventArgs.Partition.PartitionId}', Data: '{data}'");

            var devid = eventArgs.Data.SystemProperties["iothub-connection-device-id"].ToString();
            // Date and time the Device-to-Cloud message was received by IoT Hub.
            var iothubTimestamp = DateTimeOffset.Parse(eventArgs.Data.SystemProperties["iothub-enqueuedtime"].ToString());
            var telemetry       = JsonConvert.DeserializeObject <ChillerTelemetry>(data);

            // Invoke API Service.
            var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
            var newmsg  = new ChillerMessage()
            {
                DeviceId    = devid,
                Id          = Guid.NewGuid().ToString(),
                Humidity    = telemetry.humidity,
                Pressure    = telemetry.pressure,
                Temperature = telemetry.temperature,
                TimeStamp   = iothubTimestamp
            };

            request.Content = new StringContent(JsonConvert.SerializeObject(newmsg), Encoding.UTF8, "application/json");

            var response = await _clientFactory.CreateClient().SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                await eventArgs.UpdateCheckpointAsync();
            }
        }
Exemple #3
0
 public async Task UpdateMessageAsync(string id, ChillerMessage msg)
 {
     await this._container.UpsertItemAsync <ChillerMessage>(msg, new PartitionKey(id));
 }
Exemple #4
0
 public async Task AddMessageAsync(ChillerMessage msg)
 {
     await this._container.CreateItemAsync <ChillerMessage>(msg, new PartitionKey(msg.DeviceId));
 }
Exemple #5
0
 public async Task Put(string id, [FromBody] ChillerMessage msg)
 {
     await _chillerDbService.UpdateMessageAsync(id, msg);
 }
Exemple #6
0
 public async Task Post([FromBody] ChillerMessage msg)
 {
     await _chillerDbService.AddMessageAsync(msg);
 }