コード例 #1
0
        public async Task <SensorListingResponse> GetAllSensors()
        {
            SensorListingResponse allSensorResponse =
                await PostAsync <SensorListingResponse>("/macros/all_sensors", null);

            return(allSensorResponse);
        }
コード例 #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);
            }
        }
コード例 #3
0
        public SensorListingResponse GetAllSensors()
        {
            //http://93.84.120.9:8888/macros/all_sensors
            //            SensorMonitor sensorMonitor = new SensorMonitor();
            //            sensorMonitor.Time = TimeSpan.FromMilliseconds(321);
            //            sensorMonitor.Sensors.Add(new Sensor() { Type = SensorType.WasteAbsorbanceDetector1, State = SensorState.Active, Value = 0.37f });
            //            sensorMonitor.Sensors.Add(new Sensor() { Type = SensorType.TargetAnsorbanceDetector1, State = SensorState.Active, Value = 0.37f });
            //            string json = JsonConvert.SerializeObject(sensorMonitor);

            //            [21:15:21]
            //        Aleksei Yantsevich: для первых двух 0-2.56
            //[21:15:29]
            //        Aleksei Yantsevich: для вторых двух 0-5
            //[21:15:34]
            //        Aleksei Yantsevich: для пятого 0-1

            SensorListingResponse allSensorResponse = new SensorListingResponse();
            TimeSpan time = DateTime.Now - new DateTime(2017, 4, 26);

            //allSensorResponse.Time = DateTimeOffset.UtcNow.TimeOfDay.ToString();
            allSensorResponse.Time    = time;
            allSensorResponse.Sensors = new List <SensorResponse>()
            {
                new SensorResponse()
                {
                    Value = (float)GetRandomValue(0, 5),
                    Type  = SensorType.WasteAbsorbanceDetector1,
                },
                new SensorResponse()
                {
                    Value = (float)GetRandomValue(0, 5),
                    Type  = SensorType.TargetAbsorbanceDetector1,
                },
                new SensorResponse()
                {
                    Value = (float)GetRandomValue(21, 21.3),
                    Type  = SensorType.Sensor3,
                },
            };

            return(allSensorResponse);
        }