/// <summary>
        /// Publishes a new time-bound observation value of type 'Double' to the server.
        /// </summary>
        /// <param name="observationId">Observation identifier.</param>
        /// <param name="timestamp">Date and time in UTC.</param>
        /// <param name="value">Observation value.</param>
        /// <returns>True if successful, False otherwise.</returns>
        public bool PublishObservation(int observationId, DateTime timestamp, double value)
        {
            DoubleObservation o = new DoubleObservation()
            {
                Timestamp = timestamp,
                Value     = value
            };
            string json = JsonConvert.SerializeObject(o);

            return(PublishObservationMessage(observationId, Encoding.UTF8.GetBytes(json)));
        }
Exemplo n.º 2
0
        private ObservationPackage GetBufferedObservations(out int maxId)
        {
            maxId = -1;
            ObservationPackageBuilder builder = new ObservationPackageBuilder();

            using (LiteDatabase db = new LiteDatabase(_liteDBPathName))
            {
                var col = db.GetCollection <BufferedObservation>(_OBSBUF_NAME);

                var records = col.Find(c => c.Uploaded == false).OrderBy(c => c.Id);

                IEnumerable <BufferedObservation> observations = null;
                if (UploadRowLimit > 0)
                {
                    observations = records.Take(UploadRowLimit);
                }
                else
                {
                    observations = records;
                }

                foreach (BufferedObservation bo in observations)
                {
                    maxId = bo.Id;
                    if (bo.Value != null)
                    {
                        Observation observation = null;
                        switch ((DataType)(bo.DataType))
                        {
                        case DataType.Boolean: observation = new BooleanObservation()
                        {
                                Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseBooleanValue(bo.Value)
                        }; break;

                        case DataType.Double: observation = new DoubleObservation()
                        {
                                Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseDoubleValue(bo.Value)
                        }; break;

                        case DataType.Integer: observation = new IntegerObservation()
                        {
                                Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseIntegerValue(bo.Value)
                        }; break;

                        case DataType.Position: observation = new PositionObservation()
                        {
                                Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParsePositionValue(bo.Value)
                        }; break;

                        case DataType.String: observation = new StringObservation()
                        {
                                Timestamp = bo.Timestamp, Value = bo.Value
                        }; break;

                        case DataType.Statistics: observation = new StatisticsObservation()
                        {
                                Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseStatisticsValue(bo.Value)
                        }; break;

                        default: throw new NotSupportedException("Unknown data type: " + bo.DataType.ToString());
                        }
                        IdentifiedObservation io = new IdentifiedObservation()
                        {
                            ObservationId = bo.ObservationId,
                            Observation   = observation
                        };
                        builder.Append(io);
                    }
                }
            }
            return(builder.GetAsObservationPackage());
        }