コード例 #1
0
        public object AddSensor(HttpRequestParams request)
        {
            var displayName = request.GetRequiredString("displayName");
            var channel = request.GetRequiredInt32("channel");
            var showHumidity = request.GetRequiredBool("showHumidity");

            Logger.Debug("add sensor: channel={0}; displayName={1}; showHumidity={2}", channel, displayName, showHumidity);

            using (var session = Context.OpenSession())
            {
                var sensor = new TemperatureSensor
                {
                    Id = Guid.NewGuid(),
                    Channel = channel,
                    DisplayName = displayName,
                    ShowHumidity = showHumidity,
                    Timestamp = DateTime.Now
                };

                session.Save(sensor);
                session.Flush();

                return sensor.Id;
            }
        }
コード例 #2
0
 private object CreateSensorDetailsItemModel(TemperatureSensor sensor, IEnumerable<TemperatureData> gr, DateTime now)
 {
     return new
     {
         id = sensor.Id,
         displayName = sensor.DisplayName,
         showHumidity = sensor.ShowHumidity,
         data = gr.Select(d => CreateDataModel(d, now)).ToArray()
     };
 }
コード例 #3
0
 private MicroclimateData CreateMicroclimateData(TemperatureSensor sensor)
 {
     return new MicroclimateData
     {
         channel = sensor.Channel,
         temperature = sensor.CurrentTemperature,
         humidity = sensor.ShowHumidity ? sensor.CurrentHumidity : (int?)null,
         timestamp = sensor.Timestamp
     };
 }