Пример #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                JobDataMap dataMap = context.JobDetail.JobDataMap;
                string     conn    = dataMap.GetString("connectionString");
                sensorDataService = new SensorDataService(new JazzDbContext(conn));
                sensorDataService.UpdateSensorList(sensors);          //sprawdź czy sensor jest w bazie, jeśli nie to dodaj
                sensorsData = new List <Measurements>();
                sensors     = sensorDataService.GetSensorId(sensors); //zaktualizuj Id sensora
                counter++;

                sb.Append($"Przebieg: {counter.ToString()} \r\n");
                foreach (var s in sensors)
                {
                    var last = sensorDataService.GetLast(s) ?? new Measurements()
                    {
                        Station = new Station()
                        {
                            iotNet = new IotNet()
                        }
                    };
                    var measurements = (s as SensorModel).MakeMeasure() ? s.GetData() : Enumerable.Empty <Measurements>();
                    foreach (var item in measurements)
                    {
                        item.Station.Id = s.Measurements.Station.Id;
                        if (last.Station.Id == 0 || (item.MeasurementDate > last.MeasurementDate && s.Measurements.Station.Id == last.Station.Id))
                        {
                            sensorsData.Add(item);
                            sb.Append($"    Dodaję odczyt {s.GetType().Name} - {s.Measurements.Station.StationId} \r\n");
                        }
                    }
                }

                sb.Append($"Dodano odczytów: {sensorsData.Count} \r\n");
                sb.Append($"Koniec przebiegu: {counter.ToString()} \r\n\n\n");
                sensorDataService.AddSensorData(sensorsData);
            }
            catch (Exception e)
            {
                sb.Append(e.InnerException.Message);
                sb.Append("\r\n");
                sb.Append($"{e.Message} \r\n");
            }

            foreach (var item in loggerService)
            {
                item.AddLogItem(sb.ToString());
            }
        }