private PSObject CreateObject(SensorHistoryData date)
        {
            var obj = new PSObject();

            obj.Properties.Add(new PSNoteProperty("DateTime", date.DateTime));
            obj.Properties.Add(new PSNoteProperty("SensorId", date.SensorId));

            foreach (var channel in date.ChannelRecords)
            {
                if (channelUnitMap[channel.Name] != null)
                {
                    var value = GetChannelValue(channel);

                    obj.Properties.Add(new PSNoteProperty(channel.Name, value));
                }
                else
                {
                    obj.Properties.Add(new PSNoteProperty(channel.Name, channel.Value));
                }
            }

            obj.Properties.Add(new PSNoteProperty("Coverage", date.Coverage));

            obj.TypeNames.Insert(0, typeNameRecord.TypeName);

            return(obj);
        }
Exemple #2
0
        public void Save(string sensorCode, string dataText, decimal?dataNumeric, DateTime sampleDt)
        {
            //Spremi podatke u bazu prema senzoru, prikupljenoj vrijednosti i vremenu prikupljanja
            try
            {
                var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);

                var firstSensor = dc.Sensors.Single(s => s.Code == sensorCode);
                //Console.WriteLine("Save weather - Sensor name: " + firstSensor.Name);

                if (firstSensor != null)
                {
                    var sensorId          = firstSensor.SensorId;
                    var sensorHistoryData = new SensorHistoryData()
                    {
                        SensorId    = sensorId,
                        DataNumeric = dataNumeric,
                        DataText    = dataText,
                        SampledDT   = sampleDt,
                        InsertedDT  = DateTime.Now
                    };
                    dc.Add(sensorHistoryData);
                    dc.SaveChanges();
                }
                else
                {
                    Console.WriteLine(String.Format("You are trying to insert data for unregistered sensor ({0})", sensorCode));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        private SensorHistoryData Convert(SensorDataEntity entity)
        {
            SensorHistoryData result = new SensorHistoryData();

            result.SensorType = (SensorType)entity.DataType;
            result.TypedData  = entity.TypedData;
            result.Time       = entity.Time;
            return(result);
        }
        private SensorHistoryData Convert(IntBarSensorData typedData)
        {
            SensorHistoryData result = new SensorHistoryData();

            result.TypedData  = JsonSerializer.Serialize(typedData);
            result.Time       = typedData.EndTime;
            result.SensorType = SensorType.IntegerBarSensor;
            return(result);
        }
        private PSObject PrepareObject(SensorHistoryData data, bool isNew = false)
        {
            var ps = CreateObject(data);

            if (!xmlLoaded)
            {
                LoadFormat(ps, isNew);
                xmlLoaded = true;
            }

            return(ps);
        }
        public static SensorHistoryData ConvertToFileSensorBytes(this SensorHistoryData sensorData)
        {
            if (sensorData.SensorType != SensorType.FileSensor)
            {
                return(sensorData);
            }

            return(new()
            {
                Time = sensorData.Time,
                SensorType = SensorType.FileSensorBytes,
                TypedData = GetTypedDataForFileSensorBytes(sensorData.TypedData),
            });
        }
Exemple #7
0
        public void SaveCurrentWeather(string sensorCode, string dataText, decimal?dataNumeric, DateTime sampleDt)
        {
            //Spremi podatke u bazu prema senzoru, prikupljenoj vrijednosti i vremenu prikupljanja
            try
            {
                #region Deprecated: Snimanje podataka kroz Disposable klasu
                //Console.WriteLine(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);
                //using (var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection))
                //{
                //    var first = dc.Sensors.First(s => s.Code == sensorCode);
                //    Console.WriteLine("Save weather - Sensor name: " + first.Name);
                //    if (first != null)
                //    {
                //        var sensorId = first.SensorId;
                //        Console.WriteLine("Save weather - Sensor Id:" + Convert.ToString(sensorId));
                //        var sensorHistoryData = new SensorHistoryData()
                //        {
                //            SensorId = sensorId,
                //            DataNumeric = dataNumeric,
                //            DataText = dataText,
                //            SampledDT = sampleDt,
                //            InsertedDT = DateTime.Now
                //        };
                //        dc.Add(sensorHistoryData);
                //        dc.SaveChanges();
                //    }
                //    else
                //    {
                //        //TODO: Obavijestiti da ne postoji sensorCode
                //    }
                //}
                #endregion

                var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);

                var firstSensor = dc.Sensors.Single(s => s.Code == sensorCode);
                //Console.WriteLine("Save weather - Sensor name: " + firstSensor.Name);

                if (firstSensor != null)
                {
                    var sensorId          = firstSensor.SensorId;
                    var sensorHistoryData = new SensorHistoryData()
                    {
                        SensorId    = sensorId,
                        DataNumeric = dataNumeric,
                        DataText    = dataText,
                        SampledDT   = sampleDt,
                        InsertedDT  = DateTime.Now
                    };
                    dc.Add(sensorHistoryData);
                    dc.SaveChanges();
                }
                else
                {
                    Console.WriteLine(String.Format("You are trying to insert data for unregistered sensor ({0})", sensorCode));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }