Exemplo n.º 1
0
 protected Task SetRealtimeListAsync(List <VmRealtime> realtimeList, VmRealtime DetectedData)
 {
     return(Task.Run(async() =>
     {
         var realtimeData = await IsRealtimeStationExistsAsync(DetectedData.StationId);
         if (realtimeData == null)
         {
             realtimeData = DetectedData;
             realtimeList.Add(DetectedData);
         }
         else
         {
             realtimeData = DetectedData;
         }
     }));
 }
Exemplo n.º 2
0
        public async Task <ActionResult> PostClimate([FromRoute] int StationId, [FromBody] Climate SensorData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using var transection = _context.Database.BeginTransaction();
            try
            {
                var realtimeData = new VmRealtime
                {
                    StationId     = StationId,
                    DateFormatted = SensorData.ObsTime,
                    Temperature   = SensorData.Temperature,
                    RH            = SensorData.Rh >= 0 && SensorData.Rh <= 100 ? SensorData.Rh : null,
                    Lux           = SensorData.Lux
                };

                await _sensorHub.Clients.All.SendAsync("SensorDetected", realtimeData);

                // 小溫室本身資料要存檔
                if (StationId == 0)
                {
                    _context.Climate.Add(SensorData);
                    await _context.SaveChangesAsync();

                    transection.Commit();
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
Exemplo n.º 3
0
 public async Task SensorDetected(VmRealtime DetectedData)
 {
     await Clients.All.SendAsync("SensorDetected", DetectedData);
 }