Example #1
0
        public SensorListing CreateSensorListing()
        {
            var sensorListing = new SensorListing()
            {
                Time = DateTimeOffset.UtcNow.TimeOfDay
            };

            sensorListing.Sensors.Add(CreateSensor());

            return(GetOrCreate(() => sensorListing));
        }
Example #2
0
        public static void UpdateSensorListings([TimerTrigger("00:00:02", RunOnStartup = true)] TimerInfo info, TextWriter log)
        {
            log.WriteLine("--- Updating sensor listings");

            try
            {
                using (var commonDbContext = new CommonDbContext())
                {
                    var sw = Stopwatch.StartNew();

                    //SensorRestService sensorRestService = new SensorRestService();
                    SensorStubRestService sensorRestService     = new SensorStubRestService();
                    SensorListingResponse sensorListingResponse = sensorRestService.GetAllSensors();

                    SensorListing sensorListing = new SensorListing();

                    sensorListing.Time = sensorListingResponse.Time;

                    foreach (SensorResponse sensorResponse in sensorListingResponse.Sensors)
                    {
                        sensorListing.Sensors.Add(new Sensor()
                        {
                            Type  = (SensorType)sensorResponse.Type,
                            State = (SensorState)sensorResponse.State,
                            Value = sensorResponse.Value,
                        });
                    }

                    commonDbContext.SensorListings.Add(sensorListing);

                    commonDbContext.SaveChanges();

                    sw.Stop();

                    log.WriteLine($"--- Sensor listings were updated successfully. ElapsedMilliseconds: {sw.ElapsedMilliseconds}.");
                }
            }
            catch (Exception ex)
            {
                log.WriteLine(ex.Message);
            }
        }
        private void SetLastCreatedAt(SystemMonitorViewModel systemMonitorViewModel, IEnumerable <SensorListing> sensorListings)
        {
            SensorListing lastSensorListing = sensorListings.LastOrDefault();

            systemMonitorViewModel.LastCreatedAt = lastSensorListing?.CreatedAt ?? DateTimeOffset.MinValue;
        }